|
| 1 | +// REQUIRES: aspect-usm_shared_allocations |
| 2 | + |
| 3 | +// RUN: %{build} -o %t.out |
| 4 | +// RUN: %{run} %t.out |
| 5 | + |
| 6 | +// This test verifies that we can compile, run and get correct results when |
| 7 | +// using a free function kernel that uses the work group scratch memory feature. |
| 8 | + |
| 9 | +#include <sycl/ext/oneapi/work_group_static.hpp> |
| 10 | + |
| 11 | +#include "helpers.hpp" |
| 12 | +#include <cassert> |
| 13 | +#include <sycl/ext/oneapi/experimental/enqueue_functions.hpp> |
| 14 | +#include <sycl/ext/oneapi/free_function_queries.hpp> |
| 15 | +#include <sycl/usm.hpp> |
| 16 | + |
| 17 | +namespace syclext = sycl::ext::oneapi; |
| 18 | +namespace syclexp = sycl::ext::oneapi::experimental; |
| 19 | + |
| 20 | +constexpr int SIZE = 16; |
| 21 | + |
| 22 | +SYCL_EXT_ONEAPI_FUNCTION_PROPERTY((syclexp::nd_range_kernel<1>)) |
| 23 | +void double_kernel(float *src, float *dst) { |
| 24 | + size_t lid = syclext::this_work_item::get_nd_item<1>().get_local_linear_id(); |
| 25 | + |
| 26 | + float *local_mem = (float *)syclexp::get_work_group_scratch_memory(); |
| 27 | + |
| 28 | + for (int i = 0; i < SIZE; i++) { |
| 29 | + local_mem[lid] = 2 * src[i]; |
| 30 | + dst[i] = local_mem[i]; |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +int main() { |
| 35 | + sycl::queue q; |
| 36 | + float *src = sycl::malloc_shared<float>(SIZE, q); |
| 37 | + float *dst = sycl::malloc_shared<float>(SIZE, q); |
| 38 | + |
| 39 | + for (int i = 1; i < SIZE; i++) { |
| 40 | + src[i] = i; |
| 41 | + } |
| 42 | + |
| 43 | + auto kbndl = |
| 44 | + syclexp::get_kernel_bundle<double_kernel, sycl::bundle_state::executable>( |
| 45 | + q.get_context()); |
| 46 | + sycl::kernel k = kbndl.template ext_oneapi_get_kernel<double_kernel>(); |
| 47 | + |
| 48 | + syclexp::launch_config cfg{ |
| 49 | + ::sycl::nd_range<1>(::sycl::range<1>(SIZE), ::sycl::range<1>(SIZE)), |
| 50 | + syclexp::properties{ |
| 51 | + syclexp::work_group_scratch_size(SIZE * sizeof(float))}}; |
| 52 | + |
| 53 | + syclexp::nd_launch(q, cfg, k, src, dst); |
| 54 | + q.wait(); |
| 55 | + |
| 56 | + for (int i = 0; i < SIZE; i++) { |
| 57 | + assert(dst[i] == 2 * src[i]); |
| 58 | + } |
| 59 | + |
| 60 | + sycl::free(src, q); |
| 61 | + sycl::free(dst, q); |
| 62 | + return 0; |
| 63 | +} |
0 commit comments