|
| 1 | +// RUN: %{build} -o %t.out |
| 2 | +// RUN: %{run} %t.out |
| 3 | + |
| 4 | +#include <iostream> |
| 5 | +#include <sycl/atomic_ref.hpp> |
| 6 | +#include <sycl/detail/core.hpp> |
| 7 | +#include <sycl/usm.hpp> |
| 8 | + |
| 9 | +int main() { |
| 10 | + |
| 11 | + sycl::device dev; |
| 12 | + sycl::queue q(dev); |
| 13 | + auto ctxt = q.get_context(); |
| 14 | + |
| 15 | + // This test does not validate any output |
| 16 | + // Only that the work_item scope does not error |
| 17 | + try { |
| 18 | + |
| 19 | + // Allocate device memory |
| 20 | + int *data = sycl::malloc_device<int>(1, q); |
| 21 | + |
| 22 | + q.submit([&](sycl::handler &cgh) { |
| 23 | + cgh.parallel_for(10, [=](sycl::id<> id) { |
| 24 | + data[0] = 0; |
| 25 | + |
| 26 | + // Check atomic_ref functionality |
| 27 | + sycl::atomic_ref<int, sycl::memory_order::relaxed, |
| 28 | + sycl::memory_scope::work_item, |
| 29 | + sycl::access::address_space::generic_space> |
| 30 | + at(data[0]); |
| 31 | + |
| 32 | + auto lock = at.is_lock_free(); |
| 33 | + at.store(1); |
| 34 | + auto load = at.load(); |
| 35 | + auto xch = at.exchange(2); |
| 36 | + auto weak = |
| 37 | + at.compare_exchange_weak(data[0], 3, sycl::memory_order::relaxed, |
| 38 | + sycl::memory_order::relaxed); |
| 39 | + auto strong = |
| 40 | + at.compare_exchange_strong(data[0], 4, sycl::memory_order::relaxed, |
| 41 | + sycl::memory_order::relaxed); |
| 42 | + auto fetch_add = at.fetch_add(5); |
| 43 | + auto fetch_sub = at.fetch_sub(6); |
| 44 | + auto fetch_and = at.fetch_and(7); |
| 45 | + auto fetch_or = at.fetch_or(8); |
| 46 | + auto fetch_xor = at.fetch_xor(9); |
| 47 | + auto fetch_min = at.fetch_min(10); |
| 48 | + auto fetch_max = at.fetch_max(11); |
| 49 | + }); |
| 50 | + }); |
| 51 | + q.wait_and_throw(); |
| 52 | + |
| 53 | + sycl::free(data, q); |
| 54 | + |
| 55 | + } catch (sycl::exception e) { |
| 56 | + std::cerr << "SYCL exception caught! : " << e.what() << "\n"; |
| 57 | + return 1; |
| 58 | + } catch (...) { |
| 59 | + std::cerr << "Unknown exception caught!\n"; |
| 60 | + return 2; |
| 61 | + } |
| 62 | + |
| 63 | + std::cout << "Test passed!" << std::endl; |
| 64 | + return 0; |
| 65 | +} |
0 commit comments