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
|
|
|
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_program.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2020-02-24 05:44:01 +08: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 08:01:38 +08:00
|
|
|
#include "shared/test/unit_test/helpers/default_hw_info.h"
|
2020-04-09 21:08:17 +08:00
|
|
|
#include "shared/test/unit_test/mocks/mock_compiler_interface.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/context/context.h"
|
|
|
|
#include "opencl/source/program/create.inl"
|
|
|
|
#include "opencl/source/program/kernel_info.h"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/helpers/ult_limits.h"
|
2020-10-08 17:36:31 +08:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_cl_device.h"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_compilers.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_graphics_allocation.h"
|
2020-02-22 16:28:27 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2020-10-16 21:00:28 +08:00
|
|
|
ClDeviceVector toClDeviceVector(ClDevice &clDevice) {
|
|
|
|
ClDeviceVector deviceVector;
|
|
|
|
deviceVector.push_back(&clDevice);
|
|
|
|
return deviceVector;
|
|
|
|
}
|
2020-10-13 17:41:48 +08:00
|
|
|
ProgramInfo *GlobalMockSipProgram::globalSipProgramInfo;
|
2020-02-20 15:12:44 +08:00
|
|
|
Device *MockProgram::getDevicePtr() { return this->pDevice; }
|
2020-01-14 21:32:11 +08:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-10-13 17:41:48 +08:00
|
|
|
void GlobalMockSipProgram::initSipProgramInfo() {
|
|
|
|
globalSipProgramInfo = new ProgramInfo();
|
2018-05-14 17:25:18 +08:00
|
|
|
std::vector<char> binary = MockCompilerInterface::getDummyGenBinary();
|
2020-10-13 17:41:48 +08: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 17:25:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GlobalMockSipProgram::resetAllocation(GraphicsAllocation *allocation) {
|
2020-10-13 17:41:48 +08:00
|
|
|
globalSipProgramInfo->kernelInfos[0]->kernelAllocation = allocation;
|
2018-05-14 17:25:18 +08:00
|
|
|
}
|
|
|
|
GraphicsAllocation *GlobalMockSipProgram::getAllocation() {
|
2020-10-13 17:41:48 +08:00
|
|
|
return globalSipProgramInfo->kernelInfos[0]->kernelAllocation;
|
2018-05-14 17:25:18 +08:00
|
|
|
}
|
|
|
|
void GlobalMockSipProgram::deleteAllocation() {
|
2020-10-13 17:41:48 +08:00
|
|
|
auto allocation = globalSipProgramInfo->kernelInfos[0]->kernelAllocation;
|
|
|
|
alignedFree(allocation->getUnderlyingBuffer());
|
|
|
|
delete allocation;
|
|
|
|
globalSipProgramInfo->kernelInfos[0]->kernelAllocation = nullptr;
|
2018-05-14 17:25:18 +08:00
|
|
|
}
|
|
|
|
|
2020-10-13 17:41:48 +08: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 17:25:18 +08:00
|
|
|
}
|
2020-10-13 17:41:48 +08: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-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;
|
2020-01-26 02:18:48 +08:00
|
|
|
NEO::populateProgramInfo(programInfo, programTokens);
|
2020-10-13 17:41:48 +08:00
|
|
|
return programInfo;
|
2018-08-08 19:05:16 +08:00
|
|
|
}
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|