Debian Codegraph @

packages/kokkos-kernels/batched/dense/unit_test/Test_Batched_VectorLogical.hpp

raw
1 //@HEADER
2 // ************************************************************************
3 //
4 // Kokkos v. 4.0
5 // Copyright (2022) National Technology & Engineering
6 // Solutions of Sandia, LLC (NTESS).
7 //
8 // Under the terms of Contract DE-NA0003525 with NTESS,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12 // See https://kokkos.org/LICENSE for license information.
13 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14 //
15 //@HEADER
16 /// \author Kyungjoo Kim ([email protected])
17
18 // Note: Luc Berger-Vergiat 04/14/21
19 // This test does not run on cuda or HIP
20 // backends so the whole file is guarded
21 // to ensure it is not included in these
22 // backends unit-test
23
24 #if !defined(TEST_CUDA_BATCHED_DENSE_CPP) && !defined(TEST_HIP_BATCHED_DENSE_CPP) && \
25 !defined(TEST_SYCL_BATCHED_DENSE_CPP) && !defined(TEST_OPENMPTARGET_BATCHED_DENSE_CPP)
26
27 #include "gtest/gtest.h"
28 #include "Kokkos_Core.hpp"
29 #include "Kokkos_Random.hpp"
30
31 #include "KokkosBatched_Vector.hpp"
32
33 #include "KokkosKernels_TestUtils.hpp"
34
35 using namespace KokkosBatched;
36
37 namespace Test {
38
39 template <typename ValueType, int VectorLength>
40 void impl_test_batched_vector_logical() {
41 /// random data initialization
42 typedef Vector<SIMD<int>, VectorLength> vector_int_type;
43 typedef ValueType value_type;
44 const int vector_length = VectorLength;
45
46 typedef Kokkos::ArithTraits<value_type> ats;
47 typedef typename ats::mag_type mag_type;
48
49 vector_int_type a, b;
50
51 Random<mag_type> random;
52 for (int iter = 0; iter < 100; ++iter) {
53 for (int k = 0; k < vector_length; ++k) {
54 a[k] = (random.value() > 0 ? 1 : -1);
55 b[k] = (random.value() < 0 ? 1 : -1);
56 }
57
58 {
59 #undef CHECK
60 #define CHECK(op) \
61 { \
62 const auto comparison = a op b; \
63 for (int i = 0; i < vector_length; ++i) EXPECT_EQ(comparison[i], a[i] op b[i]); \
64 }
65
66 CHECK(||);
67 CHECK(&&);
68
69 #undef CHECK
70 #define CHECK(op) \
71 { \
72 const auto comparison = a op 0; \
73 for (int i = 0; i < vector_length; ++i) EXPECT_EQ(comparison[i], a[i] op 0); \
74 }
75
76 CHECK(||);
77 CHECK(&&);
78
79 #undef CHECK
80 #define CHECK(op) \
81 { \
82 const auto comparison = 0 op b; \
83 for (int i = 0; i < vector_length; ++i) EXPECT_EQ(comparison[i], 0 op b[i]); \
84 }
85
86 CHECK(||);
87 CHECK(&&);
88
89 #undef CHECK
90
91 } // end test body
92 } // end for
93 } // impl
94 } // namespace Test
95
96 template <typename DeviceType, typename ValueType, int VectorLength>
97 int test_batched_vector_logical() {
98 static_assert(Kokkos::SpaceAccessibility<DeviceType, Kokkos::HostSpace>::accessible,
99 "vector datatype is only tested on host space");
100 Test::impl_test_batched_vector_logical<ValueType, VectorLength>();
101
102 return 0;
103 }
104
105 ///
106 /// SIMD
107 ///
108
109 #if defined(KOKKOSKERNELS_INST_FLOAT)
110 TEST_F(TestCategory, batched_vector_logical_simd_float3) { test_batched_vector_logical<TestDevice, float, 3>(); }
111 TEST_F(TestCategory, batched_vector_logical_simd_float8) { test_batched_vector_logical<TestDevice, float, 8>(); }
112 #endif
113
114 #if defined(KOKKOSKERNELS_INST_DOUBLE)
115 TEST_F(TestCategory, batched_vector_logical_simd_double3) { test_batched_vector_logical<TestDevice, double, 3>(); }
116 TEST_F(TestCategory, batched_vector_logical_simd_double4) { test_batched_vector_logical<TestDevice, double, 4>(); }
117 #endif
118
119 // #if defined(KOKKOSKERNELS_INST_COMPLEX_FLOAT)
120 // TEST_F( TestCategory, batched_vector_logical_simd_scomplex3 ) {
121 // test_batched_vector_logical<TestDevice,Kokkos::complex<float>,3>();
122 // }
123 // TEST_F( TestCategory, batched_vector_logical_simd_scomplex4 ) {
124 // test_batched_vector_logical<TestDevice,Kokkos::complex<float>,4>();
125 // }
126 // #endif
127
128 // #if defined(KOKKOSKERNELS_INST_COMPLEX_DOUBLE)
129 // TEST_F( TestCategory, batched_vector_logical_simd_dcomplex3 ) {
130 // test_batched_vector_logical<TestDevice,Kokkos::complex<double>,3>();
131 // }
132 // TEST_F( TestCategory, batched_vector_logical_simd_dcomplex2 ) {
133 // test_batched_vector_logical<TestDevice,Kokkos::complex<double>,2>();
134 // }
135 // #endif
136
137 #endif // check to not include this in a device test