diff --git a/CMakeLists.txt b/CMakeLists.txt index abfbc87..32505e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ include(FetchContent) set(KOKKOS_FETCH_TAG "5.1.1" CACHE STRING "Kokkos git tag to fetch") find_package(Kokkos 5.1.1 QUIET) if (NOT Kokkos_FOUND) - message(STATUS "Kokkos not found locally - fetching tag " "${KOKKOS_FETCH_TAG} via FetchContent") + message(STATUS "Kokkos not found locally - fetching tag ${KOKKOS_FETCH_TAG} via FetchContent") FetchContent_Declare(kokkos GIT_REPOSITORY https://github.com/kokkos/kokkos.git GIT_TAG ${KOKKOS_FETCH_TAG} GIT_SHALLOW ON) FetchContent_MakeAvailable(kokkos) else() diff --git a/kokkos_tree/CMakeLists.txt b/kokkos_tree/CMakeLists.txt index 738823a..728f26a 100644 --- a/kokkos_tree/CMakeLists.txt +++ b/kokkos_tree/CMakeLists.txt @@ -1,17 +1,11 @@ cmake_minimum_required(VERSION 3.21) -include(GoogleTest) if(NOT PROJECT_NAME) project(test_dyn_rank CXX) set(CMAKE_CXX_STANDARD 20) find_package(Kokkos 5.1.1 REQUIRED) - enable_testing() endif() add_executable(Kokkos_qun_test test_dyn_rank.cpp) target_link_libraries(Kokkos_qun_test PRIVATE Kokkos::kokkos GTest::gtest) - -add_test( - NAME Kokkos_qun_test - COMMAND Kokkos_qun_test -) +add_test(NAME Kokkos_qun_test COMMAND Kokkos_qun_test) diff --git a/kokkos_tree/desul/Compare_Exchange_Cuda.hpp b/kokkos_tree/desul/Compare_Exchange_Cuda.hpp new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/kokkos_tree/desul/Compare_Exchange_Cuda.hpp @@ -0,0 +1 @@ + diff --git a/kokkos_tree/desul/desul_test.hpp b/kokkos_tree/desul/desul_test.hpp index 3f9dabc..8e16c90 100644 --- a/kokkos_tree/desul/desul_test.hpp +++ b/kokkos_tree/desul/desul_test.hpp @@ -62,4 +62,16 @@ TEST(DesulAtomicTest, CmpExchFailureOrder_TypeMapping) { desul::Impl::cmpexch_failure_memory_order, desul::MemoryOrderSeqCst>::value)); } +TEST(DesulNumericLimitsTest,atomics_include_desul_atomics_Common_hpp_L82 ){ + constexpr uint32_t desul_max = desul::Impl::numeric_limits_max::value; + constexpr uint32_t std_max = std::numeric_limits::max(); + EXPECT_EQ(desul_max, std_max) << "Doesn't match"; + constexpr uint64_t desul_max64 = desul::Impl::numeric_limits_max::value; + constexpr uint64_t std_max64 = std::numeric_limits::max(); + EXPECT_EQ(desul_max64, std_max64) << "Doesn't match"; + auto val = sizeof(int64_t); + EXPECT_EQ(val, 8) << "Doesn't match"; + ASSERT_TRUE((std::is_same_v, int64_t>)) << "Doesn't match"; +} + } // namespace Test \ No newline at end of file diff --git a/kokkos_tree/kokkos_core/cuda_Error.hpp b/kokkos_tree/kokkos_core/cuda_Error.hpp new file mode 100644 index 0000000..e63a43f --- /dev/null +++ b/kokkos_tree/kokkos_core/cuda_Error.hpp @@ -0,0 +1,112 @@ +#include +#include +#include +#include +#include // That's for std::is_void_v +#include +#include +namespace Test{ +TEST(KokkosCudaError, InternalErrorThrowsRuntimeError){ + EXPECT_THROW({ + Kokkos::Impl::cuda_internal_error_throw(cudaErrorInvalidValue,"PlasmaKernal",__FILE__,__LINE__); + }, std::runtime_error); +} +struct InternalCudaFunctor{ + Kokkos::View data; + InternalCudaFunctor(Kokkos::View d):data(d){} + KOKKOS_INLINE_FUNCTION void operator()(const int i) const{ + data(i) = i * 2; + } +}; + +TEST(Kokkos_internal, InterCudaFunctorCase01){ + const int N=100000; + using CudaPolicy = Kokkos::RangePolicy; + Kokkos::View data("data",N); + Kokkos::parallel_for("TestCudaInternal",CudaPolicy(0,N),InternalCudaFunctor(data)); + Kokkos::fence(); + auto h_data = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(),data); + for(int i=0;i data("data",N); + using CudaPolicy = Kokkos::RangePolicy; + using Functor = InternalCudaFunctor; + CudaPolicy policy(0,N); + Functor functor(data); + using ImplParallelFor = Kokkos::Impl::ParallelFor; + ImplParallelFor impl_parallel_for(functor,policy); + impl_parallel_for.execute(); + Kokkos::Cuda().fence("Wait for internal launch to finish"); + auto h_data = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(),data); + for(int i=0;i data; + TagDispatchFunctor(Kokkos::View d):data(d){} + KOKKOS_INLINE_FUNCTION void operator()(const int i) const{ + data(i) = i * 2; + } + KOKKOS_INLINE_FUNCTION void operator()(const SpecialTag&,const int i) const{ + data(i) = i * 3; + } +}; +TEST(kokkos_internal, InterCudaFunctorCase03){ + const int N = 12800; + using KView = Kokkos::View; + using ImplParallelFor = Kokkos::Impl::ParallelFor,Kokkos::Cuda>; + using CudaPolicy = ImplParallelFor::Policy; + KView d("data",N); + ImplParallelFor imppf(TagDispatchFunctor(d),CudaPolicy(0,N)); + imppf.execute(); + Kokkos::Cuda().fence("Wait for void tag launch"); + auto h_data = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace(), d); + for(int i = 0; i < N; ++i) { + EXPECT_EQ(h_data(i), i * 2) << "Void overload failed!"; + } +} +TEST(kokkos_internal, CudaWarpAllocationGranularity){ + cudaDeviceProp prop; + prop.major = 8; + prop.minor = 6; + EXPECT_EQ(Kokkos::Impl::cuda_warp_per_sm_allocation_granularity(prop), 4u) << "Expected 4 warps per SM for Ampere"; + prop.major = 6; + prop.minor = 0; + EXPECT_EQ(Kokkos::Impl::cuda_warp_per_sm_allocation_granularity(prop), 2u) << "Expected 2 warps per SM for Pascal"; + prop.major = 6; + prop.minor = 1; + EXPECT_EQ(Kokkos::Impl::cuda_warp_per_sm_allocation_granularity(prop), 4u) << "Expected 4 warps per SM for Pascal"; + prop.major = 23; + prop.minor = 0; + EXPECT_THROW({Kokkos::Impl::cuda_warp_per_sm_allocation_granularity(prop);},std::runtime_error) << "Expected runtime error for unknown architecture"; +} +TEST(kokkos_internal, CudaBlockSizeDeduction){ + cudaDeviceProp prop; + prop.major = 8; + prop.sharedMemPerBlockOptin = 100000; + prop.reservedSharedMemPerBlock = 1024; + size_t shrd_mem = Kokkos::Impl::get_max_shared_mem_per_block(prop); + EXPECT_EQ(shrd_mem, 98976) << "Shared memory per block calculation failed for Ampere"; +} +TEST(kokkos_internal, CudaMaxWarpPerSmRegisters){ + cudaDeviceProp prop; + cudaFuncAttributes attr; + prop.major = 8; + prop.minor = 6; + prop.warpSize = 32; + prop.regsPerBlock = 65536; + attr.numRegs = 32; + int optimal_wraps = Kokkos::Impl::cuda_max_warps_per_sm_registers(prop,attr); + EXPECT_EQ(optimal_warps, 64)<< "Expected 32 warps per SM for Ampere with 32 registers per thread"; + attr.numRegs = 64; + int optimal_wraps = Kokkos::Impl::cuda_max_warps_per_sm_registers(prop,attr); + EXPECT_EQ(optimal_warps, 32)<< "Expected 16 warps per SM for Ampere with 64 registers per thread"; + +} +} \ No newline at end of file diff --git a/kokkos_tree/test_dyn_rank.cpp b/kokkos_tree/test_dyn_rank.cpp index bd3afae..28a5503 100644 --- a/kokkos_tree/test_dyn_rank.cpp +++ b/kokkos_tree/test_dyn_rank.cpp @@ -2,6 +2,7 @@ #include "kokkos_core/kokkos_pair_investigation.hpp" #include "mdspan/kokkos_raw_mdspan.hpp" #include "kokkos_core/test_drank.hpp" +#include "kokkos_core/cuda_Error.hpp" #include #include int main(int argc, char **argv) {