forked from kokkos/kokkos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestMDRangePolicyConstructors.hpp
144 lines (124 loc) · 5.39 KB
/
TestMDRangePolicyConstructors.hpp
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//@HEADER
// ************************************************************************
//
// Kokkos v. 4.0
// Copyright (2022) National Technology & Engineering
// Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//@HEADER
#include <gtest/gtest.h>
#include <Kokkos_Core.hpp>
#include <regex>
namespace {
template <class IndexType>
void construct_mdrange_policy_variable_type() {
(void)Kokkos::MDRangePolicy<TEST_EXECSPACE, Kokkos::Rank<2>>{
Kokkos::Array<IndexType, 2>{}, Kokkos::Array<IndexType, 2>{}};
(void)Kokkos::MDRangePolicy<TEST_EXECSPACE, Kokkos::Rank<2>>{
{{IndexType(0), IndexType(0)}}, {{IndexType(2), IndexType(2)}}};
(void)Kokkos::MDRangePolicy<TEST_EXECSPACE, Kokkos::Rank<2>>{
{IndexType(0), IndexType(0)}, {IndexType(2), IndexType(2)}};
}
TEST(TEST_CATEGORY, md_range_policy_construction_from_arrays) {
{
// Check that construction from Kokkos::Array of the specified index type
// works.
using IndexType = unsigned long long;
Kokkos::MDRangePolicy<TEST_EXECSPACE, Kokkos::Rank<2>,
Kokkos::IndexType<IndexType>>
p1(Kokkos::Array<IndexType, 2>{{0, 1}},
Kokkos::Array<IndexType, 2>{{2, 3}});
Kokkos::MDRangePolicy<TEST_EXECSPACE, Kokkos::Rank<2>,
Kokkos::IndexType<IndexType>>
p2(Kokkos::Array<IndexType, 2>{{0, 1}},
Kokkos::Array<IndexType, 2>{{2, 3}});
Kokkos::MDRangePolicy<TEST_EXECSPACE, Kokkos::Rank<2>,
Kokkos::IndexType<IndexType>>
p3(Kokkos::Array<IndexType, 2>{{0, 1}},
Kokkos::Array<IndexType, 2>{{2, 3}},
Kokkos::Array<IndexType, 1>{{4}});
}
{
// Check that construction from double-braced initializer list
// works.
using index_type = unsigned long long;
Kokkos::MDRangePolicy<TEST_EXECSPACE, Kokkos::Rank<2>> p1({{0, 1}},
{{2, 3}});
Kokkos::MDRangePolicy<TEST_EXECSPACE, Kokkos::Rank<2>,
Kokkos::IndexType<index_type>>
p2({{0, 1}}, {{2, 3}});
}
{
// Check that construction from Kokkos::Array of long compiles for backwards
// compability. This was broken in
// https://github.com/kokkos/kokkos/pull/3527/commits/88ea8eec6567c84739d77bdd25fdbc647fae28bb#r512323639
Kokkos::MDRangePolicy<TEST_EXECSPACE, Kokkos::Rank<2>> p1(
Kokkos::Array<long, 2>{{0, 1}}, Kokkos::Array<long, 2>{{2, 3}});
Kokkos::MDRangePolicy<TEST_EXECSPACE, Kokkos::Rank<2>> p2(
Kokkos::Array<long, 2>{{0, 1}}, Kokkos::Array<long, 2>{{2, 3}});
Kokkos::MDRangePolicy<TEST_EXECSPACE, Kokkos::Rank<2>> p3(
Kokkos::Array<long, 2>{{0, 1}}, Kokkos::Array<long, 2>{{2, 3}},
Kokkos::Array<long, 1>{{4}});
}
// Check that construction from various index types works.
construct_mdrange_policy_variable_type<char>();
construct_mdrange_policy_variable_type<int>();
construct_mdrange_policy_variable_type<unsigned long>();
construct_mdrange_policy_variable_type<std::int64_t>();
}
#ifndef KOKKOS_ENABLE_OPENMPTARGET // FIXME_OPENMPTARGET
TEST(TEST_CATEGORY_DEATH, policy_bounds_unsafe_narrowing_conversions) {
using Policy = Kokkos::MDRangePolicy<TEST_EXECSPACE, Kokkos::Rank<2>,
Kokkos::IndexType<unsigned>>;
std::string msg =
"Kokkos::MDRangePolicy bound type error: an unsafe implicit conversion "
"is "
"performed on a bound (-1) in dimension (0), which may not preserve its "
"original value.\n";
std::string expected = std::regex_replace(msg, std::regex("\\(|\\)"), "\\$&");
::testing::FLAGS_gtest_death_test_style = "threadsafe";
ASSERT_DEATH({ (void)Policy({-1, 0}, {2, 3}); }, expected);
}
TEST(TEST_CATEGORY_DEATH, policy_invalid_bounds) {
using Policy = Kokkos::MDRangePolicy<TEST_EXECSPACE, Kokkos::Rank<2>>;
::testing::FLAGS_gtest_death_test_style = "threadsafe";
auto [dim0, dim1] = (Policy::inner_direction == Kokkos::Iterate::Right)
? std::make_pair(1, 0)
: std::make_pair(0, 1);
std::string msg1 =
"Kokkos::MDRangePolicy bounds error: The lower bound (100) is greater "
"than its upper bound (90) in dimension " +
std::to_string(dim0) + ".\n";
std::string msg2 =
"Kokkos::MDRangePolicy bounds error: The lower bound (100) is greater "
"than its upper bound (90) in dimension " +
std::to_string(dim1) + ".\n";
#if !defined(KOKKOS_ENABLE_DEPRECATED_CODE_4)
// escape the parentheses in the regex to match the error message
msg1 = std::regex_replace(msg1, std::regex("\\(|\\)"), "\\$&");
(void)msg2;
ASSERT_DEATH({ (void)Policy({100, 100}, {90, 90}); }, msg1);
#else
if (!Kokkos::show_warnings()) {
GTEST_SKIP() << "Kokkos warning messages are disabled";
}
::testing::internal::CaptureStderr();
(void)Policy({100, 100}, {90, 90});
#ifdef KOKKOS_ENABLE_DEPRECATION_WARNINGS
ASSERT_EQ(::testing::internal::GetCapturedStderr(), msg1 + msg2);
#else
ASSERT_TRUE(::testing::internal::GetCapturedStderr().empty());
(void)msg1;
(void)msg2;
#endif
#endif
}
#endif
} // namespace