|
| 1 | +// REQUIRES: gpu |
| 2 | +// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out |
| 3 | +// RUN: %GPU_RUN_PLACEHOLDER %t.out |
| 4 | + |
| 5 | +#include <CL/sycl.hpp> |
| 6 | +#include <algorithm> |
| 7 | +#include <cstdio> |
| 8 | +#include <numeric> |
| 9 | + |
| 10 | +namespace { |
| 11 | + |
| 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>(); |
| 18 | + |
| 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()); |
| 22 | +} |
| 23 | + |
| 24 | +void async_sycl_error(cl::sycl::exception_list el) { |
| 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); |
| 32 | + } |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +} // namespace |
| 37 | + |
| 38 | +int test(sycl::device &D) { |
| 39 | + sycl::context C(D); |
| 40 | + constexpr size_t N = 1024 * 1000; |
| 41 | + |
| 42 | + int *src = sycl::malloc_shared<int>(N, D, C); |
| 43 | + int *dst = sycl::malloc_shared<int>(N, D, C); |
| 44 | + |
| 45 | + std::iota(src, src + N, 0); |
| 46 | + std::fill(dst, dst + N, 0); |
| 47 | + |
| 48 | + for (int i = 0; i < 256; ++i) { |
| 49 | + sycl::queue Q{ |
| 50 | + C, D, |
| 51 | + async_sycl_error}; //, sycl::property::queue::enable_profiling() }; |
| 52 | + |
| 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 | + } |
| 61 | + |
| 62 | + sycl::free(dst, C); |
| 63 | + sycl::free(src, C); |
| 64 | + |
| 65 | + return 0; |
| 66 | +} |
| 67 | + |
| 68 | +int main() { |
| 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); |
| 74 | + } |
| 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; |
| 80 | +} |
0 commit comments