Skip to content

[SYCL] Create memory allocators for contexts with single root-device #4317

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 1 commit into from
Aug 12, 2021
Merged
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
54 changes: 34 additions & 20 deletions sycl/plugins/level_zero/pi_level_zero.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ struct _pi_context : _pi_object {
OwnZeContext{OwnZeContext}, Devices{Devs, Devs + NumDevices},
ZeCommandListInit{nullptr}, ZeEventPool{nullptr},
NumEventsAvailableInEventPool{}, NumEventsUnreleasedInEventPool{} {
// NOTE: one must additionally call initialize() to complete
// PI context creation.

// Create USM allocator context for each pair (device, context).
for (uint32_t I = 0; I < NumDevices; I++) {
pi_device Device = Devs[I];
Expand All @@ -395,8 +398,6 @@ struct _pi_context : _pi_object {
std::piecewise_construct, std::make_tuple(Device),
std::make_tuple(std::unique_ptr<SystemMemory>(
new USMDeviceMemoryAlloc(this, Device))));
// NOTE: one must additionally call initialize() to complete
// PI context creation.
}
// Create USM allocator context for host. Device and Shared USM allocations
// are device-specific. Host allocations are not device-dependent therefore
Expand All @@ -406,27 +407,40 @@ struct _pi_context : _pi_object {

if (NumDevices == 1) {
SingleRootDevice = Devices[0];
return;
}

// Check if we have context with subdevices of the same device (context may
// include root device itself as well)
SingleRootDevice =
Devices[0]->RootDevice ? Devices[0]->RootDevice : Devices[0];
} else {

// Check if we have context with subdevices of the same device (context
// may include root device itself as well)
SingleRootDevice =
Devices[0]->RootDevice ? Devices[0]->RootDevice : Devices[0];

// For context with sub subdevices, the SingleRootDevice might still
// not be the root device.
// Check whether the SingleRootDevice is the subdevice or root device.
if (SingleRootDevice->isSubDevice()) {
SingleRootDevice = SingleRootDevice->RootDevice;
}

// For context with sub subdevices, the SingleRootDevice might still
// not be the root device.
// Check whether the SingleRootDevice is the subdevice or root device.
if (SingleRootDevice->isSubDevice()) {
SingleRootDevice = SingleRootDevice->RootDevice;
for (auto &Device : Devices) {
if ((!Device->RootDevice && Device != SingleRootDevice) ||
(Device->RootDevice && Device->RootDevice != SingleRootDevice)) {
SingleRootDevice = nullptr;
break;
}
}
}

for (auto &Device : Devices) {
if ((!Device->RootDevice && Device != SingleRootDevice) ||
(Device->RootDevice && Device->RootDevice != SingleRootDevice)) {
SingleRootDevice = nullptr;
break;
}
// We may allocate memory to this root device so create allocators.
if (SingleRootDevice && DeviceMemAllocContexts.find(SingleRootDevice) ==
DeviceMemAllocContexts.end()) {
SharedMemAllocContexts.emplace(
std::piecewise_construct, std::make_tuple(SingleRootDevice),
std::make_tuple(std::unique_ptr<SystemMemory>(
new USMSharedMemoryAlloc(this, SingleRootDevice))));
DeviceMemAllocContexts.emplace(
std::piecewise_construct, std::make_tuple(SingleRootDevice),
std::make_tuple(std::unique_ptr<SystemMemory>(
new USMDeviceMemoryAlloc(this, SingleRootDevice))));
}
}

Expand Down