Skip to content

Commit

Permalink
Add test case
Browse files Browse the repository at this point in the history
Introduce a test case which fails before this commit
and passes afterwards. Based on #49
  • Loading branch information
EwanC committed Mar 17, 2023
1 parent ea3c0b6 commit e638c37
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions sycl/test/graph/graph-record-temp-scope.cpp
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;
}

0 comments on commit e638c37

Please sign in to comment.