refactor ocl patchtokens tests

Related-To: NEO-7131

Signed-off-by: Krystian Chmielewski <krystian.chmielewski@intel.com>
This commit is contained in:
Krystian Chmielewski
2022-09-16 15:01:18 +00:00
committed by Compute-Runtime-Automation
parent ffad5c6c09
commit 6b3ac9f1e2
7 changed files with 73 additions and 180 deletions

View File

@ -16,7 +16,6 @@
#include "shared/source/program/kernel_info.h"
#include "shared/source/source_level_debugger/source_level_debugger.h"
#include "shared/source/utilities/logger.h"
#include "shared/source/utilities/time_measure_wrapper.h"
#include "opencl/source/cl_device/cl_device.h"
#include "opencl/source/gtpin/gtpin_notify.h"
@ -153,21 +152,7 @@ cl_int Program::build(
}
updateNonUniformFlag();
for (auto &clDevice : deviceVector) {
if (BuildPhase::BinaryProcessing == phaseReached[clDevice->getRootDeviceIndex()]) {
continue;
}
if (DebugManager.flags.PrintProgramBinaryProcessingTime.get()) {
retVal = TimeMeasureWrapper::functionExecution(*this, &Program::processGenBinary, *clDevice);
} else {
retVal = processGenBinary(*clDevice);
}
if (retVal != CL_SUCCESS) {
break;
}
phaseReached[clDevice->getRootDeviceIndex()] = BuildPhase::BinaryProcessing;
}
retVal = processGenBinaries(deviceVector, phaseReached);
auto containsStatefulAccess = AddressingModeHelper::containsStatefulAccess(buildInfos[clDevices[0]->getRootDeviceIndex()].kernelInfoArray);
auto isUserKernel = !isBuiltIn;

View File

@ -16,6 +16,7 @@
#include "shared/source/program/program_info.h"
#include "shared/source/program/program_initialization.h"
#include "shared/source/source_level_debugger/source_level_debugger.h"
#include "shared/source/utilities/time_measure_wrapper.h"
#include "opencl/source/cl_device/cl_device.h"
#include "opencl/source/context/context.h"
@ -137,6 +138,26 @@ cl_int Program::linkBinary(Device *pDevice, const void *constantsInitData, const
return CL_SUCCESS;
}
cl_int Program::processGenBinaries(const ClDeviceVector &clDevices, std::unordered_map<uint32_t, BuildPhase> &phaseReached) {
cl_int retVal = CL_SUCCESS;
for (auto &clDevice : clDevices) {
if (BuildPhase::BinaryProcessing == phaseReached[clDevice->getRootDeviceIndex()]) {
continue;
}
if (DebugManager.flags.PrintProgramBinaryProcessingTime.get()) {
retVal = TimeMeasureWrapper::functionExecution(*this, &Program::processGenBinary, *clDevice);
} else {
retVal = processGenBinary(*clDevice);
}
if (retVal != CL_SUCCESS) {
break;
}
phaseReached[clDevice->getRootDeviceIndex()] = BuildPhase::BinaryProcessing;
}
return retVal;
}
cl_int Program::processGenBinary(const ClDevice &clDevice) {
auto rootDeviceIndex = clDevice.getRootDeviceIndex();
if (nullptr == this->buildInfos[rootDeviceIndex].unpackedDeviceBinary) {

View File

@ -192,10 +192,9 @@ cl_int Program::createProgramFromBinary(
this->options += " " + NEO::CompilerOptions::allowZebin.str();
}
if (false == singleDeviceBinary.debugData.empty()) {
this->buildInfos[rootDeviceIndex].debugData = makeCopy(reinterpret_cast<const char *>(singleDeviceBinary.debugData.begin()), singleDeviceBinary.debugData.size());
this->buildInfos[rootDeviceIndex].debugDataSize = singleDeviceBinary.debugData.size();
}
this->buildInfos[rootDeviceIndex].debugData = makeCopy(reinterpret_cast<const char *>(singleDeviceBinary.debugData.begin()), singleDeviceBinary.debugData.size());
this->buildInfos[rootDeviceIndex].debugDataSize = singleDeviceBinary.debugData.size();
bool forceRebuildBuiltInFromIr = isBuiltIn && DebugManager.flags.RebuildPrecompiledKernels.get();
if ((false == singleDeviceBinary.deviceBinary.empty()) && (false == forceRebuildBuiltInFromIr)) {
this->buildInfos[rootDeviceIndex].unpackedDeviceBinary = makeCopy<char>(reinterpret_cast<const char *>(singleDeviceBinary.deviceBinary.begin()), singleDeviceBinary.deviceBinary.size());

View File

@ -140,6 +140,7 @@ class Program : public BaseObject<_cl_program> {
cl_int build(const ClDeviceVector &deviceVector, const char *buildOptions, bool enableCaching,
std::unordered_map<std::string, BuiltinDispatchInfoBuilder *> &builtinsMap);
cl_int processGenBinaries(const ClDeviceVector &clDevices, std::unordered_map<uint32_t, BuildPhase> &phaseReached);
MOCKABLE_VIRTUAL cl_int processGenBinary(const ClDevice &clDevice);
MOCKABLE_VIRTUAL cl_int processProgramInfo(ProgramInfo &dst, const ClDevice &clDevice);

View File

@ -47,6 +47,7 @@ class MockProgram : public Program {
using Program::linkBinary;
using Program::options;
using Program::packDeviceBinary;
using Program::processGenBinaries;
using Program::Program;
using Program::requiresRebuild;
using Program::setBuildStatus;

View File

@ -27,6 +27,7 @@
#include "shared/source/memory_manager/graphics_allocation.h"
#include "shared/source/memory_manager/surface.h"
#include "shared/source/os_interface/os_context.h"
#include "shared/source/utilities/arrayref.h"
#include "shared/test/common/device_binary_format/patchtokens_tests.h"
#include "shared/test/common/helpers/debug_manager_state_restore.h"
#include "shared/test/common/helpers/gtest_helpers.h"
@ -100,6 +101,31 @@ class SucceedingGenBinaryProgram : public MockProgram {
cl_int processGenBinary(const ClDevice &clDevice) override { return CL_SUCCESS; }
};
class PatchtokensProgramWithDebugData : public MockProgram {
public:
using MockProgram::MockProgram;
PatchtokensProgramWithDebugData(ClDevice &device) : MockProgram(toClDeviceVector(device)) {
auto rootDeviceIdx = device.getRootDeviceIndex();
const auto &hwInfo = device.getHardwareInfo();
this->buildInfos.resize(rootDeviceIdx + 1);
auto &buildInfo = this->buildInfos[rootDeviceIdx];
buildInfo.unpackedDeviceBinarySize = sizeof(SProgramBinaryHeader);
buildInfo.unpackedDeviceBinary = std::make_unique<char[]>(buildInfo.unpackedDeviceBinarySize);
memset(buildInfo.unpackedDeviceBinary.get(), 0, buildInfo.unpackedDeviceBinarySize);
auto programBinaryHeader = reinterpret_cast<SProgramBinaryHeader *>(buildInfo.unpackedDeviceBinary.get());
programBinaryHeader->Magic = iOpenCL::MAGIC_CL;
programBinaryHeader->Version = iOpenCL::CURRENT_ICBE_VERSION;
programBinaryHeader->Device = hwInfo.platform.eRenderCoreFamily;
programBinaryHeader->GPUPointerSizeInBytes = sizeof(uintptr_t);
buildInfo.debugData = std::make_unique<char[]>(0x10);
buildInfo.debugDataSize = 0x10;
}
};
using ProgramFromBinaryTest = ProgramFromBinaryFixture;
TEST_F(ProgramFromBinaryTest, WhenBuildingProgramThenSuccessIsReturned) {
@ -1398,72 +1424,6 @@ class CommandStreamReceiverMock : public UltCommandStreamReceiver<FamilyType> {
std::map<const void *, size_t> residency;
};
HWTEST_F(PatchTokenTests, givenKernelRequiringConstantAllocationWhenMakeResidentIsCalledThenConstantAllocationIsMadeResident) {
createProgramFromBinary(pContext, pContext->getDevices(), "test_constant_memory");
ASSERT_NE(nullptr, pProgram);
retVal = pProgram->build(
pProgram->getDevices(),
nullptr,
false);
ASSERT_EQ(CL_SUCCESS, retVal);
auto pKernelInfo = pProgram->getKernelInfo("test", rootDeviceIndex);
if (pKernelInfo->kernelDescriptor.kernelAttributes.binaryFormat == NEO::DeviceBinaryFormat::Zebin) {
GTEST_SKIP();
}
ASSERT_NE(nullptr, pProgram->getConstantSurface(pClDevice->getRootDeviceIndex()));
uint32_t expectedValues[] = {0xabcd5432u, 0xaabb5533u};
uint32_t *constBuff = reinterpret_cast<uint32_t *>(pProgram->getConstantSurface(pClDevice->getRootDeviceIndex())->getUnderlyingBuffer());
EXPECT_EQ(expectedValues[0], constBuff[0]);
EXPECT_EQ(expectedValues[1], constBuff[1]);
std::unique_ptr<Kernel> pKernel(Kernel::create(pProgram, *pKernelInfo, *pClDevice, &retVal));
ASSERT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, pKernel);
auto pCommandStreamReceiver = new CommandStreamReceiverMock<FamilyType>(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
ASSERT_NE(nullptr, pCommandStreamReceiver);
pDevice->resetCommandStreamReceiver(pCommandStreamReceiver);
pCommandStreamReceiver->residency.clear();
pKernel->makeResident(*pCommandStreamReceiver);
EXPECT_EQ(2u, pCommandStreamReceiver->residency.size());
auto &residencyVector = pCommandStreamReceiver->getResidencyAllocations();
// we expect kernel ISA here and constant allocation
auto kernelIsa = pKernel->getKernelInfo().getGraphicsAllocation();
auto constantAllocation = pProgram->getConstantSurface(pDevice->getRootDeviceIndex());
auto element = std::find(residencyVector.begin(), residencyVector.end(), kernelIsa);
EXPECT_NE(residencyVector.end(), element);
element = std::find(residencyVector.begin(), residencyVector.end(), constantAllocation);
EXPECT_NE(residencyVector.end(), element);
auto crossThreadData = pKernel->getCrossThreadData();
uint32_t *constBuffGpuAddr = reinterpret_cast<uint32_t *>(pProgram->getConstantSurface(pContext->getDevice(0)->getRootDeviceIndex())->getGpuAddressToPatch());
uintptr_t *pDst = reinterpret_cast<uintptr_t *>(crossThreadData + pKernelInfo->kernelDescriptor.payloadMappings.implicitArgs.globalConstantsSurfaceAddress.stateless);
EXPECT_EQ(*pDst, reinterpret_cast<uintptr_t>(constBuffGpuAddr));
pCommandStreamReceiver->makeSurfacePackNonResident(pCommandStreamReceiver->getResidencyAllocations(), true);
EXPECT_EQ(0u, pCommandStreamReceiver->residency.size());
std::vector<Surface *> surfaces;
pKernel->getResidency(surfaces);
EXPECT_EQ(2u, surfaces.size());
for (Surface *surface : surfaces) {
delete surface;
}
}
TEST_F(PatchTokenTests, WhenBuildingProgramThenGwsIsSet) {
createProgramFromBinary(pContext, pContext->getDevices(), "kernel_data_param");
@ -1647,63 +1607,30 @@ TEST(ProgramFromBinaryTests, givenEmptyProgramThenErrorIsReturned) {
EXPECT_EQ(CL_INVALID_BINARY, retVal);
}
using ProgramWithDebugSymbolsTests = Test<ProgramSimpleFixture>;
using ProgramWithDebugDataTests = Test<ProgramSimpleFixture>;
TEST_F(ProgramWithDebugSymbolsTests, GivenProgramCreatedWithDashGOptionWhenGettingProgramBinariesThenDebugDataIsIncluded) {
createProgramFromBinary(pContext, pContext->getDevices(), "CopyBuffer_simd16", "-g");
TEST_F(ProgramWithDebugDataTests, GivenPatchtokensProgramWithDebugSymbolsWhenPackDeviceBinaryThenDebugDataIsAddedToSingleDeviceBinary) {
auto clDevice = pContext->getDevices()[0];
auto &hwInfo = clDevice->getHardwareInfo();
auto rootDeviceIdx = clDevice->getRootDeviceIndex();
ASSERT_NE(nullptr, pProgram);
pProgram = new PatchtokensProgramWithDebugData(*clDevice);
auto &buildInfo = pProgram->buildInfos[rootDeviceIdx];
retVal = pProgram->build(
pProgram->getDevices(),
"-g",
false);
EXPECT_EQ(CL_SUCCESS, retVal);
size_t paramValueSize = sizeof(size_t);
size_t paramValueSizeRet = 0;
size_t size = 0;
pProgram->buildInfos[rootDeviceIndex].packedDeviceBinary.reset();
pProgram->buildInfos[rootDeviceIndex].packedDeviceBinarySize = 0U;
retVal = pProgram->packDeviceBinary(*pClDevice);
retVal = pProgram->getInfo(
CL_PROGRAM_BINARY_SIZES,
paramValueSize,
&size,
nullptr);
EXPECT_EQ(CL_SUCCESS, retVal);
auto testBinary = std::make_unique<char[]>(size);
retVal = pProgram->getInfo(
CL_PROGRAM_BINARIES,
paramValueSize,
&testBinary,
&paramValueSizeRet);
EXPECT_EQ(CL_SUCCESS, retVal);
ArrayRef<const uint8_t> archive(reinterpret_cast<const uint8_t *>(testBinary.get()), size);
if (NEO::isDeviceBinaryFormat<NEO::DeviceBinaryFormat::Zebin>(archive)) {
GTEST_SKIP();
}
auto productAbbreviation = hardwarePrefix[pDevice->getHardwareInfo().platform.eProductFamily];
HardwareInfo copyHwInfo = pDevice->getHardwareInfo();
NEO::CompilerHwInfoConfig::get(copyHwInfo.platform.eProductFamily)->adjustHwInfoForIgc(copyHwInfo);
TargetDevice targetDevice = NEO::targetDeviceFromHwInfo(copyHwInfo);
pProgram->packDeviceBinary(*clDevice);
EXPECT_NE(nullptr, buildInfo.packedDeviceBinary.get());
auto packedDeviceBinary = ArrayRef<const uint8_t>::fromAny(buildInfo.packedDeviceBinary.get(), buildInfo.packedDeviceBinarySize);
TargetDevice targetDevice = NEO::targetDeviceFromHwInfo(hwInfo);
std::string decodeErrors;
std::string decodeWarnings;
auto singleDeviceBinary = unpackSingleDeviceBinary(archive, ConstStringRef(productAbbreviation, strlen(productAbbreviation)), targetDevice,
auto singleDeviceBinary = unpackSingleDeviceBinary(packedDeviceBinary, {}, targetDevice,
decodeErrors, decodeWarnings);
EXPECT_TRUE(decodeWarnings.empty()) << decodeWarnings;
EXPECT_TRUE(decodeErrors.empty()) << decodeErrors;
EXPECT_FALSE(singleDeviceBinary.debugData.empty());
EXPECT_NE(nullptr, pProgram->getDebugData(rootDeviceIdx));
EXPECT_NE(0u, pProgram->getDebugDataSize(rootDeviceIdx));
}
TEST_F(ProgramTests, WhenProgramIsCreatedThenCorrectOclVersionIsInOptions) {
@ -2276,30 +2203,12 @@ TEST_F(ProgramTests, GivenGtpinReraFlagWhenBuildingProgramThenCorrectOptionsAreS
EXPECT_TRUE(CompilerOptions::contains(cip->buildInternalOptions, CompilerOptions::gtpinRera)) << cip->buildInternalOptions;
}
TEST_F(ProgramTests, GivenFailingGenBinaryProgramWhenRebuildingBinaryThenInvalidBinaryErrorIsReturned) {
cl_int retVal;
TEST_F(ProgramTests, GivenFailureDuringProcessGenBinaryWhenProcessGenBinariesIsCalledThenErrorIsReturned) {
auto program = std::make_unique<FailingGenBinaryProgram>(toClDeviceVector(*pClDevice));
EXPECT_NE(nullptr, program);
// Load a binary program file
std::string filePath;
retrieveBinaryKernelFilename(filePath, "CopyBuffer_simd16_", ".bin");
size_t binarySize = 0;
auto pBinary = loadDataFromFile(filePath.c_str(), binarySize);
EXPECT_NE(0u, binarySize);
if (NEO::isDeviceBinaryFormat<NEO::DeviceBinaryFormat::Zebin>({reinterpret_cast<const uint8_t *>(pBinary.get()), binarySize})) {
GTEST_SKIP();
}
// Create program from loaded binary
retVal = program->createProgramFromBinary(pBinary.get(), binarySize, *pClDevice);
EXPECT_EQ(CL_SUCCESS, retVal);
// Ask to rebuild program from its IR binary - it should fail (simulated invalid binary)
retVal = program->rebuildProgramFromIr();
std::unordered_map<uint32_t, Program::BuildPhase> phaseReached;
phaseReached[0] = Program::BuildPhase::BinaryCreation;
cl_int retVal = program->processGenBinaries(toClDeviceVector(*pClDevice), phaseReached);
EXPECT_EQ(CL_INVALID_BINARY, retVal);
}

View File

@ -42,29 +42,6 @@ TEST_F(ProgramTests, givenProgramObjectWhenEnableKernelDebugIsCalledThenProgramH
EXPECT_TRUE(program.isKernelDebugEnabled());
}
TEST(ProgramFromBinary, givenBinaryWithDebugDataWhenCreatingProgramFromBinaryThenDebugDataIsAvailable) {
if (!defaultHwInfo->capabilityTable.debuggerSupported) {
GTEST_SKIP();
}
std::string filePath;
retrieveBinaryKernelFilename(filePath, "-cl-kernel-debug-enable_", ".bin");
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
auto program = std::make_unique<MockProgram>(toClDeviceVector(*device));
program->enableKernelDebug();
size_t binarySize = 0;
auto pBinary = loadDataFromFile(filePath.c_str(), binarySize);
if (NEO::isDeviceBinaryFormat<NEO::DeviceBinaryFormat::Zebin>({reinterpret_cast<const uint8_t *>(pBinary.get()), binarySize})) {
GTEST_SKIP();
}
cl_int retVal = program->createProgramFromBinary(pBinary.get(), binarySize, *device);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_NE(nullptr, program->getDebugData(device->getRootDeviceIndex()));
EXPECT_NE(0u, program->getDebugDataSize(device->getRootDeviceIndex()));
}
class ProgramWithKernelDebuggingTest : public ProgramFixture,
public ::testing::Test {
public: