Skip to content

Commit bb7e32a

Browse files
committed
[UR][L0 adapter] Move init code to platform
Signed-off-by: Mateusz P. Nowak <[email protected]>
1 parent 0caa83c commit bb7e32a

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

unified-runtime/source/adapters/level_zero/image_common.cpp

+6-18
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,15 @@
1919
#include "helpers/memory_helpers.hpp"
2020
#include "image_common.hpp"
2121
#include "logger/ur_logger.hpp"
22+
#include "platform.hpp"
2223
#include "sampler.hpp"
2324
#include "ur_interface_loader.hpp"
2425

2526
typedef ze_result_t(ZE_APICALL *zeMemGetPitchFor2dImage_pfn)(
2627
ze_context_handle_t hContext, ze_device_handle_t hDevice, size_t imageWidth,
2728
size_t imageHeight, unsigned int elementSizeInBytes, size_t *rowPitch);
2829

29-
typedef ze_result_t(ZE_APICALL *zeImageGetDeviceOffsetExp_pfn)(
30-
ze_image_handle_t hImage, uint64_t *pDeviceOffset);
31-
3230
zeMemGetPitchFor2dImage_pfn zeMemGetPitchFor2dImageFunctionPtr = nullptr;
33-
zeImageGetDeviceOffsetExp_pfn zeImageGetDeviceOffsetExpFunctionPtr = nullptr;
3431

3532
namespace {
3633

@@ -351,25 +348,16 @@ ur_result_t bindlessImagesCreateImpl(ur_context_handle_t hContext,
351348
return UR_RESULT_ERROR_INVALID_VALUE;
352349
}
353350

354-
static std::once_flag InitFlag;
355-
std::call_once(InitFlag, [&]() {
356-
ze_driver_handle_t DriverHandle = hContext->getPlatform()->ZeDriver;
357-
auto Result = zeDriverGetExtensionFunctionAddress(
358-
DriverHandle, "zeImageGetDeviceOffsetExp",
359-
(void **)&zeImageGetDeviceOffsetExpFunctionPtr);
360-
if (Result != ZE_RESULT_SUCCESS)
361-
logger::error("zeDriverGetExtensionFunctionAddress "
362-
"zeImageGetDeviceOffsetExpv failed, err = {}",
363-
Result);
364-
});
365-
if (!zeImageGetDeviceOffsetExpFunctionPtr)
351+
if (!hDevice->Platform->ZeImageGetDeviceOffsetExt.Supported)
366352
return UR_RESULT_ERROR_INVALID_OPERATION;
353+
367354
uint64_t DeviceOffset{};
368355
ze_image_handle_t ZeImageTranslated;
369356
ZE2UR_CALL(zelLoaderTranslateHandle,
370357
(ZEL_HANDLE_IMAGE, ZeImage, (void **)&ZeImageTranslated));
371-
ZE2UR_CALL(zeImageGetDeviceOffsetExpFunctionPtr,
372-
(ZeImageTranslated, &DeviceOffset));
358+
ZE2UR_CALL(
359+
hDevice->Platform->ZeImageGetDeviceOffsetExt.zeImageGetDeviceOffsetExp,
360+
(ZeImageTranslated, &DeviceOffset));
373361
*phImage = DeviceOffset;
374362

375363
std::shared_lock<ur_shared_mutex> Lock(hDevice->Mutex);

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

+8
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,14 @@ ur_result_t ur_platform_handle_t_::initialize() {
543543
.zeCommandListImmediateAppendCommandListsExp != nullptr;
544544
}
545545

546+
ZE_CALL_NOCHECK(zeDriverGetExtensionFunctionAddress,
547+
(ZeDriver, "zeImageGetDeviceOffsetExp",
548+
reinterpret_cast<void **>(
549+
&ZeImageGetDeviceOffsetExt.zeImageGetDeviceOffsetExp)));
550+
551+
ZeImageGetDeviceOffsetExt.Supported =
552+
ZeImageGetDeviceOffsetExt.zeImageGetDeviceOffsetExp != nullptr;
553+
546554
return UR_RESULT_SUCCESS;
547555
}
548556

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

+5
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,9 @@ struct ur_platform_handle_t_ : public ur_platform {
169169
ze_command_list_handle_t, uint32_t, ze_command_list_handle_t *,
170170
ze_event_handle_t, uint32_t, ze_event_handle_t *);
171171
} ZeCommandListImmediateAppendExt;
172+
173+
struct ZeImageGetDeviceOffsetExtension {
174+
bool Supported = false;
175+
ze_result_t (*zeImageGetDeviceOffsetExp)(ze_image_handle_t, uint64_t *);
176+
} ZeImageGetDeviceOffsetExt;
172177
};

0 commit comments

Comments
 (0)