|
2 | 2 | // RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
|
3 | 3 | // RUN: %GPU_RUN_PLACEHOLDER %t.out
|
4 | 4 |
|
| 5 | +#include <CL/sycl.hpp> |
| 6 | +#include <algorithm> |
5 | 7 | #include <cstdio>
|
6 | 8 | #include <numeric>
|
7 |
| -#include <algorithm> |
8 |
| -#include <CL/sycl.hpp> |
9 | 9 |
|
10 | 10 | namespace {
|
11 | 11 |
|
12 |
| -void print_device_properties(sycl::device const & dev) { |
13 |
| - auto plat_name = dev.get_platform().template get_info<sycl::info::platform::name>(); |
14 |
| - auto dev_name = dev.template get_info<sycl::info::device::name>(); |
15 |
| - auto driver_version = dev.template get_info<sycl::info::device::driver_version>(); |
| 12 | +void print_device_properties(sycl::device const &dev) { |
| 13 | + auto plat_name = |
| 14 | + dev.get_platform().template get_info<sycl::info::platform::name>(); |
| 15 | + auto dev_name = dev.template get_info<sycl::info::device::name>(); |
| 16 | + auto driver_version = |
| 17 | + dev.template get_info<sycl::info::device::driver_version>(); |
16 | 18 |
|
17 |
| - fprintf(stdout, " platform name: %s\n", plat_name.c_str()); |
18 |
| - fprintf(stdout, " device name: %s\n", dev_name.c_str()); |
19 |
| - fprintf(stdout, "driver version: %s\n", driver_version.c_str()); |
| 19 | + fprintf(stdout, " platform name: %s\n", plat_name.c_str()); |
| 20 | + fprintf(stdout, " device name: %s\n", dev_name.c_str()); |
| 21 | + fprintf(stdout, "driver version: %s\n", driver_version.c_str()); |
20 | 22 | }
|
21 | 23 |
|
22 | 24 | void async_sycl_error(cl::sycl::exception_list el) {
|
23 |
| - fprintf(stderr,"async exceptions caught:\n"); |
24 |
| - for (auto l = el.begin(); l != el.end(); ++l) { |
25 |
| - try { |
26 |
| - std::rethrow_exception(*l); |
27 |
| - } catch(const cl::sycl::exception & e) { |
28 |
| - fprintf(stderr, "what: %s code: %d\n", e.what(), e.get_cl_code()); |
29 |
| - std::exit(-1); |
30 |
| - } |
| 25 | + fprintf(stderr, "async exceptions caught:\n"); |
| 26 | + for (auto l = el.begin(); l != el.end(); ++l) { |
| 27 | + try { |
| 28 | + std::rethrow_exception(*l); |
| 29 | + } catch (const cl::sycl::exception &e) { |
| 30 | + fprintf(stderr, "what: %s code: %d\n", e.what(), e.get_cl_code()); |
| 31 | + std::exit(-1); |
31 | 32 | }
|
| 33 | + } |
32 | 34 | }
|
33 | 35 |
|
34 |
| -} |
| 36 | +} // namespace |
35 | 37 |
|
36 |
| -int test(sycl::device & D) { |
37 |
| - sycl::context C ( D ); |
38 |
| - constexpr size_t N = 1024 * 1000; |
| 38 | +int test(sycl::device &D) { |
| 39 | + sycl::context C(D); |
| 40 | + constexpr size_t N = 1024 * 1000; |
39 | 41 |
|
40 |
| - int * src = sycl::malloc_shared<int>(N, D, C); |
41 |
| - int * dst = sycl::malloc_shared<int>(N, D, C); |
| 42 | + int *src = sycl::malloc_shared<int>(N, D, C); |
| 43 | + int *dst = sycl::malloc_shared<int>(N, D, C); |
42 | 44 |
|
43 |
| - std::iota(src, src + N, 0); |
44 |
| - std::fill(dst, dst + N, 0); |
| 45 | + std::iota(src, src + N, 0); |
| 46 | + std::fill(dst, dst + N, 0); |
45 | 47 |
|
46 |
| - for (int i = 0; i < 256; ++i) { |
47 |
| - sycl::queue Q { C , D, async_sycl_error };//, sycl::property::queue::enable_profiling() }; |
| 48 | + for (int i = 0; i < 256; ++i) { |
| 49 | + sycl::queue Q{ |
| 50 | + C, D, |
| 51 | + async_sycl_error}; //, sycl::property::queue::enable_profiling() }; |
48 | 52 |
|
49 |
| - Q.submit([&](sycl::handler &SH) { |
50 |
| - sycl::range<1> r (N); |
51 |
| - SH.parallel_for<class X>(r, [=](sycl::id<1> id) { |
52 |
| - size_t i = id.get(0); |
53 |
| - dst[i] = src[i] + 1; |
54 |
| - }); |
55 |
| - }); |
56 |
| - } |
| 53 | + Q.submit([&](sycl::handler &SH) { |
| 54 | + sycl::range<1> r(N); |
| 55 | + SH.parallel_for<class X>(r, [=](sycl::id<1> id) { |
| 56 | + size_t i = id.get(0); |
| 57 | + dst[i] = src[i] + 1; |
| 58 | + }); |
| 59 | + }); |
| 60 | + } |
57 | 61 |
|
58 |
| - sycl::free(dst, C); |
59 |
| - sycl::free(src, C); |
| 62 | + sycl::free(dst, C); |
| 63 | + sycl::free(src, C); |
60 | 64 |
|
61 |
| - return 0; |
| 65 | + return 0; |
62 | 66 | }
|
63 | 67 |
|
64 | 68 | int main() {
|
65 |
| - try { |
66 |
| - sycl::device D1 { sycl::gpu_selector {} }; |
67 |
| - print_device_properties(D1); |
68 |
| - for (int i = 0; i < 10; ++i) { test(D1); } |
| 69 | + try { |
| 70 | + sycl::device D1{sycl::gpu_selector{}}; |
| 71 | + print_device_properties(D1); |
| 72 | + for (int i = 0; i < 10; ++i) { |
| 73 | + test(D1); |
69 | 74 | }
|
70 |
| - catch (sycl::exception & e) { |
71 |
| - fprintf(stderr, "...sycl failed to entertain with \"%s\" (%d) \n", e.what(), e.get_cl_code()); |
72 |
| - } |
73 |
| - return 0; |
| 75 | + } catch (sycl::exception &e) { |
| 76 | + fprintf(stderr, "...sycl failed to entertain with \"%s\" (%d) \n", e.what(), |
| 77 | + e.get_cl_code()); |
| 78 | + } |
| 79 | + return 0; |
74 | 80 | }
|
75 |
| - |
|
0 commit comments