2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-02-07 19:15:46 +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/compiler_interface/compiler_interface.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_cif.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
#include "ocl_igc_interface/fcl_ocl_device_ctx.h"
|
2018-07-17 15:40:41 +08:00
|
|
|
#include "ocl_igc_interface/igc_ocl_device_ctx.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
struct MockCompilerDebugVars {
|
|
|
|
bool forceBuildFailure = false;
|
|
|
|
bool forceCreateFailure = false;
|
|
|
|
bool forceRegisterFail = false;
|
|
|
|
bool internalOptionsExpected = false;
|
|
|
|
bool appendOptionsToFileName = true;
|
|
|
|
void *debugDataToReturn = nullptr;
|
|
|
|
size_t debugDataToReturnSize = 0;
|
2018-07-30 23:04:50 +08:00
|
|
|
void *binaryToReturn = nullptr;
|
|
|
|
size_t binaryToReturnSize = 0;
|
2017-12-21 07:45:38 +08:00
|
|
|
bool failCreatePlatformInterface = false;
|
|
|
|
bool failCreateGtSystemInfoInterface = false;
|
|
|
|
bool failCreateIgcFeWaInterface = false;
|
|
|
|
std::string *receivedInternalOptionsOutput = nullptr;
|
|
|
|
std::string *receivedInput = nullptr;
|
|
|
|
|
|
|
|
std::string fileName;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MockCompilerEnableGuard {
|
|
|
|
MockCompilerEnableGuard(bool autoEnable = false);
|
|
|
|
~MockCompilerEnableGuard();
|
|
|
|
|
|
|
|
void Enable();
|
|
|
|
void Disable();
|
|
|
|
|
|
|
|
const char *oldFclDllName;
|
|
|
|
const char *oldIgcDllName;
|
|
|
|
|
|
|
|
bool enabled = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
void setFclDebugVars(MockCompilerDebugVars &dbgv);
|
|
|
|
void setIgcDebugVars(MockCompilerDebugVars &dbgv);
|
|
|
|
void clearFclDebugVars();
|
|
|
|
void clearIgcDebugVars();
|
|
|
|
|
|
|
|
MockCompilerDebugVars getFclDebugVars();
|
|
|
|
MockCompilerDebugVars getIgcDebugVars();
|
|
|
|
|
2020-02-07 19:15:46 +08:00
|
|
|
struct MockCIFPlatform : MockCIF<IGC::PlatformTagOCL> {
|
2018-06-07 22:18:53 +08:00
|
|
|
IGC::TypeErasedEnum GetProductFamily() const override {
|
|
|
|
return productFamily;
|
|
|
|
}
|
|
|
|
void SetProductFamily(IGC::TypeErasedEnum v) override {
|
|
|
|
productFamily = v;
|
|
|
|
}
|
|
|
|
IGC::TypeErasedEnum GetRenderCoreFamily() const override {
|
|
|
|
return renderCoreFamily;
|
|
|
|
}
|
|
|
|
void SetRenderCoreFamily(IGC::TypeErasedEnum v) override {
|
|
|
|
renderCoreFamily = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
IGC::TypeErasedEnum productFamily;
|
|
|
|
IGC::TypeErasedEnum renderCoreFamily;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct MockGTSystemInfo : MockCIF<IGC::GTSystemInfoTagOCL> {
|
2018-06-07 22:18:53 +08:00
|
|
|
uint32_t GetEUCount() const override {
|
|
|
|
return this->euCount;
|
|
|
|
}
|
|
|
|
void SetEUCount(uint32_t v) override {
|
|
|
|
euCount = v;
|
|
|
|
}
|
|
|
|
uint32_t GetThreadCount() const override {
|
|
|
|
return this->threadCount;
|
|
|
|
}
|
|
|
|
void SetThreadCount(uint32_t v) override {
|
|
|
|
threadCount = v;
|
|
|
|
}
|
|
|
|
uint32_t GetSliceCount() const override {
|
|
|
|
return this->sliceCount;
|
|
|
|
}
|
|
|
|
void SetSliceCount(uint32_t v) override {
|
|
|
|
sliceCount = v;
|
|
|
|
}
|
|
|
|
uint32_t GetSubSliceCount() const override {
|
|
|
|
return this->subsliceCount;
|
|
|
|
}
|
|
|
|
void SetSubSliceCount(uint32_t v) override {
|
|
|
|
subsliceCount = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
uint32_t euCount;
|
|
|
|
uint32_t threadCount;
|
|
|
|
uint32_t sliceCount;
|
|
|
|
uint32_t subsliceCount;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct MockIgcFeaturesAndWorkarounds : MockCIF<IGC::IgcFeaturesAndWorkaroundsTagOCL> {
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MockIgcOclTranslationCtx : MockCIF<IGC::IgcOclTranslationCtxTagOCL> {
|
2018-07-17 15:40:41 +08:00
|
|
|
using MockCIF<IGC::IgcOclTranslationCtxTagOCL>::TranslateImpl;
|
2017-12-21 07:45:38 +08:00
|
|
|
MockIgcOclTranslationCtx();
|
2020-03-13 16:17:01 +08:00
|
|
|
~MockIgcOclTranslationCtx() override;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
IGC::OclTranslationOutputBase *TranslateImpl(
|
|
|
|
CIF::Version_t outVersion,
|
|
|
|
CIF::Builtins::BufferSimple *src,
|
|
|
|
CIF::Builtins::BufferSimple *options,
|
|
|
|
CIF::Builtins::BufferSimple *internalOptions,
|
|
|
|
CIF::Builtins::BufferSimple *tracingOptions,
|
|
|
|
uint32_t tracingOptionsCount) override;
|
2018-08-06 19:19:32 +08:00
|
|
|
|
|
|
|
IGC::OclTranslationOutputBase *TranslateImpl(
|
|
|
|
CIF::Version_t outVersion,
|
|
|
|
CIF::Builtins::BufferSimple *src,
|
|
|
|
CIF::Builtins::BufferSimple *options,
|
|
|
|
CIF::Builtins::BufferSimple *internalOptions,
|
|
|
|
CIF::Builtins::BufferSimple *tracingOptions,
|
|
|
|
uint32_t tracingOptionsCount,
|
|
|
|
void *gtpinInput) override;
|
2019-04-25 18:46:43 +08:00
|
|
|
|
|
|
|
bool GetSpecConstantsInfoImpl(
|
|
|
|
CIF::Builtins::BufferSimple *src,
|
|
|
|
CIF::Builtins::BufferSimple *outSpecConstantsIds,
|
|
|
|
CIF::Builtins::BufferSimple *outSpecConstantsSizes) override;
|
|
|
|
|
|
|
|
IGC::OclTranslationOutputBase *TranslateImpl(
|
|
|
|
CIF::Version_t outVersion,
|
|
|
|
CIF::Builtins::BufferSimple *src,
|
|
|
|
CIF::Builtins::BufferSimple *specConstantsIds,
|
|
|
|
CIF::Builtins::BufferSimple *specConstantsValues,
|
|
|
|
CIF::Builtins::BufferSimple *options,
|
|
|
|
CIF::Builtins::BufferSimple *internalOptions,
|
|
|
|
CIF::Builtins::BufferSimple *tracingOptions,
|
|
|
|
uint32_t tracingOptionsCount,
|
|
|
|
void *gtPinInput) override;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct MockOclTranslationOutput : MockCIF<IGC::OclTranslationOutputTagOCL> {
|
|
|
|
MockOclTranslationOutput();
|
|
|
|
~MockOclTranslationOutput() override;
|
|
|
|
CIF::Builtins::BufferBase *GetBuildLogImpl(CIF::Version_t bufferVersion) override;
|
|
|
|
CIF::Builtins::BufferBase *GetOutputImpl(CIF::Version_t bufferVersion) override;
|
|
|
|
CIF::Builtins::BufferBase *GetDebugDataImpl(CIF::Version_t bufferVersion) override;
|
|
|
|
|
|
|
|
bool Successful() const override {
|
|
|
|
return failed == false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setError() {
|
|
|
|
setError("");
|
|
|
|
}
|
|
|
|
void setError(const std::string &message);
|
|
|
|
void setOutput(const void *data, size_t dataLen);
|
|
|
|
void setDebugData(const void *data, size_t dataLen);
|
|
|
|
|
|
|
|
bool failed = false;
|
|
|
|
MockCIFBuffer *output = nullptr;
|
|
|
|
MockCIFBuffer *log = nullptr;
|
|
|
|
MockCIFBuffer *debugData = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MockIgcOclDeviceCtx : MockCIF<IGC::IgcOclDeviceCtxTagOCL> {
|
|
|
|
static CIF::ICIF *Create(CIF::InterfaceId_t intId, CIF::Version_t version);
|
|
|
|
|
|
|
|
MockIgcOclDeviceCtx();
|
|
|
|
~MockIgcOclDeviceCtx() override;
|
|
|
|
|
|
|
|
IGC::PlatformBase *GetPlatformHandleImpl(CIF::Version_t ver) override {
|
|
|
|
if (getIgcDebugVars().failCreatePlatformInterface) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return platform;
|
|
|
|
}
|
|
|
|
|
|
|
|
IGC::GTSystemInfoBase *GetGTSystemInfoHandleImpl(CIF::Version_t ver) override {
|
|
|
|
if (getIgcDebugVars().failCreateGtSystemInfoInterface) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return gtSystemInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
IGC::IgcFeaturesAndWorkaroundsBase *GetIgcFeaturesAndWorkaroundsHandleImpl(CIF::Version_t ver) override {
|
|
|
|
if (getIgcDebugVars().failCreateIgcFeWaInterface) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return igcFeWa;
|
|
|
|
}
|
|
|
|
|
|
|
|
IGC::IgcOclTranslationCtxBase *CreateTranslationCtxImpl(CIF::Version_t ver,
|
|
|
|
IGC::CodeType::CodeType_t inType,
|
|
|
|
IGC::CodeType::CodeType_t outType) override;
|
|
|
|
|
|
|
|
void SetDebugVars(MockCompilerDebugVars &debugVars) {
|
|
|
|
this->debugVars = debugVars;
|
|
|
|
}
|
|
|
|
|
2020-02-07 19:15:46 +08:00
|
|
|
MockCIFPlatform *platform = nullptr;
|
2017-12-21 07:45:38 +08:00
|
|
|
MockGTSystemInfo *gtSystemInfo = nullptr;
|
|
|
|
MockIgcFeaturesAndWorkarounds *igcFeWa = nullptr;
|
|
|
|
MockCompilerDebugVars debugVars;
|
2018-08-07 17:48:30 +08:00
|
|
|
|
|
|
|
using TranslationOpT = std::pair<IGC::CodeType::CodeType_t, IGC::CodeType::CodeType_t>;
|
|
|
|
std::vector<TranslationOpT> requestedTranslationCtxs;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct MockFclOclTranslationCtx : MockCIF<IGC::FclOclTranslationCtxTagOCL> {
|
|
|
|
MockFclOclTranslationCtx();
|
|
|
|
~MockFclOclTranslationCtx() override;
|
|
|
|
|
|
|
|
IGC::OclTranslationOutputBase *TranslateImpl(
|
|
|
|
CIF::Version_t outVersion,
|
|
|
|
CIF::Builtins::BufferSimple *src,
|
|
|
|
CIF::Builtins::BufferSimple *options,
|
|
|
|
CIF::Builtins::BufferSimple *internalOptions,
|
|
|
|
CIF::Builtins::BufferSimple *tracingOptions,
|
|
|
|
uint32_t tracingOptionsCount) override;
|
|
|
|
};
|
|
|
|
|
2020-03-16 20:37:12 +08:00
|
|
|
struct MockFclOclDeviceCtx : MockCIF<IGC::FclOclDeviceCtx<3>> {
|
2017-12-21 07:45:38 +08:00
|
|
|
MockFclOclDeviceCtx();
|
2020-03-13 16:17:01 +08:00
|
|
|
~MockFclOclDeviceCtx() override;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
static CIF::ICIF *Create(CIF::InterfaceId_t intId, CIF::Version_t version);
|
|
|
|
void SetOclApiVersion(uint32_t version) override {
|
|
|
|
oclApiVersion = version;
|
|
|
|
}
|
|
|
|
|
|
|
|
IGC::FclOclTranslationCtxBase *CreateTranslationCtxImpl(CIF::Version_t ver,
|
|
|
|
IGC::CodeType::CodeType_t inType,
|
|
|
|
IGC::CodeType::CodeType_t outType) override;
|
|
|
|
|
2020-03-16 20:37:12 +08:00
|
|
|
IGC::FclOclTranslationCtxBase *CreateTranslationCtxImpl(CIF::Version_t ver,
|
|
|
|
IGC::CodeType::CodeType_t inType,
|
|
|
|
IGC::CodeType::CodeType_t outType,
|
|
|
|
CIF::Builtins::BufferSimple *err) override;
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
uint32_t oclApiVersion = 120;
|
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|