|
| 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 <cstdio> |
| 6 | +#include <numeric> |
| 7 | +#include <algorithm> |
| 8 | +#include <CL/sycl.hpp> |
| 9 | + |
| 10 | +namespace { |
| 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>(); |
| 16 | + |
| 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()); |
| 20 | +} |
| 21 | + |
| 22 | +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 | + } |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +} |
| 35 | + |
| 36 | +int test(sycl::device & D) { |
| 37 | + sycl::context C ( D ); |
| 38 | + constexpr size_t N = 1024 * 1000; |
| 39 | + |
| 40 | + int * src = sycl::malloc_shared<int>(N, D, C); |
| 41 | + int * dst = sycl::malloc_shared<int>(N, D, C); |
| 42 | + |
| 43 | + std::iota(src, src + N, 0); |
| 44 | + std::fill(dst, dst + N, 0); |
| 45 | + |
| 46 | + for (int i = 0; i < 256; ++i) { |
| 47 | + sycl::queue Q { C , D, async_sycl_error };//, sycl::property::queue::enable_profiling() }; |
| 48 | + |
| 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 | + } |
| 57 | + |
| 58 | + sycl::free(dst, C); |
| 59 | + sycl::free(src, C); |
| 60 | + |
| 61 | + return 0; |
| 62 | +} |
| 63 | + |
| 64 | +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 | + } |
| 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; |
| 74 | +} |
| 75 | + |
0 commit comments