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 131
[SYCL] Test queue::ext_oneapi_empty() API #1427
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out | ||
// RUN: %ACC_RUN_PLACEHOLDER %t.out | ||
// RUN: %CPU_RUN_PLACEHOLDER %t.out | ||
// RUN: %GPU_RUN_PLACEHOLDER %t.out | ||
|
||
// Test checks that queue::ext_oneapi_empty() returns status of the in-order | ||
// queue. | ||
|
||
#include <chrono> | ||
#include <sycl.hpp> | ||
#include <thread> | ||
|
||
static void CheckArray(int *x, size_t buffer_size, int expected) { | ||
for (size_t i = 0; i < buffer_size; ++i) { | ||
assert(x[i] == expected); | ||
} | ||
} | ||
|
||
using namespace sycl; | ||
|
||
void TestFunc(queue &Q) { | ||
static constexpr int Size = 100; | ||
|
||
assert(Q.ext_oneapi_empty() && "Queue is expected to be empty"); | ||
|
||
int *X = malloc_host<int>(Size, Q); | ||
int *Y = malloc_host<int>(Size, Q); | ||
|
||
auto FillEv = Q.fill(X, 99, Size); | ||
auto SingleTaskEv = Q.submit([&](handler &CGH) { | ||
auto SingleTask = [=] { | ||
for (int I = 0; I < Size; I++) | ||
X[I] += 1; | ||
}; | ||
CGH.single_task(SingleTask); | ||
}); | ||
auto MemCpyEv = Q.copy(X, Y, Size); | ||
constexpr int NumIter = 5; | ||
for (int I = 0; I < NumIter; I++) { | ||
Q.submit([&](handler &CGH) { | ||
CGH.parallel_for<class Kernel1>(sycl::range<1>(Size), | ||
[=](sycl::id<1> WI) { Y[WI] *= 2; }); | ||
}); | ||
} | ||
|
||
// Wait a bit to give a chance for tasks to complete. | ||
std::this_thread::sleep_for(std::chrono::milliseconds(500)); | ||
|
||
// We expect that all submitted tasks are finished if ext_oneapi_empty is | ||
// true. | ||
if (Q.ext_oneapi_empty()) | ||
CheckArray(Y, Size, 3200); | ||
|
||
Q.wait(); | ||
|
||
// After synchronization queue must be empty. | ||
assert(Q.ext_oneapi_empty() && "Queue is expected to be empty"); | ||
|
||
free(X, Q); | ||
free(Y, Q); | ||
} | ||
|
||
int main() { | ||
// Test in-order queue. | ||
queue Q1{property::queue::in_order()}; | ||
TestFunc(Q1); | ||
|
||
// Test in-order queue with discard_events property. | ||
sycl::property_list Props{ | ||
property::queue::in_order{}, | ||
sycl::ext::oneapi::property::queue::discard_events{}}; | ||
queue Q2{Props}; | ||
|
||
bool ExceptionThrown = false; | ||
try { | ||
TestFunc(Q2); | ||
} catch (sycl::exception &E) { | ||
ExceptionThrown = true; | ||
} | ||
|
||
// Feature is not supported for OpenCL, exception must be thrown. | ||
if (Q2.get_device().get_backend() == backend::opencl) | ||
return ExceptionThrown ? 0 : -1; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out | ||
// RUN: %ACC_RUN_PLACEHOLDER %t.out | ||
// RUN: %CPU_RUN_PLACEHOLDER %t.out | ||
// RUN: %GPU_RUN_PLACEHOLDER %t.out | ||
|
||
// Test checks that queue::ext_oneapi_empty() returns status of the out-of-order | ||
// queue. | ||
|
||
#include <chrono> | ||
#include <sycl.hpp> | ||
#include <thread> | ||
|
||
static void CheckArray(int *x, size_t buffer_size, int expected) { | ||
for (size_t i = 0; i < buffer_size; ++i) { | ||
assert(x[i] == expected); | ||
} | ||
} | ||
|
||
using namespace sycl; | ||
|
||
void TestFunc(queue &Q) { | ||
static constexpr int Size = 100; | ||
|
||
assert(Q.ext_oneapi_empty() && "Queue is expected to be empty"); | ||
|
||
int *X = malloc_host<int>(Size, Q); | ||
int *Y = malloc_host<int>(Size, Q); | ||
|
||
auto FillEv = Q.fill(X, 99, Size); | ||
auto HostEv = Q.submit([&](handler &CGH) { | ||
CGH.depends_on(FillEv); | ||
auto HostTask = [=] { | ||
for (int I = 0; I < Size; I++) | ||
X[I] += 1; | ||
}; | ||
CGH.host_task(HostTask); | ||
}); | ||
auto MemCpyEv = Q.copy(X, Y, Size, {HostEv}); | ||
constexpr int NumIter = 5; | ||
for (int I = 0; I < NumIter; I++) { | ||
Q.submit([&](handler &CGH) { | ||
CGH.depends_on(MemCpyEv); | ||
CGH.parallel_for<class Kernel1>( | ||
sycl::range<1>(Size / NumIter), | ||
[=](sycl::id<1> WI) { Y[WI + I * Size / NumIter] *= 2; }); | ||
}); | ||
} | ||
|
||
// Wait a bit to give a chance for tasks to complete. | ||
std::this_thread::sleep_for(std::chrono::milliseconds(500)); | ||
|
||
// We expect that all submitted tasks are finished if ext_oneapi_empty is | ||
// true. | ||
if (Q.ext_oneapi_empty()) | ||
CheckArray(Y, Size, 200); | ||
|
||
Q.wait(); | ||
|
||
// After synchronization queue must be empty. | ||
assert(Q.ext_oneapi_empty() && "Queue is expected to be empty"); | ||
|
||
free(X, Q); | ||
free(Y, Q); | ||
} | ||
|
||
int main() { | ||
queue Q; | ||
|
||
bool ExceptionThrown = false; | ||
try { | ||
TestFunc(Q); | ||
} catch (sycl::exception &E) { | ||
ExceptionThrown = true; | ||
} | ||
|
||
// Feature is not supported for OpenCL, exception must be thrown. | ||
if (Q.get_device().get_backend() == backend::opencl) | ||
return ExceptionThrown ? 0 : -1; | ||
|
||
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.
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.
could we try to avoid sleeps in tests? we could not rely on such approach.
what if to add host_task as the last task that would signal cv, atomic or lock/unlock mutex and simply wait for it instead of sleep, will it help?
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.
Unfortunately, as far as I know SYCL doesn't guarantee that such waiting will ever complete. User must perform synchronization to guarantee completion. I mean it is not guaranteed that queue will be flushed and we may just wait forever.
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.
@KseniyaTikhomirova, unfortunately, I don't have good ideas how to get rid of sleep right now for the reasons I described above. I can probably replace it with some loop - try several times to see if queue is empty and give up if it is not empty - but I'm not sure whether it is better or not.
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.
ok, unfortunately I also do not have better ideas about how to get rid of sleep call. If we want to check that the right value could be returned even without wait call - may be it could be done with unittest. Although I do not want to block you 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.
Thank you! Unittest may be a good idea.