|
| 1 | +// REQUIRES: cpu, accelerator, aoc |
| 2 | + |
| 3 | +// UNSUPPORTED: cuda, level_zero |
| 4 | + |
| 5 | +// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -fsycl-targets=%sycl_triple %s -o %t1.out |
| 6 | +// RUN: %CPU_RUN_PLACEHOLDER CL_CONFIG_CPU_EMULATE_DEVICES=2 %t1.out |
| 7 | +// RUN: %CPU_RUN_PLACEHOLDER CL_CONFIG_CPU_EMULATE_DEVICES=4 %t1.out |
| 8 | +// RUN: %clangxx -fsycl -fintelfpga -fsycl-unnamed-lambda %s -o %t2.out |
| 9 | +// RUN: %ACC_RUN_PLACEHOLDER CL_CONFIG_CPU_EMULATE_DEVICES=2 %t2.out |
| 10 | + |
| 11 | +#include <CL/sycl.hpp> |
| 12 | + |
| 13 | +void exceptionHandler(sycl::exception_list exceptions) { |
| 14 | + for (std::exception_ptr const &e : exceptions) { |
| 15 | + try { |
| 16 | + std::rethrow_exception(e); |
| 17 | + } catch (sycl::exception const &e) { |
| 18 | + std::cerr << "Caught asynchronous SYCL exception:\n" |
| 19 | + << e.what() << std::endl; |
| 20 | + } |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +int main() { |
| 25 | + auto DeviceList = sycl::device::get_devices(); |
| 26 | + |
| 27 | + // remove host device from the list |
| 28 | + DeviceList.erase(std::remove_if(DeviceList.begin(), DeviceList.end(), |
| 29 | + [](auto Device) { return Device.is_host(); }), |
| 30 | + DeviceList.end()); |
| 31 | + |
| 32 | + sycl::context Context(DeviceList, &exceptionHandler); |
| 33 | + |
| 34 | + std::vector<sycl::queue> QueueList; |
| 35 | + for (const auto &Device : Context.get_devices()) { |
| 36 | + QueueList.emplace_back(Context, Device, &exceptionHandler); |
| 37 | + } |
| 38 | + |
| 39 | + for (auto &Queue : QueueList) { |
| 40 | + Queue.submit( |
| 41 | + [&](sycl::handler &cgh) { cgh.parallel_for(100, [=](auto i) {}); }); |
| 42 | + } |
| 43 | + |
| 44 | + return 0; |
| 45 | +} |
0 commit comments