-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbadptr.cpp
More file actions
64 lines (55 loc) · 1.7 KB
/
badptr.cpp
File metadata and controls
64 lines (55 loc) · 1.7 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
#include "CL/sycl.hpp"
struct JustBool {
bool b;
};
struct WithPtr {
bool b;
void* p;
};
struct InUnion {
bool b;
union U { void* p; } u;
};
int main() {
cl::sycl::device device{cl::sycl::default_selector()};
cl::sycl::queue queue(device);
int i = 2;
JustBool jb{true};
WithPtr np{true, nullptr};
WithPtr wp{true, &i};
InUnion iu{true, {&i}};
{
cl::sycl::buffer<int, 1> ibuffer(&i, cl::sycl::range<1>(1));
queue.submit([&](cl::sycl::handler& cgh) {
auto iaccess =
ibuffer.get_access<cl::sycl::access::mode::discard_write>(cgh);
cgh.single_task([=]() {
if (jb.b) iaccess[0] = 3;
});
});
queue.submit([&](cl::sycl::handler& cgh) {
auto iaccess =
ibuffer.get_access<cl::sycl::access::mode::discard_write>(cgh);
cgh.single_task([=]() {
if (np.b) iaccess[0] = 5;
});
});
queue.submit([&](cl::sycl::handler& cgh) {
auto iaccess =
ibuffer.get_access<cl::sycl::access::mode::discard_write>(cgh);
cgh.single_task([=]() {
if (iu.b) iaccess[0] = 7;
});
});
// terminate called after throwing an instance of 'cl::sycl::runtime_error'
// what(): Native API failed. Native API returns: -30 (CL_INVALID_VALUE) -30 (CL_INVALID_VALUE)
queue.submit([&](cl::sycl::handler& cgh) {
auto iaccess =
ibuffer.get_access<cl::sycl::access::mode::discard_write>(cgh);
cgh.single_task([=]() {
if (wp.b) iaccess[0] = 11;
});
});
}
return 0;
}