Skip to content

Commit

Permalink
Change Packed binary Returned in L0 GetNative to be the Target Device…
Browse files Browse the repository at this point in the history
… binary

- Packed Binary Returned to a customer in L0 GetNative is now
the target device's native binary.

Signed-off-by: Neil R Spruit <[email protected]>
  • Loading branch information
nrspruit authored and Compute-Runtime-Automation committed May 25, 2022
1 parent 359e848 commit 8c894fa
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 4 deletions.
2 changes: 1 addition & 1 deletion level_zero/api/core/ze_module.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2021 Intel Corporation
* Copyright (C) 2020-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down
10 changes: 8 additions & 2 deletions level_zero/core/source/module/module_imp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,14 @@ bool ModuleTranslationUnit::createFromNativeBinary(const char *input, size_t inp
if ((false == singleDeviceBinary.deviceBinary.empty()) && (false == rebuild)) {
this->unpackedDeviceBinary = makeCopy<char>(reinterpret_cast<const char *>(singleDeviceBinary.deviceBinary.begin()), singleDeviceBinary.deviceBinary.size());
this->unpackedDeviceBinarySize = singleDeviceBinary.deviceBinary.size();
this->packedDeviceBinary = makeCopy<char>(reinterpret_cast<const char *>(archive.begin()), archive.size());
this->packedDeviceBinarySize = archive.size();
// If the Native Binary was an Archive, then packedTargetDeviceBinary will be the packed Binary for the Target Device.
if (singleDeviceBinary.packedTargetDeviceBinary.size() > 0) {
this->packedDeviceBinary = makeCopy<char>(reinterpret_cast<const char *>(singleDeviceBinary.packedTargetDeviceBinary.begin()), singleDeviceBinary.packedTargetDeviceBinary.size());
this->packedDeviceBinarySize = singleDeviceBinary.packedTargetDeviceBinary.size();
} else {
this->packedDeviceBinary = makeCopy<char>(reinterpret_cast<const char *>(archive.begin()), archive.size());
this->packedDeviceBinarySize = archive.size();
}
}
}

Expand Down
33 changes: 33 additions & 0 deletions level_zero/core/test/unit_tests/sources/module/test_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "shared/source/compiler_interface/compiler_options/compiler_options.h"
#include "shared/source/compiler_interface/compiler_warnings/compiler_warnings.h"
#include "shared/source/device_binary_format/ar/ar_decoder.h"
#include "shared/source/device_binary_format/ar/ar_encoder.h"
#include "shared/source/device_binary_format/debug_zebin.h"
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/gmm_helper/gmm_helper.h"
Expand All @@ -19,6 +21,7 @@
#include "shared/test/common/mocks/mock_graphics_allocation.h"
#include "shared/test/common/test_macros/test.h"
#include "shared/test/unit_test/compiler_interface/linker_mock.h"
#include "shared/test/unit_test/device_binary_format/patchtokens_tests.h"
#include "shared/test/unit_test/device_binary_format/zebin_tests.h"

#include "level_zero/core/source/context/context.h"
Expand Down Expand Up @@ -1975,6 +1978,36 @@ HWTEST_F(ModuleTranslationUnitTest, WhenCreatingFromNativeBinaryThenSetsUpRequir
EXPECT_FALSE(success);
}

HWTEST_F(ModuleTranslationUnitTest, WhenCreatingFromNativeBinaryThenSetsUpPackedTargetDeviceBinary) {
PatchTokensTestData::ValidEmptyProgram programTokens;
const auto &hwInfoConfig = *NEO::HwInfoConfig::get(productFamily);
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo;
auto productConfig = hwInfoConfig.getProductConfigFromHwInfo(hwInfo);

NEO::Ar::ArEncoder encoder;
std::string requiredProduct = NEO::hardwarePrefix[productFamily];
std::string requiredStepping = std::to_string(programTokens.header->SteppingId);
std::string requiredPointerSize = (programTokens.header->GPUPointerSizeInBytes == 4) ? "32" : "64";
std::string requiredProductConfig = NEO::ProductConfigHelper::parseMajorMinorRevisionValue(productConfig);

ASSERT_TRUE(encoder.appendFileEntry(requiredPointerSize, programTokens.storage));
ASSERT_TRUE(encoder.appendFileEntry(requiredPointerSize + "." + requiredProduct, programTokens.storage));
ASSERT_TRUE(encoder.appendFileEntry(requiredPointerSize + "unk." + requiredStepping, programTokens.storage));
ASSERT_TRUE(encoder.appendFileEntry(requiredPointerSize + "." + requiredProductConfig, programTokens.storage));

NEO::TargetDevice target;
target.coreFamily = static_cast<GFXCORE_FAMILY>(programTokens.header->Device);
target.productConfig = hwInfoConfig.getProductConfigFromHwInfo(hwInfo);
target.stepping = programTokens.header->SteppingId;
target.maxPointerSizeInBytes = programTokens.header->GPUPointerSizeInBytes;

auto arData = encoder.encode();
L0::ModuleTranslationUnit moduleTuValid(this->device);
bool success = moduleTuValid.createFromNativeBinary(reinterpret_cast<const char *>(arData.data()), arData.size());
EXPECT_TRUE(success);
EXPECT_NE(moduleTuValid.packedDeviceBinarySize, arData.size());
}

HWTEST_F(ModuleTranslationUnitTest, WhenCreatingFromZebinThenAppendAllowZebinFlagToBuildOptions) {
ZebinTestData::ValidEmptyProgram zebin;
auto hwInfo = device->getNEODevice()->getHardwareInfo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "shared/source/device_binary_format/ar/ar.h"
#include "shared/source/device_binary_format/ar/ar_decoder.h"
#include "shared/source/device_binary_format/device_binary_formats.h"
#include "shared/source/helpers/string.h"

namespace NEO {
void searchForBinary(Ar::Ar &archiveData, const ConstStringRef filter, Ar::ArFileEntryHeaderAndData *&matched) {
Expand Down Expand Up @@ -70,7 +71,7 @@ SingleDeviceBinary unpackSingleDeviceBinary<NEO::DeviceBinaryFormat::Archive>(co
unpacked.intermediateRepresentation = unpackedGenericIr.intermediateRepresentation;
}
}

unpacked.packedTargetDeviceBinary = ArrayRef<const uint8_t>(matchedFile->fileData.begin(), matchedFile->fileData.size());
return unpacked;
}
if (binaryForRecompilation.intermediateRepresentation.empty() && (false == unpacked.intermediateRepresentation.empty())) {
Expand Down
1 change: 1 addition & 0 deletions shared/source/device_binary_format/device_binary_formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct SingleDeviceBinary {
ArrayRef<const uint8_t> deviceBinary;
ArrayRef<const uint8_t> debugData;
ArrayRef<const uint8_t> intermediateRepresentation;
ArrayRef<const uint8_t> packedTargetDeviceBinary;
ConstStringRef buildOptions;
TargetDevice targetDevice;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,36 @@ TEST(UnpackSingleDeviceBinaryAr, WhenBinaryWithProductConfigIsFoundThenChooseItA
EXPECT_EQ(NEO::DeviceBinaryFormat::Patchtokens, unpacked.format);
}

TEST(UnpackSingleDeviceBinaryAr, WhenBinaryWithProductConfigIsFoundThenPackedTargetDeviceBinaryIsSet) {
PatchTokensTestData::ValidEmptyProgram programTokens;
const auto &hwInfoConfig = *NEO::HwInfoConfig::get(productFamily);
NEO::HardwareInfo hwInfo = *NEO::defaultHwInfo;
auto productConfig = hwInfoConfig.getProductConfigFromHwInfo(hwInfo);

NEO::Ar::ArEncoder encoder;
std::string requiredProduct = NEO::hardwarePrefix[productFamily];
std::string requiredProductConfig = NEO::ProductConfigHelper::parseMajorMinorRevisionValue(productConfig);
std::string requiredStepping = std::to_string(programTokens.header->SteppingId);
std::string requiredPointerSize = (programTokens.header->GPUPointerSizeInBytes == 4) ? "32" : "64";

ASSERT_TRUE(encoder.appendFileEntry(requiredPointerSize, programTokens.storage));
ASSERT_TRUE(encoder.appendFileEntry(requiredPointerSize + "." + requiredProductConfig, programTokens.storage));
ASSERT_TRUE(encoder.appendFileEntry(requiredPointerSize + "." + requiredProduct + "." + requiredStepping, programTokens.storage));
ASSERT_TRUE(encoder.appendFileEntry(requiredPointerSize + "unk." + requiredStepping, programTokens.storage));

NEO::TargetDevice target;
target.coreFamily = static_cast<GFXCORE_FAMILY>(programTokens.header->Device);
target.productConfig = productConfig;
target.stepping = programTokens.header->SteppingId;
target.maxPointerSizeInBytes = programTokens.header->GPUPointerSizeInBytes;

auto arData = encoder.encode();
std::string unpackErrors;
std::string unpackWarnings;
auto unpacked = NEO::unpackSingleDeviceBinary<NEO::DeviceBinaryFormat::Archive>(arData, requiredProduct, target, unpackErrors, unpackWarnings);
EXPECT_NE(0U, unpacked.packedTargetDeviceBinary.size());
}

TEST(UnpackSingleDeviceBinaryAr, WhenMultipleBinariesMatchedThenChooseBestMatch) {
PatchTokensTestData::ValidEmptyProgram programTokens;
const auto &hwInfoConfig = *NEO::HwInfoConfig::get(productFamily);
Expand Down

0 comments on commit 8c894fa

Please sign in to comment.