Skip to content

Commit

Permalink
Fix compiling SIMD unit tests on NVIDIA
Browse files Browse the repository at this point in the history
  • Loading branch information
masterleinad committed Oct 5, 2023
1 parent 4ce289b commit 96edf73
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 39 deletions.
2 changes: 1 addition & 1 deletion simd/src/Kokkos_SIMD_AVX2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ class simd<float, simd_abi::avx2_fixed_size<4>> {
std::is_invocable_r_v<value_type, G,
std::integral_constant<std::size_t, 0>>,
bool> = false>
KOKKOS_FORCEINLINE_FUNCTION simd(G&& gen)
KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION simd(G&& gen)
: m_value(_mm_setr_ps(gen(std::integral_constant<std::size_t, 0>()),
gen(std::integral_constant<std::size_t, 1>()),
gen(std::integral_constant<std::size_t, 2>()),
Expand Down
52 changes: 28 additions & 24 deletions simd/src/Kokkos_SIMD_Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ template <class T, class Abi>
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
namespace Experimental {
template <class T, class Abi>
[[nodiscard]] KOKKOS_DEPRECATED KOKKOS_FORCEINLINE_FUNCTION
[[nodiscard]] KOKKOS_DEPRECATED KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION
Experimental::simd<T, Abi>
min(Experimental::simd<T, Abi> const& a,
Experimental::simd<T, Abi> const& b) {
Expand All @@ -403,7 +403,7 @@ template <class T, class Abi>
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
namespace Experimental {
template <class T, class Abi>
[[nodiscard]] KOKKOS_DEPRECATED KOKKOS_FORCEINLINE_FUNCTION
[[nodiscard]] KOKKOS_DEPRECATED KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION
Experimental::simd<T, Abi>
max(Experimental::simd<T, Abi> const& a,
Experimental::simd<T, Abi> const& b) {
Expand Down Expand Up @@ -431,8 +431,9 @@ template <class T, class Abi>
} \
namespace Experimental { \
template <class T, class Abi> \
[[nodiscard]] KOKKOS_DEPRECATED KOKKOS_FORCEINLINE_FUNCTION simd<T, Abi> \
FUNC(simd<T, Abi> const& a) { \
[[nodiscard]] KOKKOS_DEPRECATED KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION \
simd<T, Abi> \
FUNC(simd<T, Abi> const& a) { \
return Kokkos::FUNC(a); \
} \
}
Expand Down Expand Up @@ -488,8 +489,9 @@ KOKKOS_IMPL_SIMD_UNARY_FUNCTION(lgamma)
} \
namespace Experimental { \
template <class T, class Abi> \
[[nodiscard]] KOKKOS_DEPRECATED KOKKOS_FORCEINLINE_FUNCTION simd<T, Abi> \
FUNC(simd<T, Abi> const& a, simd<T, Abi> const& b) { \
[[nodiscard]] KOKKOS_DEPRECATED KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION \
simd<T, Abi> \
FUNC(simd<T, Abi> const& a, simd<T, Abi> const& b) { \
Kokkos::FUNC(a, b); \
} \
}
Expand All @@ -513,24 +515,26 @@ KOKKOS_IMPL_SIMD_BINARY_FUNCTION(atan2)
KOKKOS_IMPL_SIMD_BINARY_FUNCTION(copysign)

#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
#define KOKKOS_IMPL_SIMD_TERNARY_FUNCTION(FUNC) \
template <class T, class Abi> \
[[nodiscard]] KOKKOS_FORCEINLINE_FUNCTION Experimental::simd<T, Abi> FUNC( \
Experimental::simd<T, Abi> const& a, \
Experimental::simd<T, Abi> const& b, \
Experimental::simd<T, Abi> const& c) { \
Experimental::simd<T, Abi> result; \
for (std::size_t i = 0; i < Experimental::simd<T, Abi>::size(); ++i) { \
result[i] = Kokkos::FUNC(a[i], b[i], c[i]); \
} \
return result; \
} \
namespace Experimental { \
template <class T, class Abi> \
[[nodiscard]] KOKKOS_DEPRECATED KOKKOS_FORCEINLINE_FUNCTION simd<T, Abi> \
FUNC(simd<T, Abi> const& a, simd<T, Abi> const& b, simd<T, Abi> const& c) { \
return Kokkos::FUNC(a, b, c); \
} \
#define KOKKOS_IMPL_SIMD_TERNARY_FUNCTION(FUNC) \
template <class T, class Abi> \
[[nodiscard]] KOKKOS_FORCEINLINE_FUNCTION Experimental::simd<T, Abi> FUNC( \
Experimental::simd<T, Abi> const& a, \
Experimental::simd<T, Abi> const& b, \
Experimental::simd<T, Abi> const& c) { \
Experimental::simd<T, Abi> result; \
for (std::size_t i = 0; i < Experimental::simd<T, Abi>::size(); ++i) { \
result[i] = Kokkos::FUNC(a[i], b[i], c[i]); \
} \
return result; \
} \
namespace Experimental { \
template <class T, class Abi> \
[[nodiscard]] KOKKOS_DEPRECATED KOKKOS_IMPL_HOST_FORCEINLINE_FUNCTION \
simd<T, Abi> \
FUNC(simd<T, Abi> const& a, simd<T, Abi> const& b, \
simd<T, Abi> const& c) { \
return Kokkos::FUNC(a, b, c); \
} \
}
#else
#define KOKKOS_IMPL_SIMD_TERNARY_FUNCTION(FUNC) \
Expand Down
6 changes: 1 addition & 5 deletions simd/unit_tests/include/SIMDTesting_Ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class absolutes {
template <typename T>
auto on_host(T const& a) const {
if constexpr (std::is_signed_v<typename T::value_type>) {
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
#if defined(KOKKOS_ENABLE_DEPRECATED_CODE_4) && !defined(KOKKOS_COMPILER_NVCC)
return Kokkos::Experimental::abs(a);
#else
return Kokkos::abs(a);
Expand All @@ -95,11 +95,7 @@ class absolutes {
template <typename T>
KOKKOS_INLINE_FUNCTION auto on_device(T const& a) const {
if constexpr (std::is_signed_v<typename T::value_type>) {
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE_4
return Kokkos::Experimental::abs(a);
#else
return Kokkos::abs(a);
#endif
}
return a;
}
Expand Down
31 changes: 22 additions & 9 deletions simd/unit_tests/include/TestSIMD_GeneratorCtors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,33 @@ inline void host_check_gen_ctor() {
expected[i] = (init_mask[i]) ? init[i] * 9 : init[i];
}

simd_type basic(KOKKOS_LAMBDA(std::size_t i) { return init[i]; });
mask_type mask(KOKKOS_LAMBDA(std::size_t i) { return init_mask[i]; });

simd_type rhs;
rhs.copy_from(init, Kokkos::Experimental::element_aligned_tag());
host_check_equality(basic, rhs, lanes);

simd_type lhs(KOKKOS_LAMBDA(std::size_t i) { return init[i] * 9; });
simd_type result(
KOKKOS_LAMBDA(std::size_t i) { return (mask[i]) ? lhs[i] : rhs[i]; });

simd_type blend;
blend.copy_from(expected, Kokkos::Experimental::element_aligned_tag());
host_check_equality(blend, result, lanes);

if constexpr (std::is_same_v<Abi, Kokkos::Experimental::simd_abi::scalar>) {
simd_type basic(KOKKOS_LAMBDA(std::size_t i) { return init[i]; });
host_check_equality(basic, rhs, lanes);

simd_type lhs(KOKKOS_LAMBDA(std::size_t i) { return init[i] * 9; });
mask_type mask(KOKKOS_LAMBDA(std::size_t i) { return init_mask[i]; });
simd_type result(
KOKKOS_LAMBDA(std::size_t i) { return (mask[i]) ? lhs[i] : rhs[i]; });

host_check_equality(blend, result, lanes);
} else {
simd_type basic([=](std::size_t i) { return init[i]; });
host_check_equality(basic, rhs, lanes);

simd_type lhs([=](std::size_t i) { return init[i] * 9; });
mask_type mask([=](std::size_t i) { return init_mask[i]; });
simd_type result(
[=](std::size_t i) { return (mask[i]) ? lhs[i] : rhs[i]; });

host_check_equality(blend, result, lanes);
}
}

template <typename Abi, typename... DataTypes>
Expand Down

0 comments on commit 96edf73

Please sign in to comment.