File: elf_tests_data.h

package info (click to toggle)
intel-compute-runtime 25.44.36015.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,632 kB
  • sloc: cpp: 931,547; lisp: 2,074; sh: 719; makefile: 162; python: 21
file content (70 lines) | stat: -rw-r--r-- 3,586 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * Copyright (C) 2022-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#pragma once

#include "shared/source/compiler_interface/intermediate_representations.h"
#include "shared/source/device_binary_format/elf/elf_encoder.h"
#include "shared/source/device_binary_format/elf/ocl_elf.h"
#include "shared/source/helpers/compiler_product_helper.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/helpers/string.h"

#include "patch_list.h"

using namespace NEO;

enum class EnabledIrFormat {
    none,
    spirv,
    llvm
};

template <EnabledIrFormat irFormat = EnabledIrFormat::none>
struct MockElfBinaryPatchtokens {
    MockElfBinaryPatchtokens(const HardwareInfo &hwInfo) : MockElfBinaryPatchtokens(std::string{}, hwInfo){};
    MockElfBinaryPatchtokens(const std::string &buildOptions, const HardwareInfo &inputHwInfo) {
        auto hwInfo = inputHwInfo;
        auto compilerProductHelper = NEO::CompilerProductHelper::create(hwInfo.platform.eProductFamily);
        compilerProductHelper->adjustHwInfoForIgc(hwInfo);
        mockDevBinaryHeader.Device = hwInfo.platform.eRenderCoreFamily;
        mockDevBinaryHeader.GPUPointerSizeInBytes = sizeof(void *);
        mockDevBinaryHeader.Version = iOpenCL::CURRENT_ICBE_VERSION;
        constexpr size_t mockDevBinaryDataSize = sizeof(mockDevBinaryHeader) + mockDataSize;
        constexpr size_t mockSpirvBinaryDataSize = sizeof(spirvMagic) + mockDataSize;
        constexpr size_t mockLlvmBinaryDataSize = sizeof(llvmBcMagic) + mockDataSize;

        char mockDevBinaryData[mockDevBinaryDataSize]{};
        memcpy_s(mockDevBinaryData, mockDevBinaryDataSize, &mockDevBinaryHeader, sizeof(mockDevBinaryHeader));
        memset(mockDevBinaryData + sizeof(mockDevBinaryHeader), '\x01', mockDataSize);

        char mockSpirvBinaryData[mockSpirvBinaryDataSize]{};
        memcpy_s(mockSpirvBinaryData, mockSpirvBinaryDataSize, spirvMagic.data(), spirvMagic.size());
        memset(mockSpirvBinaryData + spirvMagic.size(), '\x02', mockDataSize);

        char mockLlvmBinaryData[mockLlvmBinaryDataSize]{};
        memcpy_s(mockLlvmBinaryData, mockLlvmBinaryDataSize, llvmBcMagic.data(), llvmBcMagic.size());
        memset(mockLlvmBinaryData + llvmBcMagic.size(), '\x03', mockDataSize);

        Elf::ElfEncoder<Elf::EI_CLASS_64> enc;
        enc.getElfFileHeader().identity = Elf::ElfFileHeaderIdentity(Elf::EI_CLASS_64);
        enc.getElfFileHeader().type = NEO::Elf::ET_OPENCL_EXECUTABLE;
        enc.appendSection(Elf::SHT_OPENCL_DEV_BINARY, Elf::SectionNamesOpenCl::deviceBinary, ArrayRef<const uint8_t>::fromAny(mockDevBinaryData, mockDevBinaryDataSize));
        if (irFormat == EnabledIrFormat::spirv) {
            enc.appendSection(Elf::SHT_OPENCL_SPIRV, Elf::SectionNamesOpenCl::spirvObject, ArrayRef<const uint8_t>::fromAny(mockSpirvBinaryData, mockSpirvBinaryDataSize));
        } else if (irFormat == EnabledIrFormat::llvm) {
            enc.appendSection(Elf::SHT_OPENCL_LLVM_BINARY, Elf::SectionNamesOpenCl::llvmObject, ArrayRef<const uint8_t>::fromAny(mockLlvmBinaryData, mockLlvmBinaryDataSize));
        }
        if (false == buildOptions.empty()) {
            enc.appendSection(Elf::SHT_OPENCL_OPTIONS, Elf::SectionNamesOpenCl::buildOptions, ArrayRef<const uint8_t>::fromAny(buildOptions.data(), buildOptions.size()));
        }
        storage = enc.encode();
    }
    static constexpr size_t mockDataSize = 0x10;
    iOpenCL::SProgramBinaryHeader mockDevBinaryHeader = iOpenCL::SProgramBinaryHeader{iOpenCL::MAGIC_CL, 0, 0, 0, 0, 0, 0};
    std::vector<uint8_t> storage;
};