forked from alpaka-group/alpaka3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhere.cpp
More file actions
53 lines (41 loc) · 1.54 KB
/
where.cpp
File metadata and controls
53 lines (41 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* Copyright 2026 René Widera
* SPDX-License-Identifier: MPL-2.0
*/
#include <alpaka/alpaka.hpp>
#include <catch2/catch_test_macros.hpp>
#include <cstdint>
#include <iostream>
#include <string>
#include <tuple>
/** @file
*
* This file is testing simd where expression
*/
TEST_CASE("simd where", "[simd vector]")
{
using namespace alpaka;
Simd<double, 8> a{1, 2, 3, 4, 5, 6, 7, 8};
Simd<double, 8> b{8, 7, 6, 5, 4, 3, 2, 1};
auto m = a > b;
auto m_reference = makeSimdMask<double>(false, false, false, false, true, true, true, true);
CHECK((m == m_reference).reduce(std::logical_and{}));
where(m, a) = b;
Simd<double, 8> a0_reference{1, 2, 3, 4, 4, 3, 2, 1};
CHECK((a == a0_reference).reduce(std::logical_and{}));
where(m, a) += b;
Simd<double, 8> a1_reference{1, 2, 3, 4, 8, 6, 4, 2};
CHECK((a == a1_reference).reduce(std::logical_and{}));
where(b >= 5., b) = 42.;
Simd<double, 8> b0_reference{42, 42, 42, 42, 4, 3, 2, 1};
CHECK((b == b0_reference).reduce(std::logical_and{}));
where(b >= 5., b) += 1.;
Simd<double, 8> b1_reference{43, 43, 43, 43, 4, 3, 2, 1};
CHECK((b == b1_reference).reduce(std::logical_and{}));
// test upcast of scalar values
where(b >= float{4}, b) = float{43};
Simd<double, 8> b2_reference{43, 43, 43, 43, 43, 3, 2, 1};
CHECK((b == b2_reference).reduce(std::logical_and{}));
where(b < float{4}, b) -= float{3};
Simd<double, 8> b3_reference{43, 43, 43, 43, 43, 0, -1, -2};
CHECK((b == b3_reference).reduce(std::logical_and{}));
}