From fed68efb15fb8cee72ce33a970f9544fe9f84ff0 Mon Sep 17 00:00:00 2001 From: Attila Krasznahorkay Date: Thu, 8 Jul 2021 14:40:47 +0200 Subject: [PATCH] Implemented additional tests for vecmem::static_array. Testing the new functions of the class, and just some very minimal functionality inside of device code as well. --- tests/core/test_core_containers.cpp | 31 ++++++++++++++++++++++ tests/cuda/test_cuda_containers_kernels.cu | 8 +++--- tests/hip/test_hip_containers_kernels.hip | 8 +++--- tests/sycl/test_sycl_containers.sycl | 7 +++-- 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/tests/core/test_core_containers.cpp b/tests/core/test_core_containers.cpp index bf1074e9..397db53c 100644 --- a/tests/core/test_core_containers.cpp +++ b/tests/core/test_core_containers.cpp @@ -11,6 +11,7 @@ #include "vecmem/containers/const_device_vector.hpp" #include "vecmem/containers/device_array.hpp" #include "vecmem/containers/device_vector.hpp" +#include "vecmem/containers/static_array.hpp" #include "vecmem/containers/static_vector.hpp" #include "vecmem/containers/vector.hpp" #include "vecmem/memory/host_memory_resource.hpp" @@ -122,3 +123,33 @@ TEST_F(core_container_test, device_array) { EXPECT_TRUE(test_array[i] == m_reference_vector[i]); } } + +/// Test(s) for @c vecmem::static_array +TEST_F(core_container_test, static_array) { + + static constexpr int ARRAY_SIZE = 10; + const vecmem::static_array test_array1 = {0, 1, 2, 3, 4, + 5, 6, 7, 8, 9}; + EXPECT_EQ(test_array1.size(), ARRAY_SIZE); + EXPECT_EQ(test_array1.max_size(), ARRAY_SIZE); + EXPECT_FALSE(test_array1.empty()); + const vecmem::static_array test_array2 = test_array1; + vecmem::static_array test_array3 = {2, 3, 4, 5, 6, + 7, 8, 9, 0, 1}; + EXPECT_EQ(test_array1, test_array2); + EXPECT_NE(test_array1, test_array3); + EXPECT_TRUE(std::equal(test_array1.begin(), test_array1.end(), + test_array2.begin())); + EXPECT_FALSE(std::equal(test_array1.begin(), test_array1.end(), + test_array3.begin())); + EXPECT_EQ(std::accumulate(test_array1.begin(), test_array1.end(), 0), + std::accumulate(test_array2.rbegin(), test_array2.rend(), 0)); + test_array3.fill(12); + for (int i = 0; i < ARRAY_SIZE; ++i) { + EXPECT_EQ(test_array3.at(i), 12); + } + const vecmem::static_array test_array4; + EXPECT_EQ(test_array4.size(), 0); + EXPECT_EQ(test_array4.max_size(), 0); + EXPECT_TRUE(test_array4.empty()); +} diff --git a/tests/cuda/test_cuda_containers_kernels.cu b/tests/cuda/test_cuda_containers_kernels.cu index f5d98df7..99586544 100644 --- a/tests/cuda/test_cuda_containers_kernels.cu +++ b/tests/cuda/test_cuda_containers_kernels.cu @@ -12,6 +12,7 @@ #include "vecmem/containers/const_device_vector.hpp" #include "vecmem/containers/device_vector.hpp" #include "vecmem/containers/jagged_device_vector.hpp" +#include "vecmem/containers/static_array.hpp" #include "vecmem/memory/atomic.hpp" /// Kernel performing a linear transformation using the vector helper types @@ -27,13 +28,14 @@ __global__ void linearTransformKernel( } // Create the helper containers. - const vecmem::const_device_array constantarray(constants); + const vecmem::const_device_array constantarray1(constants); + const vecmem::static_array constantarray2 = {constantarray1[0], + constantarray1[1]}; const vecmem::const_device_vector inputvec(input); vecmem::device_vector outputvec(output); // Perform the linear transformation. - outputvec.at(i) = - inputvec.at(i) * constantarray.at(0) + constantarray.at(1); + outputvec.at(i) = inputvec.at(i) * constantarray1.at(0) + constantarray2[1]; return; } diff --git a/tests/hip/test_hip_containers_kernels.hip b/tests/hip/test_hip_containers_kernels.hip index 452feb49..c2b7eefc 100644 --- a/tests/hip/test_hip_containers_kernels.hip +++ b/tests/hip/test_hip_containers_kernels.hip @@ -16,6 +16,7 @@ #include "vecmem/containers/const_device_vector.hpp" #include "vecmem/containers/device_vector.hpp" #include "vecmem/containers/jagged_device_vector.hpp" +#include "vecmem/containers/static_array.hpp" #include "vecmem/memory/atomic.hpp" /// Kernel performing a linear transformation using the vector helper types @@ -31,13 +32,14 @@ __global__ void linearTransformKernel( } // Create the helper containers. - const vecmem::const_device_array constantarray(constants); + const vecmem::const_device_array constantarray1(constants); + const vecmem::static_array constantarray2 = {constantarray1[0], + constantarray1[1]}; const vecmem::const_device_vector inputvec(input); vecmem::device_vector outputvec(output); // Perform the linear transformation. - outputvec.at(i) = - inputvec.at(i) * constantarray.at(0) + constantarray.at(1); + outputvec.at(i) = inputvec.at(i) * constantarray1.at(0) + constantarray2[1]; return; } diff --git a/tests/sycl/test_sycl_containers.sycl b/tests/sycl/test_sycl_containers.sycl index aeb3ec6d..79bac23e 100644 --- a/tests/sycl/test_sycl_containers.sycl +++ b/tests/sycl/test_sycl_containers.sycl @@ -14,6 +14,7 @@ #include "vecmem/containers/const_device_array.hpp" #include "vecmem/containers/const_device_vector.hpp" #include "vecmem/containers/device_vector.hpp" +#include "vecmem/containers/static_array.hpp" #include "vecmem/containers/vector.hpp" #include "vecmem/memory/atomic.hpp" #include "vecmem/memory/sycl/device_memory_resource.hpp" @@ -60,14 +61,16 @@ TEST_F(sycl_containers_test, shared_memory) { } // Create the helper containers. - const vecmem::const_device_array constantarray( + const vecmem::const_device_array constantarray1( constants); + const vecmem::static_array constantarray2 = { + constantarray1[0], constantarray1[1]}; const vecmem::const_device_vector inputvec(input); vecmem::device_vector outputvec(output); // Perform the linear transformation. outputvec.at(id) = - inputvec.at(id) * constantarray.at(0) + constantarray.at(1); + inputvec.at(id) * constantarray1.at(0) + constantarray2[1]; return; }); });