Skip to content

Commit

Permalink
TestRKAB: Added host and device annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Sanches committed Oct 24, 2024
1 parent 165c16d commit e05f124
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
17 changes: 12 additions & 5 deletions TestRKAB/src/gaussian.hxx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#ifndef TEST_RKAB_GAUSSIAN_HXX
#define TEST_RKAB_GAUSSIAN_HXX

#include <cctk.h>

#include <cmath>

namespace TestRKAB::gauss {

template <typename T>
static inline auto phi(T W, T A, T t, T x, T y, T z) noexcept -> T {
static inline auto CCTK_HOST CCTK_DEVICE phi(T W, T A, T t, T x, T y,
T z) noexcept -> T {
using std::sqrt, std::cosh, std::sinh;

const auto r{sqrt(x * x + y * y + z * z)};
Expand All @@ -24,7 +27,8 @@ static inline auto phi(T W, T A, T t, T x, T y, T z) noexcept -> T {
}

template <typename T>
static inline auto Pi(T W, T A, T t, T x, T y, T z) noexcept -> T {
static inline auto CCTK_HOST CCTK_DEVICE Pi(T W, T A, T t, T x, T y,
T z) noexcept -> T {
using std::sqrt, std::cosh, std::sinh;

const auto r{sqrt(x * x + y * y + z * z)};
Expand All @@ -46,7 +50,8 @@ static inline auto Pi(T W, T A, T t, T x, T y, T z) noexcept -> T {
}

template <typename T>
static inline auto Dx(T W, T A, T t, T x, T y, T z) noexcept -> T {
static inline auto CCTK_HOST CCTK_DEVICE Dx(T W, T A, T t, T x, T y,
T z) noexcept -> T {
using std::sqrt, std::cosh, std::sinh;

const auto r{sqrt(x * x + y * y + z * z)};
Expand All @@ -71,7 +76,8 @@ static inline auto Dx(T W, T A, T t, T x, T y, T z) noexcept -> T {
}

template <typename T>
static inline auto Dy(T W, T A, T t, T x, T y, T z) noexcept -> T {
static inline auto CCTK_HOST CCTK_DEVICE Dy(T W, T A, T t, T x, T y,
T z) noexcept -> T {
using std::sqrt, std::cosh, std::sinh;

const auto r{sqrt(x * x + y * y + z * z)};
Expand All @@ -96,7 +102,8 @@ static inline auto Dy(T W, T A, T t, T x, T y, T z) noexcept -> T {
}

template <typename T>
static inline auto Dz(T W, T A, T t, T x, T y, T z) noexcept -> T {
static inline auto CCTK_HOST CCTK_DEVICE Dz(T W, T A, T t, T x, T y,
T z) noexcept -> T {
using std::sqrt, std::cosh, std::sinh;

const auto r{sqrt(x * x + y * y + z * z)};
Expand Down
18 changes: 9 additions & 9 deletions TestRKAB/src/initial.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ extern "C" void TestRKAB_Initial(CCTK_ARGUMENTS) {
noise_boundary};
std::mt19937 noise_engine{noise_seed};

grid.loop_int_device<0, 0, 0>(grid.nghostzones,
[&] CCTK_DEVICE(const Loop::PointDesc &p)
CCTK_ATTRIBUTE_ALWAYS_INLINE {
phi(p.I) = noise_distrib(noise_engine);
Pi(p.I) = noise_distrib(noise_engine);
Dx(p.I) = noise_distrib(noise_engine);
Dy(p.I) = noise_distrib(noise_engine);
Dz(p.I) = noise_distrib(noise_engine);
});
grid.loop_int<0, 0, 0>(grid.nghostzones,
[&] CCTK_HOST(const Loop::PointDesc &p)
CCTK_ATTRIBUTE_ALWAYS_INLINE {
phi(p.I) = noise_distrib(noise_engine);
Pi(p.I) = noise_distrib(noise_engine);
Dx(p.I) = noise_distrib(noise_engine);
Dy(p.I) = noise_distrib(noise_engine);
Dz(p.I) = noise_distrib(noise_engine);
});
} else {
CCTK_VERROR("Unknown initial condition \"%s\"", initial_condition);
}
Expand Down
4 changes: 2 additions & 2 deletions TestRKAB/src/rhs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ using namespace Arith;
enum class fd_dir : std::size_t { x = 0, y = 1, z = 2 };

template <fd_dir direction, typename T>
static inline auto fd_c_1_4(const Loop::PointDesc &p,
const Loop::GF3D2<T> &gf) noexcept -> T {
static inline auto CCTK_HOST CCTK_DEVICE
fd_c_1_4(const Loop::PointDesc &p, const Loop::GF3D2<T> &gf) noexcept -> T {
constexpr auto d{static_cast<size_t>(direction)};
const auto num{gf(p.I - 2 * p.DI[d]) - 8.0 * gf(p.I - 1 * p.DI[d]) +
8.0 * gf(p.I + 1 * p.DI[d]) - 1.0 * gf(p.I + 2 * p.DI[d])};
Expand Down
18 changes: 12 additions & 6 deletions TestRKAB/src/standing_wave.hxx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#ifndef TEST_RKAB_STANDING_WAVE_HXX
#define TEST_RKAB_STANDING_WAVE_HXX

#include <cctk.h>

#include <cmath>

namespace TestRKAB::sw {

template <typename T>
static inline auto phi(T A, T kx, T ky, T kz, T t, T x, T y,
T z) noexcept -> T {
static inline auto CCTK_HOST CCTK_DEVICE phi(T A, T kx, T ky, T kz, T t, T x,
T y, T z) noexcept -> T {
using std::sqrt, std::sin, std::cos, std::acos;
const auto pi{acos(T{-1})};
const auto omega{sqrt(kx * kx + ky * ky + kz * kz)};
Expand All @@ -16,7 +18,8 @@ static inline auto phi(T A, T kx, T ky, T kz, T t, T x, T y,
}

template <typename T>
static inline auto Pi(T A, T kx, T ky, T kz, T t, T x, T y, T z) noexcept -> T {
static inline auto CCTK_HOST CCTK_DEVICE Pi(T A, T kx, T ky, T kz, T t, T x,
T y, T z) noexcept -> T {
using std::sqrt, std::sin, std::cos, std::acos;
const auto pi{acos(T{-1})};
const auto omega{sqrt(kx * kx + ky * ky + kz * kz)};
Expand All @@ -25,7 +28,8 @@ static inline auto Pi(T A, T kx, T ky, T kz, T t, T x, T y, T z) noexcept -> T {
}

template <typename T>
static inline auto Dx(T A, T kx, T ky, T kz, T t, T x, T y, T z) noexcept -> T {
static inline auto CCTK_HOST CCTK_DEVICE Dx(T A, T kx, T ky, T kz, T t, T x,
T y, T z) noexcept -> T {
using std::sqrt, std::sin, std::cos, std::acos;
const auto pi{acos(T{-1})};
const auto omega{sqrt(kx * kx + ky * ky + kz * kz)};
Expand All @@ -34,7 +38,8 @@ static inline auto Dx(T A, T kx, T ky, T kz, T t, T x, T y, T z) noexcept -> T {
}

template <typename T>
static inline auto Dy(T A, T kx, T ky, T kz, T t, T x, T y, T z) noexcept -> T {
static inline auto CCTK_HOST CCTK_DEVICE Dy(T A, T kx, T ky, T kz, T t, T x,
T y, T z) noexcept -> T {
using std::sqrt, std::sin, std::cos, std::acos;
const auto pi{acos(T{-1})};
const auto omega{sqrt(kx * kx + ky * ky + kz * kz)};
Expand All @@ -43,7 +48,8 @@ static inline auto Dy(T A, T kx, T ky, T kz, T t, T x, T y, T z) noexcept -> T {
}

template <typename T>
static inline auto Dz(T A, T kx, T ky, T kz, T t, T x, T y, T z) noexcept -> T {
static inline auto CCTK_HOST CCTK_DEVICE Dz(T A, T kx, T ky, T kz, T t, T x,
T y, T z) noexcept -> T {
using std::sqrt, std::sin, std::cos, std::acos;
const auto pi{acos(T{-1})};
const auto omega{sqrt(kx * kx + ky * ky + kz * kz)};
Expand Down

0 comments on commit e05f124

Please sign in to comment.