Skip to content
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

[UR][L0] Prefer to build to a device in the context where the first(!… #901

Closed
wants to merge 1 commit into from
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
[UR][L0] Prefer to build to a device in the context where the first(!…
…) queue is created

Co-authored-by: Sergey Maslov <sergey.v.maslov@intel.com>
Signed-off-by: Spruit, Neil R <neil.r.spruit@intel.com>
  • Loading branch information
nrspruit and smaslov-intel committed Sep 27, 2023
commit fdce5a9768cfa90be085b39a49a1ec7cdf8840f8
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
Loading