forked from alpaka-group/alpaka3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimdMask.cpp
More file actions
76 lines (65 loc) · 2.45 KB
/
simdMask.cpp
File metadata and controls
76 lines (65 loc) · 2.45 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/* Copyright 2024 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 mask functionality.
* We do not use constexpr because depending on the implementation the underlying native types are not constexpr.
* At least in any case the constructor of std::simd_mask is not constexpr.
*/
TEST_CASE("simd mask 1D", "[simd mask vector]")
{
using namespace alpaka;
auto mask = makeSimdMask<int>(true);
CHECK(mask.width() == 1);
CHECK(mask.x() == true);
CHECK((mask == makeSimdMask<int>(true)).reduce(std::logical_and{}));
auto typeLambda = [](auto const typeDummy)
{
using type = std::decay_t<decltype(typeDummy)>;
constexpr type falseValue = type{0};
constexpr type trueValue = std::numeric_limits<type>::max();
auto inputData = std::make_tuple(
std::make_tuple(
std::logical_and{},
makeSimdMask<type>(true),
makeSimdMask<type>(true),
makeSimdMask<type>(true)),
std::make_tuple(
std::logical_and{},
makeSimdMask<type>(false),
makeSimdMask<type>(true),
makeSimdMask<type>(false)),
std::make_tuple(
std::logical_and{},
SimdMask(trueValue),
makeSimdMask<type>(true),
makeSimdMask<type>(true)),
std::make_tuple(
std::logical_and{},
SimdMask(falseValue),
makeSimdMask<type>(true),
makeSimdMask<type>(false)),
std::make_tuple(std::logical_and{}, SimdMask(falseValue), SimdMask(falseValue), SimdMask(falseValue)),
std::make_tuple(std::logical_and{}, SimdMask(trueValue), SimdMask(trueValue), SimdMask(trueValue)));
bool x = std::apply(
[&](auto... args)
{
return (
(std::get<0>(args)(std::get<1>(args), std::get<2>(args)) == std::get<3>(args))
.reduce(std::logical_and{})
&& ...);
},
inputData);
return x;
};
constexpr auto inputTypes = std::tuple<uint32_t, uint64_t>{};
bool x = std::apply([&](auto... args) { return (typeLambda(args) && ...); }, inputTypes);
CHECK(x);
}