mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-10 15:12:56 +08:00
test: mock filesystem in ULTs 2/n
Remove USE_REAL_FILE_SYSTEM() macro uses from API, program, kernel and gtpin tests. Related-To: NEO-15069 Signed-off-by: Oskar Hubert Weber <oskar.hubert.weber@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
36bdde47a0
commit
1c722ddb7c
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "shared/source/device_binary_format/elf/elf_decoder.h"
|
||||
#include "shared/source/device_binary_format/elf/elf_encoder.h"
|
||||
#include "shared/source/device_binary_format/zebin/zeinfo.h"
|
||||
#include "shared/source/helpers/compiler_product_helper.h"
|
||||
#include "shared/source/helpers/ptr_math.h"
|
||||
#include "shared/test/common/mocks/mock_elf.h"
|
||||
@@ -228,14 +229,32 @@ void ZebinWithL0TestCommonModule::recalcPtr() {
|
||||
elfHeader = reinterpret_cast<NEO::Elf::ElfFileHeader<NEO::Elf::EI_CLASS_64> *>(storage.data());
|
||||
}
|
||||
|
||||
template ZebinCopyBufferSimdModule<ElfIdentifierClass::EI_CLASS_32>::ZebinCopyBufferSimdModule(const NEO::HardwareInfo &hwInfo, uint8_t simdSize);
|
||||
template ZebinCopyBufferSimdModule<ElfIdentifierClass::EI_CLASS_64>::ZebinCopyBufferSimdModule(const NEO::HardwareInfo &hwInfo, uint8_t simdSize);
|
||||
template ZebinCopyBufferModule<ElfIdentifierClass::EI_CLASS_32>::ZebinCopyBufferModule(const NEO::HardwareInfo &hwInfo, Descriptor desc);
|
||||
template ZebinCopyBufferModule<ElfIdentifierClass::EI_CLASS_64>::ZebinCopyBufferModule(const NEO::HardwareInfo &hwInfo, Descriptor desc);
|
||||
|
||||
template <ElfIdentifierClass numBits>
|
||||
ZebinCopyBufferSimdModule<numBits>::ZebinCopyBufferSimdModule(const NEO::HardwareInfo &hwInfo, uint8_t simdSize) {
|
||||
zeInfoSize = static_cast<size_t>(snprintf(nullptr, 0, zeInfoCopyBufferSimdPlaceholder.c_str(), simdSize, simdSize, getLocalIdSize(hwInfo, simdSize)) + 1);
|
||||
ZebinCopyBufferModule<numBits>::ZebinCopyBufferModule(const NEO::HardwareInfo &hwInfo, Descriptor desc) {
|
||||
using namespace NEO::Zebin::ZeInfo::Tags::Kernel;
|
||||
const char *addrmode = desc.isStateless ? "stateless" : "stateful";
|
||||
|
||||
if (!desc.isStateless) {
|
||||
std::stringstream os;
|
||||
os << " binding_table_indices:\n";
|
||||
if (!desc.bindingTableIndices.empty()) {
|
||||
for (const auto &bti : desc.bindingTableIndices) {
|
||||
os << " - bti_value: " << std::to_string(bti.btiValue) << '\n';
|
||||
os << " arg_index: " << std::to_string(bti.argIndex) << '\n';
|
||||
}
|
||||
}
|
||||
zeInfoCopyBufferSimdPlaceholder += os.str();
|
||||
}
|
||||
|
||||
const std::string userAttributesStr = desc.userAttributes.toZeInfoYaml();
|
||||
const std::string execEnvStr = desc.execEnv.toZeInfoYaml();
|
||||
|
||||
zeInfoSize = static_cast<size_t>(snprintf(nullptr, 0, zeInfoCopyBufferSimdPlaceholder.c_str(), userAttributesStr.c_str(), execEnvStr.c_str(), addrmode, addrmode));
|
||||
zeInfoCopyBuffer.resize(zeInfoSize);
|
||||
snprintf(zeInfoCopyBuffer.data(), zeInfoSize, zeInfoCopyBufferSimdPlaceholder.c_str(), simdSize, simdSize, getLocalIdSize(hwInfo, simdSize));
|
||||
snprintf(zeInfoCopyBuffer.data(), zeInfoSize, zeInfoCopyBufferSimdPlaceholder.c_str(), userAttributesStr.c_str(), execEnvStr.c_str(), addrmode, addrmode);
|
||||
|
||||
MockElfEncoder<numBits> elfEncoder;
|
||||
auto &elfHeader = elfEncoder.getElfFileHeader();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "neo_igfxfmid.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -265,8 +266,52 @@ kernels:
|
||||
};
|
||||
|
||||
template <NEO::Elf::ElfIdentifierClass numBits>
|
||||
struct ZebinCopyBufferSimdModule {
|
||||
ZebinCopyBufferSimdModule(const NEO::HardwareInfo &hwInfo, uint8_t simdSize);
|
||||
struct ZebinCopyBufferModule {
|
||||
struct KernelTags {
|
||||
KernelTags(const char *section) : section(section) {}
|
||||
|
||||
KernelTags(const char *section, std::map<std::string, std::string> vars) : section(section), vars(vars) {}
|
||||
|
||||
std::string &operator[](NEO::ConstStringRef strRef) {
|
||||
return vars[strRef.str()];
|
||||
}
|
||||
|
||||
std::string &operator[](const char *str) {
|
||||
return vars[str];
|
||||
}
|
||||
|
||||
std::string toZeInfoYaml() const {
|
||||
std::stringstream os;
|
||||
if (vars.empty()) {
|
||||
return "";
|
||||
}
|
||||
os << "\n " << section << ":";
|
||||
for (const auto &[var, value] : vars) {
|
||||
if (!value.empty()) {
|
||||
os << "\n " << var << ": " << value;
|
||||
}
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
||||
const char *section;
|
||||
std::map<std::string, std::string> vars;
|
||||
};
|
||||
|
||||
struct BindingTableIndex {
|
||||
uint8_t btiValue;
|
||||
uint8_t argIndex;
|
||||
};
|
||||
|
||||
struct Descriptor {
|
||||
KernelTags execEnv{"execution_env", {{"simd_size", "32"}, {"grf_count", "128"}, {"inline_data_payload_size", "32"}, {"offset_to_skip_per_thread_data_load", "192"}}};
|
||||
KernelTags userAttributes{"user_attributes"};
|
||||
std::vector<BindingTableIndex> bindingTableIndices{{0, 0}, {1, 1}};
|
||||
bool isStateless = false;
|
||||
};
|
||||
|
||||
ZebinCopyBufferModule(const NEO::HardwareInfo &hwInfo, Descriptor copyBufferDesc);
|
||||
ZebinCopyBufferModule(const NEO::HardwareInfo &hwInfo) : ZebinCopyBufferModule(hwInfo, Descriptor{}) {}
|
||||
inline size_t getLocalIdSize(const NEO::HardwareInfo &hwInfo, uint8_t simdSize) {
|
||||
return alignUp(simdSize * sizeof(uint16_t), hwInfo.capabilityTable.grfSize) * 3;
|
||||
}
|
||||
@@ -276,62 +321,36 @@ struct ZebinCopyBufferSimdModule {
|
||||
size_t zeInfoSize;
|
||||
std::string zeInfoCopyBufferSimdPlaceholder = std::string("version :\'") + versionToString(NEO::Zebin::ZeInfo::zeInfoDecoderVersion) + R"===('
|
||||
kernels:
|
||||
- name: CopyBuffer
|
||||
execution_env:
|
||||
disable_mid_thread_preemption: true
|
||||
grf_count: 128
|
||||
has_no_stateless_write: true
|
||||
inline_data_payload_size: 32
|
||||
offset_to_skip_per_thread_data_load: 192
|
||||
required_sub_group_size: %d
|
||||
simd_size: %d
|
||||
subgroup_independent_forward_progress: true
|
||||
- name: CopyBuffer%s%s
|
||||
payload_arguments:
|
||||
- arg_type: global_id_offset
|
||||
- arg_type: indirect_data_pointer
|
||||
offset: 0
|
||||
size: 12
|
||||
- arg_type: local_size
|
||||
offset: 12
|
||||
size: 12
|
||||
size: 8
|
||||
- arg_type: scratch_pointer
|
||||
offset: 8
|
||||
size: 8
|
||||
- arg_type: arg_bypointer
|
||||
offset: 0
|
||||
size: 0
|
||||
offset: 16
|
||||
size: 8
|
||||
arg_index: 0
|
||||
addrmode: stateful
|
||||
addrmode: %s
|
||||
addrspace: global
|
||||
access_type: readwrite
|
||||
- arg_type: buffer_address
|
||||
offset: 32
|
||||
offset: 24
|
||||
size: 8
|
||||
arg_index: 0
|
||||
- arg_type: arg_bypointer
|
||||
offset: 0
|
||||
size: 0
|
||||
offset: 32
|
||||
size: 8
|
||||
arg_index: 1
|
||||
addrmode: stateful
|
||||
addrmode: %s
|
||||
addrspace: global
|
||||
access_type: readwrite
|
||||
- arg_type: buffer_address
|
||||
offset: 40
|
||||
size: 8
|
||||
arg_index: 1
|
||||
- arg_type: buffer_offset
|
||||
offset: 48
|
||||
size: 4
|
||||
arg_index: 0
|
||||
- arg_type: buffer_offset
|
||||
offset: 52
|
||||
size: 4
|
||||
arg_index: 1
|
||||
per_thread_payload_arguments:
|
||||
- arg_type: local_id
|
||||
offset: 0
|
||||
size: %d
|
||||
binding_table_indices:
|
||||
- bti_value: 0
|
||||
arg_index: 0
|
||||
- bti_value: 1
|
||||
arg_index: 1
|
||||
)===";
|
||||
};
|
||||
|
||||
|
||||
@@ -10,20 +10,29 @@
|
||||
#include "shared/test/common/libult/global_environment.h"
|
||||
#include "shared/test/common/mocks/mock_modules_zebin.h"
|
||||
|
||||
namespace NEO {
|
||||
extern std::map<std::string, std::stringstream> virtualFileList;
|
||||
}
|
||||
|
||||
namespace NEO {
|
||||
template <size_t binariesCount = 1u, Elf::ElfIdentifierClass numBits = is32bit ? Elf::EI_CLASS_32 : Elf::EI_CLASS_64>
|
||||
struct MockZebinWrapper {
|
||||
MockZebinWrapper(const HardwareInfo &hwInfo, uint8_t simdSize)
|
||||
: data(hwInfo, simdSize) {
|
||||
using Descriptor = ZebinTestData::ZebinCopyBufferModule<numBits>::Descriptor;
|
||||
|
||||
MockZebinWrapper(const HardwareInfo &hwInfo, Descriptor desc)
|
||||
: data(hwInfo, desc) {
|
||||
std::fill_n(binaries.begin(), binariesCount, reinterpret_cast<const unsigned char *>(this->data.storage.data()));
|
||||
std::fill_n(binarySizes.begin(), binariesCount, this->data.storage.size());
|
||||
}
|
||||
|
||||
MockZebinWrapper(const HardwareInfo &hwInfo) : MockZebinWrapper(hwInfo, Descriptor{}) {}
|
||||
|
||||
auto &getFlags() {
|
||||
return reinterpret_cast<Zebin::Elf::ZebinTargetFlags &>(this->data.elfHeader->flags);
|
||||
}
|
||||
|
||||
void setAsMockCompilerReturnedBinary() {
|
||||
debugVarsRestore.reset();
|
||||
MockCompilerDebugVars debugVars;
|
||||
debugVars.binaryToReturn = const_cast<unsigned char *>(this->binaries[0]);
|
||||
debugVars.binaryToReturnSize = sizeof(unsigned char) * this->binarySizes[0];
|
||||
@@ -35,9 +44,40 @@ struct MockZebinWrapper {
|
||||
}};
|
||||
}
|
||||
|
||||
ZebinTestData::ZebinCopyBufferSimdModule<numBits> data;
|
||||
void setAsMockCompilerLoadedFile(const std::string &fileName) {
|
||||
debugVarsRestore.reset();
|
||||
virtualFileList[fileName] << this->binaries[0];
|
||||
MockCompilerDebugVars debugVars;
|
||||
debugVars.fileName = fileName;
|
||||
gEnvironment->igcPushDebugVars(debugVars);
|
||||
gEnvironment->fclPushDebugVars(debugVars);
|
||||
this->debugVarsRestore = std::unique_ptr<void, void (*)(void *)>{&gEnvironment, [](void *) -> void {
|
||||
gEnvironment->igcPopDebugVars();
|
||||
gEnvironment->fclPopDebugVars();
|
||||
}};
|
||||
}
|
||||
|
||||
ZebinTestData::ZebinCopyBufferModule<numBits> data;
|
||||
std::array<const unsigned char *, binariesCount> binaries;
|
||||
std::array<size_t, binariesCount> binarySizes;
|
||||
std::unique_ptr<void, void (*)(void *)> debugVarsRestore{nullptr, nullptr};
|
||||
const char *kernelName = "CopyBuffer";
|
||||
};
|
||||
|
||||
class FixtureWithMockZebin {
|
||||
public:
|
||||
void setUp() {
|
||||
zebinPtr = std::make_unique<MockZebinWrapper<>>(*defaultHwInfo);
|
||||
zebinPtr->setAsMockCompilerReturnedBinary();
|
||||
}
|
||||
|
||||
void tearDown() {
|
||||
zebinPtr.reset();
|
||||
}
|
||||
|
||||
static constexpr const char sourceKernel[] = "example_kernel(){}";
|
||||
static constexpr size_t sourceKernelSize = sizeof(sourceKernel);
|
||||
const char *sources[1] = {sourceKernel};
|
||||
std::unique_ptr<MockZebinWrapper<>> zebinPtr;
|
||||
};
|
||||
} // namespace NEO
|
||||
Reference in New Issue
Block a user