Skip to content
Snippets Groups Projects
Unverified Commit 6c7d5ec7 authored by Jayesh Badwaik's avatar Jayesh Badwaik
Browse files

- nola: tested array with cuda

  - this gives us the confidence that the basic data structures and
    functions can work on both host and device
parent a8fd2219
No related branches found
No related tags found
No related merge requests found
Pipeline #134201 passed
......@@ -33,8 +33,8 @@ public:
public:
array() = default;
NOLA_HOST_DEVICE
template <typename... U>
NOLA_HOST_DEVICE
constexpr explicit array(U... u)
requires(sizeof...(U) == N and std::conjunction_v<std::is_same<T, U>...>);
......@@ -79,8 +79,8 @@ constexpr auto to_array(Args&&... args) -> nola::array<T, sizeof...(Args)>
// -------------------------------------------------------------------------------------------------
template <typename T, std::size_t N>
NOLA_HOST_DEVICE
template <typename... U>
NOLA_HOST_DEVICE
constexpr array<T, N>::array(U... u)
requires(sizeof...(U) == N and std::conjunction_v<std::is_same<T, U>...>)
: value_{u...}
......
// -------------------------------------------------------------------------------------------------
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: (C) 2022 Jayesh Badwaik <j.badwaik@fz-juelich.de>
// -------------------------------------------------------------------------------------------------
#include <array>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>
#include <nola/array.hpp>
#include <testmol/compat/catch_main.hpp>
#include <testmol/compat/cuda_test_case.cuhpp>
#include <type_traits>
/* NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)*/
TESTMOL_CATCH_MAIN("test/unit/nola/cpp/array")
class base {
int value_{-1};
public:
__host__ __device__ explicit base(int a) : value_(a) {}
__host__ __device__ auto value() const noexcept -> int { return value_; }
base() = default;
};
TEMPLATE_TEST_CASE("01: construct from array", "[all]", int, base)
{
static_assert(std::is_trivially_copy_constructible_v<nola::array<TestType, 4>>);
static_assert(std::is_trivially_move_constructible_v<nola::array<TestType, 4>>);
static_assert(std::is_trivially_move_assignable_v<nola::array<TestType, 4>>);
static_assert(std::is_trivially_copy_assignable_v<nola::array<TestType, 4>>);
static_assert(std::is_trivially_destructible_v<nola::array<TestType, 4>>);
}
CUDA_TEST_CASE("02: construct from array", "[all]", 256)
{
auto const value = nola::array<int, 4>(4, 2, 3, 5);
CUDA_REQUIRE(value[0] == 4);
CUDA_REQUIRE(value[1] == 2);
CUDA_REQUIRE(value[2] == 3);
CUDA_REQUIRE(value[3] == 5);
}
CUDA_TEST_CASE("03: operator []", "[all]", 256)
{
auto value = nola::array<int, 4>(4, 2, 3, 5);
CUDA_REQUIRE(value[0] == 4);
CUDA_REQUIRE(value[1] == 2);
CUDA_REQUIRE(value[2] == 3);
CUDA_REQUIRE(value[3] == 5);
value[0] = 5;
value[1] = 3;
value[2] = 2;
value[3] = 4;
CUDA_REQUIRE(value[0] == 5);
CUDA_REQUIRE(value[1] == 3);
CUDA_REQUIRE(value[2] == 2);
CUDA_REQUIRE(value[3] == 4);
}
CUDA_TEST_CASE("04: iterator ", "[all]", 256)
{
auto const value = nola::array<int, 4>(0, 1, 2, 3);
for (auto it = value.begin(); it != value.end(); ++it) {
CUDA_REQUIRE(*it == (it - value.begin()));
}
}
CUDA_TEST_CASE("05: const_iterator ", "[all]", 256)
{
auto value = nola::array<int, 4>(0, 1, 2, 3);
// NOLINTNEXTLINE(modernize-loop-convert)
for (auto it = value.begin(); it != value.end(); ++it) {
*it *= 2;
}
for (auto it = value.begin(); it != value.end(); ++it) {
CUDA_REQUIRE(*it == 2 * (it - value.begin()));
}
}
CUDA_TEST_CASE("05: operator=", "[all]", 256)
{
auto value = nola::array<int, 4>(0, 1, 2, 3);
value = 4;
CUDA_REQUIRE(value[0] == 4);
CUDA_REQUIRE(value[1] == 4);
CUDA_REQUIRE(value[2] == 4);
CUDA_REQUIRE(value[3] == 4);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment