Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph Testing: Add missing waits and USM device tests #115

Merged
merged 2 commits into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
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
96 changes: 96 additions & 0 deletions sycl/test/graph/graph-explicit-dotp-device-mem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
#include <sycl/sycl.hpp>

#include <sycl/ext/oneapi/experimental/graph.hpp>

const size_t n = 10;

float host_gold_result() {
float alpha = 1.0f;
float beta = 2.0f;
float gamma = 3.0f;

float sum = 0.0f;

for (size_t i = 0; i < n; ++i) {
sum += (alpha * 1.0f + beta * 2.0f) * (gamma * 3.0f + beta * 2.0f);
}

return sum;
}

int main() {
float alpha = 1.0f;
float beta = 2.0f;
float gamma = 3.0f;

sycl::property_list properties{
sycl::property::queue::in_order{},
sycl::ext::oneapi::property::queue::lazy_execution{}};

sycl::queue q{sycl::gpu_selector_v, properties};

sycl::ext::oneapi::experimental::command_graph g;

float *dotp = sycl::malloc_device<float>(1, q);

float *x = sycl::malloc_device<float>(n, q);
float *y = sycl::malloc_device<float>(n, q);
float *z = sycl::malloc_device<float>(n, q);

/* init data on the device */
auto n_i = g.add([&](sycl::handler &h) {
h.parallel_for(n, [=](sycl::id<1> it) {
const size_t i = it[0];
x[i] = 1.0f;
y[i] = 2.0f;
z[i] = 3.0f;
});
});

auto node_a = g.add(
[&](sycl::handler &h) {
h.parallel_for(sycl::range<1>{n}, [=](sycl::id<1> it) {
const size_t i = it[0];
x[i] = alpha * x[i] + beta * y[i];
});
},
{n_i});

auto node_b = g.add(
[&](sycl::handler &h) {
h.parallel_for(sycl::range<1>{n}, [=](sycl::id<1> it) {
const size_t i = it[0];
z[i] = gamma * z[i] + beta * y[i];
});
},
{n_i});

auto node_c = g.add(
[&](sycl::handler &h) {
h.parallel_for(sycl::range<1>{n},
sycl::reduction(dotp, 0.0f, std::plus()),
[=](sycl::id<1> it, auto &sum) {
const size_t i = it[0];
sum += x[i] * z[i];
});
},
{node_a, node_b});

auto executable_graph = g.finalize(q.get_context());

// Using shortcut for executing a graph of commands
q.ext_oneapi_graph(executable_graph).wait();

std::vector<float> dotp_host(1);
q.copy(dotp, dotp_host.data(), 1).wait();

assert(dotp_host[0] == host_gold_result());

sycl::free(dotp, q);
sycl::free(x, q);
sycl::free(y, q);
sycl::free(z, q);

return 0;
}
8 changes: 6 additions & 2 deletions sycl/test/graph/graph-explicit-repeated-exec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ int main() {
assert(arr[i] == 0);
}

q.submit([&](sycl::handler &h) { h.ext_oneapi_graph(executable_graph); });
q.submit([&](sycl::handler &h) {
h.ext_oneapi_graph(executable_graph);
}).wait();

for (int i = 0; i < n; i++) {
assert(arr[i] == 1);
}

q.submit([&](sycl::handler &h) { h.ext_oneapi_graph(executable_graph); });
q.submit([&](sycl::handler &h) {
h.ext_oneapi_graph(executable_graph);
}).wait();

for (int i = 0; i < n; i++)
assert(arr[i] == 2);
Expand Down
4 changes: 3 additions & 1 deletion sycl/test/graph/graph-explicit-single-node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ int main() {
assert(arr[i] == 0);
}

q.submit([&](sycl::handler &h) { h.ext_oneapi_graph(executable_graph); });
q.submit([&](sycl::handler &h) {
h.ext_oneapi_graph(executable_graph);
}).wait();

for (int i = 0; i < n; i++)
assert(arr[i] == 1);
Expand Down
2 changes: 1 addition & 1 deletion sycl/test/graph/graph-record-dotp-buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ int main() {

auto exec_graph = g.finalize(q.get_context());

q.submit([&](sycl::handler &h) { h.ext_oneapi_graph(exec_graph); });
q.submit([&](sycl::handler &h) { h.ext_oneapi_graph(exec_graph); }).wait();
}

assert(dotpData == host_gold_result());
Expand Down
2 changes: 1 addition & 1 deletion sycl/test/graph/graph-record-dotp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int main() {

auto exec_graph = g.finalize(q.get_context());

q.submit([&](sycl::handler &h) { h.ext_oneapi_graph(exec_graph); });
q.submit([&](sycl::handler &h) { h.ext_oneapi_graph(exec_graph); }).wait();

assert(dotp[0] == host_gold_result());

Expand Down
2 changes: 1 addition & 1 deletion sycl/test/graph/graph-record-simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int main() {

auto exec_graph = g.finalize(q.get_context());

q.submit([&](sycl::handler &h) { h.ext_oneapi_graph(exec_graph); });
q.submit([&](sycl::handler &h) { h.ext_oneapi_graph(exec_graph); }).wait();

// Verify results
for (size_t i = 0; i < n; i++) {
Expand Down
2 changes: 1 addition & 1 deletion sycl/test/graph/graph-record-temp-scope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ int main() {

auto exec_graph = g.finalize(q.get_context());

q.submit([&](sycl::handler &h) { h.ext_oneapi_graph(exec_graph); });
q.submit([&](sycl::handler &h) { h.ext_oneapi_graph(exec_graph); }).wait();

// Verify results
for (size_t i = 0; i < n; i++) {
Expand Down