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 22:44:01 +01:00
|
|
|
#include "shared/source/compiler_interface/compiler_cache.h"
|
|
|
|
#include "shared/source/device_binary_format/patchtokens_decoder.h"
|
|
|
|
#include "shared/source/helpers/hash.h"
|
|
|
|
#include "shared/source/program/program_info_from_patchtokens.h"
|
2020-02-24 01:01:38 +01:00
|
|
|
#include "shared/test/unit_test/helpers/default_hw_info.h"
|
2020-04-09 15:08:17 +02:00
|
|
|
#include "shared/test/unit_test/mocks/mock_compiler_interface.h"
|
2020-11-02 15:54:01 +01:00
|
|
|
#include "shared/test/unit_test/mocks/mock_graphics_allocation.h"
|
2020-02-24 10:22:30 +01:00
|
|
|
|
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"
|
2020-10-08 11:36:31 +02:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_cl_device.h"
|
2020-02-23 15:20:22 +01:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_compilers.h"
|
2020-02-22 09:28:27 +01:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2020-10-16 15:00:28 +02:00
|
|
|
ClDeviceVector toClDeviceVector(ClDevice &clDevice) {
|
|
|
|
ClDeviceVector deviceVector;
|
|
|
|
deviceVector.push_back(&clDevice);
|
|
|
|
return deviceVector;
|
|
|
|
}
|
2020-10-13 11:41:48 +02:00
|
|
|
ProgramInfo *GlobalMockSipProgram::globalSipProgramInfo;
|
2020-02-20 08:12:44 +01:00
|
|
|
Device *MockProgram::getDevicePtr() { return this->pDevice; }
|
2020-10-30 11:10:00 +01:00
|
|
|
int MockProgram::initInternalOptionsCalled = 0;
|
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());
|
2020-10-30 11:10:00 +01:00
|
|
|
auto internalOptions = getInitInternalOptions();
|
|
|
|
auto internalOpts = ArrayRef<const char>(internalOptions.c_str(), 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
|
|
|
}
|
|
|
|
|
2020-10-13 11:41:48 +02:00
|
|
|
void GlobalMockSipProgram::initSipProgramInfo() {
|
|
|
|
globalSipProgramInfo = new ProgramInfo();
|
2018-05-14 11:25:18 +02:00
|
|
|
std::vector<char> binary = MockCompilerInterface::getDummyGenBinary();
|
2020-10-13 11:41:48 +02:00
|
|
|
auto blob = ArrayRef<const uint8_t>(reinterpret_cast<const uint8_t *>(binary.data()), binary.size());
|
|
|
|
SingleDeviceBinary deviceBinary = {};
|
|
|
|
deviceBinary.deviceBinary = blob;
|
|
|
|
std::string decodeErrors;
|
|
|
|
std::string decodeWarnings;
|
|
|
|
|
|
|
|
NEO::decodeSingleDeviceBinary(*globalSipProgramInfo, deviceBinary, decodeErrors, decodeWarnings);
|
|
|
|
auto sipAllocationStorage = alignedMalloc(globalSipProgramInfo->kernelInfos[0]->heapInfo.KernelHeapSize, MemoryConstants::pageSize);
|
|
|
|
memcpy(sipAllocationStorage, globalSipProgramInfo->kernelInfos[0]->heapInfo.pKernelHeap, globalSipProgramInfo->kernelInfos[0]->heapInfo.KernelHeapSize);
|
|
|
|
globalSipProgramInfo->kernelInfos[0]->heapInfo.pKernelHeap = sipAllocationStorage;
|
|
|
|
globalSipProgramInfo->kernelInfos[0]->kernelAllocation = new MockGraphicsAllocation(sipAllocationStorage, globalSipProgramInfo->kernelInfos[0]->heapInfo.KernelHeapSize);
|
|
|
|
}
|
|
|
|
void GlobalMockSipProgram::shutDownSipProgramInfo() {
|
|
|
|
deleteAllocation();
|
|
|
|
delete globalSipProgramInfo;
|
2018-05-14 11:25:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GlobalMockSipProgram::resetAllocation(GraphicsAllocation *allocation) {
|
2020-10-13 11:41:48 +02:00
|
|
|
globalSipProgramInfo->kernelInfos[0]->kernelAllocation = allocation;
|
2018-05-14 11:25:18 +02:00
|
|
|
}
|
|
|
|
GraphicsAllocation *GlobalMockSipProgram::getAllocation() {
|
2020-10-13 11:41:48 +02:00
|
|
|
return globalSipProgramInfo->kernelInfos[0]->kernelAllocation;
|
2018-05-14 11:25:18 +02:00
|
|
|
}
|
|
|
|
void GlobalMockSipProgram::deleteAllocation() {
|
2020-10-13 11:41:48 +02:00
|
|
|
auto allocation = globalSipProgramInfo->kernelInfos[0]->kernelAllocation;
|
|
|
|
alignedFree(allocation->getUnderlyingBuffer());
|
|
|
|
delete allocation;
|
|
|
|
globalSipProgramInfo->kernelInfos[0]->kernelAllocation = nullptr;
|
2018-05-14 11:25:18 +02:00
|
|
|
}
|
|
|
|
|
2020-10-13 11:41:48 +02:00
|
|
|
void GlobalMockSipProgram::resetAllocationState() {
|
|
|
|
auto allocation = static_cast<MockGraphicsAllocation *>(globalSipProgramInfo->kernelInfos[0]->kernelAllocation);
|
|
|
|
for (uint32_t index = 0u; index < allocation->usageInfos.size(); index++) {
|
|
|
|
globalSipProgramInfo->kernelInfos[0]->kernelAllocation->releaseResidencyInOsContext(index);
|
|
|
|
}
|
|
|
|
allocation->resetInspectionIds();
|
2018-05-14 11:25:18 +02:00
|
|
|
}
|
2020-10-13 11:41:48 +02:00
|
|
|
ProgramInfo GlobalMockSipProgram::getSipProgramInfo() {
|
|
|
|
ProgramInfo programInfo;
|
|
|
|
programInfo.kernelInfos.push_back(new KernelInfo{});
|
|
|
|
programInfo.kernelInfos[0]->heapInfo = GlobalMockSipProgram::globalSipProgramInfo->kernelInfos[0]->heapInfo;
|
|
|
|
programInfo.kernelInfos[0]->kernelAllocation = GlobalMockSipProgram::getAllocation();
|
|
|
|
return programInfo;
|
|
|
|
}
|
|
|
|
ProgramInfo GlobalMockSipProgram::getSipProgramInfoWithCustomBinary() {
|
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-10-13 11:41:48 +02:00
|
|
|
return programInfo;
|
2018-08-08 13:05:16 +02:00
|
|
|
}
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|