Skip to content

Commit

Permalink
Implemented additional tests for vecmem::static_array.
Browse files Browse the repository at this point in the history
Testing the new functions of the class, and just some very minimal
functionality inside of device code as well.
  • Loading branch information
krasznaa committed Jul 8, 2021
1 parent 3d60f22 commit fed68ef
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
31 changes: 31 additions & 0 deletions tests/core/test_core_containers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<int, ARRAY_SIZE> 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<int, ARRAY_SIZE> test_array2 = test_array1;
vecmem::static_array<int, ARRAY_SIZE> 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<int, 0> test_array4;
EXPECT_EQ(test_array4.size(), 0);
EXPECT_EQ(test_array4.max_size(), 0);
EXPECT_TRUE(test_array4.empty());
}
8 changes: 5 additions & 3 deletions tests/cuda/test_cuda_containers_kernels.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,13 +28,14 @@ __global__ void linearTransformKernel(
}

// Create the helper containers.
const vecmem::const_device_array<int, 2> constantarray(constants);
const vecmem::const_device_array<int, 2> constantarray1(constants);
const vecmem::static_array<int, 2> constantarray2 = {constantarray1[0],
constantarray1[1]};
const vecmem::const_device_vector<int> inputvec(input);
vecmem::device_vector<int> 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;
}

Expand Down
8 changes: 5 additions & 3 deletions tests/hip/test_hip_containers_kernels.hip
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,13 +32,14 @@ __global__ void linearTransformKernel(
}

// Create the helper containers.
const vecmem::const_device_array<int, 2> constantarray(constants);
const vecmem::const_device_array<int, 2> constantarray1(constants);
const vecmem::static_array<int, 2> constantarray2 = {constantarray1[0],
constantarray1[1]};
const vecmem::const_device_vector<int> inputvec(input);
vecmem::device_vector<int> 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;
}

Expand Down
7 changes: 5 additions & 2 deletions tests/sycl/test_sycl_containers.sycl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -60,14 +61,16 @@ TEST_F(sycl_containers_test, shared_memory) {
}

// Create the helper containers.
const vecmem::const_device_array<int, 2> constantarray(
const vecmem::const_device_array<int, 2> constantarray1(
constants);
const vecmem::static_array<int, 2> constantarray2 = {
constantarray1[0], constantarray1[1]};
const vecmem::const_device_vector<int> inputvec(input);
vecmem::device_vector<int> 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;
});
});
Expand Down

0 comments on commit fed68ef

Please sign in to comment.