This repository was archived by the owner on Mar 28, 2023. It is now read-only.
forked from llvm/llvm-test-suite
-
Notifications
You must be signed in to change notification settings - Fork 130
[SYCL][CUDA] Add test for a multi-device context #1102
Open
t4c1
wants to merge
13
commits into
intel:intel
Choose a base branch
from
t4c1:multi_device_context
base: intel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
319aeb6
added mutlti device context test
t4c1 a0409fc
fix tracing test
t4c1 46eeae8
Merge branch 'intel' into multi_device_context
t4c1 daad593
fix tests for other backends
t4c1 11a9a73
Apply suggestions from code review
t4c1 50a968b
addressed review comments
t4c1 c163f83
format
t4c1 eec9e92
fixed another test
t4c1 18b6693
Merge branch 'intel' into multi_device_context
t4c1 a6ba809
Merge branch 'intel' into multi_device_context
t4c1 da75b7a
Merge remote-tracking branch 'origin/intel' into multi_device_context
npmiller 684afdd
Remove deprecated host placeholder
npmiller e0d387b
Merge remote-tracking branch 'upstream/intel' into multi_device_context
npmiller 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out | ||
// RUN: %CPU_RUN_PLACEHOLDER %t.out | ||
// RUN: %GPU_RUN_PLACEHOLDER %t.out | ||
|
||
// REQUIRES: cuda | ||
|
||
#include <stdlib.h> | ||
#include <sycl/sycl.hpp> | ||
|
||
sycl::event add(sycl::queue &q, sycl::buffer<int> &buff, int *usm, | ||
sycl::event &e) { | ||
return q.submit([&](sycl::handler &cgh) { | ||
auto acc = buff.get_access<sycl::access::mode::read_write>(cgh); | ||
cgh.depends_on(e); | ||
cgh.single_task([=]() { acc[0] += *usm; }); | ||
}); | ||
} | ||
|
||
int main() { | ||
sycl::platform plat = sycl::platform::get_platforms()[0]; | ||
auto devices = plat.get_devices(); | ||
if (devices.size() < 2) { | ||
std::cout << "Need two devices for the test!" << std::endl; | ||
return 0; | ||
} | ||
|
||
sycl::device dev1 = devices[0]; | ||
sycl::device dev2 = devices[1]; | ||
|
||
sycl::context ctx{{dev1, dev2}}; | ||
|
||
sycl::queue q1{ctx, dev1}; | ||
sycl::queue q2{ctx, dev2}; | ||
|
||
int a = 1; | ||
int b = 2; | ||
{ | ||
sycl::buffer<int> buff1(&a, 1); | ||
sycl::buffer<int> buff2(&b, 1); | ||
|
||
// Test copying usm. | ||
int *usm1 = sycl::malloc_device<int>(1, q1); | ||
int *usm2 = sycl::malloc_device<int>(1, q2); | ||
sycl::event e1 = q1.fill(usm1, 4, 1); | ||
sycl::event e2 = q2.fill(usm2, 5, 1); | ||
|
||
// Test combination of usm and buffers in a kernel. | ||
sycl::event e3 = add(q1, buff1, usm1, e1); | ||
sycl::event e4 = add(q2, buff2, usm2, e2); | ||
|
||
// Change values in usm to ensure results are distinct. | ||
sycl::event e5 = q1.fill(usm1, 5, 1, e3); | ||
sycl::event e6 = q2.fill(usm2, 4, 1, e4); | ||
|
||
// Use each buffer on the other device than before - tests that copying | ||
// between devices works. | ||
add(q1, buff2, usm1, e5); | ||
add(q2, buff1, usm2, e6); | ||
} | ||
assert(a == 1 + 2 * 4); | ||
assert(b == 2 + 2 * 5); | ||
|
||
return 0; | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the main purpose of the test? Can we use explict
q.wait()
to eliminate the need for all the events?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To check that common operations work when using two devices within the same context, including transferring buffer data between the devices and waiting on event , associated with an operation on another device. So while we could change each event synchronization with a wait on one or both of the queues, that would reduce the scope of the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, would the test somewhat reliably fail if we didn't pass the events around?
In other words, would race condition manifest itself on a reasonable HW with such small workloads?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe a race condition would be relatively unlikely to manifest in such a test. But I still prefer events, as a race condition is not the only possible mode of failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also using waits would not make code much more readable, as there would need to be a wait call after every operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every other, I think. Anyway, I'm fine with events.
For my education, what are the others here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could imagine a deadlock.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something completely unexpected is also always an option.