Skip to content

Commit fe8c284

Browse files
[SYCL][NewOffload][E2E] add a single test for --offload-new-driver (#14129)
A single basic file to compile and run to test functionality of --offload-new-driver --------- Co-authored-by: Marcos Maronas <[email protected]>
1 parent 3910d0c commit fe8c284

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//==------------------- buffer.cpp - SYCL buffer basic test ----------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// A basic test using the --offload-new-driver flag.
10+
11+
// REQUIRES: level_zero
12+
// RUN: %clangxx -fsycl --offload-new-driver %s -o %t.out
13+
// RUN: %{run} %t.out
14+
15+
#include <sycl/detail/core.hpp>
16+
17+
int main() {
18+
// Creating buffer of 4 elements to be used inside the kernel code.
19+
sycl::buffer<size_t, 1> Buffer(4);
20+
21+
// Creating SYCL queue.
22+
sycl::queue Queue;
23+
24+
// Size of index space for kernel.
25+
sycl::range<1> NumOfWorkItems{Buffer.size()};
26+
27+
// Submitting command group(work) to queue.
28+
Queue.submit([&](sycl::handler &cgh) {
29+
// Getting write only access to the buffer on a device.
30+
sycl::accessor Accessor{Buffer, cgh, sycl::write_only};
31+
// Executing kernel.
32+
cgh.parallel_for<class FillBuffer>(NumOfWorkItems, [=](sycl::id<1> WIid) {
33+
// Fill buffer with indexes.
34+
Accessor[WIid] = WIid.get(0);
35+
});
36+
});
37+
38+
// Getting read only access to the buffer on the host.
39+
// Implicit barrier waiting for queue to complete the work.
40+
sycl::host_accessor HostAccessor{Buffer, sycl::read_only};
41+
42+
// Check the results.
43+
bool MismatchFound = false;
44+
for (size_t I = 0; I < Buffer.size(); ++I) {
45+
if (HostAccessor[I] != I) {
46+
std::cout << "The result is incorrect for element: " << I
47+
<< " , expected: " << I << " , got: " << HostAccessor[I]
48+
<< std::endl;
49+
MismatchFound = true;
50+
}
51+
}
52+
53+
if (!MismatchFound) {
54+
std::cout << "The results are correct!" << std::endl;
55+
}
56+
57+
return MismatchFound;
58+
}

0 commit comments

Comments
 (0)