Skip to content

[UR][L0 adapter] Move a piece of init code code to platform #18237

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

Open
wants to merge 1 commit into
base: sycl
Choose a base branch
from
Open
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
24 changes: 6 additions & 18 deletions unified-runtime/source/adapters/level_zero/image_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@
#include "helpers/memory_helpers.hpp"
#include "image_common.hpp"
#include "logger/ur_logger.hpp"
#include "platform.hpp"
#include "sampler.hpp"
#include "ur_interface_loader.hpp"

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

typedef ze_result_t(ZE_APICALL *zeImageGetDeviceOffsetExp_pfn)(
ze_image_handle_t hImage, uint64_t *pDeviceOffset);

zeMemGetPitchFor2dImage_pfn zeMemGetPitchFor2dImageFunctionPtr = nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this one as well?

zeImageGetDeviceOffsetExp_pfn zeImageGetDeviceOffsetExpFunctionPtr = nullptr;

namespace {

Expand Down Expand Up @@ -351,25 +348,16 @@ ur_result_t bindlessImagesCreateImpl(ur_context_handle_t hContext,
return UR_RESULT_ERROR_INVALID_VALUE;
}

static std::once_flag InitFlag;
std::call_once(InitFlag, [&]() {
ze_driver_handle_t DriverHandle = hContext->getPlatform()->ZeDriver;
auto Result = zeDriverGetExtensionFunctionAddress(
DriverHandle, "zeImageGetDeviceOffsetExp",
(void **)&zeImageGetDeviceOffsetExpFunctionPtr);
if (Result != ZE_RESULT_SUCCESS)
logger::error("zeDriverGetExtensionFunctionAddress "
"zeImageGetDeviceOffsetExpv failed, err = {}",
Result);
});
if (!zeImageGetDeviceOffsetExpFunctionPtr)
if (!hDevice->Platform->ZeImageGetDeviceOffsetExt.Supported)
return UR_RESULT_ERROR_INVALID_OPERATION;

uint64_t DeviceOffset{};
ze_image_handle_t ZeImageTranslated;
ZE2UR_CALL(zelLoaderTranslateHandle,
(ZEL_HANDLE_IMAGE, ZeImage, (void **)&ZeImageTranslated));
ZE2UR_CALL(zeImageGetDeviceOffsetExpFunctionPtr,
(ZeImageTranslated, &DeviceOffset));
ZE2UR_CALL(
hDevice->Platform->ZeImageGetDeviceOffsetExt.zeImageGetDeviceOffsetExp,
(ZeImageTranslated, &DeviceOffset));
*phImage = DeviceOffset;

std::shared_lock<ur_shared_mutex> Lock(hDevice->Mutex);
Expand Down
8 changes: 8 additions & 0 deletions unified-runtime/source/adapters/level_zero/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,14 @@ ur_result_t ur_platform_handle_t_::initialize() {
.zeCommandListImmediateAppendCommandListsExp != nullptr;
}

ZE_CALL_NOCHECK(zeDriverGetExtensionFunctionAddress,
(ZeDriver, "zeImageGetDeviceOffsetExp",
reinterpret_cast<void **>(
&ZeImageGetDeviceOffsetExt.zeImageGetDeviceOffsetExp)));

ZeImageGetDeviceOffsetExt.Supported =
ZeImageGetDeviceOffsetExt.zeImageGetDeviceOffsetExp != nullptr;

return UR_RESULT_SUCCESS;
}

Expand Down
5 changes: 5 additions & 0 deletions unified-runtime/source/adapters/level_zero/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,9 @@ struct ur_platform_handle_t_ : public ur_platform {
ze_command_list_handle_t, uint32_t, ze_command_list_handle_t *,
ze_event_handle_t, uint32_t, ze_event_handle_t *);
} ZeCommandListImmediateAppendExt;

struct ZeImageGetDeviceOffsetExtension {
bool Supported = false;
ze_result_t (*zeImageGetDeviceOffsetExp)(ze_image_handle_t, uint64_t *);
} ZeImageGetDeviceOffsetExt;
};