2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2023-01-04 00:20:12 +08:00
|
|
|
* Copyright (C) 2018-2023 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/device/device.h"
|
|
|
|
#include "shared/source/helpers/hash.h"
|
|
|
|
#include "shared/source/helpers/string.h"
|
2023-01-04 00:20:12 +08:00
|
|
|
#include "shared/source/memory_manager/graphics_allocation.h"
|
2021-09-30 03:10:53 +08:00
|
|
|
#include "shared/source/program/kernel_info.h"
|
2021-12-20 19:02:31 +08:00
|
|
|
#include "shared/test/common/test_macros/mock_method_macros.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-03-20 18:15:25 +08:00
|
|
|
#include "opencl/source/cl_device/cl_device.h"
|
2021-03-24 01:11:41 +08:00
|
|
|
#include "opencl/source/kernel/multi_device_kernel.h"
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/program/program.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2018-07-31 17:01:13 +08:00
|
|
|
#include <string>
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
class GraphicsAllocation;
|
2020-10-16 21:00:28 +08:00
|
|
|
ClDeviceVector toClDeviceVector(ClDevice &clDevice);
|
2018-05-28 22:16:06 +08:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Program - Core implementation
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2022-12-01 20:19:45 +08:00
|
|
|
class MockNeoProgram : public NEO::Program {
|
|
|
|
public:
|
|
|
|
using Base = NEO::Program;
|
|
|
|
using Base::buildInfos;
|
|
|
|
using Base::exportedFunctionsKernelId;
|
|
|
|
|
|
|
|
MockNeoProgram(NEO::Context *context, bool isBuiltIn, const NEO::ClDeviceVector &devices)
|
|
|
|
: NEO::Program(context, isBuiltIn, devices) {}
|
|
|
|
|
|
|
|
void resizeAndPopulateKernelInfoArray(size_t size) {
|
|
|
|
buildInfos[0].kernelInfoArray.resize(size);
|
|
|
|
for (auto &entry : buildInfos[0].kernelInfoArray) {
|
|
|
|
entry = new KernelInfo();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
class MockProgram : public Program {
|
|
|
|
public:
|
2021-10-05 00:37:12 +08:00
|
|
|
using Program::allowNonUniform;
|
2019-04-25 18:46:43 +08:00
|
|
|
using Program::areSpecializationConstantsInitialized;
|
2020-09-09 00:23:10 +08:00
|
|
|
using Program::buildInfos;
|
2022-12-21 22:09:51 +08:00
|
|
|
using Program::containsVmeUsage;
|
2019-07-04 23:14:51 +08:00
|
|
|
using Program::context;
|
2020-02-17 05:49:47 +08:00
|
|
|
using Program::createdFrom;
|
2021-10-05 00:37:12 +08:00
|
|
|
using Program::createProgramFromBinary;
|
|
|
|
using Program::deviceBuildInfos;
|
2022-12-22 23:09:00 +08:00
|
|
|
using Program::disableZebinIfVmeEnabled;
|
2023-01-12 00:46:43 +08:00
|
|
|
using Program::enforceFallbackToPatchtokens;
|
2019-12-01 23:13:21 +08:00
|
|
|
using Program::extractInternalOptions;
|
2019-08-29 21:10:51 +08:00
|
|
|
using Program::getKernelInfo;
|
2021-10-05 00:37:12 +08:00
|
|
|
using Program::internalOptionsToExtract;
|
2018-08-07 00:12:20 +08:00
|
|
|
using Program::irBinary;
|
|
|
|
using Program::irBinarySize;
|
2021-11-22 21:05:54 +08:00
|
|
|
using Program::isBuiltIn;
|
2022-02-09 21:18:18 +08:00
|
|
|
using Program::isCreatedFromBinary;
|
2018-08-07 00:12:20 +08:00
|
|
|
using Program::isSpirV;
|
2021-10-05 00:37:12 +08:00
|
|
|
using Program::kernelDebugEnabled;
|
|
|
|
using Program::linkBinary;
|
2020-01-26 02:18:48 +08:00
|
|
|
using Program::options;
|
|
|
|
using Program::packDeviceBinary;
|
2022-09-16 23:01:18 +08:00
|
|
|
using Program::processGenBinaries;
|
2020-08-21 20:29:00 +08:00
|
|
|
using Program::Program;
|
2022-04-07 20:29:43 +08:00
|
|
|
using Program::requiresRebuild;
|
2021-10-05 00:37:12 +08:00
|
|
|
using Program::setBuildStatus;
|
2019-08-29 21:10:51 +08:00
|
|
|
using Program::sourceCode;
|
2019-04-25 18:46:43 +08:00
|
|
|
using Program::specConstantsIds;
|
|
|
|
using Program::specConstantsSizes;
|
|
|
|
using Program::specConstantsValues;
|
2021-10-05 00:37:12 +08:00
|
|
|
using Program::updateNonUniformFlag;
|
2018-03-09 21:40:31 +08:00
|
|
|
|
2020-10-16 21:00:28 +08:00
|
|
|
MockProgram(const ClDeviceVector &deviceVector) : Program(nullptr, false, deviceVector) {
|
2020-08-24 19:07:06 +08:00
|
|
|
}
|
2018-08-06 22:36:12 +08:00
|
|
|
|
2020-03-13 16:17:01 +08:00
|
|
|
~MockProgram() override {
|
2017-12-21 07:45:38 +08:00
|
|
|
if (contextSet)
|
|
|
|
context = nullptr;
|
|
|
|
}
|
|
|
|
KernelInfo mockKernelInfo;
|
|
|
|
void setBuildOptions(const char *buildOptions) {
|
|
|
|
options = buildOptions != nullptr ? buildOptions : "";
|
|
|
|
}
|
|
|
|
void setConstantSurface(GraphicsAllocation *gfxAllocation) {
|
2020-09-15 23:34:49 +08:00
|
|
|
if (gfxAllocation) {
|
|
|
|
buildInfos[gfxAllocation->getRootDeviceIndex()].constantSurface = gfxAllocation;
|
|
|
|
} else {
|
|
|
|
for (auto &buildInfo : buildInfos) {
|
|
|
|
buildInfo.constantSurface = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
void setGlobalSurface(GraphicsAllocation *gfxAllocation) {
|
2020-09-15 23:34:49 +08:00
|
|
|
if (gfxAllocation) {
|
|
|
|
buildInfos[gfxAllocation->getRootDeviceIndex()].globalSurface = gfxAllocation;
|
|
|
|
} else {
|
|
|
|
for (auto &buildInfo : buildInfos) {
|
|
|
|
buildInfo.globalSurface = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2020-12-01 01:38:28 +08:00
|
|
|
std::vector<KernelInfo *> &getKernelInfoArray(uint32_t rootDeviceIndex) {
|
|
|
|
return buildInfos[rootDeviceIndex].kernelInfoArray;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2020-12-01 01:38:28 +08:00
|
|
|
void addKernelInfo(KernelInfo *inInfo, uint32_t rootDeviceIndex) {
|
|
|
|
buildInfos[rootDeviceIndex].kernelInfoArray.push_back(inInfo);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
void setContext(Context *context) {
|
|
|
|
this->context = context;
|
|
|
|
contextSet = true;
|
|
|
|
}
|
2020-08-24 19:07:06 +08:00
|
|
|
void setSourceCode(const char *ptr) { sourceCode = ptr; }
|
|
|
|
void clearOptions() { options = ""; }
|
|
|
|
void setCreatedFromBinary(bool createdFromBin) { isCreatedFromBinary = createdFromBin; }
|
|
|
|
void clearLog(uint32_t rootDeviceIndex) { buildInfos[rootDeviceIndex].buildLog.clear(); }
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-08-24 19:07:06 +08:00
|
|
|
void setIrBinary(char *ptr, bool isSpirv) {
|
2019-08-29 21:10:51 +08:00
|
|
|
irBinary.reset(ptr);
|
2018-06-18 20:36:23 +08:00
|
|
|
this->isSpirV = isSpirV;
|
|
|
|
}
|
2020-08-24 19:07:06 +08:00
|
|
|
void setIrBinarySize(size_t bsz, bool isSpirv) {
|
2018-06-18 20:36:23 +08:00
|
|
|
irBinarySize = bsz;
|
|
|
|
this->isSpirV = isSpirV;
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-07-31 17:01:13 +08:00
|
|
|
std::string getCachedFileName() const;
|
2018-02-16 16:15:36 +08:00
|
|
|
void setAllowNonUniform(bool allow) {
|
|
|
|
allowNonUniform = allow;
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-12-01 23:13:21 +08:00
|
|
|
bool isFlagOption(ConstStringRef option) override {
|
2019-11-27 21:56:48 +08:00
|
|
|
if (isFlagOptionOverride != -1) {
|
|
|
|
return (isFlagOptionOverride > 0);
|
|
|
|
}
|
|
|
|
return Program::isFlagOption(option);
|
|
|
|
}
|
|
|
|
|
2019-12-01 23:13:21 +08:00
|
|
|
bool isOptionValueValid(ConstStringRef option, ConstStringRef value) override {
|
2019-11-27 21:56:48 +08:00
|
|
|
if (isOptionValueValidOverride != -1) {
|
|
|
|
return (isOptionValueValidOverride > 0);
|
|
|
|
}
|
|
|
|
return Program::isOptionValueValid(option, value);
|
|
|
|
}
|
|
|
|
|
2020-01-26 02:18:48 +08:00
|
|
|
cl_int rebuildProgramFromIr() {
|
|
|
|
this->isCreatedFromBinary = false;
|
2022-04-07 20:29:43 +08:00
|
|
|
this->requiresRebuild = true;
|
2020-10-27 00:13:50 +08:00
|
|
|
setBuildStatus(CL_BUILD_NONE);
|
2020-01-26 02:18:48 +08:00
|
|
|
std::unordered_map<std::string, BuiltinDispatchInfoBuilder *> builtins;
|
2020-10-30 18:10:00 +08:00
|
|
|
return this->build(getDevices(), this->options.c_str(), false, builtins);
|
2019-10-28 02:48:26 +08:00
|
|
|
}
|
|
|
|
|
2021-12-22 23:06:58 +08:00
|
|
|
cl_int recompile() {
|
|
|
|
this->isCreatedFromBinary = false;
|
2022-04-07 20:29:43 +08:00
|
|
|
this->requiresRebuild = true;
|
2021-12-22 23:06:58 +08:00
|
|
|
setBuildStatus(CL_BUILD_NONE);
|
|
|
|
return this->compile(getDevices(), this->options.c_str(), 0, nullptr, nullptr);
|
|
|
|
}
|
|
|
|
|
2021-10-21 20:37:31 +08:00
|
|
|
void replaceDeviceBinary(std::unique_ptr<char[]> &&newBinary, size_t newBinarySize, uint32_t rootDeviceIndex) override {
|
2020-10-30 18:10:00 +08:00
|
|
|
if (replaceDeviceBinaryCalledPerRootDevice.find(rootDeviceIndex) == replaceDeviceBinaryCalledPerRootDevice.end()) {
|
|
|
|
replaceDeviceBinaryCalledPerRootDevice.insert({rootDeviceIndex, 1});
|
|
|
|
} else {
|
|
|
|
replaceDeviceBinaryCalledPerRootDevice[rootDeviceIndex]++;
|
|
|
|
}
|
|
|
|
Program::replaceDeviceBinary(std::move(newBinary), newBinarySize, rootDeviceIndex);
|
|
|
|
}
|
2020-11-10 00:55:46 +08:00
|
|
|
cl_int processGenBinary(const ClDevice &clDevice) override {
|
|
|
|
auto rootDeviceIndex = clDevice.getRootDeviceIndex();
|
2020-10-30 18:10:00 +08:00
|
|
|
if (processGenBinaryCalledPerRootDevice.find(rootDeviceIndex) == processGenBinaryCalledPerRootDevice.end()) {
|
|
|
|
processGenBinaryCalledPerRootDevice.insert({rootDeviceIndex, 1});
|
|
|
|
} else {
|
|
|
|
processGenBinaryCalledPerRootDevice[rootDeviceIndex]++;
|
|
|
|
}
|
2020-11-10 00:55:46 +08:00
|
|
|
return Program::processGenBinary(clDevice);
|
2020-10-30 18:10:00 +08:00
|
|
|
}
|
|
|
|
|
2022-01-13 18:14:33 +08:00
|
|
|
std::string getInternalOptions() const override {
|
|
|
|
getInternalOptionsCalled++;
|
|
|
|
return Program::getInternalOptions();
|
2020-10-30 18:10:00 +08:00
|
|
|
};
|
|
|
|
|
2021-03-22 23:26:03 +08:00
|
|
|
const KernelInfo &getKernelInfoForKernel(const char *kernelName) const {
|
|
|
|
return *getKernelInfo(kernelName, getDevices()[0]->getRootDeviceIndex());
|
|
|
|
}
|
|
|
|
|
2020-12-03 02:19:05 +08:00
|
|
|
const KernelInfoContainer getKernelInfosForKernel(const char *kernelName) const {
|
|
|
|
KernelInfoContainer kernelInfos;
|
|
|
|
kernelInfos.resize(getMaxRootDeviceIndex() + 1);
|
|
|
|
for (auto i = 0u; i < kernelInfos.size(); i++) {
|
|
|
|
kernelInfos[i] = getKernelInfo(kernelName, i);
|
|
|
|
}
|
|
|
|
return kernelInfos;
|
|
|
|
}
|
|
|
|
|
2022-02-09 21:18:18 +08:00
|
|
|
void processDebugData(uint32_t rootDeviceIndex) override {
|
|
|
|
Program::processDebugData(rootDeviceIndex);
|
|
|
|
wasProcessDebugDataCalled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void createDebugZebin(uint32_t rootDeviceIndex) override {
|
|
|
|
Program::createDebugZebin(rootDeviceIndex);
|
|
|
|
wasCreateDebugZebinCalled = true;
|
|
|
|
}
|
|
|
|
|
2022-05-20 18:21:08 +08:00
|
|
|
void debugNotify(const ClDeviceVector &deviceVector, std::unordered_map<uint32_t, BuildPhase> &phasesReached) override {
|
|
|
|
Program::debugNotify(deviceVector, phasesReached);
|
|
|
|
wasDebuggerNotified = true;
|
|
|
|
}
|
|
|
|
|
2022-11-04 00:50:55 +08:00
|
|
|
void callPopulateZebinExtendedArgsMetadataOnce(uint32_t rootDeviceIndex) override {
|
|
|
|
wasPopulateZebinExtendedArgsMetadataOnceCalled = true;
|
|
|
|
|
|
|
|
if (callBasePopulateZebinExtendedArgsMetadataOnce) {
|
|
|
|
return Program::callPopulateZebinExtendedArgsMetadataOnce(rootDeviceIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-01 01:44:06 +08:00
|
|
|
std::vector<NEO::ExternalFunctionInfo> externalFunctions;
|
2020-10-30 18:10:00 +08:00
|
|
|
std::map<uint32_t, int> processGenBinaryCalledPerRootDevice;
|
|
|
|
std::map<uint32_t, int> replaceDeviceBinaryCalledPerRootDevice;
|
2022-01-13 18:14:33 +08:00
|
|
|
static int getInternalOptionsCalled;
|
2017-12-21 07:45:38 +08:00
|
|
|
bool contextSet = false;
|
2019-11-27 21:56:48 +08:00
|
|
|
int isFlagOptionOverride = -1;
|
|
|
|
int isOptionValueValidOverride = -1;
|
2022-02-09 21:18:18 +08:00
|
|
|
bool wasProcessDebugDataCalled = false;
|
|
|
|
bool wasCreateDebugZebinCalled = false;
|
2022-05-20 18:21:08 +08:00
|
|
|
bool wasDebuggerNotified = false;
|
2022-11-04 00:50:55 +08:00
|
|
|
bool wasPopulateZebinExtendedArgsMetadataOnceCalled = false;
|
|
|
|
bool callBasePopulateZebinExtendedArgsMetadataOnce = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2018-03-06 22:29:06 +08:00
|
|
|
|
2021-12-20 19:02:31 +08:00
|
|
|
class MockProgramAppendKernelDebugOptions : public Program {
|
2018-12-05 17:58:08 +08:00
|
|
|
public:
|
|
|
|
using Program::Program;
|
2021-12-20 19:02:31 +08:00
|
|
|
ADDMETHOD_NOBASE(appendKernelDebugOptions, bool, true, (ClDevice & clDevice, std::string &internalOptions));
|
2022-11-02 21:36:46 +08:00
|
|
|
ADDMETHOD_NOBASE(processGenBinary, cl_int, CL_SUCCESS, (const ClDevice &clDevice));
|
2018-12-05 17:58:08 +08:00
|
|
|
};
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|