Skip to content

Commit

Permalink
Zebin: Create mock zebin module for L0 common test module
Browse files Browse the repository at this point in the history
Signed-off-by: Kacper Nowak <[email protected]>
  • Loading branch information
km-nowak authored and Compute-Runtime-Automation committed Aug 17, 2022
1 parent 8da78d3 commit 497e5a4
Show file tree
Hide file tree
Showing 25 changed files with 657 additions and 491 deletions.
66 changes: 23 additions & 43 deletions level_zero/core/test/unit_tests/fixtures/module_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
#include "shared/source/helpers/file_io.h"
#include "shared/source/memory_manager/allocation_properties.h"
#include "shared/source/program/kernel_info.h"
#include "shared/test/common/device_binary_format/zebin_tests.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/test_files.h"
#include "shared/test/common/mocks/mock_compilers.h"
#include "shared/test/common/mocks/mock_graphics_allocation.h"
#include "shared/test/common/mocks/mock_memory_manager.h"
#include "shared/test/common/mocks/mock_modules_zebin.h"

#include "level_zero/core/source/module/module.h"
#include "level_zero/core/source/module/module_imp.h"
Expand Down Expand Up @@ -156,22 +156,15 @@ struct ModuleImmutableDataFixture : public DeviceFixture {
DeviceFixture::setupWithExecutionEnvironment(*executionEnvironment);
}

void createModuleFromBinary(uint32_t perHwThreadPrivateMemorySize, bool isInternal, MockImmutableData *mockKernelImmData) {
std::string testFile;
retrieveBinaryKernelFilenameApiSpecific(testFile, binaryFilename + "_", ".bin");

size_t size = 0;
auto src = loadDataFromFile(
testFile.c_str(),
size);

ASSERT_NE(0u, size);
ASSERT_NE(nullptr, src);
void createModuleFromMockBinary(uint32_t perHwThreadPrivateMemorySize, bool isInternal, MockImmutableData *mockKernelImmData,
std::initializer_list<ZebinTestData::appendElfAdditionalSection> additionalSections = {}) {
zebinData = std::make_unique<ZebinTestData::ZebinWithL0TestCommonModule>(device->getHwInfo(), additionalSections);
const auto &src = zebinData->storage;

ze_module_desc_t moduleDesc = {};
moduleDesc.format = ZE_MODULE_FORMAT_NATIVE;
moduleDesc.pInputModule = reinterpret_cast<const uint8_t *>(src.get());
moduleDesc.inputSize = size;
moduleDesc.pInputModule = reinterpret_cast<const uint8_t *>(src.data());
moduleDesc.inputSize = src.size();

ModuleBuildLog *moduleBuildLog = nullptr;

Expand Down Expand Up @@ -201,32 +194,25 @@ struct ModuleImmutableDataFixture : public DeviceFixture {
const std::string kernelName = "test";
const uint32_t numKernelArguments = 6;
std::unique_ptr<MockModule> module;
std::unique_ptr<ZebinTestData::ZebinWithL0TestCommonModule> zebinData;
MockImmutableMemoryManager *memoryManager;
};

struct ModuleFixture : public DeviceFixture {
void setUp() {
NEO::MockCompilerEnableGuard mock(true);
DeviceFixture::setUp();
createModuleFromBinary();
createModuleFromMockBinary();
}

void createModuleFromBinary(ModuleType type = ModuleType::User) {
std::string testFile;
retrieveBinaryKernelFilenameApiSpecific(testFile, binaryFilename + "_", ".bin");

size_t size = 0;
auto src = loadDataFromFile(
testFile.c_str(),
size);

ASSERT_NE(0u, size);
ASSERT_NE(nullptr, src);
void createModuleFromMockBinary(ModuleType type = ModuleType::User) {
zebinData = std::make_unique<ZebinTestData::ZebinWithL0TestCommonModule>(device->getHwInfo());
const auto &src = zebinData->storage;

ze_module_desc_t moduleDesc = {};
moduleDesc.format = ZE_MODULE_FORMAT_NATIVE;
moduleDesc.pInputModule = reinterpret_cast<const uint8_t *>(src.get());
moduleDesc.inputSize = size;
moduleDesc.pInputModule = reinterpret_cast<const uint8_t *>(src.data());
moduleDesc.inputSize = src.size();

ModuleBuildLog *moduleBuildLog = nullptr;

Expand All @@ -248,11 +234,11 @@ struct ModuleFixture : public DeviceFixture {
DeviceFixture::tearDown();
}

const std::string binaryFilename = "test_kernel";
const std::string kernelName = "test";
const uint32_t numKernelArguments = 6;
std::unique_ptr<L0::Module> module;
std::unique_ptr<WhiteBox<::L0::Kernel>> kernel;
std::unique_ptr<ZebinTestData::ZebinWithL0TestCommonModule> zebinData;
};

struct MultiDeviceModuleFixture : public MultiDeviceFixture {
Expand All @@ -261,24 +247,18 @@ struct MultiDeviceModuleFixture : public MultiDeviceFixture {
modules.resize(numRootDevices);
}

void createModuleFromBinary(uint32_t rootDeviceIndex) {
std::string testFile;
retrieveBinaryKernelFilenameApiSpecific(testFile, binaryFilename + "_", ".bin");

size_t size = 0;
auto src = loadDataFromFile(testFile.c_str(), size);

ASSERT_NE(0u, size);
ASSERT_NE(nullptr, src);
void createModuleFromMockBinary(uint32_t rootDeviceIndex) {
auto device = driverHandle->devices[rootDeviceIndex];
zebinData = std::make_unique<ZebinTestData::ZebinWithL0TestCommonModule>(device->getHwInfo());
const auto &src = zebinData->storage;

ze_module_desc_t moduleDesc = {};
moduleDesc.format = ZE_MODULE_FORMAT_NATIVE;
moduleDesc.pInputModule = reinterpret_cast<const uint8_t *>(src.get());
moduleDesc.inputSize = size;
moduleDesc.pInputModule = reinterpret_cast<const uint8_t *>(src.data());
moduleDesc.inputSize = src.size();

ModuleBuildLog *moduleBuildLog = nullptr;

auto device = driverHandle->devices[rootDeviceIndex];
modules[rootDeviceIndex].reset(Module::create(device,
&moduleDesc,
moduleBuildLog, ModuleType::User));
Expand All @@ -301,11 +281,11 @@ struct MultiDeviceModuleFixture : public MultiDeviceFixture {
MultiDeviceFixture::tearDown();
}

const std::string binaryFilename = "test_kernel";
const std::string kernelName = "test";
const uint32_t numKernelArguments = 6;
std::vector<std::unique_ptr<L0::Module>> modules;
std::unique_ptr<WhiteBox<::L0::Kernel>> kernel;
std::unique_ptr<ZebinTestData::ZebinWithL0TestCommonModule> zebinData;
};

struct ModuleWithZebinFixture : public DeviceFixture {
Expand Down Expand Up @@ -428,7 +408,7 @@ struct MultiTileModuleFixture : public MultiDeviceModuleFixture {
MultiDeviceFixture::numSubDevices = 2u;

MultiDeviceModuleFixture::setUp();
createModuleFromBinary(0);
createModuleFromMockBinary(0);

device = driverHandle->devices[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void MultiTileCommandListAppendLaunchFunctionFixture::setUp() {
MultiDeviceFixture::numSubDevices = 4u;

MultiDeviceModuleFixture::setUp();
createModuleFromBinary(0u);
createModuleFromMockBinary(0u);
createKernel(0u);

device = driverHandle->devices[0];
Expand Down Expand Up @@ -49,7 +49,7 @@ void MultiTileImmediateCommandListAppendLaunchFunctionFixture::setUp() {
MultiDeviceFixture::numSubDevices = 2u;

MultiDeviceModuleFixture::setUp();
createModuleFromBinary(0u);
createModuleFromMockBinary(0u);
createKernel(0u);

device = driverHandle->devices[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ HWTEST2_F(CmdlistAppendLaunchKernelTests,
auto kernelDescriptor = mockKernelImmData->kernelDescriptor;
kernelDescriptor->kernelAttributes.flags.requiresImplicitArgs = false;
kernelDescriptor->kernelAttributes.perThreadScratchSize[0] = scratchPerThreadSize;
createModuleFromBinary(0u, false, mockKernelImmData.get());
createModuleFromMockBinary(0u, false, mockKernelImmData.get());

auto kernel = std::make_unique<MockKernel>(module.get());

Expand Down Expand Up @@ -518,7 +518,7 @@ HWTEST2_F(CmdlistAppendLaunchKernelTests,
kernelDescriptor->kernelAttributes.flags.requiresImplicitArgs = false;
kernelDescriptor->kernelAttributes.perThreadScratchSize[0] = scratchPerThreadSize;
kernelDescriptor->kernelAttributes.perThreadScratchSize[1] = privateScratchPerThreadSize;
createModuleFromBinary(0u, false, mockKernelImmData.get());
createModuleFromMockBinary(0u, false, mockKernelImmData.get());

auto kernel = std::make_unique<MockKernel>(module.get());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ struct CmdlistAppendLaunchKernelWithImplicitArgsTests : CmdlistAppendLaunchKerne
kernelDescriptor->kernelAttributes.workgroupDimensionsOrder[0] = workgroupDimOrder[0];
kernelDescriptor->kernelAttributes.workgroupDimensionsOrder[1] = workgroupDimOrder[1];
kernelDescriptor->kernelAttributes.workgroupDimensionsOrder[2] = workgroupDimOrder[2];
createModuleFromBinary(0u, false, mockKernelImmData.get());
createModuleFromMockBinary(0u, false, mockKernelImmData.get());

auto kernel = std::make_unique<MockKernel>(module.get());

Expand Down Expand Up @@ -1108,7 +1108,7 @@ HWTEST_F(CmdlistAppendLaunchKernelTests, givenKernelWithoutImplicitArgsWhenAppen
std::unique_ptr<MockImmutableData> mockKernelImmData = std::make_unique<MockImmutableData>(0u);
auto kernelDescriptor = mockKernelImmData->kernelDescriptor;
kernelDescriptor->kernelAttributes.flags.requiresImplicitArgs = false;
createModuleFromBinary(0u, false, mockKernelImmData.get());
createModuleFromMockBinary(0u, false, mockKernelImmData.get());

auto kernel = std::make_unique<MockKernel>(module.get());

Expand Down Expand Up @@ -1146,7 +1146,7 @@ HWTEST2_F(CmdlistAppendLaunchKernelTests, givenKernelWitchScratchAndPrivateWhenA
kernelDescriptor->kernelAttributes.flags.requiresImplicitArgs = false;
kernelDescriptor->kernelAttributes.perThreadScratchSize[0] = 0x200;
kernelDescriptor->kernelAttributes.perThreadScratchSize[1] = 0x100;
createModuleFromBinary(0u, false, mockKernelImmData.get());
createModuleFromMockBinary(0u, false, mockKernelImmData.get());

auto kernel = std::make_unique<MockKernel>(module.get());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -793,36 +793,32 @@ HWTEST_F(NotifyModuleLoadTest, givenDebuggingEnabledWhenModuleIsCreatedAndFullyL
auto debugger = MockDebuggerL0Hw<FamilyType>::allocate(neoDevice);
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->debugger.reset(debugger);

std::string testFile;
retrieveBinaryKernelFilenameApiSpecific(testFile, binaryFilename + "_", ".bin");

size_t size = 0;
auto src = loadDataFromFile(testFile.c_str(), size);

ASSERT_NE(0u, size);
ASSERT_NE(nullptr, src);
auto elfAdditionalSections = {ZebinTestData::appendElfAdditionalSection::CONSTANT}; //for const surface allocation copy
auto zebinData = std::make_unique<ZebinTestData::ZebinWithL0TestCommonModule>(device->getHwInfo(), elfAdditionalSections);
const auto &src = zebinData->storage;

ze_module_desc_t moduleDesc = {};
moduleDesc.format = ZE_MODULE_FORMAT_NATIVE;
moduleDesc.pInputModule = reinterpret_cast<const uint8_t *>(src.get());
moduleDesc.inputSize = size;
moduleDesc.pInputModule = reinterpret_cast<const uint8_t *>(src.data());
moduleDesc.inputSize = src.size();

ModuleBuildLog *moduleBuildLog = nullptr;
neoDevice->executionEnvironment->rootDeviceEnvironments[0]->osInterface.reset(nullptr);

auto module = std::unique_ptr<L0::ModuleImp>(new L0::ModuleImp(device, moduleBuildLog, ModuleType::User));
auto module = std::make_unique<WhiteBox<::L0::Module>>(device, moduleBuildLog, ModuleType::User);
ASSERT_NE(nullptr, module.get());

memoryOperationsHandler->makeResidentCalledCount = 0;

auto linkerInput = std::make_unique<::WhiteBox<NEO::LinkerInput>>();
linkerInput->traits.requiresPatchingOfInstructionSegments = true;
module->translationUnit->programInfo.linkerInput = std::move(linkerInput);
module->initialize(&moduleDesc, neoDevice);

auto numIsaAllocations = static_cast<int>(module->getKernelImmutableDataVector().size());

auto expectedMakeResidentCallsCount = numIsaAllocations + 1; // const surface
if (module->getTranslationUnit()->programInfo.linkerInput) {
expectedMakeResidentCallsCount += numIsaAllocations;
}
auto expectedMakeResidentCallsCount = numIsaAllocations + 1; //const surface
expectedMakeResidentCallsCount += numIsaAllocations;

EXPECT_EQ(expectedMakeResidentCallsCount, memoryOperationsHandler->makeResidentCalledCount);

Expand Down Expand Up @@ -855,19 +851,13 @@ HWTEST_F(NotifyModuleLoadTest, givenDebuggingEnabledWhenModuleWithUnresolvedSymb
auto debugger = MockDebuggerL0Hw<FamilyType>::allocate(neoDevice);
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->debugger.reset(debugger);

std::string testFile;
retrieveBinaryKernelFilenameApiSpecific(testFile, binaryFilename + "_", ".bin");

size_t size = 0;
auto src = loadDataFromFile(testFile.c_str(), size);

ASSERT_NE(0u, size);
ASSERT_NE(nullptr, src);
auto zebinData = std::make_unique<ZebinTestData::ZebinWithL0TestCommonModule>(device->getHwInfo());
const auto &src = zebinData->storage;

ze_module_desc_t moduleDesc = {};
moduleDesc.format = ZE_MODULE_FORMAT_NATIVE;
moduleDesc.pInputModule = reinterpret_cast<const uint8_t *>(src.get());
moduleDesc.inputSize = size;
moduleDesc.pInputModule = reinterpret_cast<const uint8_t *>(src.data());
moduleDesc.inputSize = src.size();

ModuleBuildLog *moduleBuildLog = nullptr;

Expand Down Expand Up @@ -909,19 +899,13 @@ HWTEST_F(NotifyModuleLoadTest, givenDebuggingEnabledWhenModuleWithUnresolvedSymb
auto debugger = MockDebuggerL0Hw<FamilyType>::allocate(neoDevice);
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->debugger.reset(debugger);

std::string testFile;
retrieveBinaryKernelFilenameApiSpecific(testFile, binaryFilename + "_", ".bin");

size_t size = 0;
auto src = loadDataFromFile(testFile.c_str(), size);

ASSERT_NE(0u, size);
ASSERT_NE(nullptr, src);
auto zebinData = std::make_unique<ZebinTestData::ZebinWithL0TestCommonModule>(device->getHwInfo());
const auto &src = zebinData->storage;

ze_module_desc_t moduleDesc = {};
moduleDesc.format = ZE_MODULE_FORMAT_NATIVE;
moduleDesc.pInputModule = reinterpret_cast<const uint8_t *>(src.get());
moduleDesc.inputSize = size;
moduleDesc.pInputModule = reinterpret_cast<const uint8_t *>(src.data());
moduleDesc.inputSize = src.size();

ModuleBuildLog *moduleBuildLog = nullptr;

Expand Down
Loading

0 comments on commit 497e5a4

Please sign in to comment.