Skip to content

Commit 0833052

Browse files
authored
[SYCL][CUDA] Add the Use Default Stream property (#4004)
Adding a queue property that uses the default CUDA stream instead of creating a new CUDA stream. This is used for interop with CUDA runtime applications that use the default stream. Signed-off-by: Ruyman Reyes <ruyman@codeplay.com>
1 parent 5fca77b commit 0833052

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

sycl/include/CL/sycl/detail/property_helper.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ enum DataLessPropKind {
3232
BufferUsePinnedHostMemory = 5,
3333
UsePrimaryContext = 6,
3434
InitializeToIdentity = 7,
35+
UseDefaultStream = 8,
3536
// Indicates the last known dataless property.
36-
LastKnownDataLessPropKind = 7,
37+
LastKnownDataLessPropKind = 8,
3738
// Exceeding 32 may cause ABI breaking change on some of OSes.
3839
DataLessPropKindSize = 32
3940
};

sycl/include/CL/sycl/properties/queue_properties.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ namespace queue {
1717
class in_order : public detail::DataLessProperty<detail::InOrder> {};
1818
class enable_profiling
1919
: public detail::DataLessProperty<detail::QueueEnableProfiling> {};
20+
namespace cuda {
21+
class use_default_stream
22+
: public detail::DataLessProperty<detail::UseDefaultStream> {};
23+
} // namespace cuda
2024
} // namespace queue
2125
} // namespace property
2226
} // namespace sycl

sycl/source/detail/queue_impl.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#pragma once
1010

1111
#include <CL/sycl/context.hpp>
12+
#include <CL/sycl/detail/cuda_definitions.hpp>
1213
#include <CL/sycl/device.hpp>
1314
#include <CL/sycl/event.hpp>
1415
#include <CL/sycl/exception.hpp>
@@ -248,6 +249,9 @@ class queue_impl {
248249
if (MPropList.has_property<property::queue::enable_profiling>()) {
249250
CreationFlags |= PI_QUEUE_PROFILING_ENABLE;
250251
}
252+
if (MPropList.has_property<property::queue::cuda::use_default_stream>()) {
253+
CreationFlags |= __SYCL_PI_CUDA_USE_DEFAULT_STREAM;
254+
}
251255
RT::PiQueue Queue{};
252256
RT::PiContext Context = MContext->getHandleRef();
253257
RT::PiDevice Device = MDevice->getHandleRef();

sycl/unittests/pi/cuda/test_queue.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@
1010

1111
#include <cuda.h>
1212

13+
#include "TestGetPlatforms.hpp"
1314
#include "TestGetPlugin.hpp"
1415
#include <CL/sycl.hpp>
16+
#include <CL/sycl/backend/cuda.hpp>
1517
#include <CL/sycl/detail/cuda_definitions.hpp>
1618
#include <CL/sycl/detail/pi.hpp>
1719
#include <detail/plugin.hpp>
1820
#include <pi_cuda.hpp>
1921

20-
using namespace cl::sycl;
22+
using namespace sycl;
2123

22-
struct CudaTestQueue : public ::testing::Test {
24+
struct CudaTestQueue : public ::testing::TestWithParam<platform> {
2325

2426
protected:
2527
detail::plugin plugin = pi::initializeAndGet(backend::cuda);
@@ -149,3 +151,15 @@ TEST_F(CudaTestQueue, PICreateQueueInterop) {
149151
ASSERT_EQ((plugin.call_nocheck<detail::PiApiKind::piQueueRelease>(queue)),
150152
PI_SUCCESS);
151153
}
154+
155+
TEST_P(CudaTestQueue, SYCLQueueDefaultStream) {
156+
std::vector<device> CudaDevices = GetParam().get_devices();
157+
auto deviceA_ = CudaDevices[0];
158+
queue Queue(deviceA_, async_handler{},
159+
{property::queue::cuda::use_default_stream{}});
160+
161+
CUstream CudaStream = get_native<backend::cuda>(Queue);
162+
unsigned int flags;
163+
cuStreamGetFlags(CudaStream, &flags);
164+
ASSERT_EQ(flags, CU_STREAM_DEFAULT);
165+
}

0 commit comments

Comments
 (0)