mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-11 08:07:19 +08:00
Add initial implementation of specialization constants
Related-To: NEO-2260 Change-Id: Ib722109039555a028eb4ec0862e9de72342f9730 Signed-off-by: Jobczyk, Lukasz <lukasz.jobczyk@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
3a75c4fb71
commit
971eb7a1b4
@@ -4659,3 +4659,21 @@ cl_int CL_API_CALL clAddCommentINTEL(cl_platform_id platform, const char *commen
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
cl_int CL_API_CALL clSetProgramSpecializationConstant(cl_program program, cl_uint specId, size_t specSize, const void *specValue) {
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
API_ENTER(&retVal);
|
||||
DBG_LOG_INPUTS("program", program,
|
||||
"specId", specId,
|
||||
"specSize", specSize,
|
||||
"specValue", specValue);
|
||||
|
||||
Program *pProgram = nullptr;
|
||||
retVal = validateObjects(WithCastToInternal(program, &pProgram), specValue);
|
||||
|
||||
if (retVal == CL_SUCCESS) {
|
||||
retVal = pProgram->setProgramSpecializationConstant(specId, specSize, specValue);
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@@ -916,3 +916,11 @@ extern CL_API_ENTRY cl_program CL_API_CALL clCreateProgramWithILKHR(
|
||||
size_t length,
|
||||
cl_int *errcodeRet) CL_API_SUFFIX__VERSION_1_2;
|
||||
}
|
||||
|
||||
// OpenCL 2.2
|
||||
|
||||
cl_int CL_API_CALL clSetProgramSpecializationConstant(
|
||||
cl_program program,
|
||||
cl_uint specId,
|
||||
size_t specSize,
|
||||
const void *specValue);
|
||||
|
||||
@@ -131,7 +131,7 @@ cl_int CompilerInterface::build(
|
||||
if (!binaryLoaded) {
|
||||
auto igcTranslationCtx = createIgcTranslationCtx(device, intermediateCodeType, IGC::CodeType::oclGenBin);
|
||||
|
||||
auto igcOutput = translate(igcTranslationCtx.get(), intermediateRepresentation.get(),
|
||||
auto igcOutput = translate(igcTranslationCtx.get(), intermediateRepresentation.get(), program.getSpecConstIdsBuffer().get(), program.getSpecConstValuesBuffer().get(),
|
||||
fclOptions.get(), fclInternalOptions.get(), inputArgs.GTPinInput);
|
||||
|
||||
if (igcOutput == nullptr) {
|
||||
@@ -272,6 +272,27 @@ cl_int CompilerInterface::link(
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
cl_int CompilerInterface::getSpecConstantsInfo(Program &program, const TranslationArgs &inputArgs) {
|
||||
if (false == isCompilerAvailable()) {
|
||||
return CL_COMPILER_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
auto igcTranslationCtx = createIgcTranslationCtx(program.getDevice(0), IGC::CodeType::spirV, IGC::CodeType::oclGenBin);
|
||||
|
||||
auto inSrc = CIF::Builtins::CreateConstBuffer(igcMain.get(), inputArgs.pInput, inputArgs.InputSize);
|
||||
program.getSpecConstIdsBuffer() = CIF::Builtins::CreateConstBuffer(igcMain.get(), nullptr, 0);
|
||||
program.getSpecConstSizesBuffer() = CIF::Builtins::CreateConstBuffer(igcMain.get(), nullptr, 0);
|
||||
program.getSpecConstValuesBuffer() = CIF::Builtins::CreateConstBuffer(igcMain.get(), nullptr, 0);
|
||||
|
||||
auto retVal = getSpecConstantsInfoImpl(igcTranslationCtx.get(), inSrc.get(), program.getSpecConstIdsBuffer().get(), program.getSpecConstSizesBuffer().get(), program.getSpecConstValuesBuffer().get());
|
||||
|
||||
if (!retVal) {
|
||||
return CL_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
cl_int CompilerInterface::createLibrary(
|
||||
Program &program,
|
||||
const TranslationArgs &inputArgs) {
|
||||
|
||||
@@ -57,6 +57,8 @@ class CompilerInterface {
|
||||
|
||||
MOCKABLE_VIRTUAL cl_int link(Program &program, const TranslationArgs &pInputArgs);
|
||||
|
||||
MOCKABLE_VIRTUAL cl_int getSpecConstantsInfo(Program &program, const TranslationArgs &inputArgs);
|
||||
|
||||
cl_int createLibrary(Program &program, const TranslationArgs &pInputArgs);
|
||||
|
||||
MOCKABLE_VIRTUAL cl_int getSipKernelBinary(SipKernelType kernel, const Device &device, std::vector<char> &retBinary);
|
||||
|
||||
@@ -54,6 +54,37 @@ inline CIF::RAII::UPtr_t<IGC::OclTranslationOutputTagOCL> translate(TranslationC
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename TranslationCtx>
|
||||
inline bool getSpecConstantsInfoImpl(TranslationCtx *tCtx,
|
||||
CIFBuffer *src,
|
||||
CIFBuffer *outSpecConstantsIds,
|
||||
CIFBuffer *outSpecConstantsSizes,
|
||||
CIFBuffer *outSpecConstantsValues) {
|
||||
if (!NEO::areNotNullptr(tCtx, src, outSpecConstantsIds, outSpecConstantsSizes, outSpecConstantsValues)) {
|
||||
return false;
|
||||
}
|
||||
return tCtx->GetSpecConstantsInfoImpl(src, outSpecConstantsIds, outSpecConstantsSizes);
|
||||
}
|
||||
|
||||
template <typename TranslationCtx>
|
||||
inline CIF::RAII::UPtr_t<IGC::OclTranslationOutputTagOCL> translate(TranslationCtx *tCtx, CIFBuffer *src, CIFBuffer *specConstantsIds, CIFBuffer *specConstantsValues, CIFBuffer *options,
|
||||
CIFBuffer *internalOptions, void *gtpinInit) {
|
||||
if (false == NEO::areNotNullptr(tCtx, src, options, internalOptions)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto ret = tCtx->Translate(src, specConstantsIds, specConstantsValues, options, internalOptions, nullptr, 0, gtpinInit);
|
||||
if (ret == nullptr) {
|
||||
return nullptr; // assume OOM or internal error
|
||||
}
|
||||
|
||||
if (!NEO::areNotNullptr(ret->GetOutput(), ret->GetBuildLog(), ret->GetDebugData())) {
|
||||
return nullptr; // assume OOM or internal error
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
CIF::CIFMain *createMainNoSanitize(CIF::CreateCIFMainFunc_t createFunc);
|
||||
|
||||
template <template <CIF::Version_t> class EntryPointT>
|
||||
|
||||
@@ -210,6 +210,56 @@ cl_int Program::rebuildProgramFromIr() {
|
||||
return retVal;
|
||||
}
|
||||
|
||||
cl_int Program::setProgramSpecializationConstant(cl_uint specId, size_t specSize, const void *specValue) {
|
||||
if (!isSpirV) {
|
||||
return CL_INVALID_PROGRAM;
|
||||
}
|
||||
|
||||
static std::mutex mutex;
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
if (!areSpecializationConstantsInitialized) {
|
||||
auto pCompilerInterface = this->executionEnvironment.getCompilerInterface();
|
||||
if (nullptr == pCompilerInterface) {
|
||||
return CL_OUT_OF_HOST_MEMORY;
|
||||
}
|
||||
|
||||
TranslationArgs inputArgs = {};
|
||||
inputArgs.pInput = const_cast<char *>(sourceCode.c_str());
|
||||
inputArgs.InputSize = static_cast<uint32_t>(sourceCode.size());
|
||||
inputArgs.pOptions = options.c_str();
|
||||
inputArgs.OptionsSize = static_cast<uint32_t>(options.length());
|
||||
inputArgs.pInternalOptions = internalOptions.c_str();
|
||||
inputArgs.InternalOptionsSize = static_cast<uint32_t>(internalOptions.length());
|
||||
inputArgs.pTracingOptions = nullptr;
|
||||
inputArgs.TracingOptionsCount = 0;
|
||||
|
||||
auto retVal = pCompilerInterface->getSpecConstantsInfo(*this, inputArgs);
|
||||
|
||||
if (retVal != CL_SUCCESS) {
|
||||
return retVal;
|
||||
}
|
||||
|
||||
areSpecializationConstantsInitialized = true;
|
||||
}
|
||||
|
||||
return updateSpecializationConstant(specId, specSize, specValue);
|
||||
}
|
||||
|
||||
cl_int Program::updateSpecializationConstant(cl_uint specId, size_t specSize, const void *specValue) {
|
||||
for (uint32_t i = 0; i < specConstantsIds->GetSize<cl_uint>(); i++) {
|
||||
if (specConstantsIds->GetMemory<cl_uint>()[i] == specId) {
|
||||
if (specConstantsSizes->GetMemory<size_t>()[i] == specSize) {
|
||||
specConstantsValues->GetMemoryWriteable<const void *>()[i] = specValue;
|
||||
return CL_SUCCESS;
|
||||
} else {
|
||||
return CL_INVALID_VALUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return CL_INVALID_SPEC_ID;
|
||||
}
|
||||
|
||||
void Program::getProgramCompilerVersion(
|
||||
SProgramBinaryHeader *pSectionData,
|
||||
uint32_t &binaryVersion) const {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "runtime/helpers/string_helpers.h"
|
||||
|
||||
#include "block_kernel_manager.h"
|
||||
#include "cif/builtins/memory/buffer/buffer.h"
|
||||
#include "igfxfmid.h"
|
||||
#include "kernel_info.h"
|
||||
#include "patch_list.h"
|
||||
@@ -117,6 +118,9 @@ class Program : public BaseObject<_cl_program> {
|
||||
void(CL_CALLBACK *funcNotify)(cl_program program, void *userData),
|
||||
void *userData);
|
||||
|
||||
cl_int setProgramSpecializationConstant(cl_uint specId, size_t specSize, const void *specValue);
|
||||
MOCKABLE_VIRTUAL cl_int updateSpecializationConstant(cl_uint specId, size_t specSize, const void *specValue);
|
||||
|
||||
size_t getNumKernels() const;
|
||||
const KernelInfo *getKernelInfo(const char *kernelName) const;
|
||||
const KernelInfo *getKernelInfo(size_t ordinal) const;
|
||||
@@ -242,6 +246,18 @@ class Program : public BaseObject<_cl_program> {
|
||||
return debugDataSize;
|
||||
}
|
||||
|
||||
CIF::RAII::UPtr_t<CIF::Builtins::BufferSimple> &getSpecConstIdsBuffer() {
|
||||
return this->specConstantsIds;
|
||||
}
|
||||
|
||||
CIF::RAII::UPtr_t<CIF::Builtins::BufferSimple> &getSpecConstValuesBuffer() {
|
||||
return this->specConstantsValues;
|
||||
}
|
||||
|
||||
CIF::RAII::UPtr_t<CIF::Builtins::BufferSimple> &getSpecConstSizesBuffer() {
|
||||
return this->specConstantsSizes;
|
||||
}
|
||||
|
||||
protected:
|
||||
Program(ExecutionEnvironment &executionEnvironment);
|
||||
|
||||
@@ -286,60 +302,64 @@ class Program : public BaseObject<_cl_program> {
|
||||
|
||||
static const std::string clOptNameClVer;
|
||||
static const std::string clOptNameUniformWgs;
|
||||
// clang-format off
|
||||
cl_program_binary_type programBinaryType;
|
||||
bool isSpirV = false;
|
||||
|
||||
cl_program_binary_type programBinaryType;
|
||||
bool isSpirV = false;
|
||||
CLElfLib::ElfBinaryStorage elfBinary;
|
||||
size_t elfBinarySize;
|
||||
size_t elfBinarySize;
|
||||
|
||||
char* genBinary;
|
||||
size_t genBinarySize;
|
||||
char *genBinary;
|
||||
size_t genBinarySize;
|
||||
|
||||
char* irBinary;
|
||||
size_t irBinarySize;
|
||||
char *irBinary;
|
||||
size_t irBinarySize;
|
||||
|
||||
char* debugData;
|
||||
size_t debugDataSize;
|
||||
char *debugData;
|
||||
size_t debugDataSize;
|
||||
|
||||
CreatedFrom createdFrom = CreatedFrom::UNKNOWN;
|
||||
CreatedFrom createdFrom = CreatedFrom::UNKNOWN;
|
||||
|
||||
std::vector<KernelInfo*> kernelInfoArray;
|
||||
std::vector<KernelInfo*> parentKernelInfoArray;
|
||||
std::vector<KernelInfo*> subgroupKernelInfoArray;
|
||||
BlockKernelManager * blockKernelManager;
|
||||
std::vector<KernelInfo *> kernelInfoArray;
|
||||
std::vector<KernelInfo *> parentKernelInfoArray;
|
||||
std::vector<KernelInfo *> subgroupKernelInfoArray;
|
||||
BlockKernelManager *blockKernelManager;
|
||||
|
||||
const void* programScopePatchList;
|
||||
size_t programScopePatchListSize;
|
||||
const void *programScopePatchList;
|
||||
size_t programScopePatchListSize;
|
||||
|
||||
GraphicsAllocation* constantSurface;
|
||||
GraphicsAllocation* globalSurface;
|
||||
GraphicsAllocation *constantSurface;
|
||||
GraphicsAllocation *globalSurface;
|
||||
|
||||
size_t globalVarTotalSize;
|
||||
size_t globalVarTotalSize;
|
||||
|
||||
cl_build_status buildStatus;
|
||||
bool isCreatedFromBinary;
|
||||
bool isProgramBinaryResolved;
|
||||
cl_build_status buildStatus;
|
||||
bool isCreatedFromBinary;
|
||||
bool isProgramBinaryResolved;
|
||||
|
||||
std::string sourceCode;
|
||||
std::string options;
|
||||
std::string internalOptions;
|
||||
std::string sourceCode;
|
||||
std::string options;
|
||||
std::string internalOptions;
|
||||
static const std::vector<std::string> internalOptionsToExtract;
|
||||
std::string hashFileName;
|
||||
std::string hashFilePath;
|
||||
std::string hashFileName;
|
||||
std::string hashFilePath;
|
||||
|
||||
uint32_t programOptionVersion;
|
||||
bool allowNonUniform;
|
||||
uint32_t programOptionVersion;
|
||||
bool allowNonUniform;
|
||||
|
||||
std::map<const Device*, std::string> buildLog;
|
||||
std::map<const Device *, std::string> buildLog;
|
||||
|
||||
ExecutionEnvironment& executionEnvironment;
|
||||
Context* context;
|
||||
Device* pDevice;
|
||||
cl_uint numDevices;
|
||||
bool areSpecializationConstantsInitialized = false;
|
||||
CIF::RAII::UPtr_t<CIF::Builtins::BufferSimple> specConstantsIds;
|
||||
CIF::RAII::UPtr_t<CIF::Builtins::BufferSimple> specConstantsSizes;
|
||||
CIF::RAII::UPtr_t<CIF::Builtins::BufferSimple> specConstantsValues;
|
||||
|
||||
bool isBuiltIn;
|
||||
bool kernelDebugEnabled = false;
|
||||
ExecutionEnvironment &executionEnvironment;
|
||||
Context *context;
|
||||
Device *pDevice;
|
||||
cl_uint numDevices;
|
||||
|
||||
bool isBuiltIn;
|
||||
bool kernelDebugEnabled = false;
|
||||
friend class OfflineCompiler;
|
||||
// clang-format on
|
||||
};
|
||||
} // namespace NEO
|
||||
|
||||
Reference in New Issue
Block a user