Skip to content

Commit eb951dc

Browse files
authored
[UR][Offload] Fix offload adapter after #18901 (#18926)
We were storing handles in vectors, which is now forbidden.
1 parent c4fd965 commit eb951dc

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

unified-runtime/source/adapters/offload/adapter.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,17 @@ ur_result_t ur_adapter_handle_t_::init() {
4343
} else if (Backend != OL_PLATFORM_BACKEND_UNKNOWN) {
4444
auto URPlatform =
4545
std::find_if(Platforms->begin(), Platforms->end(), [&](auto &P) {
46-
return P.OffloadPlatform == Platform;
46+
return P->OffloadPlatform == Platform;
4747
});
4848

4949
if (URPlatform == Platforms->end()) {
50-
URPlatform =
51-
Platforms->insert(URPlatform, ur_platform_handle_t_(Platform));
50+
URPlatform = Platforms->insert(
51+
URPlatform, std::make_unique<ur_platform_handle_t_>(Platform));
5252
}
5353

54-
URPlatform->Devices.push_back(ur_device_handle_t_{&*URPlatform, D});
54+
(*URPlatform)
55+
->Devices.push_back(
56+
std::make_unique<ur_device_handle_t_>(URPlatform->get(), D));
5557
}
5658
return false;
5759
},

unified-runtime/source/adapters/offload/adapter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct ur_adapter_handle_t_ : ur::offload::handle_base {
2424
std::atomic_uint32_t RefCount = 0;
2525
logger::Logger &Logger = logger::get_logger("offload");
2626
ol_device_handle_t HostDevice = nullptr;
27-
std::vector<ur_platform_handle_t_> Platforms;
27+
std::vector<std::unique_ptr<ur_platform_handle_t_>> Platforms;
2828

2929
ur_result_t init();
3030
};

unified-runtime/source/adapters/offload/device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGet(ur_platform_handle_t hPlatform,
2929
std::min(static_cast<uint32_t>(hPlatform->Devices.size()), NumEntries);
3030

3131
for (size_t I = 0; I < NumDevices; I++) {
32-
phDevices[I] = &hPlatform->Devices[I];
32+
phDevices[I] = hPlatform->Devices[I].get();
3333
}
3434

3535
return UR_RESULT_SUCCESS;

unified-runtime/source/adapters/offload/platform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ urPlatformGet(ur_adapter_handle_t, uint32_t NumEntries,
2828
if (phPlatforms) {
2929
size_t PlatformIndex = 0;
3030
for (auto &Platform : Adapter.Platforms) {
31-
phPlatforms[PlatformIndex++] = &Platform;
31+
phPlatforms[PlatformIndex++] = Platform.get();
3232
if (PlatformIndex == NumEntries) {
3333
break;
3434
}

unified-runtime/source/adapters/offload/platform.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ struct ur_platform_handle_t_ : ur::offload::handle_base {
2020
: handle_base(), OffloadPlatform(OffloadPlatform) {};
2121

2222
ol_platform_handle_t OffloadPlatform;
23-
std::vector<ur_device_handle_t_> Devices;
23+
std::vector<std::unique_ptr<ur_device_handle_t_>> Devices;
2424
};

0 commit comments

Comments
 (0)