Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 99c83d3

Browse files
authored
Guard double type usage with aspect::fp64 check in invoke_simd_conv.cpp (#1366)
Signed-off-by: Konstantin S Bobrovsky <[email protected]>
1 parent b279d46 commit 99c83d3

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

SYCL/InvokeSimd/invoke_simd_conv.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ inline auto createExceptionHandler() {
8686
template <class, class, bool> class TestID;
8787

8888
template <class SpmdT, class SimdElemT, bool IsUniform> bool test(queue q) {
89+
std::cout << "Testing SpmdT='" << typeid(SpmdT).name() << "', SimdElemT='"
90+
<< typeid(SimdElemT).name() << "', uniform=" << IsUniform << "... ";
91+
8992
// 3 subgroups per workgroup
9093
unsigned GroupSize = VL * 3;
9194
unsigned NGroups = 7;
@@ -121,6 +124,7 @@ template <class SpmdT, class SimdElemT, bool IsUniform> bool test(queue q) {
121124
} catch (sycl::exception const &e) {
122125
std::cout << "SYCL exception caught: " << e.what() << '\n';
123126
sycl::free(A, q);
127+
std::cout << "failed\n";
124128
return false;
125129
}
126130
int err_cnt = 0;
@@ -141,6 +145,7 @@ template <class SpmdT, class SimdElemT, bool IsUniform> bool test(queue q) {
141145
<< (Size - err_cnt) << "/" << Size << ")\n";
142146
}
143147
sycl::free(A, q);
148+
std::cout << (err_cnt ? "failed\n" : "passed\n");
144149
return err_cnt == 0;
145150
}
146151

@@ -155,26 +160,38 @@ int main(void) {
155160
constexpr bool UNIFORM = true;
156161
constexpr bool NON_UNIFORM = false;
157162

163+
const bool SupportsDouble = dev.has(aspect::fp64);
164+
158165
// With uniform parameters SPMD actual argument corresponds to SIMD scalar
159166
// argument, and standard C++ arithmetic conversion are implicitly
160167
// applied by the compiler. Any aritimetic type can be implicitly coverted to
161168
// any other arithmetic type.
162169

170+
#ifndef TEST_DOUBLE_TYPE
163171
passed &= test<int, float, UNIFORM>(q);
164172
passed &= test<unsigned char, uint64_t, UNIFORM>(q);
165-
passed &= test<char, double, UNIFORM>(q);
166-
passed &= test<double, char, UNIFORM>(q);
173+
#else
174+
if (SupportsDouble) {
175+
passed &= test<char, double, UNIFORM>(q);
176+
passed &= test<double, char, UNIFORM>(q);
177+
}
178+
#endif // TEST_DOUBLE_TYPE
167179

168180
// With non-uniform parameters, SPMD actual argument of type T is "widened" to
169181
// std::simd<T, VL> and then convered to SIMD vector argument
170182
// (std::simd<T1, VL>) using std::simd implicit conversion constructors. They
171183
// allow only non-narrowing conversions (e.g. int -> float is narrowing and
172184
// hence is prohibited).
173185

186+
#ifndef TEST_DOUBLE_TYPE
174187
passed &= test<char, long, NON_UNIFORM>(q);
175188
passed &= test<short, short, NON_UNIFORM>(q);
176-
passed &= test<float, double, NON_UNIFORM>(q);
189+
#else
190+
if (SupportsDouble) {
191+
passed &= test<float, double, NON_UNIFORM>(q);
192+
}
193+
#endif // TEST_DOUBLE_TYPE
177194

178-
std::cout << (passed ? "Passed\n" : "FAILED\n");
195+
std::cout << (passed ? "Test passed\n" : "TEST FAILED\n");
179196
return passed ? 0 : 1;
180197
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// The test checks that invoke_simd implementation performs proper conversions
2+
// on the actual arguments of 'double' type.
3+
4+
// TODO: enable on Windows once driver is ready
5+
// REQUIRES: gpu && linux
6+
// UNSUPPORTED: cuda || hip
7+
8+
// RUN: %clangxx -fsycl -fno-sycl-device-code-split-esimd -Xclang -fsycl-allow-func-ptr %s -o %t.out
9+
// RUN: env IGC_VCSaveStackCallLinkage=1 IGC_VCDirectCallsOnly=1 %GPU_RUN_PLACEHOLDER %t.out
10+
11+
#define TEST_DOUBLE_TYPE
12+
#include "invoke_simd_conv.cpp"

0 commit comments

Comments
 (0)