-
Notifications
You must be signed in to change notification settings - Fork 797
[SYCL] Don't block execution when flushing a stream #2581
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 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1237b60
[SYCL] Don't block execution when flushing a stream
againull 5c5e621
Merge remote-tracking branch 'origin/sycl' into pipes
againull c1bfd2e
Use std::atexit to setup a cleanup function for library
againull 0cc101b
Fix host queue querying from scheduler
againull b98e179
Merge remote-tracking branch 'origin/sycl' into pipes
againull 86bc599
[SYCL] Gather streams to deallocate during cleanup graph traversal
againull c519866
Fix test and formatting
againull 656584f
Merge remote-tracking branch 'origin/sycl' into pipes
againull 857b6c2
Fix stream.cpp test: add missing sync point
againull f5aff93
Address concerns for reviewers
againull 935602c
Fix typo
againull 6ed7e99
Fix scalar_vec_access.cpp test: add missing sync point
againull 9c3de3b
Fix linear-host-dev.cpp test: add missing sync point
againull 6450892
Merge remote-tracking branch 'origin/sycl' into pipes
againull 813b307
Print the warning only if tracing enabled
againull 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
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <CL/sycl/queue.hpp> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should all these includes using |
||
#include <detail/scheduler/scheduler.hpp> | ||
#include <detail/stream_impl.hpp> | ||
|
||
|
@@ -33,24 +34,25 @@ stream_impl::stream_impl(size_t BufferSize, size_t MaxStatementSize, | |
GlobalBufAccessorT stream_impl::accessGlobalBuf(handler &CGH) { | ||
return detail::Scheduler::getInstance() | ||
.StreamBuffersPool.find(this) | ||
->second.Buf.get_access<cl::sycl::access::mode::read_write>( | ||
->second->Buf.get_access<cl::sycl::access::mode::read_write>( | ||
CGH, range<1>(BufferSize_), id<1>(OffsetSize)); | ||
} | ||
|
||
// Method to provide an accessor to the global flush buffer | ||
GlobalBufAccessorT stream_impl::accessGlobalFlushBuf(handler &CGH) { | ||
return detail::Scheduler::getInstance() | ||
.StreamBuffersPool.find(this) | ||
->second.FlushBuf.get_access<cl::sycl::access::mode::read_write>( | ||
->second->FlushBuf.get_access<cl::sycl::access::mode::read_write>( | ||
CGH, range<1>(MaxStatementSize_), id<1>(0)); | ||
} | ||
|
||
// Method to provide an atomic access to the offset in the global stream | ||
// buffer and offset in the flush buffer | ||
GlobalOffsetAccessorT stream_impl::accessGlobalOffset(handler &CGH) { | ||
auto OffsetSubBuf = buffer<char, 1>( | ||
detail::Scheduler::getInstance().StreamBuffersPool.find(this)->second.Buf, | ||
id<1>(0), range<1>(OffsetSize)); | ||
auto OffsetSubBuf = buffer<char, 1>(detail::Scheduler::getInstance() | ||
.StreamBuffersPool.find(this) | ||
->second->Buf, | ||
id<1>(0), range<1>(OffsetSize)); | ||
auto ReinterpretedBuf = OffsetSubBuf.reinterpret<unsigned, 1>(range<1>(2)); | ||
return ReinterpretedBuf.get_access<cl::sycl::access::mode::atomic>( | ||
CGH, range<1>(2), id<1>(0)); | ||
|
@@ -60,20 +62,33 @@ size_t stream_impl::get_size() const { return BufferSize_; } | |
size_t stream_impl::get_max_statement_size() const { return MaxStatementSize_; } | ||
|
||
void stream_impl::flush() { | ||
// Access the stream buffer on the host. This access guarantees that kernel is | ||
// executed and buffer contains streamed data. | ||
{ | ||
auto HostAcc = detail::Scheduler::getInstance() | ||
.StreamBuffersPool.find(this) | ||
->second.Buf.get_access<cl::sycl::access::mode::read>( | ||
range<1>(BufferSize_), id<1>(OffsetSize)); | ||
|
||
printf("%s", HostAcc.get_pointer()); | ||
fflush(stdout); | ||
} | ||
|
||
// Flushed the stream, can deallocate the buffers now. | ||
detail::Scheduler::getInstance().deallocateStreamBuffers(this); | ||
// We don't want stream flushing to be blocking operation that is why submit a | ||
// host task to print stream buffer. It will fire up as soon as the kernel | ||
// finishes execution. | ||
auto Q = detail::createSyclObjFromImpl<queue>( | ||
cl::sycl::detail::Scheduler::getInstance().getDefaultHostQueue()); | ||
Q.submit([&](handler &cgh) { | ||
auto BufHostAcc = | ||
detail::Scheduler::getInstance() | ||
.StreamBuffersPool.find(this) | ||
->second->Buf | ||
.get_access<access::mode::read_write, access::target::host_buffer>( | ||
cgh, range<1>(BufferSize_), id<1>(OffsetSize)); | ||
// Create accessor to the flush buffer even if not using it yet. Otherwise | ||
// kernel will be a leaf for the flush buffer and scheduler will not be able | ||
// to cleanup the kernel. TODO: git rid of finalize method by using host | ||
// accessor to the flush buffer. | ||
auto FlushBufHostAcc = | ||
detail::Scheduler::getInstance() | ||
.StreamBuffersPool.find(this) | ||
->second->FlushBuf | ||
.get_access<access::mode::read_write, access::target::host_buffer>( | ||
cgh); | ||
cgh.codeplay_host_task([=] { | ||
printf("%s", BufHostAcc.get_pointer()); | ||
fflush(stdout); | ||
}); | ||
}); | ||
} | ||
} // namespace detail | ||
} // namespace sycl | ||
|
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
Oops, something went wrong.
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.