Skip to content

Commit 8cac804

Browse files
author
Dan Toškan
committed
Refactored usages of old GetDefaultStream() API
1 parent f569a32 commit 8cac804

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

cpp/open3d/core/CUDAUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void Synchronize(const CUDAStream& stream) {
154154
CUDAStream& CUDAStream::GetInstance() {
155155
// The global stream state is given per thread like CUDA's internal
156156
// device state.
157-
thread_local CUDAStream instance = cuda::GetDefaultStream();
157+
thread_local CUDAStream instance = CUDAStream::Default();
158158
return instance;
159159
}
160160

@@ -188,7 +188,7 @@ void CUDAStream::Set(cudaStream_t stream) { stream_ = stream; }
188188
void CUDAStream::Destroy() {
189189
OPEN3D_ASSERT(!IsDefaultStream());
190190
OPEN3D_CUDA_CHECK(cudaStreamDestroy(stream_));
191-
*this = cuda::GetDefaultStream();
191+
*this = CUDAStream::Default();
192192
}
193193

194194
CUDAScopedDevice::CUDAScopedDevice(int device_id)

cpp/open3d/core/CUDAUtils.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ class CUDAStream {
7070
/// calling Destroy().
7171
static CUDAStream CreateNew();
7272

73+
/// Explicitly constructs a default stream. The default constructor could be
74+
/// used, but this is clearer and closer to the old API.
75+
static CUDAStream Default() { return {}; }
76+
77+
/// Default constructor. Refers to the default CUDA stream.
78+
CUDAStream() = default;
79+
7380
/// Sets the flag indicating if all memory copy operations done within
7481
/// this stream from device -> host should be synchronized. True by
7582
/// default. The default CUDA stream is implicitly synchronized with every
@@ -311,7 +318,6 @@ bool SupportsMemoryPools(const Device& device);
311318
#ifdef BUILD_CUDA_MODULE
312319

313320
int GetDevice();
314-
CUDAStream GetDefaultStream();
315321

316322
/// Calls cudaStreamSynchronize() for the specified CUDA stream.
317323
/// \param stream The stream to be synchronized.

cpp/open3d/core/hashmap/CUDA/StdGPUHashBackend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ void StdGPUHashBackend<Key, Hash, Eq>::Allocate(int64_t capacity) {
401401
// stdgpu initializes on the default stream. Set the current stream to
402402
// ensure correct behavior.
403403
{
404-
CUDAScopedStream scoped_stream(cuda::GetDefaultStream());
404+
CUDAScopedStream scoped_stream(CUDAStream::Default());
405405

406406
impl_ = InternalStdGPUHashBackend<Key, Hash, Eq>::createDeviceObject(
407407
this->capacity_,
@@ -419,7 +419,7 @@ void StdGPUHashBackend<Key, Hash, Eq>::Free() {
419419
// stdgpu initializes on the default stream. Set the current stream to
420420
// ensure correct behavior.
421421
{
422-
CUDAScopedStream scoped_stream(cuda::GetDefaultStream());
422+
CUDAScopedStream scoped_stream(CUDAStream::Default());
423423

424424
InternalStdGPUHashBackend<Key, Hash, Eq>::destroyDeviceObject(impl_);
425425
}

cpp/tests/core/CUDAUtils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void CheckScopedStreamManually() {
4545
int current_device = core::cuda::GetDevice();
4646

4747
ASSERT_EQ(core::CUDAStream::GetInstance().Get(),
48-
core::cuda::GetDefaultStream().Get());
48+
core::CUDAStream::Default().Get());
4949
ASSERT_EQ(core::cuda::GetDevice(), current_device);
5050

5151
core::CUDAStream stream = core::CUDAStream::CreateNew();
@@ -68,20 +68,20 @@ void CheckScopedStreamAutomatically() {
6868
int current_device = core::cuda::GetDevice();
6969

7070
ASSERT_EQ(core::CUDAStream::GetInstance().Get(),
71-
core::cuda::GetDefaultStream());
71+
core::CUDAStream::Default());
7272
ASSERT_EQ(core::cuda::GetDevice(), current_device);
7373

7474
{
7575
core::CUDAScopedStream scoped_stream(
7676
core::CUDAScopedStream::CreateNewStream);
7777

7878
ASSERT_NE(core::CUDAStream::GetInstance().Get(),
79-
core::cuda::GetDefaultStream());
79+
core::CUDAStream::Default());
8080
ASSERT_EQ(core::cuda::GetDevice(), current_device);
8181
}
8282

8383
ASSERT_EQ(core::CUDAStream::GetInstance().Get(),
84-
core::cuda::GetDefaultStream());
84+
core::CUDAStream::Default());
8585
ASSERT_EQ(core::cuda::GetDevice(), current_device);
8686
}
8787

0 commit comments

Comments
 (0)