Skip to content
Closed
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
7 changes: 7 additions & 0 deletions source/adapters/level_zero/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ struct ur_context_handle_t_ : _ur_object {
std::vector<ur_device_handle_t> Devices;
uint32_t NumDevices{};

// Selects the single device in the context to which the urProgramBuild
// should choose to build the program to.
// TODO: this should be removed and program should be built to all the
// devices in the context (possibly on demand only).
//
ur_device_handle_t Build2Device = nullptr;

// Immediate Level Zero command list for the device in this context, to be
// used for initializations. To be created as:
// - Immediate command list: So any command appended to it is immediately
Expand Down
5 changes: 4 additions & 1 deletion source/adapters/level_zero/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramBuild(
ZeModuleDesc.pBuildFlags = Options;
ZeModuleDesc.pConstants = Shim.ze();

ze_device_handle_t ZeDevice = Context->Devices[0]->ZeDevice;
auto Build2Device = Context->Build2Device;
if (!Build2Device)
Build2Device = Context->Devices[0];
ze_device_handle_t ZeDevice = Build2Device->ZeDevice;
ze_context_handle_t ZeContext = Program->Context->ZeContext;
ze_module_handle_t ZeModule = nullptr;

Expand Down
27 changes: 14 additions & 13 deletions source/adapters/level_zero/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,21 +294,22 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreate(
{ // Lock context for thread-safe update
std::scoped_lock<ur_shared_mutex> Lock(Context->Mutex);
UR_ASSERT(Context->isValidDevice(Device), UR_RESULT_ERROR_INVALID_DEVICE);

auto MakeFirst = Context->Devices.begin();
for (auto I = Context->Devices.begin(); I != Context->Devices.end(); ++I) {
if (*I == Device) {
MakeFirst = I;
if (!Device->RootDevice)
break;
// continue the search for possible root-device in the context
} else if (*I == Device->RootDevice) {
MakeFirst = I;
break; // stop the search
if (!Context->Build2Device) {
auto DeviceIt = Context->Devices.begin();
for (auto I = Context->Devices.begin(); I != Context->Devices.end();
++I) {
if (*I == Device) {
DeviceIt = I;
if (!Device->RootDevice)
break;
// continue the search for possible root-device in the context
} else if (*I == Device->RootDevice) {
DeviceIt = I;
break; // stop the search
}
}
Context->Build2Device = *DeviceIt;
}
if (MakeFirst != Context->Devices.begin())
std::iter_swap(MakeFirst, Context->Devices.begin());
}
ur_queue_flags_t Flags{};
if (Props) {
Expand Down