Skip to content

Commit 4521a09

Browse files
committed
Another portion of applied remarks
Signed-off-by: Mikhail Lychkov <[email protected]>
1 parent 79d8403 commit 4521a09

File tree

3 files changed

+62
-17
lines changed

3 files changed

+62
-17
lines changed

sycl/source/detail/scheduler/scheduler_helpers.hpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,32 @@ namespace sycl {
1616
namespace detail {
1717

1818
void initStream(StreamImplPtr Stream, QueueImplPtr Queue) {
19-
auto StreamBuf =
20-
Scheduler::getInstance().StreamBuffersPool.find(Stream.get());
21-
assert((StreamBuf != Scheduler::getInstance().StreamBuffersPool.end()) &&
22-
"Stream is unexpectedly not found in pool.");
19+
Scheduler::StreamBuffers *StrBufs{};
2320

24-
auto &FlushBuf = StreamBuf->second->FlushBuf;
25-
// Only size of buffer_impl object has been resized.
26-
// Value of Range field of FlushBuf instance is still equal to
27-
// MaxStatementSize only.
28-
size_t FlushBufSize = getSyclObjImpl(FlushBuf)->get_count();
21+
{
22+
std::lock_guard<std::mutex> lock(
23+
Scheduler::getInstance().StreamBuffersPoolMutex);
24+
25+
auto StreamBuf =
26+
Scheduler::getInstance().StreamBuffersPool.find(Stream.get());
27+
assert((StreamBuf != Scheduler::getInstance().StreamBuffersPool.end()) &&
28+
"Stream is unexpectedly not found in pool.");
29+
30+
StrBufs = StreamBuf->second;
31+
}
32+
33+
assert(StrBufs && "No buffers for a stream.");
34+
35+
// Real size of full flush buffer is saved only in buffer_impl field of
36+
// FlushBuf object.
37+
size_t FlushBufSize = getSyclObjImpl(StrBufs->FlushBuf)->get_count();
2938

3039
auto Q = createSyclObjFromImpl<queue>(Queue);
3140
Q.submit([&](handler &cgh) {
32-
auto FlushBufAcc = FlushBuf.get_access<access::mode::discard_write,
33-
access::target::host_buffer>(
34-
cgh, range<1>(FlushBufSize), id<1>(0));
41+
auto FlushBufAcc =
42+
StrBufs->FlushBuf.get_access<access::mode::discard_write,
43+
access::target::host_buffer>(
44+
cgh, range<1>(FlushBufSize), id<1>(0));
3545
cgh.codeplay_host_task([=] {
3646
char *FlushBufPtr = FlushBufAcc.get_pointer();
3747
std::memset(FlushBufPtr, 0, FlushBufAcc.get_size());

sycl/source/stream.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
//#include <CL/sycl/exception.hpp>
109
#include <CL/sycl/stream.hpp>
1110
#include <detail/queue_impl.hpp>
1211
#include <detail/stream_impl.hpp>
@@ -27,10 +26,10 @@ stream::stream(size_t BufferSize, size_t MaxStatementSize, handler &CGH)
2726
GlobalFlushBuf(impl->accessGlobalFlushBuf(CGH)),
2827
FlushBufferSize(MaxStatementSize + detail::FLUSH_BUF_OFFSET_SIZE) {
2928
if (MaxStatementSize > MAX_STATEMENT_SIZE) {
30-
throw invalid_parameter_error("Maximum statement size exceeds limit of " +
31-
std::to_string(MAX_STATEMENT_SIZE) +
32-
" bytes.",
33-
PI_INVALID_VALUE);
29+
throw sycl::invalid_parameter_error(
30+
"Maximum statement size exceeds limit of " +
31+
std::to_string(MAX_STATEMENT_SIZE) + " bytes.",
32+
PI_INVALID_VALUE);
3433
}
3534

3635
// Save stream implementation in the handler so that stream will be alive
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2+
// RUN: env SYCL_DEVICE_TYPE=HOST SYCL_PRINT_EXECUTION_GRAPH=after_addCG %t.out
3+
// RUN: cat graph_2after_addCG.dot | FileCheck %s
4+
// RUN: rm *.dot
5+
6+
// This test is executed on host device only because flush buffer initialized
7+
// via a separate call group task for this device only.
8+
9+
#include <CL/sycl.hpp>
10+
11+
using namespace cl;
12+
13+
int main() {
14+
{
15+
sycl::queue Queue;
16+
Queue.submit([&](sycl::handler &cgh) {
17+
sycl::stream Out(100, 100, cgh);
18+
cgh.single_task<class test_flush_buf_init_dep>(
19+
[=]() { Out << "Hello world!" << sycl::endl; });
20+
});
21+
Queue.wait();
22+
}
23+
// CHECK: [[MAIN_CG:"0x[0-9a-f]+"]] {{.*}}EXEC CG ON HOST{{.*}}test_flush_buf_init_dep
24+
// First 3 lines show dependencies on global buffer related commands
25+
// CHECK: [[MAIN_CG]]
26+
// CHECK: [[MAIN_CG]]
27+
// CHECK: [[MAIN_CG]]
28+
// CHECK: [[MAIN_CG]] -> [[EMPTY_NODE:"0x[0-9a-f]+"]] [ label = "Access mode: read_write\nMemObj: [[FLUSHBUF_MEMOBJ:0x[0-9a-f]+]]
29+
// CHECK: [[EMPTY_NODE]] {{.*}}EMPTY NODE
30+
// CHECK: [[EMPTY_NODE]] -> [[FILL_TASK:"0x[0-9a-f]+"]] [ label = "Access mode: discard_write\nMemObj: [[FLUSHBUF_MEMOBJ]]
31+
// CHECK: [[FILL_TASK]] {{.*}}EXEC CG ON HOST\nCG type: host task
32+
// CHECK: [[FILL_TASK]] -> [[ALLOC_TASK:"0x[0-9a-f]+"]] [ label = "Access mode: discard_write\nMemObj: [[FLUSHBUF_MEMOBJ]]
33+
// CHECK: [[ALLOC_TASK]] {{.*}}ALLOCA ON HOST\n MemObj : [[FLUSHBUF_MEMOBJ]]
34+
}
35+
return 0;
36+
}

0 commit comments

Comments
 (0)