Skip to content

Commit e1b75fd

Browse files
committed
Add test for restricted host tasks in the non-native path
1 parent fff50cb commit e1b75fd

2 files changed

Lines changed: 71 additions & 1 deletion

File tree

sycl/source/detail/scheduler/commands.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ class DispatchHostTask {
382382
if (NativeHostTaskSupport) {
383383
auto NativeHostTaskData =
384384
std::make_unique<detail::EnqueueHostTaskData>(
385-
std::move(HostTask.MHostTask->MHostTask));
385+
HostTask.MHostTask->MHostTask);
386386
ur_event_handle_t HostTaskEvent{};
387387
Queue->getAdapter().call<UrApiKind::urEnqueueHostTaskExp>(
388388
Queue->getHandleRef(), detail::NativeHostTask<true>,
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// REQUIRES: aspect-usm_shared_allocations
2+
3+
// RUN: %{build} -o %t.out
4+
// RUN: %{run} %t.out
5+
// RUN: %if level_zero %{%{l0_leak_check} %{run} %t.out 2>&1 | FileCheck %s --implicit-check-not=LEAK %}
6+
7+
// Tests that restricted host_task can be recorded via the command-buffer path
8+
9+
#include "../graph_common.hpp"
10+
11+
#include <sycl/ext/oneapi/experimental/enqueue_functions.hpp>
12+
#include <sycl/properties/all_properties.hpp>
13+
14+
namespace syclex = sycl::ext::oneapi::experimental;
15+
16+
constexpr size_t N = 1024;
17+
18+
int main() {
19+
queue Queue{property::queue::in_order{}};
20+
21+
const sycl::context Context = Queue.get_context();
22+
const sycl::device Device = Queue.get_device();
23+
24+
uint32_t *Data = malloc_shared<uint32_t>(N, Queue);
25+
std::fill(Data, Data + N, 0);
26+
27+
exp_ext::command_graph Graph{Context, Device};
28+
29+
Graph.begin_recording(Queue);
30+
31+
Queue.submit([&](handler &CGH) {
32+
CGH.parallel_for(range<1>{N}, [=](id<1> idx) {
33+
Data[idx] += static_cast<uint32_t>(idx[0]) + 1;
34+
});
35+
});
36+
37+
syclex::host_task(Queue, [=] {
38+
for (size_t i = 0; i < N; i++) {
39+
Data[i] *= 2;
40+
}
41+
});
42+
43+
Queue.submit([&](handler &CGH) {
44+
CGH.parallel_for(range<1>{N}, [=](id<1> idx) { Data[idx] += 10; });
45+
});
46+
47+
Graph.end_recording(Queue);
48+
49+
auto ExecutableGraph = Graph.finalize();
50+
51+
Queue.submit([&](handler &CGH) { CGH.ext_oneapi_graph(ExecutableGraph); });
52+
Queue.wait();
53+
54+
for (size_t i = 0; i < N; i++) {
55+
uint32_t Expected = static_cast<uint32_t>((i + 1) * 2 + 10);
56+
assert(check_value(i, Expected, Data[i], "Data"));
57+
}
58+
59+
// Second execution
60+
Queue.submit([&](handler &CGH) { CGH.ext_oneapi_graph(ExecutableGraph); });
61+
Queue.wait();
62+
63+
for (size_t i = 0; i < N; i++) {
64+
uint32_t Expected = static_cast<uint32_t>((i + 1) * 6 + 30);
65+
assert(check_value(i, Expected, Data[i], "Data"));
66+
}
67+
68+
free(Data, Queue);
69+
return 0;
70+
}

0 commit comments

Comments
 (0)