2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2021-05-17 02:51:16 +08:00
|
|
|
* Copyright (C) 2018-2021 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"
|
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/kernel_info.h"
|
|
|
|
#include "opencl/source/program/program.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2018-12-05 17:58:08 +08:00
|
|
|
#include "gmock/gmock.h"
|
2017-12-21 07:45:38 +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
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2017-12-21 07:45:38 +08:00
|
|
|
class MockProgram : public Program {
|
|
|
|
public:
|
2018-08-06 17:07:12 +08:00
|
|
|
using Program::createProgramFromBinary;
|
2020-11-04 18:08:45 +08:00
|
|
|
using Program::deviceBuildInfos;
|
2019-12-01 23:13:21 +08:00
|
|
|
using Program::internalOptionsToExtract;
|
2020-07-23 16:56:08 +08:00
|
|
|
using Program::kernelDebugEnabled;
|
2019-07-04 23:14:51 +08:00
|
|
|
using Program::linkBinary;
|
2019-10-28 02:48:26 +08:00
|
|
|
using Program::separateBlockKernels;
|
2020-10-27 00:13:50 +08:00
|
|
|
using Program::setBuildStatus;
|
2018-08-09 16:54:35 +08:00
|
|
|
using Program::updateNonUniformFlag;
|
2018-08-07 00:12:20 +08:00
|
|
|
|
2019-12-01 23:13:21 +08:00
|
|
|
using Program::applyAdditionalOptions;
|
2019-04-25 18:46:43 +08:00
|
|
|
using Program::areSpecializationConstantsInitialized;
|
2019-10-28 02:48:26 +08:00
|
|
|
using Program::blockKernelManager;
|
2020-09-09 00:23:10 +08:00
|
|
|
using Program::buildInfos;
|
2019-07-04 23:14:51 +08:00
|
|
|
using Program::context;
|
2020-02-17 05:49:47 +08:00
|
|
|
using Program::createdFrom;
|
2019-08-29 21:10:51 +08:00
|
|
|
using Program::debugData;
|
|
|
|
using Program::debugDataSize;
|
2019-12-01 23:13:21 +08:00
|
|
|
using Program::extractInternalOptions;
|
2019-08-29 21:10:51 +08:00
|
|
|
using Program::getKernelInfo;
|
2018-08-07 00:12:20 +08:00
|
|
|
using Program::irBinary;
|
|
|
|
using Program::irBinarySize;
|
|
|
|
using Program::isSpirV;
|
2020-01-26 02:18:48 +08:00
|
|
|
using Program::options;
|
|
|
|
using Program::packDeviceBinary;
|
2020-08-21 20:29:00 +08:00
|
|
|
using Program::Program;
|
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;
|
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 : "";
|
|
|
|
}
|
2020-10-30 18:10:00 +08:00
|
|
|
std::string getInitInternalOptions() const {
|
|
|
|
std::string internalOptions;
|
|
|
|
initInternalOptions(internalOptions);
|
|
|
|
return internalOptions;
|
|
|
|
};
|
2017-12-21 07:45:38 +08:00
|
|
|
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
|
|
|
}
|
2020-12-01 01:38:28 +08:00
|
|
|
std::vector<KernelInfo *> &getParentKernelInfoArray(uint32_t rootDeviceIndex) {
|
|
|
|
return buildInfos[rootDeviceIndex].parentKernelInfoArray;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2020-12-01 01:38:28 +08:00
|
|
|
std::vector<KernelInfo *> &getSubgroupKernelInfoArray(uint32_t rootDeviceIndex) {
|
|
|
|
return buildInfos[rootDeviceIndex].subgroupKernelInfoArray;
|
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;
|
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
|
|
|
}
|
|
|
|
|
2020-10-30 18:10:00 +08:00
|
|
|
void replaceDeviceBinary(std::unique_ptr<char[]> newBinary, size_t newBinarySize, uint32_t rootDeviceIndex) override {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void initInternalOptions(std::string &internalOptions) const override {
|
|
|
|
initInternalOptionsCalled++;
|
|
|
|
Program::initInternalOptions(internalOptions);
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-10-30 18:10:00 +08:00
|
|
|
std::map<uint32_t, int> processGenBinaryCalledPerRootDevice;
|
|
|
|
std::map<uint32_t, int> replaceDeviceBinaryCalledPerRootDevice;
|
|
|
|
static int initInternalOptionsCalled;
|
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;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2018-03-06 22:29:06 +08:00
|
|
|
|
2018-12-05 17:58:08 +08:00
|
|
|
class GMockProgram : public Program {
|
|
|
|
public:
|
|
|
|
using Program::Program;
|
2020-10-30 18:10:00 +08:00
|
|
|
MOCK_METHOD(bool, appendKernelDebugOptions, (ClDevice &, std::string &), (override));
|
2018-12-05 17:58:08 +08:00
|
|
|
};
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|