forked from intel/llvm-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathretain_events.cpp
More file actions
80 lines (66 loc) · 2 KB
/
retain_events.cpp
File metadata and controls
80 lines (66 loc) · 2 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
77
78
79
80
// REQUIRES: gpu
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
#include <CL/sycl.hpp>
#include <algorithm>
#include <cstdio>
#include <numeric>
namespace {
void print_device_properties(sycl::device const &dev) {
auto plat_name =
dev.get_platform().template get_info<sycl::info::platform::name>();
auto dev_name = dev.template get_info<sycl::info::device::name>();
auto driver_version =
dev.template get_info<sycl::info::device::driver_version>();
fprintf(stdout, " platform name: %s\n", plat_name.c_str());
fprintf(stdout, " device name: %s\n", dev_name.c_str());
fprintf(stdout, "driver version: %s\n", driver_version.c_str());
}
void async_sycl_error(cl::sycl::exception_list el) {
fprintf(stderr, "async exceptions caught:\n");
for (auto l = el.begin(); l != el.end(); ++l) {
try {
std::rethrow_exception(*l);
} catch (const cl::sycl::exception &e) {
fprintf(stderr, "what: %s code: %d\n", e.what(), e.get_cl_code());
std::exit(-1);
}
}
}
} // namespace
int test(sycl::device &D) {
sycl::context C(D);
constexpr size_t N = 1024 * 1000;
int *src = sycl::malloc_shared<int>(N, D, C);
int *dst = sycl::malloc_shared<int>(N, D, C);
std::iota(src, src + N, 0);
std::fill(dst, dst + N, 0);
for (int i = 0; i < 256; ++i) {
sycl::queue Q{
C, D,
async_sycl_error}; //, sycl::property::queue::enable_profiling() };
Q.submit([&](sycl::handler &SH) {
sycl::range<1> r(N);
SH.parallel_for<class X>(r, [=](sycl::id<1> id) {
size_t i = id.get(0);
dst[i] = src[i] + 1;
});
});
}
sycl::free(dst, C);
sycl::free(src, C);
return 0;
}
int main() {
try {
sycl::device D1{sycl::gpu_selector{}};
print_device_properties(D1);
for (int i = 0; i < 10; ++i) {
test(D1);
}
} catch (sycl::exception &e) {
fprintf(stderr, "...sycl failed to entertain with \"%s\" (%d) \n", e.what(),
e.get_cl_code());
}
return 0;
}