2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-01-05 01:56:34 +08:00
|
|
|
* Copyright (C) 2017-2020 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"
|
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;
|
|
|
|
|
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;
|
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;
|
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::constantSurface;
|
|
|
|
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-07-04 23:14:51 +08:00
|
|
|
using Program::exportedFunctionsSurface;
|
2019-12-01 23:13:21 +08:00
|
|
|
using Program::extractInternalOptions;
|
2019-08-29 21:10:51 +08:00
|
|
|
using Program::getKernelInfo;
|
2019-07-04 23:14:51 +08:00
|
|
|
using Program::globalSurface;
|
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;
|
|
|
|
using Program::packedDeviceBinary;
|
|
|
|
using Program::packedDeviceBinarySize;
|
2019-07-04 23:14:51 +08:00
|
|
|
using Program::pDevice;
|
2020-08-21 20:29:00 +08:00
|
|
|
using Program::Program;
|
2018-08-07 00:12:20 +08:00
|
|
|
using Program::programBinaryType;
|
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;
|
2020-01-26 02:18:48 +08:00
|
|
|
using Program::unpackedDeviceBinary;
|
|
|
|
using Program::unpackedDeviceBinarySize;
|
2018-03-09 21:40:31 +08:00
|
|
|
|
2020-08-24 19:07:06 +08:00
|
|
|
MockProgram(ExecutionEnvironment &executionEnvironment) : Program(executionEnvironment, nullptr, false, nullptr) {
|
|
|
|
}
|
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 : "";
|
|
|
|
}
|
|
|
|
std::string &getInternalOptions() { return internalOptions; };
|
|
|
|
void setConstantSurface(GraphicsAllocation *gfxAllocation) {
|
|
|
|
constantSurface = gfxAllocation;
|
|
|
|
}
|
|
|
|
void setGlobalSurface(GraphicsAllocation *gfxAllocation) {
|
|
|
|
globalSurface = gfxAllocation;
|
|
|
|
}
|
2020-02-20 15:12:44 +08:00
|
|
|
void setDevice(Device *device) {
|
2017-12-21 07:45:38 +08:00
|
|
|
this->pDevice = device;
|
|
|
|
};
|
|
|
|
std::vector<KernelInfo *> &getKernelInfoArray() {
|
|
|
|
return kernelInfoArray;
|
|
|
|
}
|
|
|
|
void addKernelInfo(KernelInfo *inInfo) {
|
|
|
|
kernelInfoArray.push_back(inInfo);
|
|
|
|
}
|
|
|
|
std::vector<KernelInfo *> &getParentKernelInfoArray() {
|
|
|
|
return parentKernelInfoArray;
|
|
|
|
}
|
|
|
|
std::vector<KernelInfo *> &getSubgroupKernelInfoArray() {
|
|
|
|
return subgroupKernelInfoArray;
|
|
|
|
}
|
|
|
|
void setContext(Context *context) {
|
|
|
|
this->context = context;
|
|
|
|
contextSet = true;
|
|
|
|
}
|
|
|
|
|
2020-08-24 19:07:06 +08:00
|
|
|
void setBuildStatus(cl_build_status st) { buildStatus = st; }
|
|
|
|
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
|
|
|
|
2020-02-20 15:12:44 +08:00
|
|
|
Device *getDevicePtr();
|
2018-03-09 18:52:14 +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;
|
|
|
|
this->buildStatus = CL_BUILD_NONE;
|
|
|
|
std::unordered_map<std::string, BuiltinDispatchInfoBuilder *> builtins;
|
2020-02-20 15:12:44 +08:00
|
|
|
auto &device = this->getDevice();
|
2020-01-26 02:18:48 +08:00
|
|
|
return this->build(&device, this->options.c_str(), false, builtins);
|
2019-10-28 02:48:26 +08:00
|
|
|
}
|
|
|
|
|
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-05-14 17:25:18 +08:00
|
|
|
class GlobalMockSipProgram : public Program {
|
|
|
|
public:
|
|
|
|
using Program::Program;
|
2020-08-21 20:29:00 +08:00
|
|
|
GlobalMockSipProgram(ExecutionEnvironment &executionEnvironment) : Program(executionEnvironment, nullptr, false, nullptr) {
|
2018-05-14 17:25:18 +08:00
|
|
|
}
|
|
|
|
cl_int processGenBinary() override;
|
|
|
|
cl_int processGenBinaryOnce();
|
|
|
|
void resetAllocationState();
|
|
|
|
void resetAllocation(GraphicsAllocation *allocation);
|
|
|
|
void deleteAllocation();
|
|
|
|
GraphicsAllocation *getAllocation();
|
|
|
|
static void initSipProgram();
|
|
|
|
static void shutDownSipProgram();
|
|
|
|
static GlobalMockSipProgram *sipProgram;
|
2018-08-08 19:05:16 +08:00
|
|
|
static Program *getSipProgramWithCustomBinary();
|
2018-05-14 17:25:18 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void *sipAllocationStorage;
|
2018-08-14 16:56:42 +08:00
|
|
|
static ExecutionEnvironment executionEnvironment;
|
2018-05-14 17:25:18 +08:00
|
|
|
};
|
|
|
|
|
2018-12-05 17:58:08 +08:00
|
|
|
class GMockProgram : public Program {
|
|
|
|
public:
|
|
|
|
using Program::Program;
|
|
|
|
MOCK_METHOD0(appendKernelDebugOptions, bool(void));
|
|
|
|
};
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|