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

Commit 20117af

Browse files
author
Pavel Samolysov
authored
[SYCL] Add support for the generic address space in tests for sycl::atomic_ref (#619)
Unfortunately, the CUDA backend in DPCPP has had no generic address space support yet. The tests for the generic address space must fail on the CUDA backend. To let us mark these tests as expectedly failed, the tests should be moved to separated .cpp files. Signed-off-by: Pavel Samolysov <pavel.samolysov@intel.com>
1 parent 314e938 commit 20117af

37 files changed

+1128
-103
lines changed

SYCL/AtomicRef/add.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ using namespace sycl;
1111

1212
// Floating-point types do not support pre- or post-increment
1313
template <> void add_test<float>(queue q, size_t N) {
14-
add_fetch_test<::sycl::ext::oneapi::atomic_ref, float>(q, N);
15-
add_fetch_test<::sycl::atomic_ref, float>(q, N);
16-
add_plus_equal_test<::sycl::ext::oneapi::atomic_ref, float>(q, N);
17-
add_plus_equal_test<::sycl::atomic_ref, float>(q, N);
14+
add_fetch_test<::sycl::ext::oneapi::atomic_ref,
15+
access::address_space::global_space, float>(q, N);
16+
add_fetch_test<::sycl::atomic_ref, access::address_space::global_space,
17+
float>(q, N);
18+
add_plus_equal_test<::sycl::ext::oneapi::atomic_ref,
19+
access::address_space::global_space, float>(q, N);
20+
add_plus_equal_test<::sycl::atomic_ref, access::address_space::global_space,
21+
float>(q, N);
1822
}
1923

2024
int main() {

SYCL/AtomicRef/add.h

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ using namespace sycl::ext::oneapi;
1111

1212
template <template <typename, memory_order, memory_scope, access::address_space>
1313
class AtomicRef,
14-
typename T, typename Difference = T>
14+
access::address_space address_space, typename T,
15+
typename Difference = T>
1516
void add_fetch_test(queue q, size_t N) {
1617
T sum = 0;
1718
std::vector<T> output(N);
@@ -27,7 +28,7 @@ void add_fetch_test(queue q, size_t N) {
2728
cgh.parallel_for(range<1>(N), [=](item<1> it) {
2829
int gid = it.get_id(0);
2930
auto atm = AtomicRef<T, memory_order::relaxed, memory_scope::device,
30-
access::address_space::global_space>(sum[0]);
31+
address_space>(sum[0]);
3132
out[gid] = atm.fetch_add(Difference(1));
3233
});
3334
});
@@ -48,7 +49,8 @@ void add_fetch_test(queue q, size_t N) {
4849

4950
template <template <typename, memory_order, memory_scope, access::address_space>
5051
class AtomicRef,
51-
typename T, typename Difference = T>
52+
access::address_space address_space, typename T,
53+
typename Difference = T>
5254
void add_plus_equal_test(queue q, size_t N) {
5355
T sum = 0;
5456
std::vector<T> output(N);
@@ -64,7 +66,7 @@ void add_plus_equal_test(queue q, size_t N) {
6466
cgh.parallel_for(range<1>(N), [=](item<1> it) {
6567
int gid = it.get_id(0);
6668
auto atm = AtomicRef<T, memory_order::relaxed, memory_scope::device,
67-
access::address_space::global_space>(sum[0]);
69+
address_space>(sum[0]);
6870
out[gid] = atm += Difference(1);
6971
});
7072
});
@@ -85,7 +87,8 @@ void add_plus_equal_test(queue q, size_t N) {
8587

8688
template <template <typename, memory_order, memory_scope, access::address_space>
8789
class AtomicRef,
88-
typename T, typename Difference = T>
90+
access::address_space address_space, typename T,
91+
typename Difference = T>
8992
void add_pre_inc_test(queue q, size_t N) {
9093
T sum = 0;
9194
std::vector<T> output(N);
@@ -101,7 +104,7 @@ void add_pre_inc_test(queue q, size_t N) {
101104
cgh.parallel_for(range<1>(N), [=](item<1> it) {
102105
int gid = it.get_id(0);
103106
auto atm = AtomicRef<T, memory_order::relaxed, memory_scope::device,
104-
access::address_space::global_space>(sum[0]);
107+
address_space>(sum[0]);
105108
out[gid] = ++atm;
106109
});
107110
});
@@ -122,7 +125,8 @@ void add_pre_inc_test(queue q, size_t N) {
122125

123126
template <template <typename, memory_order, memory_scope, access::address_space>
124127
class AtomicRef,
125-
typename T, typename Difference = T>
128+
access::address_space address_space, typename T,
129+
typename Difference = T>
126130
void add_post_inc_test(queue q, size_t N) {
127131
T sum = 0;
128132
std::vector<T> output(N);
@@ -138,7 +142,7 @@ void add_post_inc_test(queue q, size_t N) {
138142
cgh.parallel_for(range<1>(N), [=](item<1> it) {
139143
int gid = it.get_id(0);
140144
auto atm = AtomicRef<T, memory_order::relaxed, memory_scope::device,
141-
access::address_space::global_space>(sum[0]);
145+
address_space>(sum[0]);
142146
out[gid] = atm++;
143147
});
144148
});
@@ -159,12 +163,34 @@ void add_post_inc_test(queue q, size_t N) {
159163

160164
template <typename T, typename Difference = T>
161165
void add_test(queue q, size_t N) {
162-
add_fetch_test<::sycl::ext::oneapi::atomic_ref, T, Difference>(q, N);
163-
add_fetch_test<::sycl::atomic_ref, T, Difference>(q, N);
164-
add_plus_equal_test<::sycl::ext::oneapi::atomic_ref, T, Difference>(q, N);
165-
add_plus_equal_test<::sycl::atomic_ref, T, Difference>(q, N);
166-
add_pre_inc_test<::sycl::ext::oneapi::atomic_ref, T, Difference>(q, N);
167-
add_pre_inc_test<::sycl::atomic_ref, T, Difference>(q, N);
168-
add_post_inc_test<::sycl::ext::oneapi::atomic_ref, T, Difference>(q, N);
169-
add_post_inc_test<::sycl::atomic_ref, T, Difference>(q, N);
166+
add_fetch_test<::sycl::ext::oneapi::atomic_ref,
167+
access::address_space::global_space, T, Difference>(q, N);
168+
add_fetch_test<::sycl::atomic_ref, access::address_space::global_space, T,
169+
Difference>(q, N);
170+
add_plus_equal_test<::sycl::ext::oneapi::atomic_ref,
171+
access::address_space::global_space, T, Difference>(q, N);
172+
add_plus_equal_test<::sycl::atomic_ref, access::address_space::global_space,
173+
T, Difference>(q, N);
174+
add_pre_inc_test<::sycl::ext::oneapi::atomic_ref,
175+
access::address_space::global_space, T, Difference>(q, N);
176+
add_pre_inc_test<::sycl::atomic_ref, access::address_space::global_space, T,
177+
Difference>(q, N);
178+
add_post_inc_test<::sycl::ext::oneapi::atomic_ref,
179+
access::address_space::global_space, T, Difference>(q, N);
180+
add_post_inc_test<::sycl::atomic_ref, access::address_space::global_space, T,
181+
Difference>(q, N);
182+
}
183+
184+
template <typename T, typename Difference = T>
185+
void add_generic_test(queue q, size_t N) {
186+
add_fetch_test<::sycl::atomic_ref, access::address_space::generic_space, T,
187+
Difference>(q, N);
188+
add_plus_equal_test<::sycl::atomic_ref, access::address_space::generic_space,
189+
T, Difference>(q, N);
190+
add_pre_inc_test<::sycl::atomic_ref, access::address_space::generic_space, T,
191+
Difference>(q, N);
192+
add_post_inc_test<::sycl::atomic_ref, access::address_space::generic_space, T,
193+
Difference>(q, N);
194+
add_post_inc_test<::sycl::atomic_ref, access::address_space::global_space, T,
195+
Difference>(q, N);
170196
}

SYCL/AtomicRef/add_atomic64.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ using namespace sycl;
1111

1212
// Floating-point types do not support pre- or post-increment
1313
template <> void add_test<double>(queue q, size_t N) {
14-
add_fetch_test<::sycl::ext::oneapi::atomic_ref, double>(q, N);
15-
add_fetch_test<::sycl::atomic_ref, double>(q, N);
16-
add_plus_equal_test<::sycl::ext::oneapi::atomic_ref, double>(q, N);
17-
add_plus_equal_test<::sycl::atomic_ref, double>(q, N);
14+
add_fetch_test<::sycl::ext::oneapi::atomic_ref,
15+
access::address_space::global_space, double>(q, N);
16+
add_fetch_test<::sycl::atomic_ref, access::address_space::global_space,
17+
double>(q, N);
18+
add_plus_equal_test<::sycl::ext::oneapi::atomic_ref,
19+
access::address_space::global_space, double>(q, N);
20+
add_plus_equal_test<::sycl::atomic_ref, access::address_space::global_space,
21+
double>(q, N);
1822
}
1923

2024
int main() {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -fsycl-targets=%sycl_triple %s -o %t.out \
2+
// RUN: -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_60
3+
// RUN: %HOST_RUN_PLACEHOLDER %t.out
4+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
5+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
6+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
7+
8+
// CUDA backend has had no support for the generic address space yet
9+
// XFAIL: cuda
10+
11+
#include "add.h"
12+
#include <iostream>
13+
using namespace sycl;
14+
15+
// Floating-point types do not support pre- or post-increment
16+
template <> void add_generic_test<double>(queue q, size_t N) {
17+
add_fetch_test<::sycl::atomic_ref, access::address_space::generic_space,
18+
double>(q, N);
19+
add_plus_equal_test<::sycl::atomic_ref, access::address_space::generic_space,
20+
double>(q, N);
21+
}
22+
23+
int main() {
24+
queue q;
25+
26+
if (!q.get_device().has(aspect::atomic64)) {
27+
std::cout << "Skipping test\n";
28+
return 0;
29+
}
30+
31+
constexpr int N = 32;
32+
add_generic_test<double>(q, N);
33+
34+
// Include long tests if they are 64 bits wide
35+
if constexpr (sizeof(long) == 8) {
36+
add_generic_test<long>(q, N);
37+
add_generic_test<unsigned long>(q, N);
38+
}
39+
40+
// Include long long tests if they are 64 bits wide
41+
if constexpr (sizeof(long long) == 8) {
42+
add_generic_test<long long>(q, N);
43+
add_generic_test<unsigned long long>(q, N);
44+
}
45+
46+
// Include pointer tests if they are 64 bits wide
47+
if constexpr (sizeof(char *) == 8) {
48+
add_generic_test<char *, ptrdiff_t>(q, N);
49+
}
50+
51+
std::cout << "Test passed." << std::endl;
52+
}

SYCL/AtomicRef/add_generic.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -fsycl-targets=%sycl_triple %s -o %t.out \
2+
// RUN: -Xsycl-target-backend=nvptx64-nvidia-cuda --cuda-gpu-arch=sm_60
3+
// RUN: %HOST_RUN_PLACEHOLDER %t.out
4+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
5+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
6+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
7+
8+
// CUDA backend has had no support for the generic address space yet
9+
// XFAIL: cuda
10+
11+
#include "add.h"
12+
#include <iostream>
13+
using namespace sycl;
14+
15+
// Floating-point types do not support pre- or post-increment
16+
template <> void add_generic_test<float>(queue q, size_t N) {
17+
add_fetch_test<::sycl::atomic_ref, access::address_space::generic_space,
18+
float>(q, N);
19+
add_plus_equal_test<::sycl::atomic_ref, access::address_space::generic_space,
20+
float>(q, N);
21+
}
22+
23+
int main() {
24+
queue q;
25+
26+
constexpr int N = 32;
27+
add_generic_test<int>(q, N);
28+
add_generic_test<unsigned int>(q, N);
29+
add_generic_test<float>(q, N);
30+
31+
// Include long tests if they are 32 bits wide
32+
if constexpr (sizeof(long) == 4) {
33+
add_generic_test<long>(q, N);
34+
add_generic_test<unsigned long>(q, N);
35+
}
36+
37+
// Include pointer tests if they are 32 bits wide
38+
if constexpr (sizeof(char *) == 4) {
39+
add_generic_test<char *, ptrdiff_t>(q, N);
40+
}
41+
42+
std::cout << "Test passed." << std::endl;
43+
}

SYCL/AtomicRef/assignment.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ using namespace sycl::ext::oneapi;
1111

1212
template <template <typename, memory_order, memory_scope, access::address_space>
1313
class AtomicRef,
14-
typename T>
14+
access::address_space address_space, typename T>
1515
class assignment_kernel;
1616

1717
template <template <typename, memory_order, memory_scope, access::address_space>
1818
class AtomicRef,
19-
typename T>
19+
access::address_space address_space, typename T>
2020
void assignment_test(queue q, size_t N) {
2121
T initial = T(N);
2222
T assignment = initial;
@@ -25,11 +25,11 @@ void assignment_test(queue q, size_t N) {
2525
q.submit([&](handler &cgh) {
2626
auto st =
2727
assignment_buf.template get_access<access::mode::read_write>(cgh);
28-
cgh.parallel_for<assignment_kernel<AtomicRef, T>>(
28+
cgh.parallel_for<assignment_kernel<AtomicRef, address_space, T>>(
2929
range<1>(N), [=](item<1> it) {
3030
size_t gid = it.get_id(0);
3131
auto atm = AtomicRef<T, memory_order::relaxed, memory_scope::device,
32-
access::address_space::global_space>(st[0]);
32+
address_space>(st[0]);
3333
atm = T(gid);
3434
});
3535
});
@@ -42,6 +42,13 @@ void assignment_test(queue q, size_t N) {
4242
}
4343

4444
template <typename T> void assignment_test(queue q, size_t N) {
45-
assignment_test<::sycl::ext::oneapi::atomic_ref, T>(q, N);
46-
assignment_test<::sycl::atomic_ref, T>(q, N);
45+
assignment_test<::sycl::ext::oneapi::atomic_ref,
46+
access::address_space::global_space, T>(q, N);
47+
assignment_test<::sycl::atomic_ref, access::address_space::global_space, T>(
48+
q, N);
49+
}
50+
51+
template <typename T> void assignment_generic_test(queue q, size_t N) {
52+
assignment_test<::sycl::atomic_ref, access::address_space::generic_space, T>(
53+
q, N);
4754
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// RUN: %HOST_RUN_PLACEHOLDER %t.out
3+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
4+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
5+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
6+
7+
// CUDA backend has had no support for the generic address space yet
8+
// XFAIL: cuda
9+
10+
#include "assignment.h"
11+
#include <iostream>
12+
using namespace sycl;
13+
14+
int main() {
15+
queue q;
16+
17+
if (!q.get_device().has(aspect::atomic64)) {
18+
std::cout << "Skipping test\n";
19+
return 0;
20+
}
21+
22+
constexpr int N = 32;
23+
assignment_generic_test<double>(q, N);
24+
25+
// Include long tests if they are 64 bits wide
26+
if constexpr (sizeof(long) == 8) {
27+
assignment_generic_test<long>(q, N);
28+
assignment_generic_test<unsigned long>(q, N);
29+
}
30+
31+
// Include long long tests if they are 64 bits wide
32+
if constexpr (sizeof(long long) == 8) {
33+
assignment_generic_test<long long>(q, N);
34+
assignment_generic_test<unsigned long long>(q, N);
35+
}
36+
37+
// Include pointer tests if they are 64 bits wide
38+
if constexpr (sizeof(char *) == 8) {
39+
assignment_generic_test<char *>(q, N);
40+
}
41+
42+
std::cout << "Test passed." << std::endl;
43+
}

SYCL/AtomicRef/assignment_generic.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// RUN: %HOST_RUN_PLACEHOLDER %t.out
3+
// RUN: %CPU_RUN_PLACEHOLDER %t.out
4+
// RUN: %GPU_RUN_PLACEHOLDER %t.out
5+
// RUN: %ACC_RUN_PLACEHOLDER %t.out
6+
7+
// CUDA backend has had no support for the generic address space yet
8+
// XFAIL: cuda
9+
10+
#include "assignment.h"
11+
#include <iostream>
12+
using namespace sycl;
13+
14+
int main() {
15+
queue q;
16+
17+
constexpr int N = 32;
18+
assignment_generic_test<int>(q, N);
19+
assignment_generic_test<unsigned int>(q, N);
20+
assignment_generic_test<float>(q, N);
21+
22+
// Include long tests if they are 32 bits wide
23+
if constexpr (sizeof(long) == 4) {
24+
assignment_generic_test<long>(q, N);
25+
assignment_generic_test<unsigned long>(q, N);
26+
}
27+
28+
// Include pointer tests if they are 32 bits wide
29+
if constexpr (sizeof(char *) == 4) {
30+
assignment_generic_test<char *>(q, N);
31+
}
32+
33+
std::cout << "Test passed." << std::endl;
34+
}

0 commit comments

Comments
 (0)