1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
/*
* Copyright (C) 2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#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/zer_api.h>
namespace L0 {
ze_context_handle_t ZE_APICALL zerGetDefaultContext() {
return L0::DriverHandle::fromHandle(L0::globalDriverHandles->front())->getDefaultContext();
}
ze_result_t ZE_APICALL zerGetLastErrorDescription(const char **ppString) {
return L0::DriverHandle::fromHandle(L0::globalDriverHandles->front())->getErrorDescription(ppString);
}
uint32_t ZE_APICALL zerTranslateDeviceHandleToIdentifier(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 zerTranslateIdentifierToDeviceHandle(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];
}
} // namespace L0
extern "C" {
ZE_APIEXPORT ze_context_handle_t ZE_APICALL zerGetDefaultContext() {
return L0::zerGetDefaultContext();
}
ZE_APIEXPORT ze_result_t ZE_APICALL zerGetLastErrorDescription(const char **ppString) {
return L0::zerGetLastErrorDescription(ppString);
}
ZE_APIEXPORT uint32_t ZE_APICALL zerTranslateDeviceHandleToIdentifier(ze_device_handle_t device) {
return L0::zerTranslateDeviceHandleToIdentifier(device);
}
ZE_APIEXPORT ze_device_handle_t ZE_APICALL zerTranslateIdentifierToDeviceHandle(uint32_t identifier) {
return L0::zerTranslateIdentifierToDeviceHandle(identifier);
}
}
|