From d49c5d6185892d217d918ee652af8bd0f780d0a4 Mon Sep 17 00:00:00 2001 From: Krystian Chmielewski Date: Thu, 3 Feb 2022 09:17:37 +0000 Subject: [PATCH] OCL: Set target device product family In OCL product family of target device is not set which leads to a fail on validating target device in ZEBin path. This change adds function that sets all necessary fields based on provided hardware info. Signed-off-by: Krystian Chmielewski --- level_zero/core/source/module/module_imp.cpp | 16 ++++------------ opencl/source/program/process_device_binary.cpp | 2 +- opencl/source/program/program.cpp | 12 +++--------- opencl/test/unit_test/program/program_tests.cpp | 6 +----- .../device_binary_formats.cpp | 13 ++++++++++++- .../device_binary_format/device_binary_formats.h | 4 +++- 6 files changed, 24 insertions(+), 29 deletions(-) diff --git a/level_zero/core/source/module/module_imp.cpp b/level_zero/core/source/module/module_imp.cpp index b44831dc88..2b5b85c217 100644 --- a/level_zero/core/source/module/module_imp.cpp +++ b/level_zero/core/source/module/module_imp.cpp @@ -240,11 +240,7 @@ bool ModuleTranslationUnit::createFromNativeBinary(const char *input, size_t inp UNRECOVERABLE_IF((nullptr == device) || (nullptr == device->getNEODevice())); auto productAbbreviation = NEO::hardwarePrefix[device->getNEODevice()->getHardwareInfo().platform.eProductFamily]; - NEO::TargetDevice targetDevice = {}; - targetDevice.coreFamily = device->getNEODevice()->getHardwareInfo().platform.eRenderCoreFamily; - targetDevice.productFamily = device->getNEODevice()->getHardwareInfo().platform.eProductFamily; - targetDevice.stepping = device->getNEODevice()->getHardwareInfo().platform.usRevId; - targetDevice.maxPointerSizeInBytes = sizeof(uintptr_t); + NEO::TargetDevice targetDevice = NEO::targetDeviceFromHwInfo(device->getNEODevice()->getHardwareInfo()); std::string decodeErrors; std::string decodeWarnings; ArrayRef archive(reinterpret_cast(input), inputSize); @@ -294,7 +290,7 @@ bool ModuleTranslationUnit::processUnpackedBinary() { auto blob = ArrayRef(reinterpret_cast(this->unpackedDeviceBinary.get()), this->unpackedDeviceBinarySize); NEO::SingleDeviceBinary binary = {}; binary.deviceBinary = blob; - binary.targetDevice.grfSize = device->getHwInfo().capabilityTable.grfSize; + binary.targetDevice = NEO::targetDeviceFromHwInfo(device->getHwInfo()); std::string decodeErrors; std::string decodeWarnings; @@ -354,17 +350,13 @@ bool ModuleTranslationUnit::processUnpackedBinary() { kernelInfo->apply(deviceInfoConstants); } - auto gfxCore = device->getNEODevice()->getHardwareInfo().platform.eRenderCoreFamily; - auto stepping = device->getNEODevice()->getHardwareInfo().platform.usRevId; - if (this->packedDeviceBinary != nullptr) { return true; } - NEO::SingleDeviceBinary singleDeviceBinary; + NEO::SingleDeviceBinary singleDeviceBinary = {}; + singleDeviceBinary.targetDevice = NEO::targetDeviceFromHwInfo(device->getNEODevice()->getHardwareInfo()); singleDeviceBinary.buildOptions = this->options; - singleDeviceBinary.targetDevice.coreFamily = gfxCore; - singleDeviceBinary.targetDevice.stepping = stepping; singleDeviceBinary.deviceBinary = ArrayRef(reinterpret_cast(this->unpackedDeviceBinary.get()), this->unpackedDeviceBinarySize); singleDeviceBinary.intermediateRepresentation = ArrayRef(reinterpret_cast(this->irBinary.get()), this->irBinarySize); singleDeviceBinary.debugData = ArrayRef(reinterpret_cast(this->debugData.get()), this->debugDataSize); diff --git a/opencl/source/program/process_device_binary.cpp b/opencl/source/program/process_device_binary.cpp index 1fa5ad0527..7c0c89b03a 100644 --- a/opencl/source/program/process_device_binary.cpp +++ b/opencl/source/program/process_device_binary.cpp @@ -156,7 +156,7 @@ cl_int Program::processGenBinary(const ClDevice &clDevice) { auto blob = ArrayRef(reinterpret_cast(buildInfo.unpackedDeviceBinary.get()), buildInfo.unpackedDeviceBinarySize); SingleDeviceBinary binary = {}; binary.deviceBinary = blob; - binary.targetDevice.grfSize = clDevice.getDevice().getHardwareInfo().capabilityTable.grfSize; + binary.targetDevice = NEO::targetDeviceFromHwInfo(clDevice.getDevice().getHardwareInfo()); std::string decodeErrors; std::string decodeWarnings; diff --git a/opencl/source/program/program.cpp b/opencl/source/program/program.cpp index 74c642f727..2be90be410 100644 --- a/opencl/source/program/program.cpp +++ b/opencl/source/program/program.cpp @@ -162,10 +162,7 @@ cl_int Program::createProgramFromBinary( auto hwInfo = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo(); auto productAbbreviation = hardwarePrefix[hwInfo->platform.eProductFamily]; - TargetDevice targetDevice = {}; - targetDevice.coreFamily = hwInfo->platform.eRenderCoreFamily; - targetDevice.stepping = hwInfo->platform.usRevId; - targetDevice.maxPointerSizeInBytes = sizeof(uintptr_t); + TargetDevice targetDevice = targetDeviceFromHwInfo(*hwInfo); std::string decodeErrors; std::string decodeWarnings; auto singleDeviceBinary = unpackSingleDeviceBinary(archive, ConstStringRef(productAbbreviation, strlen(productAbbreviation)), targetDevice, @@ -370,14 +367,11 @@ cl_int Program::packDeviceBinary(ClDevice &clDevice) { } auto hwInfo = executionEnvironment.rootDeviceEnvironments[rootDeviceIndex]->getHardwareInfo(); - auto gfxCore = hwInfo->platform.eRenderCoreFamily; - auto stepping = hwInfo->platform.usRevId; if (nullptr != this->buildInfos[rootDeviceIndex].unpackedDeviceBinary.get()) { - SingleDeviceBinary singleDeviceBinary; + SingleDeviceBinary singleDeviceBinary = {}; + singleDeviceBinary.targetDevice = NEO::targetDeviceFromHwInfo(*hwInfo); singleDeviceBinary.buildOptions = this->options; - singleDeviceBinary.targetDevice.coreFamily = gfxCore; - singleDeviceBinary.targetDevice.stepping = stepping; singleDeviceBinary.deviceBinary = ArrayRef(reinterpret_cast(this->buildInfos[rootDeviceIndex].unpackedDeviceBinary.get()), this->buildInfos[rootDeviceIndex].unpackedDeviceBinarySize); singleDeviceBinary.intermediateRepresentation = ArrayRef(reinterpret_cast(this->irBinary.get()), this->irBinarySize); singleDeviceBinary.debugData = ArrayRef(reinterpret_cast(this->buildInfos[rootDeviceIndex].debugData.get()), this->buildInfos[rootDeviceIndex].debugDataSize); diff --git a/opencl/test/unit_test/program/program_tests.cpp b/opencl/test/unit_test/program/program_tests.cpp index 179b5a231f..ff65cf6aac 100644 --- a/opencl/test/unit_test/program/program_tests.cpp +++ b/opencl/test/unit_test/program/program_tests.cpp @@ -1625,11 +1625,7 @@ TEST_F(ProgramWithDebugSymbolsTests, GivenProgramCreatedWithDashGOptionWhenGetti ArrayRef archive(reinterpret_cast(testBinary.get()), size); auto productAbbreviation = hardwarePrefix[pDevice->getHardwareInfo().platform.eProductFamily]; - TargetDevice targetDevice = {}; - - targetDevice.coreFamily = pDevice->getHardwareInfo().platform.eRenderCoreFamily; - targetDevice.stepping = pDevice->getHardwareInfo().platform.usRevId; - targetDevice.maxPointerSizeInBytes = sizeof(uintptr_t); + TargetDevice targetDevice = NEO::targetDeviceFromHwInfo(pDevice->getHardwareInfo()); std::string decodeErrors; std::string decodeWarnings; diff --git a/shared/source/device_binary_format/device_binary_formats.cpp b/shared/source/device_binary_format/device_binary_formats.cpp index e7ba7a509d..26a7c66ef6 100644 --- a/shared/source/device_binary_format/device_binary_formats.cpp +++ b/shared/source/device_binary_format/device_binary_formats.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,8 @@ #include "shared/source/device_binary_format/device_binary_formats.h" +#include "shared/source/helpers/hw_info.h" + namespace NEO { std::vector packDeviceBinary(const SingleDeviceBinary binary, std::string &outErrReason, std::string &outWarning) { @@ -16,4 +18,13 @@ std::vector packDeviceBinary(const SingleDeviceBinary binary, std::stri return packDeviceBinary(binary, outErrReason, outWarning); } +TargetDevice targetDeviceFromHwInfo(const HardwareInfo &hwInfo) { + TargetDevice targetDevice = {}; + targetDevice.coreFamily = hwInfo.platform.eRenderCoreFamily; + targetDevice.productFamily = hwInfo.platform.eProductFamily; + targetDevice.stepping = hwInfo.platform.usRevId; + targetDevice.maxPointerSizeInBytes = sizeof(uintptr_t); + targetDevice.grfSize = hwInfo.capabilityTable.grfSize; + return targetDevice; +} } // namespace NEO diff --git a/shared/source/device_binary_format/device_binary_formats.h b/shared/source/device_binary_format/device_binary_formats.h index 3f202f50c7..eed94b02bc 100644 --- a/shared/source/device_binary_format/device_binary_formats.h +++ b/shared/source/device_binary_format/device_binary_formats.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -18,6 +18,7 @@ namespace NEO { struct ProgramInfo; +struct HardwareInfo; enum class DeviceBinaryFormat : uint8_t { Unknown, @@ -60,6 +61,7 @@ struct TargetDevice { uint32_t maxPointerSizeInBytes = 4U; uint32_t grfSize = 32U; }; +TargetDevice targetDeviceFromHwInfo(const NEO::HardwareInfo &hwInfo); struct SingleDeviceBinary { DeviceBinaryFormat format = DeviceBinaryFormat::Unknown;