File: patchtokens_decoder.h

package info (click to toggle)
intel-compute-runtime 25.35.35096.9-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,324 kB
  • sloc: cpp: 926,243; lisp: 3,433; sh: 715; makefile: 162; python: 21
file content (214 lines) | stat: -rw-r--r-- 9,187 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
 * Copyright (C) 2019-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#pragma once

#include "shared/source/device_binary_format/device_binary_formats.h"
#include "shared/source/helpers/ptr_math.h"
#include "shared/source/utilities/arrayref.h"
#include "shared/source/utilities/stackvec.h"

#include "patch_g7.h"
#include "patch_list.h"
#include "patch_shared.h"

#include <cstdint>

namespace NEO {

namespace PatchTokenBinary {

using namespace iOpenCL;

enum class ArgObjectType : uint32_t {
    none = 0,
    buffer,
    image,
    sampler,
    slm
};

using StackVecUnhandledTokens = StackVec<const SPatchItemHeader *, 4>;
using StackVecByValMap = StackVec<const SPatchDataParameterBuffer *, 8>;
using StackVecStrings = StackVec<const SPatchString *, 4>;

struct KernelArgFromPatchtokens {
    const SPatchKernelArgumentInfo *argInfo = nullptr;
    const SPatchItemHeader *objectArg = nullptr;
    ArgObjectType objectType = ArgObjectType::none;
    StackVecByValMap byValMap;
    union {
        struct {
            const SPatchDataParameterBuffer *width;
            const SPatchDataParameterBuffer *height;
            const SPatchDataParameterBuffer *depth;
            const SPatchDataParameterBuffer *channelDataType;
            const SPatchDataParameterBuffer *channelOrder;
            const SPatchDataParameterBuffer *arraySize;
            const SPatchDataParameterBuffer *numSamples;
            const SPatchDataParameterBuffer *numMipLevels;
            const SPatchDataParameterBuffer *flatBaseOffset;
            const SPatchDataParameterBuffer *flatWidth;
            const SPatchDataParameterBuffer *flatHeight;
            const SPatchDataParameterBuffer *flatPitch;
        } image;
        struct {
            const SPatchDataParameterBuffer *bufferOffset;
            const SPatchDataParameterBuffer *pureStateful;
        } buffer;
        struct {
            const SPatchDataParameterBuffer *coordinateSnapWaRequired;
            const SPatchDataParameterBuffer *addressMode;
            const SPatchDataParameterBuffer *normalizedCoords;
        } sampler;
        struct {
            const SPatchDataParameterBuffer *token;
        } slm;
        static_assert((sizeof(image) > sizeof(buffer)) && (sizeof(image) > sizeof(sampler)) && (sizeof(image) > sizeof(slm)),
                      "Union initialization based on image wont' initialize whole struct");
    } metadata = {};

    union {
        struct {
            const SPatchDataParameterBuffer *mbBlockType;
            const SPatchDataParameterBuffer *subpixelMode;
            const SPatchDataParameterBuffer *sadAdjustMode;
            const SPatchDataParameterBuffer *searchPathType;
        } vme;
    } metadataSpecialized = {};
};

using StackVecKernelArgs = StackVec<KernelArgFromPatchtokens, 12>;

struct KernelFromPatchtokens {
    DecodeError decodeStatus = DecodeError::undefined;

    const SKernelBinaryHeaderCommon *header = nullptr;
    ArrayRef<const char> name;
    ArrayRef<const uint8_t> isa;

    struct {
        ArrayRef<const uint8_t> generalState;
        ArrayRef<const uint8_t> dynamicState;
        ArrayRef<const uint8_t> surfaceState;
    } heaps;

    struct {
        ArrayRef<const uint8_t> kernelInfo;
        ArrayRef<const uint8_t> patchList;
    } blobs;

    struct {
        const SPatchSamplerStateArray *samplerStateArray = nullptr;
        const SPatchBindingTableState *bindingTableState = nullptr;
        const SPatchAllocateLocalSurface *allocateLocalSurface = nullptr;
        const SPatchMediaVFEState *mediaVfeState[2] = {nullptr, nullptr};
        const SPatchMediaInterfaceDescriptorLoad *mediaInterfaceDescriptorLoad = nullptr;
        const SPatchThreadPayload *threadPayload = nullptr;
        const SPatchExecutionEnvironment *executionEnvironment = nullptr;
        const SPatchDataParameterStream *dataParameterStream = nullptr;
        const SPatchKernelAttributesInfo *kernelAttributesInfo = nullptr;
        const SPatchAllocateStatelessPrivateSurface *allocateStatelessPrivateSurface = nullptr;
        const SPatchAllocateStatelessConstantMemorySurfaceWithInitialization *allocateStatelessConstantMemorySurfaceWithInitialization = nullptr;
        const SPatchAllocateStatelessGlobalMemorySurfaceWithInitialization *allocateStatelessGlobalMemorySurfaceWithInitialization = nullptr;
        const SPatchAllocateStatelessPrintfSurface *allocateStatelessPrintfSurface = nullptr;
        const SPatchAllocateSyncBuffer *allocateSyncBuffer = nullptr;
        const SPatchAllocateRTGlobalBuffer *allocateRTGlobalBuffer = nullptr;
        const SPatchItemHeader *inlineVmeSamplerInfo = nullptr;
        const SPatchGtpinFreeGRFInfo *gtpinFreeGrfInfo = nullptr;
        const SPatchStateSIP *stateSip = nullptr;
        const SPatchAllocateSystemThreadSurface *allocateSystemThreadSurface = nullptr;
        const SPatchItemHeader *gtpinInfo = nullptr;
        const SPatchFunctionTableInfo *programSymbolTable = nullptr;
        const SPatchFunctionTableInfo *programRelocationTable = nullptr;
        const SPatchFunctionTableInfo *hostAccessTable = nullptr;
        StackVecKernelArgs kernelArgs;
        StackVecStrings strings;
        struct {
            const SPatchDataParameterBuffer *localWorkSize[3] = {};
            const SPatchDataParameterBuffer *localWorkSize2[3] = {};
            const SPatchDataParameterBuffer *enqueuedLocalWorkSize[3] = {};
            const SPatchDataParameterBuffer *numWorkGroups[3] = {};
            const SPatchDataParameterBuffer *globalWorkOffset[3] = {};
            const SPatchDataParameterBuffer *globalWorkSize[3] = {};
            const SPatchDataParameterBuffer *maxWorkGroupSize = nullptr;
            const SPatchDataParameterBuffer *workDimensions = nullptr;
            const SPatchDataParameterBuffer *simdSize = nullptr;
            const SPatchDataParameterBuffer *parentEvent = nullptr;
            const SPatchDataParameterBuffer *privateMemoryStatelessSize = nullptr;
            const SPatchDataParameterBuffer *localMemoryStatelessWindowSize = nullptr;
            const SPatchDataParameterBuffer *localMemoryStatelessWindowStartAddress = nullptr;
            const SPatchDataParameterBuffer *preferredWorkgroupMultiple = nullptr;
            const SPatchDataParameterBuffer *implicitArgsBufferOffset = nullptr;
        } crossThreadPayloadArgs;
    } tokens;

    StackVecUnhandledTokens unhandledTokens;
};

struct ProgramFromPatchtokens {
    DecodeError decodeStatus = DecodeError::undefined;

    const SProgramBinaryHeader *header = nullptr;
    struct {
        ArrayRef<const uint8_t> programInfo;
        ArrayRef<const uint8_t> patchList;
        ArrayRef<const uint8_t> kernelsInfo;
    } blobs;

    struct {
        StackVec<const SPatchAllocateConstantMemorySurfaceProgramBinaryInfo *, 2> allocateConstantMemorySurface;
        StackVec<const SPatchAllocateGlobalMemorySurfaceProgramBinaryInfo *, 2> allocateGlobalMemorySurface;
        StackVec<const SPatchConstantPointerProgramBinaryInfo *, 4> constantPointer;
        StackVec<const SPatchGlobalPointerProgramBinaryInfo *, 4> globalPointer;
        const SPatchFunctionTableInfo *symbolTable = nullptr;
    } programScopeTokens;
    StackVec<KernelFromPatchtokens, 2> kernels;
    StackVec<const SPatchItemHeader *, 4> unhandledTokens;
};

struct KernelArgAttributesFromPatchtokens {
    ArrayRef<const char> addressQualifier;
    ArrayRef<const char> accessQualifier;
    ArrayRef<const char> argName;
    ArrayRef<const char> typeName;
    ArrayRef<const char> typeQualifiers;
};

bool decodeKernelFromPatchtokensBlob(ArrayRef<const uint8_t> kernelBlob, KernelFromPatchtokens &out);
bool decodeProgramFromPatchtokensBlob(ArrayRef<const uint8_t> programBlob, ProgramFromPatchtokens &out);
uint32_t calcKernelChecksum(const ArrayRef<const uint8_t> kernelBlob);
bool hasInvalidChecksum(const KernelFromPatchtokens &decodedKernel);

inline const uint8_t *getInlineData(const SPatchAllocateConstantMemorySurfaceProgramBinaryInfo *ptr) {
    return ptrOffset(reinterpret_cast<const uint8_t *>(ptr), sizeof(SPatchAllocateConstantMemorySurfaceProgramBinaryInfo));
}

inline const uint8_t *getInlineData(const SPatchAllocateGlobalMemorySurfaceProgramBinaryInfo *ptr) {
    return ptrOffset(reinterpret_cast<const uint8_t *>(ptr), sizeof(SPatchAllocateGlobalMemorySurfaceProgramBinaryInfo));
}

inline const uint8_t *getInlineData(const SPatchString *ptr) {
    return ptrOffset(reinterpret_cast<const uint8_t *>(ptr), sizeof(SPatchString));
}

inline uint64_t getPerHwThreadPrivateSurfaceSize(const SPatchAllocateStatelessPrivateSurface &ptr, uint32_t simdSize) {
    uint32_t multiplier = ptr.IsSimtThread ? simdSize : 1U;
    return static_cast<uint64_t>(ptr.PerThreadPrivateMemorySize) * multiplier;
}

const KernelArgAttributesFromPatchtokens getInlineData(const SPatchKernelArgumentInfo *ptr);

const iOpenCL::SProgramBinaryHeader *decodeProgramHeader(const ArrayRef<const uint8_t> programBlob);

inline bool isValidPatchTokenBinary(const ArrayRef<const uint8_t> programBlob) {
    return nullptr != decodeProgramHeader(programBlob);
}

} // namespace PatchTokenBinary

} // namespace NEO