forked from intel/llvm
-
Notifications
You must be signed in to change notification settings - Fork 3
[SYCL] Improve record and replay edge determination #46
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1b9718d
[SYCL] Record and replay edge detection
Bensuo 9cdf720
[SYCL] Properly determine edges for recorded nodes
Bensuo e7f770d
Remove unused friend declaration from stream.hpp
Bensuo cbf57a4
[SYCL] Add buffer based record-dotp example
Bensuo cf1c47a
[SYCL] Improve comment on check_for_arg
Bensuo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,112 @@ | ||
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out | ||
#include <CL/sycl.hpp> | ||
#include <iostream> | ||
#include <thread> | ||
|
||
#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 dotpData = 0.f; | ||
std::vector<float> xData(n); | ||
std::vector<float> yData(n); | ||
std::vector<float> zData(n); | ||
|
||
{ | ||
sycl::buffer dotpBuf(&dotpData, sycl::range<1>(1)); | ||
|
||
sycl::buffer xBuf(xData); | ||
sycl::buffer yBuf(yData); | ||
sycl::buffer zBuf(zData); | ||
|
||
q.begin_recording(g); | ||
|
||
/* init data on the device */ | ||
q.submit([&](sycl::handler &h) { | ||
auto x = xBuf.get_access(h); | ||
auto y = yBuf.get_access(h); | ||
auto z = zBuf.get_access(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; | ||
}); | ||
}); | ||
|
||
q.submit([&](sycl::handler &h) { | ||
auto x = xBuf.get_access(h); | ||
auto y = yBuf.get_access(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]; | ||
}); | ||
}); | ||
|
||
q.submit([&](sycl::handler &h) { | ||
auto y = yBuf.get_access(h); | ||
auto z = zBuf.get_access(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]; | ||
}); | ||
}); | ||
|
||
q.submit([&](sycl::handler &h) { | ||
auto dotp = dotpBuf.get_access(h); | ||
auto x = xBuf.get_access(h); | ||
auto z = zBuf.get_access(h); | ||
h.parallel_for(sycl::range<1>{n}, [=](sycl::id<1> it) { | ||
const size_t i = it[0]; | ||
// Doing a manual reduction here because reduction objects cause issues | ||
// with graphs. | ||
if (i == 0) { | ||
for (size_t j = 0; j < n; j++) { | ||
dotp[0] += x[j] * z[j]; | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
q.end_recording(); | ||
|
||
auto exec_graph = g.finalize(q.get_context()); | ||
|
||
q.submit([&](sycl::handler &h) { h.exec_graph(exec_graph); }); | ||
} | ||
|
||
if (dotpData != host_gold_result()) { | ||
std::cout << "Error unexpected result!\n"; | ||
} | ||
|
||
std::cout << "done.\n"; | ||
|
||
return 0; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.