Skip to content

Commit a0bf820

Browse files
committed
Address review comments and fix CI fails
1 parent cd8a698 commit a0bf820

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

sycl/source/detail/scheduler/scheduler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ void Scheduler::allocateStreamBuffers(stream_impl *Impl,
246246
{Impl, StreamBuffers(StreamBufferSize, FlushBufferSize)});
247247
}
248248

249+
void Scheduler::deallocateStreamBuffers(stream_impl *Impl) {
250+
std::lock_guard<std::mutex> lock(StreamBuffersPoolMutex);
251+
StreamBuffersPool.erase(Impl);
252+
}
253+
249254
Scheduler::Scheduler() {
250255
sycl::device HostDevice;
251256
DefaultHostQueue = QueueImplPtr(

sycl/source/detail/scheduler/scheduler.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,10 @@ class Scheduler {
716716
friend class Command;
717717
friend class DispatchHostTask;
718718

719-
class StreamBuffers {
720-
public:
719+
/// Stream buffers structure.
720+
///
721+
/// The structure contains all buffers for a stream object.
722+
struct StreamBuffers {
721723
StreamBuffers(size_t StreamBufferSize, size_t FlushBufferSize)
722724
// Initialize stream buffer with zeros, this is needed for two reasons:
723725
// 1. We don't need to care about end of line when printing out
@@ -745,8 +747,11 @@ class Scheduler {
745747
std::mutex StreamBuffersPoolMutex;
746748
std::map<stream_impl *, StreamBuffers> StreamBuffersPool;
747749

748-
// Allocate buffers in the pool for a provided stream
750+
/// Allocate buffers in the pool for a provided stream
749751
void allocateStreamBuffers(stream_impl *, size_t, size_t);
752+
753+
/// Deallocate buffers in the pool for a provided stream
754+
void deallocateStreamBuffers(stream_impl *);
750755
};
751756

752757
} // namespace detail

sycl/source/detail/stream_impl.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,18 @@ size_t stream_impl::get_max_statement_size() const { return MaxStatementSize_; }
6262
void stream_impl::flush() {
6363
// Access the stream buffer on the host. This access guarantees that kernel is
6464
// executed and buffer contains streamed data.
65-
auto HostAcc = detail::Scheduler::getInstance()
66-
.StreamBuffersPool.find(this)
67-
->second.Buf.get_access<cl::sycl::access::mode::read>(
68-
range<1>(BufferSize_), id<1>(OffsetSize));
65+
{
66+
auto HostAcc = detail::Scheduler::getInstance()
67+
.StreamBuffersPool.find(this)
68+
->second.Buf.get_access<cl::sycl::access::mode::read>(
69+
range<1>(BufferSize_), id<1>(OffsetSize));
6970

70-
printf("%s", HostAcc.get_pointer());
71-
fflush(stdout);
71+
printf("%s", HostAcc.get_pointer());
72+
fflush(stdout);
73+
}
74+
75+
// Flushed the stream, can deallocate the buffers now.
76+
detail::Scheduler::getInstance().deallocateStreamBuffers(this);
7277
}
7378
} // namespace detail
7479
} // namespace sycl

sycl/test/basic_tests/stream/release_resources_test.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33
// RUN: env SYCL_PI_TRACE=2 %GPU_RUN_PLACEHOLDER %t.out %GPU_CHECK_PLACEHOLDER
44
// RUN: env SYCL_PI_TRACE=2 %ACC_RUN_PLACEHOLDER %t.out %ACC_CHECK_PLACEHOLDER
55

6-
//==----------------------- release_resources_test.cpp ---------------------==//
7-
//
8-
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
9-
// See https://llvm.org/LICENSE.txt for license information.
10-
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
11-
//
12-
//===----------------------------------------------------------------------===//
13-
146
// Check that buffer used by a stream object is released.
157

168
#include <CL/sycl.hpp>

0 commit comments

Comments
 (0)