Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

[SYCL] Add a test for queue shortcuts with offsets #1099

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions SYCL/Basic/queue/queue_offset_shortcuts.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: %HOST_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out

//=-------queue_offset_shortcuts.cpp - SYCL queue offset shortcuts test------=//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include <sycl/sycl.hpp>

#include <cassert>

class KernelNameA;
class KernelNameB;
class KernelNameC;
int main() {
sycl::queue q;
sycl::device dev = q.get_device();
sycl::context ctx = q.get_context();
constexpr int N = 8;

if (!dev.get_info<sycl::info::device::usm_shared_allocations>()) {
return 0;
}

auto A = static_cast<int *>(sycl::malloc_shared(N * sizeof(int), dev, ctx));

for (int i = 0; i < N; i++) {
A[i] = 1;
}

sycl::id<1> offset(0);
sycl::event e = q.parallel_for<KernelNameA>(sycl::range<1>{N}, offset,
[=](sycl::item<1> i) { A[i]++; });

sycl::event e2 = q.parallel_for<KernelNameB>(
sycl::range<1>{N}, offset, e, [=](sycl::item<1> i) { A[i]++; });

q.parallel_for<KernelNameC>(sycl::range<1>{N}, offset, {e2},
[=](sycl::item<1> i) { A[i]++; });

q.wait();

for (int i = 0; i < N; i++) {
assert(A[i] == 4);
}
sycl::free(A, ctx);
}