Debian Codegraph @

packages/kokkos-kernels/batched/dense/unit_test/Test_Batched_VectorRelation.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 VectorTagType, int VectorLength>
40 void impl_test_batched_vector_relation() {
41 /// random data initialization
42 typedef Vector<VectorTagType, VectorLength> vector_type;
43
44 typedef typename vector_type::value_type value_type;
45 const int vector_length = vector_type::vector_length;
46
47 // typedef Kokkos::ArithTraits<value_type> ats;
48 // typedef typename ats::mag_type mag_type;
49
50 vector_type a, b;
51
52 Random<value_type> random;
53 for (int iter = 0; iter < 100; ++iter) {
54 for (int k = 0; k < vector_length; ++k) {
55 a[k] = random.value();
56 b[k] = random.value();
57 }
58
59 {
60 #undef CHECK
61 #define CHECK(op) \
62 { \
63 const auto comparison = a op b; \
64 for (int i = 0; i < vector_length; ++i) EXPECT_EQ(comparison[i], a[i] op b[i]); \
65 }
66
67 CHECK(<);
68 CHECK(>);
69 CHECK(<=);
70 CHECK(>=);
71 CHECK(==);
72 CHECK(!=);
73
74 #undef CHECK
75 #define CHECK(op) \
76 { \
77 const auto comparison = a op value_type(0); \
78 for (int i = 0; i < vector_length; ++i) EXPECT_EQ(comparison[i], a[i] op value_type(0)); \
79 }
80
81 CHECK(<);
82 CHECK(>);
83 CHECK(<=);
84 CHECK(>=);
85 CHECK(==);
86 CHECK(!=);
87
88 #undef CHECK
89 #define CHECK(op) \
90 { \
91 const auto comparison = value_type(0) op b; \
92 for (int i = 0; i < vector_length; ++i) EXPECT_EQ(comparison[i], value_type(0) op b[i]); \
93 }
94
95 CHECK(<);
96 CHECK(>);
97 CHECK(<=);
98 CHECK(>=);
99 CHECK(==);
100 CHECK(!=);
101
102 #undef CHECK
103
104 } // end test body
105 } // end for
106 } // impl
107 } // namespace Test
108
109 template <typename DeviceType, typename VectorTagType, int VectorLength>
110 int test_batched_vector_relation() {
111 static_assert(Kokkos::SpaceAccessibility<DeviceType, Kokkos::HostSpace>::accessible,
112 "vector datatype is only tested on host space");
113 Test::impl_test_batched_vector_relation<VectorTagType, VectorLength>();
114
115 return 0;
116 }
117
118 ///
119 /// SIMD
120 ///
121
122 #if defined(KOKKOSKERNELS_INST_FLOAT)
123 TEST_F(TestCategory, batched_vector_relation_simd_float3) {
124 test_batched_vector_relation<TestDevice, SIMD<float>, 3>();
125 }
126 TEST_F(TestCategory, batched_vector_relation_simd_float8) {
127 test_batched_vector_relation<TestDevice, SIMD<float>, 8>();
128 }
129 #endif
130
131 #if defined(KOKKOSKERNELS_INST_DOUBLE)
132 TEST_F(TestCategory, batched_vector_relation_simd_double3) {
133 test_batched_vector_relation<TestDevice, SIMD<double>, 3>();
134 }
135 TEST_F(TestCategory, batched_vector_relation_simd_double4) {
136 test_batched_vector_relation<TestDevice, SIMD<double>, 4>();
137 }
138 #endif
139
140 /// comparison of complex variables is not defined
141
142 // #if defined(KOKKOSKERNELS_INST_COMPLEX_FLOAT)
143 // TEST_F( TestCategory, batched_vector_relation_simd_scomplex4 ) {
144 // test_batched_vector_relation<TestDevice,SIMD<Kokkos::complex<float>
145 // >,4>();
146 // }
147 // #endif
148
149 // #if defined(KOKKOSKERNELS_INST_COMPLEX_DOUBLE)
150 // TEST_F( TestCategory, batched_vector_relation_simd_dcomplex2 ) {
151 // test_batched_vector_relation<TestDevice,SIMD<Kokkos::complex<double>
152 // >,2>();
153 // }
154 // #endif
155
156 #endif // check to not include this in a device test