Skip to content

Commit

Permalink
Add Space Accessibility check for Mappings
Browse files Browse the repository at this point in the history
Closes #388

See merge request gysela-developpers/gyselalibxx!748

--------------------------------------------
  • Loading branch information
EmilyBourne committed Oct 31, 2024
1 parent 9615115 commit 0ab238e
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ documentation:
script: |
rm -rf build || true
# Make docs
cmake -DGYSELALIBXX_COMPILE_SOURCE=OFF -DBUILD_DOCUMENTATION=1 -B build-docs .
cmake -DGYSELALIBXX_COMPILE_SOURCE=OFF -DGYSELALIBXX_BUILD_DOCUMENTATION=1 -B build-docs .
cmake --build build-docs
# Get files which have changed in this merge request
git diff origin/${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}..HEAD --no-indent-heuristic --unified=0 --output=pull_diff.txt --no-color
Expand Down
10 changes: 10 additions & 0 deletions vendor/sll/include/sll/mapping/circular_to_cartesian.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
#pragma once

#include <cassert>
Expand All @@ -8,6 +9,7 @@
#include "coordinate_converter.hpp"
#include "curvilinear2d_to_cartesian.hpp"
#include "jacobian.hpp"
#include "mapping_tools.hpp"
#include "pseudo_cartesian_compatible_mapping.hpp"

/**
Expand Down Expand Up @@ -321,3 +323,11 @@ class CircularToCartesian
return 1.;
}
};


namespace detail {
template <class X, class Y, class R, class Theta, class ExecSpace>
struct MappingAccessibility<ExecSpace, CircularToCartesian<X, Y, R, Theta>> : std::true_type
{
};
} // namespace detail
9 changes: 9 additions & 0 deletions vendor/sll/include/sll/mapping/czarny_to_cartesian.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// SPDX-License-Identifier: MIT
#pragma once

#include <cmath>
Expand All @@ -9,6 +10,7 @@
#include "coordinate_converter.hpp"
#include "curvilinear2d_to_cartesian.hpp"
#include "jacobian.hpp"
#include "mapping_tools.hpp"
#include "pseudo_cartesian_compatible_mapping.hpp"


Expand Down Expand Up @@ -480,3 +482,10 @@ class CzarnyToCartesian
return (2 - Kokkos::sqrt(1 + m_epsilon * m_epsilon)) / m_e / xi;
}
};

namespace detail {
template <class X, class Y, class R, class Theta, class ExecSpace>
struct MappingAccessibility<ExecSpace, CzarnyToCartesian<X, Y, R, Theta>> : std::true_type
{
};
} // namespace detail
19 changes: 19 additions & 0 deletions vendor/sll/include/sll/mapping/discrete_to_cartesian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "coordinate_converter.hpp"
#include "curvilinear2d_to_cartesian.hpp"
#include "jacobian.hpp"
#include "mapping_tools.hpp"
#include "pseudo_cartesian_compatible_mapping.hpp"

/**
Expand Down Expand Up @@ -446,3 +447,21 @@ class DiscreteToCartesian
return ddc::Coordinate<X, Y>(m_x_spline_representation(el), m_y_spline_representation(el));
}
};


namespace detail {
template <
class X,
class Y,
class SplineEvaluator,
class R,
class Theta,
class MemorySpace,
class ExecSpace>
struct MappingAccessibility<
ExecSpace,
DiscreteToCartesian<X, Y, SplineEvaluator, R, Theta, MemorySpace>>
{
static constexpr bool value = Kokkos::SpaceAccessibility<ExecSpace, MemorySpace>::accessible;
};
} // namespace detail
14 changes: 14 additions & 0 deletions vendor/sll/include/sll/mapping/mapping_tools.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
#pragma once

#include <type_traits>

namespace detail {
template <class ExecSpace, class Type>
struct MappingAccessibility : std::false_type
{
};
} // namespace detail

template <class ExecSpace, class Type>
static constexpr bool is_accessible_v = detail::MappingAccessibility<ExecSpace, Type>::value;
49 changes: 33 additions & 16 deletions vendor/sll/tests/mapping_execution_space_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ double check_logical_to_physical_coord_converter(
CoordXY const& coord_xy)
{
DeviceExecSpace exec;
static_assert(is_accessible_v<DeviceExecSpace, Mapping>);

double max_error = 0;
Kokkos::parallel_reduce(
Expand All @@ -188,6 +189,7 @@ double check_physical_to_logical_coord_converter(
CoordXY const& coord_xy)
{
DeviceExecSpace exec;
static_assert(is_accessible_v<DeviceExecSpace, Mapping>);

double max_error = 0;
Kokkos::parallel_reduce(
Expand All @@ -210,14 +212,17 @@ TEST_F(MappingMemoryAccess, HostCircularCoordConverter)
{
// Mapping
CircularToCartesian<X, Y, R, Theta> const mapping;
static_assert(is_accessible_v<
Kokkos::DefaultHostExecutionSpace,
CircularToCartesian<X, Y, R, Theta>>);

// Test coordinates
double const r = .75;
double const theta = 1 / 3. * M_PI;
CoordRTheta const coord_rtheta(r, theta);

double const x = r * Kokkos::cos(theta);
double const y = r * Kokkos::sin(theta);
double const x = r * std::cos(theta);
double const y = r * std::sin(theta);
CoordXY const coord_xy(x, y);

// Coord converter: logical -> physical.
Expand All @@ -238,16 +243,18 @@ TEST_F(MappingMemoryAccess, HostCzarnyCoordConverter)
double const epsilon = 0.3;
double const e = 1.4;
CzarnyToCartesian<X, Y, R, Theta> const mapping(epsilon, e);
static_assert(
is_accessible_v<Kokkos::DefaultHostExecutionSpace, CzarnyToCartesian<X, Y, R, Theta>>);

// Test coordinates
double const r = .75;
double const theta = 1 / 3. * M_PI;
CoordRTheta const coord_rtheta(r, theta);

const double tmp1 = Kokkos::sqrt(epsilon * (epsilon + 2.0 * r * Kokkos::cos(theta)) + 1.0);
const double tmp1 = std::sqrt(epsilon * (epsilon + 2.0 * r * std::cos(theta)) + 1.0);
const double x = (1.0 - tmp1) / epsilon;
const double y = e * r * Kokkos::sin(theta)
/ (Kokkos::sqrt(1.0 - 0.25 * epsilon * epsilon) * (2.0 - tmp1));
const double y
= e * r * std::sin(theta) / (std::sqrt(1.0 - 0.25 * epsilon * epsilon) * (2.0 - tmp1));
CoordXY const coord_xy(x, y);

// Coord converter: logical -> physical.
Expand All @@ -268,6 +275,8 @@ TEST_F(MappingMemoryAccess, HostDiscreteCoordConverter)
double const epsilon = 0.3;
double const e = 1.4;
CzarnyToCartesian<X, Y, R, Theta> const analytical_mapping(epsilon, e);
static_assert(
is_accessible_v<Kokkos::DefaultHostExecutionSpace, CzarnyToCartesian<X, Y, R, Theta>>);

SplineRThetaBuilder<HostExecSpace> builder(interpolation_idx_range_rtheta);

Expand All @@ -286,16 +295,17 @@ TEST_F(MappingMemoryAccess, HostDiscreteCoordConverter)
SplineRThetaEvaluator<HostExecSpace>>
mapping_builder(HostExecSpace(), analytical_mapping, builder, evaluator);
DiscreteToCartesian mapping = mapping_builder();
static_assert(is_accessible_v<Kokkos::DefaultHostExecutionSpace, decltype(mapping)>);

// Test coordinates
double const r = .75;
double const theta = 1 / 3. * M_PI;
CoordRTheta const coord_rtheta(r, theta);

const double tmp1 = Kokkos::sqrt(epsilon * (epsilon + 2.0 * r * Kokkos::cos(theta)) + 1.0);
const double tmp1 = std::sqrt(epsilon * (epsilon + 2.0 * r * std::cos(theta)) + 1.0);
const double x = (1.0 - tmp1) / epsilon;
const double y = e * r * Kokkos::sin(theta)
/ (Kokkos::sqrt(1.0 - 0.25 * epsilon * epsilon) * (2.0 - tmp1));
const double y
= e * r * std::sin(theta) / (std::sqrt(1.0 - 0.25 * epsilon * epsilon) * (2.0 - tmp1));
CoordXY const coord_xy(x, y);

// Coord converter: logical -> physical.
Expand All @@ -310,14 +320,16 @@ TEST_F(MappingMemoryAccess, DeviceCircularCoordConverter)
{
// Mapping
CircularToCartesian<X, Y, R, Theta> const mapping;
static_assert(
is_accessible_v<Kokkos::DefaultExecutionSpace, CircularToCartesian<X, Y, R, Theta>>);

// Test coordinates
double const r = .75;
double const theta = 1 / 3. * M_PI;
CoordRTheta const coord_rtheta(r, theta);

double const x = r * Kokkos::cos(theta);
double const y = r * Kokkos::sin(theta);
double const x = r * std::cos(theta);
double const y = r * std::sin(theta);
CoordXY const coord_xy(x, y);

// Coord converter: logical -> physical.
Expand All @@ -336,16 +348,18 @@ TEST_F(MappingMemoryAccess, DeviceCzarnyCoordConverter)
double const epsilon = 0.3;
double const e = 1.4;
CzarnyToCartesian<X, Y, R, Theta> const mapping(epsilon, e);
static_assert(
is_accessible_v<Kokkos::DefaultExecutionSpace, CzarnyToCartesian<X, Y, R, Theta>>);

// Test coordinates
double const r = .75;
double const theta = 1 / 3. * M_PI;
CoordRTheta const coord_rtheta(r, theta);

const double tmp1 = Kokkos::sqrt(epsilon * (epsilon + 2.0 * r * Kokkos::cos(theta)) + 1.0);
const double tmp1 = std::sqrt(epsilon * (epsilon + 2.0 * r * std::cos(theta)) + 1.0);
const double x = (1.0 - tmp1) / epsilon;
const double y = e * r * Kokkos::sin(theta)
/ (Kokkos::sqrt(1.0 - 0.25 * epsilon * epsilon) * (2.0 - tmp1));
const double y
= e * r * std::sin(theta) / (std::sqrt(1.0 - 0.25 * epsilon * epsilon) * (2.0 - tmp1));
CoordXY const coord_xy(x, y);

// Coord converter: logical -> physical.
Expand All @@ -364,6 +378,8 @@ TEST_F(MappingMemoryAccess, DeviceDiscreteCoordConverter)
double const epsilon = 0.3;
double const e = 1.4;
CzarnyToCartesian<X, Y, R, Theta> const analytical_mapping(epsilon, e);
static_assert(
is_accessible_v<Kokkos::DefaultExecutionSpace, CzarnyToCartesian<X, Y, R, Theta>>);

SplineRThetaBuilder<DeviceExecSpace> builder(interpolation_idx_range_rtheta);

Expand All @@ -382,16 +398,17 @@ TEST_F(MappingMemoryAccess, DeviceDiscreteCoordConverter)
SplineRThetaEvaluator<DeviceExecSpace>>
mapping_builder(DeviceExecSpace(), analytical_mapping, builder, evaluator);
DiscreteToCartesian mapping = mapping_builder();
static_assert(is_accessible_v<Kokkos::DefaultExecutionSpace, decltype(mapping)>);

// Test coordinates
double const r = .75;
double const theta = 1 / 3. * M_PI;
CoordRTheta const coord_rtheta(r, theta);

const double tmp1 = Kokkos::sqrt(epsilon * (epsilon + 2.0 * r * Kokkos::cos(theta)) + 1.0);
const double tmp1 = std::sqrt(epsilon * (epsilon + 2.0 * r * std::cos(theta)) + 1.0);
const double x = (1.0 - tmp1) / epsilon;
const double y = e * r * Kokkos::sin(theta)
/ (Kokkos::sqrt(1.0 - 0.25 * epsilon * epsilon) * (2.0 - tmp1));
const double y
= e * r * std::sin(theta) / (std::sqrt(1.0 - 0.25 * epsilon * epsilon) * (2.0 - tmp1));
CoordXY const coord_xy(x, y);

// Coord converter: logical -> physical.
Expand Down

0 comments on commit 0ab238e

Please sign in to comment.