2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-01-14 21:32:11 +08:00
|
|
|
* Copyright (C) 2017-2020 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-20 11:54:29 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
2018-09-20 11:54:29 +08:00
|
|
|
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "unit_tests/mocks/mock_program.h"
|
|
|
|
|
2019-10-21 21:47:04 +08:00
|
|
|
#include "core/compiler_interface/compiler_cache.h"
|
2019-10-17 04:21:04 +08:00
|
|
|
#include "core/helpers/hash.h"
|
2020-01-12 01:25:26 +08:00
|
|
|
#include "core/program/program_info_from_patchtokens.h"
|
|
|
|
#include "runtime/compiler_interface/patchtokens_decoder.h"
|
2018-07-31 17:01:13 +08:00
|
|
|
#include "runtime/context/context.h"
|
2018-08-08 19:05:16 +08:00
|
|
|
#include "runtime/program/create.inl"
|
2019-10-28 02:48:26 +08:00
|
|
|
#include "runtime/program/kernel_info.h"
|
2019-12-24 15:08:08 +08:00
|
|
|
#include "unit_tests/helpers/ult_limits.h"
|
2018-05-14 17:25:18 +08:00
|
|
|
#include "unit_tests/mocks/mock_compilers.h"
|
|
|
|
#include "unit_tests/mocks/mock_graphics_allocation.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2018-05-14 17:25:18 +08:00
|
|
|
GlobalMockSipProgram *GlobalMockSipProgram::sipProgram;
|
2018-08-14 16:56:42 +08:00
|
|
|
ExecutionEnvironment GlobalMockSipProgram::executionEnvironment;
|
2020-01-14 21:32:11 +08:00
|
|
|
|
|
|
|
ClDevice *MockProgram::getDevicePtr() { return this->pDevice; }
|
|
|
|
|
2018-07-31 17:01:13 +08: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 21:47:04 +08:00
|
|
|
return CompilerCache::getCachedFileName(hwInfo, input, opts, internalOpts);
|
2018-05-14 17:25:18 +08: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 15:11:16 +08:00
|
|
|
auto allocation = static_cast<MockGraphicsAllocation *>(this->kernelInfoArray[0]->kernelAllocation);
|
|
|
|
for (uint32_t index = 0u; index < allocation->usageInfos.size(); index++) {
|
2019-01-07 16:29:49 +08:00
|
|
|
this->kernelInfoArray[0]->kernelAllocation->releaseResidencyInOsContext(index);
|
2018-09-20 11:54:29 +08:00
|
|
|
}
|
2019-12-17 15:11:16 +08:00
|
|
|
allocation->resetInspectionIds();
|
2018-05-14 17:25:18 +08:00
|
|
|
}
|
|
|
|
void GlobalMockSipProgram::initSipProgram() {
|
|
|
|
cl_int retVal = 0;
|
|
|
|
std::vector<char> binary = MockCompilerInterface::getDummyGenBinary();
|
2019-12-17 15:11:16 +08:00
|
|
|
executionEnvironment.setHwInfo(*platformDevices);
|
2019-12-24 15:08:08 +08:00
|
|
|
executionEnvironment.prepareRootDeviceEnvironments(maxRootDeviceCount);
|
2019-12-24 16:59:49 +08:00
|
|
|
executionEnvironment.calculateMaxOsContextCount();
|
2018-08-14 16:56:42 +08:00
|
|
|
sipProgram = Program::createFromGenBinary<GlobalMockSipProgram>(executionEnvironment,
|
|
|
|
nullptr,
|
2018-05-14 17:25:18 +08:00
|
|
|
binary.data(),
|
|
|
|
binary.size(),
|
|
|
|
true,
|
|
|
|
&retVal);
|
|
|
|
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 19:05:16 +08:00
|
|
|
|
|
|
|
Program *GlobalMockSipProgram::getSipProgramWithCustomBinary() {
|
2020-01-12 01:25:26 +08: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;
|
|
|
|
NEO::populateProgramInfo(programInfo, programTokens, {});
|
|
|
|
|
|
|
|
Program *ret = new Program(executionEnvironment, nullptr, false);
|
|
|
|
ret->processProgramInfo(programInfo);
|
|
|
|
return ret;
|
2018-08-08 19:05:16 +08:00
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|