refactor: correct location of definition of new L0 API functions

L0 API functions have two definitions, internal and external:
- internal definition is in L0 namespace
- external defintion is in extern C scope and points to internal definition

Below API functions are corrected within this change:
- zeDriverGetDefaultContext
- zerDriverGetDefaultContext
- zerDeviceTranslateToIdentifier
- zerIdentifierTranslateToDeviceHandle
- zeDeviceSynchronize

Related-To: NEO-14560
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski 2025-05-14 10:15:56 +00:00 committed by Compute-Runtime-Automation
parent cb76bbbf7d
commit 041f879e64
9 changed files with 80 additions and 68 deletions

View File

@ -10,6 +10,7 @@
#include "level_zero/core/source/device/device.h"
#include "level_zero/core/source/driver/driver.h"
#include "level_zero/core/source/driver/driver_handle.h"
#include "level_zero/core/source/driver/driver_handle_imp.h"
#include "level_zero/core/source/semaphore/external_semaphore_imp.h"
#include <level_zero/ze_api.h>
#include <level_zero/ze_ddi.h>
@ -151,6 +152,27 @@ ze_result_t zeDeviceReleaseExternalSemaphoreExt(
return L0::ExternalSemaphoreImp::fromHandle(hSemaphore)->releaseExternalSemaphore();
}
uint32_t zerDeviceTranslateToIdentifier(ze_device_handle_t device) {
if (!device) {
auto driverHandle = static_cast<L0::DriverHandleImp *>(L0::globalDriverHandles->front());
driverHandle->setErrorDescription("Invalid device handle");
return std::numeric_limits<uint32_t>::max();
}
return L0::Device::fromHandle(device)->getIdentifier();
}
ze_device_handle_t zerIdentifierTranslateToDeviceHandle(uint32_t identifier) {
auto driverHandle = static_cast<L0::DriverHandleImp *>(L0::globalDriverHandles->front());
if (identifier >= driverHandle->devicesToExpose.size()) {
driverHandle->setErrorDescription("Invalid device identifier");
return nullptr;
}
return driverHandle->devicesToExpose[identifier];
}
ze_result_t zeDeviceSynchronize(ze_device_handle_t hDevice) {
return L0::Device::fromHandle(hDevice)->synchronize();
}
} // namespace L0
extern "C" {
@ -320,4 +342,16 @@ ZE_APIEXPORT ze_result_t ZE_APICALL zeDeviceReleaseExternalSemaphoreExt(
ze_external_semaphore_ext_handle_t hSemaphore) {
return L0::ExternalSemaphoreImp::fromHandle(hSemaphore)->releaseExternalSemaphore();
}
uint32_t ZE_APICALL zerDeviceTranslateToIdentifier(ze_device_handle_t device) {
return L0::zerDeviceTranslateToIdentifier(device);
}
ze_device_handle_t ZE_APICALL zerIdentifierTranslateToDeviceHandle(uint32_t identifier) {
return L0::zerIdentifierTranslateToDeviceHandle(identifier);
}
ze_result_t ZE_APICALL zeDeviceSynchronize(ze_device_handle_t hDevice) {
return L0::zeDeviceSynchronize(hDevice);
}
}

View File

@ -66,6 +66,15 @@ ze_result_t zeDriverGetExtensionFunctionAddress(
return L0::BaseDriver::fromHandle(hDriver)->getExtensionFunctionAddress(name, ppFunctionAddress);
}
ze_context_handle_t zeDriverGetDefaultContext(
ze_driver_handle_t hDriver) {
return L0::DriverHandle::fromHandle(hDriver)->getDefaultContext();
}
ze_context_handle_t zerDriverGetDefaultContext() {
return L0::DriverHandle::fromHandle(L0::globalDriverHandles->front())->getDefaultContext();
}
} // namespace L0
extern "C" {
@ -140,4 +149,13 @@ ZE_APIEXPORT ze_result_t ZE_APICALL zeDriverGetExtensionFunctionAddress(
name,
ppFunctionAddress);
}
ze_context_handle_t ZE_APICALL zeDriverGetDefaultContext(
ze_driver_handle_t hDriver) {
return L0::zeDriverGetDefaultContext(hDriver);
}
ze_context_handle_t ZE_APICALL zerDriverGetDefaultContext() {
return L0::zerDriverGetDefaultContext();
}
}

View File

@ -9,7 +9,6 @@ target_sources(${L0_STATIC_LIB_NAME}
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/zex_cmdlist.cpp
${CMAKE_CURRENT_SOURCE_DIR}/zex_context.cpp
${CMAKE_CURRENT_SOURCE_DIR}/zex_device.cpp
${CMAKE_CURRENT_SOURCE_DIR}/zex_driver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/zex_event.cpp
${CMAKE_CURRENT_SOURCE_DIR}/zex_memory.cpp

View File

@ -1,58 +0,0 @@
/*
* Copyright (C) 2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/command_stream/command_stream_receiver.h"
#include "shared/source/device/device.h"
#include "level_zero/core/source/device/device.h"
#include "level_zero/core/source/driver/driver.h"
#include "level_zero/core/source/driver/driver_handle_imp.h"
#include "level_zero/ze_intel_gpu.h"
uint32_t ZE_APICALL zerDeviceTranslateToIdentifier(ze_device_handle_t device) {
if (!device) {
auto driverHandle = static_cast<L0::DriverHandleImp *>(L0::globalDriverHandles->front());
driverHandle->setErrorDescription("Invalid device handle");
return std::numeric_limits<uint32_t>::max();
}
return L0::Device::fromHandle(device)->getIdentifier();
}
ze_device_handle_t ZE_APICALL zerIdentifierTranslateToDeviceHandle(uint32_t identifier) {
auto driverHandle = static_cast<L0::DriverHandleImp *>(L0::globalDriverHandles->front());
if (identifier >= driverHandle->devicesToExpose.size()) {
driverHandle->setErrorDescription("Invalid device identifier");
return nullptr;
}
return driverHandle->devicesToExpose[identifier];
}
ze_result_t ZE_APICALL zeDeviceSynchronize(ze_device_handle_t hDevice) {
auto device = L0::Device::fromHandle(hDevice);
for (auto &engine : device->getNEODevice()->getAllEngines()) {
auto waitStatus = engine.commandStreamReceiver->waitForTaskCountWithKmdNotifyFallback(
engine.commandStreamReceiver->peekTaskCount(),
engine.commandStreamReceiver->obtainCurrentFlushStamp(),
false,
NEO::QueueThrottle::MEDIUM);
if (waitStatus == NEO::WaitStatus::gpuHang) {
return ZE_RESULT_ERROR_DEVICE_LOST;
}
}
for (auto &secondaryCsr : device->getNEODevice()->getSecondaryCsrs()) {
auto waitStatus = secondaryCsr->waitForTaskCountWithKmdNotifyFallback(
secondaryCsr->peekTaskCount(),
secondaryCsr->obtainCurrentFlushStamp(),
false,
NEO::QueueThrottle::MEDIUM);
if (waitStatus == NEO::WaitStatus::gpuHang) {
return ZE_RESULT_ERROR_DEVICE_LOST;
}
}
return ZE_RESULT_SUCCESS;
}

View File

@ -63,15 +63,6 @@ zeIntelGetDriverVersionString(
return ZE_RESULT_SUCCESS;
}
ze_context_handle_t ZE_APICALL zeDriverGetDefaultContext(
ze_driver_handle_t hDriver) {
return L0::DriverHandle::fromHandle(hDriver)->getDefaultContext();
}
ze_context_handle_t ZE_APICALL zerDriverGetDefaultContext() {
return L0::DriverHandle::fromHandle(L0::globalDriverHandles->front())->getDefaultContext();
}
extern "C" {
ZE_APIEXPORT ze_result_t ZE_APICALL

View File

@ -91,6 +91,7 @@ struct Device : _ze_device_handle_t {
virtual ze_result_t getDebugProperties(zet_device_debug_properties_t *pDebugProperties) = 0;
virtual ze_result_t systemBarrier() = 0;
virtual ze_result_t synchronize() = 0;
virtual ~Device() = default;

View File

@ -2152,4 +2152,29 @@ uint32_t DeviceImp::getEventMaxKernelCount() const {
return l0GfxCoreHelper.getEventMaxKernelCount(hardwareInfo);
}
ze_result_t DeviceImp::synchronize() {
for (auto &engine : neoDevice->getAllEngines()) {
auto waitStatus = engine.commandStreamReceiver->waitForTaskCountWithKmdNotifyFallback(
engine.commandStreamReceiver->peekTaskCount(),
engine.commandStreamReceiver->obtainCurrentFlushStamp(),
false,
NEO::QueueThrottle::MEDIUM);
if (waitStatus == NEO::WaitStatus::gpuHang) {
return ZE_RESULT_ERROR_DEVICE_LOST;
}
}
for (auto &secondaryCsr : neoDevice->getSecondaryCsrs()) {
auto waitStatus = secondaryCsr->waitForTaskCountWithKmdNotifyFallback(
secondaryCsr->peekTaskCount(),
secondaryCsr->obtainCurrentFlushStamp(),
false,
NEO::QueueThrottle::MEDIUM);
if (waitStatus == NEO::WaitStatus::gpuHang) {
return ZE_RESULT_ERROR_DEVICE_LOST;
}
}
return ZE_RESULT_SUCCESS;
}
} // namespace L0

View File

@ -75,6 +75,7 @@ struct DeviceImp : public Device, NEO::NonCopyableAndNonMovableClass {
ze_result_t getDebugProperties(zet_device_debug_properties_t *pDebugProperties) override;
ze_result_t systemBarrier() override;
ze_result_t synchronize() override;
void *getExecEnvironment() override;
BuiltinFunctionsLib *getBuiltinFunctionsLib() override;
uint32_t getMOCS(bool l3enabled, bool l1enabled) override;

View File

@ -50,6 +50,7 @@ struct MockDevice : public Device {
ADDMETHOD_NOBASE(getExternalMemoryProperties, ze_result_t, ZE_RESULT_SUCCESS, (ze_device_external_memory_properties_t * pExternalMemoryProperties));
ADDMETHOD_NOBASE(getGlobalTimestamps, ze_result_t, ZE_RESULT_SUCCESS, (uint64_t * hostTimestamp, uint64_t *deviceTimestamp));
ADDMETHOD_NOBASE(systemBarrier, ze_result_t, ZE_RESULT_SUCCESS, ());
ADDMETHOD_NOBASE(synchronize, ze_result_t, ZE_RESULT_SUCCESS, ());
ADDMETHOD_NOBASE(getRootDevice, ze_result_t, ZE_RESULT_SUCCESS, (ze_device_handle_t * phRootDevice));
// Runtime internal methods
ADDMETHOD_NOBASE(getExecEnvironment, void *, nullptr, ());