Skip to content

[SYCL][CUDA] Using Custom context by default #1742

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 2 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions sycl/plugins/cuda/pi_cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3340,6 +3340,7 @@ pi_result cuda_piEnqueueMemBufferMap(pi_queue command_queue, pi_mem buffer,
pi_event *retEvent, void **ret_map) {

assert(ret_map != nullptr);
assert(command_queue != nullptr);

pi_result ret_err = PI_INVALID_OPERATION;

Expand All @@ -3361,9 +3362,15 @@ pi_result cuda_piEnqueueMemBufferMap(pi_queue command_queue, pi_mem buffer,
num_events_in_wait_list, event_wait_list, retEvent);
} else {
if (retEvent) {
*retEvent =
_pi_event::make_native(PI_COMMAND_TYPE_MEM_BUFFER_MAP, command_queue);
(*retEvent)->record();
try {
ScopedContext active(command_queue->get_context());

*retEvent = _pi_event::make_native(PI_COMMAND_TYPE_MEM_BUFFER_MAP,
command_queue);
(*retEvent)->record();
} catch (pi_result error) {
ret_err = error;
}
}
}

Expand All @@ -3380,6 +3387,7 @@ pi_result cuda_piEnqueueMemUnmap(pi_queue command_queue, pi_mem memobj,
pi_event *retEvent) {
pi_result ret_err = PI_SUCCESS;

assert(command_queue != nullptr);
assert(mapped_ptr != nullptr);
assert(memobj != nullptr);
assert(memobj->get_map_ptr() != nullptr);
Expand All @@ -3393,9 +3401,15 @@ pi_result cuda_piEnqueueMemUnmap(pi_queue command_queue, pi_mem memobj,
retEvent);
} else {
if (retEvent) {
*retEvent = _pi_event::make_native(PI_COMMAND_TYPE_MEM_BUFFER_UNMAP,
command_queue);
(*retEvent)->record();
try {
ScopedContext active(command_queue->get_context());

*retEvent = _pi_event::make_native(PI_COMMAND_TYPE_MEM_BUFFER_UNMAP,
command_queue);
(*retEvent)->record();
} catch (pi_result error) {
ret_err = error;
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions sycl/source/detail/context_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ context_impl::context_impl(const vector_class<cl::sycl::device> Devices,

if (MPlatform->is_cuda()) {
#if USE_PI_CUDA
const pi_context_properties props[] = {PI_CONTEXT_PROPERTIES_CUDA_PRIMARY,
UseCUDAPrimaryContext, 0};
const pi_context_properties props[] = {
static_cast<pi_context_properties>(PI_CONTEXT_PROPERTIES_CUDA_PRIMARY),
static_cast<pi_context_properties>(UseCUDAPrimaryContext), 0};

getPlugin().call<PiApiKind::piContextCreate>(props, DeviceIds.size(),
DeviceIds.data(), nullptr, nullptr, &MContext);
Expand Down
10 changes: 9 additions & 1 deletion sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ using DeviceImplPtr = shared_ptr_class<detail::device_impl>;
/// Sets max number of queues supported by FPGA RT.
const size_t MaxNumQueues = 256;

//// Possible CUDA context types supported by PI CUDA backend
/// TODO: Implement this as a property once there is an extension document
enum class cuda_context_type : char { primary, custom };

/// Default context type created for CUDA backend
constexpr cuda_context_type DefaultContextType = cuda_context_type::custom;

enum QueueOrder { Ordered, OOO };

class queue_impl {
Expand All @@ -50,7 +57,8 @@ class queue_impl {
const property_list &PropList)
: queue_impl(Device,
detail::getSyclObjImpl(context(
createSyclObjFromImpl<device>(Device), {}, true)),
createSyclObjFromImpl<device>(Device), {},
(DefaultContextType == cuda_context_type::primary))),
AsyncHandler, Order, PropList){};

/// Constructs a SYCL queue with an async_handler and property_list provided
Expand Down