File: cm_program.h

package info (click to toggle)
intel-media-driver 18.4.1%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 77,144 kB
  • sloc: cpp: 784,288; ansic: 95,944; asm: 42,125; python: 353; sh: 156; makefile: 15
file content (260 lines) | stat: -rw-r--r-- 8,632 bytes parent folder | download | duplicates (2)
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*
* Copyright (c) 2017, Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
//!
//! \file      cm_program.h 
//! \brief     Contains Class CmProgram definitions 
//!

#ifndef MEDIADRIVER_AGNOSTIC_COMMON_CM_CMPROGRAM_H_
#define MEDIADRIVER_AGNOSTIC_COMMON_CM_CMPROGRAM_H_

#include "cm_def.h"
#include "cm_array.h"
#include "cm_jitter_info.h"
#include "cm_visa.h"

struct attribute_info_t
{
    unsigned short nameIndex;
    unsigned char size;
    unsigned char* values;
    char *name;
};

struct gen_var_info_t
{
    unsigned short nameIndex;
    unsigned char bitProperties;
    unsigned short numElements;
    unsigned short aliasIndex;
    unsigned short aliasOffset;
    unsigned char attributeCount;
    attribute_info_t* attributes;
} ;

struct spec_var_info_t
{
    unsigned short nameIndex;
    unsigned short numElements;
    unsigned char attributeCount;
    attribute_info_t* attributes;
};

struct label_info_t
{
    unsigned short nameIndex;
    unsigned char kind;
    unsigned char attributeCount;
    attribute_info_t* attributes;
};

struct CM_KERNEL_INFO
{
    char kernelName[ CM_MAX_KERNEL_NAME_SIZE_IN_BYTE ];
    uint32_t inputCountOffset;

    //Used to store the input for the jitter from CISA
    uint32_t kernelIsaOffset;
    uint32_t kernelIsaSize;

    //Binary Size
    union
    {
        uint32_t jitBinarySize;
        uint32_t genxBinarySize;
    };

    union
    {
        void* jitBinaryCode;   //pointer to code created by jitter
        uint32_t genxBinaryOffset; //pointer to binary offset in CISA (use when jit is not enabled)
    };

    //Just a copy for original binary pointer and size (GTPin using only)
    void* origBinary;
    uint32_t origBinarySize;

    uint32_t globalStringCount;
    const char** globalStrings;
    char kernelASMName[CM_MAX_KERNEL_NAME_SIZE_IN_BYTE + 1];        //The name of the Gen assembly file for this kernel (no extension)
    uint8_t kernelSLMSize;     //Size of the SLM used by each thread group
    bool blNoBarrier;       //Indicate if the barrier is used in kernel: true means no barrier used, false means barrier is used.

    FINALIZER_INFO *jitInfo;

    uint32_t variableCount;
    gen_var_info_t *variables;
    uint32_t addressCount;
    spec_var_info_t *address;
    uint32_t predicateCount;
    spec_var_info_t *predicates;
    uint32_t labelCount;
    label_info_t *label;
    uint32_t samplerCount;
    spec_var_info_t *sampler;
    uint32_t surfaceCount;
    spec_var_info_t *surface;
    uint32_t vmeCount;
    spec_var_info_t *vme;

    uint32_t kernelInfoRefCount;    //reference counter for kernel info to reuse kernel info and jitbinary
};

//Function pointer definition for jitter compilation functions.
typedef int (__cdecl *pJITCompile)(const char *kernelName,
                                   const void *kernelIsa,
                                   uint32_t kernelIsaSize,
                                   void* &genBinary,
                                   uint32_t &genBinarySize,
                                   const char *platform,
                                   int majorVersion,
                                   int minorVersion,
                                   int numArgs,
                                   const char *args[],
                                   char *errorMsg,
                                   FINALIZER_INFO *jitInfo);

typedef int (__cdecl *pJITCompile_v2)(const char *kernelName,
                                   const void *kernelIsa,
                                   uint32_t kernelIsaSize,
                                   void* &genBinary,
                                   uint32_t &genBinarySize,
                                   const char *platform,
                                   int majorVersion,
                                   int minorVersion,
                                   int numArgs,
                                   const char *args[],
                                   char *errorMsg,
                                   FINALIZER_INFO *jitInfo,
                                   void *extra_info);

typedef void (__cdecl *pFreeBlock)(void*);

typedef void (__cdecl *pJITVersion)(unsigned int &majorV,
                                    unsigned int &minorV);

#define CM_JIT_FLAG_SIZE           256
#define CM_JIT_ERROR_MESSAGE_SIZE  512
#define CM_JIT_PROF_INFO_SIZE      4096
#define CM_RT_JITTER_MAX_NUM_FLAGS 30

#define JITCOMPILE_FUNCTION_STR "JITCompile"
#define JITCOMPILEV2_FUNCTION_STR "JITCompile_v2"
#define FREEBLOCK_FUNCTION_STR  "freeBlock"
#define JITVERSION_FUNCTION_STR "getJITVersion"

namespace CMRT_UMD
{
class CmDeviceRT;

class CmProgram
{
public:
    virtual int32_t GetCommonISACode(void* & commonISACode, uint32_t & size) = 0;
};

//*-----------------------------------------------------------------------------
//! CM Program
//*-----------------------------------------------------------------------------
class CmProgramRT : public CmProgram
{
public:
    static int32_t Create( CmDeviceRT* device, void* cisaCode, const uint32_t cisaCodeSize, CmProgramRT*& program,  const char* options, const uint32_t programId );
    static int32_t Destroy( CmProgramRT* &program );

    int32_t GetCommonISACode( void* & commonISACode, uint32_t & size ) ;
    int32_t GetKernelCount( uint32_t& kernelCount );
    int32_t GetKernelInfo( uint32_t index, CM_KERNEL_INFO*& kernelInfo );
    int32_t GetIsaFileName( char* & kernelName );
    int32_t GetKernelOptions( char* & kernelOptions );

    uint32_t GetSurfaceCount(void);
    int32_t SetSurfaceCount(uint32_t count);

    bool IsJitterEnabled( void ){ return m_isJitterEnabled; }
    bool IsHwDebugEnabled (void ){ return m_isHwDebugEnabled;}

    uint32_t AcquireKernelInfo(uint32_t index);
    uint32_t ReleaseKernelInfo(uint32_t index);
    int32_t GetKernelInfoRefCount(uint32_t index, uint32_t& refCount);

    int32_t GetCISAVersion(uint32_t& majorVersion, uint32_t& minorVersion);

    int32_t Acquire( void);
    int32_t SafeRelease( void);

    uint32_t GetProgramIndex();

#if (_RELEASE_INTERNAL)
    int32_t ReadUserFeatureValue(const char *pcMessageKey, uint32_t &value);
#endif

    //! \brief    get m_isaFile object
    //! \detail   m_isaFile object provides methods to read, parse and write ISA files.
    //! \return   Pointer to m_isaFile object
    vISA::ISAfile *getISAfile();

protected:
    CmProgramRT( CmDeviceRT* device, uint32_t programId );
    ~CmProgramRT( void );

    int32_t Initialize( void* cisaCode, const uint32_t cisaCodeSize, const char* options );
#if USE_EXTENSION_CODE
    int InitForGTPin(const char *jitFlags[CM_RT_JITTER_MAX_NUM_FLAGS], int &numJitFlags);
#endif
    CmDeviceRT* m_device;

    uint32_t m_programCodeSize;
    uint8_t *m_programCode;
    vISA::ISAfile* m_isaFile;
    char* m_options;
    char m_isaFileName[ CM_MAX_ISA_FILE_NAME_SIZE_IN_BYTE ];
    uint32_t m_surfaceCount;

    uint32_t m_kernelCount;
    CmDynamicArray m_kernelInfo;

    bool m_isJitterEnabled;
    bool m_isHwDebugEnabled;

    uint32_t m_refCount;

    uint32_t m_programIndex;

    //Function point to JIT compiling functions, get from CmDevice_RT or CmDeviceSim
    pJITCompile     m_fJITCompile;
    pFreeBlock      m_fFreeBlock;
    pJITVersion     m_fJITVersion;
    pJITCompile_v2  m_fJITCompile_v2;

public:
    uint32_t m_cisaMagicNumber;
    uint8_t m_cisaMajorVersion;
    uint8_t m_cisaMinorVersion;

private:
    CmProgramRT (const CmProgramRT& other);
    CmProgramRT& operator= (const CmProgramRT& other);
};
}; //namespace

#endif  // #ifndef MEDIADRIVER_AGNOSTIC_COMMON_CM_CMPROGRAM_H_