forked from intel/llvm
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a test case which fails before this commit and passes afterwards. Based on #49
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out | ||
|
||
#include <iostream> | ||
#include <sycl/sycl.hpp> | ||
|
||
#include <sycl/ext/oneapi/experimental/graph.hpp> | ||
|
||
const size_t n = 10; | ||
const float expectedValue = 42.0f; | ||
|
||
void run_some_kernel(sycl::queue q, float* data){ | ||
// data is captured by ref here but will have gone out of scope when the | ||
// CGF is later run when the graph is executed. | ||
q.submit([&](sycl::handler &h) { | ||
h.parallel_for(sycl::range<1>{n}, [=](sycl::id<1> idx) { | ||
size_t i = idx; | ||
data[i] = expectedValue; | ||
}); | ||
}); | ||
} | ||
|
||
int main() { | ||
|
||
sycl::property_list properties{ | ||
sycl::property::queue::in_order(), | ||
sycl::ext::oneapi::property::queue::lazy_execution{}}; | ||
|
||
sycl::queue q{sycl::default_selector_v, properties}; | ||
|
||
sycl::ext::oneapi::experimental::command_graph g; | ||
|
||
float *arr = sycl::malloc_shared<float>(n, q); | ||
|
||
g.begin_recording(q); | ||
run_some_kernel(q, arr); | ||
g.end_recording(q); | ||
|
||
auto exec_graph = g.finalize(q.get_context()); | ||
|
||
q.submit([&](sycl::handler &h) { h.ext_oneapi_graph(exec_graph); }); | ||
|
||
int errors = 0; | ||
// Verify results | ||
for (size_t i = 0; i < n; i++) { | ||
if (arr[i] != expectedValue) { | ||
std::cout << "Test failed: Unexpected result at index: " << i | ||
<< ", expected: " << expectedValue << " actual: " << arr[i] | ||
<< "\n"; | ||
errors++; | ||
} | ||
} | ||
|
||
if (errors == 0) { | ||
std::cout << "Test passed successfuly.\n"; | ||
} | ||
|
||
std::cout << "done.\n"; | ||
|
||
sycl::free(arr, q.get_context()); | ||
|
||
return errors; | ||
} |