From 90f6ed4d040c434cf7722174697ac747ed15370b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Widera?= Date: Wed, 27 Jul 2022 15:50:41 +0200 Subject: [PATCH] refactore atomic unit tests Unify CPU and HIP/CUDA atomic tests. For CUDA run tests only for 32bit and 64bit data types. --- test/unit/atomic/src/AtomicTest.cpp | 419 +--------------------------- 1 file changed, 6 insertions(+), 413 deletions(-) diff --git a/test/unit/atomic/src/AtomicTest.cpp b/test/unit/atomic/src/AtomicTest.cpp index 43583d5a4c85..976a9285ac04 100644 --- a/test/unit/atomic/src/AtomicTest.cpp +++ b/test/unit/atomic/src/AtomicTest.cpp @@ -338,438 +338,31 @@ class AtomicTestKernel>> // testAtomicAnd(acc, success, operandOrig); // testAtomicOr(acc, success, operandOrig); // testAtomicXor(acc, success, operandOrig); - // testAtomicCas(acc, success, operandOrig); - } -}; - -#if defined(ALPAKA_ACC_GPU_CUDA_ENABLED) && BOOST_LANG_CUDA -template -class AtomicTestKernel, int> -{ -public: - ALPAKA_NO_HOST_ACC_WARNING - ALPAKA_FN_ACC auto operator()(alpaka::AccGpuCudaRt const& acc, bool* success, int operandOrig) const - -> void - { - testAtomicAdd(acc, success, operandOrig); - testAtomicSub(acc, success, operandOrig); - - testAtomicMin(acc, success, operandOrig); - testAtomicMax(acc, success, operandOrig); - - testAtomicExch(acc, success, operandOrig); - - testAtomicInc(acc, success, operandOrig); - testAtomicDec(acc, success, operandOrig); - - testAtomicAnd(acc, success, operandOrig); - testAtomicOr(acc, success, operandOrig); - testAtomicXor(acc, success, operandOrig); testAtomicCas(acc, success, operandOrig); } }; -// NOTE: unsigned int is the only type supported by all atomic CUDA operations. -template -class AtomicTestKernel, unsigned int> -{ -public: - ALPAKA_NO_HOST_ACC_WARNING - ALPAKA_FN_ACC auto operator()(alpaka::AccGpuCudaRt const& acc, bool* success, unsigned int operandOrig) - const -> void - { - testAtomicAdd(acc, success, operandOrig); - testAtomicSub(acc, success, operandOrig); +#if(defined(ALPAKA_ACC_GPU_CUDA_ENABLED) && BOOST_LANG_CUDA) || (defined(ALPAKA_ACC_GPU_HIP_ENABLED) && BOOST_LANG_HIP) - testAtomicMin(acc, success, operandOrig); - testAtomicMax(acc, success, operandOrig); - - testAtomicExch(acc, success, operandOrig); - - testAtomicInc(acc, success, operandOrig); - testAtomicDec(acc, success, operandOrig); - - testAtomicAnd(acc, success, operandOrig); - testAtomicOr(acc, success, operandOrig); - testAtomicXor(acc, success, operandOrig); - - testAtomicCas(acc, success, operandOrig); - } -}; - -template -class AtomicTestKernel, unsigned long int> -{ -public: - ALPAKA_NO_HOST_ACC_WARNING - ALPAKA_FN_ACC auto operator()( - alpaka::AccGpuCudaRt const& acc, - bool* success, - unsigned long int operandOrig) const -> void - { - testAtomicAdd(acc, success, operandOrig); - testAtomicSub(acc, success, operandOrig); - -# if ULONG_MAX == ULLONG_MAX // LP64 -# if BOOST_ARCH_PTX >= BOOST_VERSION_NUMBER(3, 5, 0) - testAtomicMin(acc, success, operandOrig); - testAtomicMax(acc, success, operandOrig); -# endif -# endif - - testAtomicExch(acc, success, operandOrig); - - testAtomicInc(acc, success, operandOrig); - testAtomicDec(acc, success, operandOrig); - -# if ULONG_MAX == ULLONG_MAX // LP64 -# if BOOST_ARCH_PTX >= BOOST_VERSION_NUMBER(3, 5, 0) - testAtomicAnd(acc, success, operandOrig); - testAtomicOr(acc, success, operandOrig); - testAtomicXor(acc, success, operandOrig); -# endif -# endif - - testAtomicCas(acc, success, operandOrig); - } -}; - -template -class AtomicTestKernel, unsigned long long int> -{ -public: - ALPAKA_NO_HOST_ACC_WARNING - ALPAKA_FN_ACC auto operator()( - alpaka::AccGpuCudaRt const& acc, - bool* success, - unsigned long long int operandOrig) const -> void - { - testAtomicAdd(acc, success, operandOrig); - testAtomicSub(acc, success, operandOrig); - -# if BOOST_ARCH_PTX >= BOOST_VERSION_NUMBER(3, 5, 0) - testAtomicMin(acc, success, operandOrig); - testAtomicMax(acc, success, operandOrig); -# endif - - testAtomicExch(acc, success, operandOrig); - - testAtomicInc(acc, success, operandOrig); - testAtomicDec(acc, success, operandOrig); - -# if BOOST_ARCH_PTX >= BOOST_VERSION_NUMBER(3, 5, 0) - testAtomicAnd(acc, success, operandOrig); - testAtomicOr(acc, success, operandOrig); - testAtomicXor(acc, success, operandOrig); -# endif - - testAtomicCas(acc, success, operandOrig); - } -}; - -template -class AtomicTestKernel, float> -{ -public: - ALPAKA_NO_HOST_ACC_WARNING - ALPAKA_FN_ACC auto operator()(alpaka::AccGpuCudaRt const& acc, bool* success, float operandOrig) const - -> void - { - testAtomicAdd(acc, success, operandOrig); - testAtomicSub(acc, success, operandOrig); - - testAtomicMin(acc, success, operandOrig); - testAtomicMax(acc, success, operandOrig); - - testAtomicExch(acc, success, operandOrig); - - // Not supported - // testAtomicInc(acc, success, operandOrig); - // testAtomicDec(acc, success, operandOrig); - - // Not supported - // testAtomicAnd(acc, success, operandOrig); - // testAtomicOr(acc, success, operandOrig); - // testAtomicXor(acc, success, operandOrig); - - // Not supported - // testAtomicCas(acc, success, operandOrig); - } -}; - -template -class AtomicTestKernel, double> -{ -public: - ALPAKA_NO_HOST_ACC_WARNING - ALPAKA_FN_ACC auto operator()(alpaka::AccGpuCudaRt const& acc, bool* success, double operandOrig) const - -> void - { - testAtomicAdd(acc, success, operandOrig); - testAtomicSub(acc, success, operandOrig); - - testAtomicMin(acc, success, operandOrig); - testAtomicMax(acc, success, operandOrig); - - testAtomicExch(acc, success, operandOrig); - - // Not supported - // testAtomicInc(acc, success, operandOrig); - // testAtomicDec(acc, success, operandOrig); - - // Not supported - // testAtomicAnd(acc, success, operandOrig); - // testAtomicOr(acc, success, operandOrig); - // testAtomicXor(acc, success, operandOrig); - - // Not supported - // testAtomicCas(acc, success, operandOrig); - } -}; - -template +template class AtomicTestKernel< - alpaka::AccGpuCudaRt, + alpaka::AccGpuUniformCudaHipRt, T, - std::enable_if_t, - T>::value>> + std::enable_if_t> { public: ALPAKA_NO_HOST_ACC_WARNING ALPAKA_FN_ACC auto operator()( - alpaka::AccGpuCudaRt const& /* acc */, + alpaka::AccGpuUniformCudaHipRt const& /* acc */, bool* success, T /* operandOrig */) const -> void { - // All other types are not supported by CUDA atomic operations. - ALPAKA_CHECK(*success, true); - } -}; -#endif - -#if defined(ALPAKA_ACC_GPU_HIP_ENABLED) && BOOST_LANG_HIP -template -class AtomicTestKernel, int> -{ -public: - ALPAKA_NO_HOST_ACC_WARNING - ALPAKA_FN_ACC auto operator()(alpaka::AccGpuHipRt const& acc, bool* success, int operandOrig) const - -> void - { - testAtomicAdd(acc, success, operandOrig); - testAtomicSub(acc, success, operandOrig); - - testAtomicMin(acc, success, operandOrig); - testAtomicMax(acc, success, operandOrig); - - testAtomicExch(acc, success, operandOrig); - - testAtomicInc(acc, success, operandOrig); - testAtomicDec(acc, success, operandOrig); - - testAtomicAnd(acc, success, operandOrig); - testAtomicOr(acc, success, operandOrig); - testAtomicXor(acc, success, operandOrig); - - testAtomicCas(acc, success, operandOrig); - } -}; - -// NOTE: unsigned int is the only type supported by all atomic HIP operations. -template -class AtomicTestKernel, unsigned int> -{ -public: - ALPAKA_NO_HOST_ACC_WARNING - ALPAKA_FN_ACC auto operator()(alpaka::AccGpuHipRt const& acc, bool* success, unsigned int operandOrig) - const -> void - { - testAtomicAdd(acc, success, operandOrig); - testAtomicSub(acc, success, operandOrig); - - testAtomicMin(acc, success, operandOrig); - testAtomicMax(acc, success, operandOrig); - - testAtomicExch(acc, success, operandOrig); - - testAtomicInc(acc, success, operandOrig); - testAtomicDec(acc, success, operandOrig); - - testAtomicAnd(acc, success, operandOrig); - testAtomicOr(acc, success, operandOrig); - testAtomicXor(acc, success, operandOrig); - - testAtomicCas(acc, success, operandOrig); - } -}; - -template -class AtomicTestKernel, unsigned long int> -{ -public: - ALPAKA_NO_HOST_ACC_WARNING - ALPAKA_FN_ACC auto operator()( - alpaka::AccGpuHipRt const& acc, - bool* success, - unsigned long int operandOrig) const -> void - { - testAtomicAdd(acc, success, operandOrig); - testAtomicSub(acc, success, operandOrig); - -# if ULONG_MAX == ULLONG_MAX // LP64 -# if BOOST_ARCH_PTX >= BOOST_VERSION_NUMBER(3, 5, 0) - testAtomicMin(acc, success, operandOrig); - testAtomicMax(acc, success, operandOrig); -# endif -# endif - - testAtomicExch(acc, success, operandOrig); - - testAtomicInc(acc, success, operandOrig); - testAtomicDec(acc, success, operandOrig); - -# if ULONG_MAX == ULLONG_MAX // LP64 -# if BOOST_ARCH_PTX >= BOOST_VERSION_NUMBER(3, 5, 0) - testAtomicAnd(acc, success, operandOrig); - testAtomicOr(acc, success, operandOrig); - testAtomicXor(acc, success, operandOrig); -# endif -# endif - - testAtomicCas(acc, success, operandOrig); - } -}; - -template -class AtomicTestKernel, unsigned long long int> -{ -public: - ALPAKA_NO_HOST_ACC_WARNING - ALPAKA_FN_ACC auto operator()( - alpaka::AccGpuHipRt const& acc, - bool* success, - unsigned long long int operandOrig) const -> void - { - testAtomicAdd(acc, success, operandOrig); - testAtomicSub(acc, success, operandOrig); - -# if BOOST_ARCH_PTX >= BOOST_VERSION_NUMBER(3, 5, 0) - testAtomicMin(acc, success, operandOrig); - testAtomicMax(acc, success, operandOrig); -# endif - - testAtomicExch(acc, success, operandOrig); - - testAtomicInc(acc, success, operandOrig); - testAtomicDec(acc, success, operandOrig); - -# if BOOST_ARCH_PTX >= BOOST_VERSION_NUMBER(3, 5, 0) - testAtomicAnd(acc, success, operandOrig); - testAtomicOr(acc, success, operandOrig); - testAtomicXor(acc, success, operandOrig); -# endif - - testAtomicCas(acc, success, operandOrig); - } -}; - -template -class AtomicTestKernel, float> -{ -public: - ALPAKA_NO_HOST_ACC_WARNING - ALPAKA_FN_ACC auto operator()(alpaka::AccGpuHipRt const& acc, bool* success, float operandOrig) const - -> void - { - testAtomicAdd(acc, success, operandOrig); - testAtomicSub(acc, success, operandOrig); - - testAtomicMin(acc, success, operandOrig); - testAtomicMax(acc, success, operandOrig); - - testAtomicExch(acc, success, operandOrig); - - // Not supported - // testAtomicInc(acc, success, operandOrig); - // testAtomicDec(acc, success, operandOrig); - - // Not supported - // testAtomicAnd(acc, success, operandOrig); - // testAtomicOr(acc, success, operandOrig); - // testAtomicXor(acc, success, operandOrig); - - // Not supported - // testAtomicCas(acc, success, operandOrig); - } -}; - -template -class AtomicTestKernel, double> -{ -public: - ALPAKA_NO_HOST_ACC_WARNING - ALPAKA_FN_ACC auto operator()(alpaka::AccGpuHipRt const& acc, bool* success, double operandOrig) const - -> void - { - testAtomicAdd(acc, success, operandOrig); - testAtomicSub(acc, success, operandOrig); - - testAtomicMin(acc, success, operandOrig); - testAtomicMax(acc, success, operandOrig); - - testAtomicExch(acc, success, operandOrig); - - // Not supported - // testAtomicInc(acc, success, operandOrig); - // testAtomicDec(acc, success, operandOrig); - - // Not supported - // testAtomicAnd(acc, success, operandOrig); - // testAtomicOr(acc, success, operandOrig); - // testAtomicXor(acc, success, operandOrig); - - // Not supported - // testAtomicCas(acc, success, operandOrig); - } -}; - -template -class AtomicTestKernel< - alpaka::AccGpuHipRt, - T, - std::enable_if_t, - T>::value>> -{ -public: - ALPAKA_NO_HOST_ACC_WARNING - ALPAKA_FN_ACC auto operator()(alpaka::AccGpuHipRt const& /* acc */, bool* success, T /* operandOrig */) - const -> void - { - // All other types are not supported by HIP atomic operations. + // All other types are not supported by CUDA/HIP atomic operations. ALPAKA_CHECK(*success, true); } }; -#endif -#ifdef ALPAKA_ACC_ANY_BT_OACC_ENABLED -template -class AtomicTestKernel< - alpaka::AccOacc, - T, - std::enable_if_t> // disable 8-bit and 16-bit tests -{ -public: - ALPAKA_NO_HOST_ACC_WARNING - ALPAKA_FN_ACC auto operator()(alpaka::AccOacc const& /* acc */, bool* success, T /* operandOrig */) - const -> void - { - // All other types are not supported by Oacc atomic operations. - ALPAKA_CHECK(*success, true); - } -}; #endif template