2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2020-01-14 14:32:11 +01:00
|
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-19 20:54:29 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
2018-09-19 20:54:29 -07:00
|
|
|
|
2020-02-23 15:20:22 +01:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_program.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2020-02-23 18:46:50 +01:00
|
|
|
#include "compiler_interface/compiler_cache.h"
|
|
|
|
|
#include "device_binary_format/patchtokens_decoder.h"
|
|
|
|
|
#include "helpers/hash.h"
|
|
|
|
|
#include "program/program_info_from_patchtokens.h"
|
|
|
|
|
#include "unit_tests/helpers/default_hw_info.h"
|
2020-02-22 22:50:57 +01:00
|
|
|
#include "opencl/source/context/context.h"
|
|
|
|
|
#include "opencl/source/program/create.inl"
|
|
|
|
|
#include "opencl/source/program/kernel_info.h"
|
2020-02-23 15:20:22 +01:00
|
|
|
#include "opencl/test/unit_test/helpers/ult_limits.h"
|
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_compilers.h"
|
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_graphics_allocation.h"
|
2020-02-22 09:28:27 +01:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2018-05-14 11:25:18 +02:00
|
|
|
GlobalMockSipProgram *GlobalMockSipProgram::sipProgram;
|
2018-08-14 10:56:42 +02:00
|
|
|
ExecutionEnvironment GlobalMockSipProgram::executionEnvironment;
|
2020-01-14 14:32:11 +01:00
|
|
|
|
2020-02-20 08:12:44 +01:00
|
|
|
Device *MockProgram::getDevicePtr() { return this->pDevice; }
|
2020-01-14 14:32:11 +01:00
|
|
|
|
2018-07-31 11:01:13 +02:00
|
|
|
std::string MockProgram::getCachedFileName() const {
|
|
|
|
|
auto hwInfo = this->context->getDevice(0)->getHardwareInfo();
|
|
|
|
|
auto input = ArrayRef<const char>(this->sourceCode.c_str(), this->sourceCode.size());
|
|
|
|
|
auto opts = ArrayRef<const char>(this->options.c_str(), this->options.size());
|
|
|
|
|
auto internalOpts = ArrayRef<const char>(this->internalOptions.c_str(), this->internalOptions.size());
|
2019-10-21 15:47:04 +02:00
|
|
|
return CompilerCache::getCachedFileName(hwInfo, input, opts, internalOpts);
|
2018-05-14 11:25:18 +02:00
|
|
|
}
|
|
|
|
|
cl_int GlobalMockSipProgram::processGenBinary() {
|
|
|
|
|
return CL_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cl_int GlobalMockSipProgram::processGenBinaryOnce() {
|
|
|
|
|
cl_int ret = Program::processGenBinary();
|
|
|
|
|
sipAllocationStorage = alignedMalloc(this->kernelInfoArray[0]->heapInfo.pKernelHeader->KernelHeapSize, MemoryConstants::pageSize);
|
|
|
|
|
this->kernelInfoArray[0]->kernelAllocation = new MockGraphicsAllocation(sipAllocationStorage, this->kernelInfoArray[0]->heapInfo.pKernelHeader->KernelHeapSize);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
void GlobalMockSipProgram::resetAllocationState() {
|
2019-12-17 08:11:16 +01:00
|
|
|
auto allocation = static_cast<MockGraphicsAllocation *>(this->kernelInfoArray[0]->kernelAllocation);
|
|
|
|
|
for (uint32_t index = 0u; index < allocation->usageInfos.size(); index++) {
|
2019-01-07 09:29:49 +01:00
|
|
|
this->kernelInfoArray[0]->kernelAllocation->releaseResidencyInOsContext(index);
|
2018-09-19 20:54:29 -07:00
|
|
|
}
|
2019-12-17 08:11:16 +01:00
|
|
|
allocation->resetInspectionIds();
|
2018-05-14 11:25:18 +02:00
|
|
|
}
|
|
|
|
|
void GlobalMockSipProgram::initSipProgram() {
|
|
|
|
|
cl_int retVal = 0;
|
|
|
|
|
std::vector<char> binary = MockCompilerInterface::getDummyGenBinary();
|
2019-12-17 08:11:16 +01:00
|
|
|
executionEnvironment.setHwInfo(*platformDevices);
|
2019-12-24 08:08:08 +01:00
|
|
|
executionEnvironment.prepareRootDeviceEnvironments(maxRootDeviceCount);
|
2019-12-24 09:59:49 +01:00
|
|
|
executionEnvironment.calculateMaxOsContextCount();
|
2018-08-14 10:56:42 +02:00
|
|
|
sipProgram = Program::createFromGenBinary<GlobalMockSipProgram>(executionEnvironment,
|
|
|
|
|
nullptr,
|
2018-05-14 11:25:18 +02:00
|
|
|
binary.data(),
|
|
|
|
|
binary.size(),
|
|
|
|
|
true,
|
2020-02-20 08:12:44 +01:00
|
|
|
&retVal,
|
|
|
|
|
nullptr);
|
2018-05-14 11:25:18 +02:00
|
|
|
DEBUG_BREAK_IF(retVal != 0);
|
|
|
|
|
sipProgram->processGenBinaryOnce();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GlobalMockSipProgram::resetAllocation(GraphicsAllocation *allocation) {
|
|
|
|
|
this->kernelInfoArray[0]->kernelAllocation = allocation;
|
|
|
|
|
}
|
|
|
|
|
GraphicsAllocation *GlobalMockSipProgram::getAllocation() {
|
|
|
|
|
return this->kernelInfoArray[0]->kernelAllocation;
|
|
|
|
|
}
|
|
|
|
|
void GlobalMockSipProgram::deleteAllocation() {
|
|
|
|
|
delete this->kernelInfoArray[0]->kernelAllocation;
|
|
|
|
|
alignedFree(sipAllocationStorage);
|
|
|
|
|
this->kernelInfoArray[0]->kernelAllocation = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GlobalMockSipProgram::shutDownSipProgram() {
|
|
|
|
|
sipProgram->deleteAllocation();
|
|
|
|
|
|
|
|
|
|
delete sipProgram;
|
|
|
|
|
}
|
2018-08-08 13:05:16 +02:00
|
|
|
|
|
|
|
|
Program *GlobalMockSipProgram::getSipProgramWithCustomBinary() {
|
2020-01-11 18:25:26 +01:00
|
|
|
NEO::PatchTokenBinary::ProgramFromPatchtokens programTokens;
|
|
|
|
|
programTokens.kernels.resize(1);
|
|
|
|
|
|
|
|
|
|
const uint8_t isa[] = "kernel morphEUs()";
|
|
|
|
|
const char name[] = "sip";
|
|
|
|
|
|
|
|
|
|
SProgramBinaryHeader progHeader = {};
|
|
|
|
|
progHeader.NumberOfKernels = 1;
|
|
|
|
|
|
|
|
|
|
SKernelBinaryHeaderCommon kernHeader = {};
|
|
|
|
|
kernHeader.KernelNameSize = sizeof(name);
|
|
|
|
|
kernHeader.KernelHeapSize = sizeof(isa);
|
|
|
|
|
kernHeader.KernelUnpaddedSize = sizeof(isa);
|
|
|
|
|
|
|
|
|
|
programTokens.header = &progHeader;
|
|
|
|
|
programTokens.kernels[0].header = &kernHeader;
|
|
|
|
|
programTokens.kernels[0].isa = isa;
|
|
|
|
|
programTokens.kernels[0].name = name;
|
|
|
|
|
|
|
|
|
|
NEO::ProgramInfo programInfo;
|
2020-01-25 19:18:48 +01:00
|
|
|
NEO::populateProgramInfo(programInfo, programTokens);
|
2020-01-11 18:25:26 +01:00
|
|
|
|
2020-02-20 08:12:44 +01:00
|
|
|
Program *ret = new Program(executionEnvironment, nullptr, false, nullptr);
|
2020-01-11 18:25:26 +01:00
|
|
|
ret->processProgramInfo(programInfo);
|
|
|
|
|
return ret;
|
2018-08-08 13:05:16 +02:00
|
|
|
}
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|