-
Notifications
You must be signed in to change notification settings - Fork 518
/
hiprtc.h
421 lines (385 loc) · 15.5 KB
/
hiprtc.h
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
/*
Copyright (c) 2015 - 2023 Advanced Micro Devices, Inc. All rights reserved.
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.
*/
#pragma once
#include <hip/hip_common.h>
#if !defined(__HIP_PLATFORM_AMD__) && defined(__HIP_PLATFORM_NVIDIA__)
#include <hip/nvidia_detail/nvidia_hiprtc.h>
#elif defined(__HIP_PLATFORM_AMD__) && !defined(__HIP_PLATFORM_NVIDIA__)
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <stdlib.h>
#if !defined(_WIN32)
#pragma GCC visibility push(default)
#endif
/**
*
* @addtogroup GlobalDefs
* @{
*
*/
/**
* hiprtc error code
*/
typedef enum hiprtcResult {
HIPRTC_SUCCESS = 0, ///< Success
HIPRTC_ERROR_OUT_OF_MEMORY = 1, ///< Out of memory
HIPRTC_ERROR_PROGRAM_CREATION_FAILURE = 2, ///< Failed to create program
HIPRTC_ERROR_INVALID_INPUT = 3, ///< Invalid input
HIPRTC_ERROR_INVALID_PROGRAM = 4, ///< Invalid program
HIPRTC_ERROR_INVALID_OPTION = 5, ///< Invalid option
HIPRTC_ERROR_COMPILATION = 6, ///< Compilation error
HIPRTC_ERROR_BUILTIN_OPERATION_FAILURE = 7, ///< Failed in builtin operation
HIPRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION = 8, ///< No name expression after compilation
HIPRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION = 9, ///< No lowered names before compilation
HIPRTC_ERROR_NAME_EXPRESSION_NOT_VALID = 10, ///< Invalid name expression
HIPRTC_ERROR_INTERNAL_ERROR = 11, ///< Internal error
HIPRTC_ERROR_LINKING = 100 ///< Error in linking
} hiprtcResult;
/**
* hiprtc JIT option
*/
typedef enum hiprtcJIT_option {
HIPRTC_JIT_MAX_REGISTERS = 0, ///< CUDA Only Maximum registers may be used in a thread, passed to compiler
HIPRTC_JIT_THREADS_PER_BLOCK, ///< CUDA Only Number of thread per block
HIPRTC_JIT_WALL_TIME, ///< CUDA Only Value for total wall clock time
HIPRTC_JIT_INFO_LOG_BUFFER, ///< CUDA Only Pointer to the buffer with logged information
HIPRTC_JIT_INFO_LOG_BUFFER_SIZE_BYTES, ///< CUDA Only Size of the buffer in bytes for logged info
HIPRTC_JIT_ERROR_LOG_BUFFER, ///< CUDA Only Pointer to the buffer with logged error(s)
HIPRTC_JIT_ERROR_LOG_BUFFER_SIZE_BYTES, ///< CUDA Only Size of the buffer in bytes for logged error(s)
HIPRTC_JIT_OPTIMIZATION_LEVEL, ///< Value of optimization level for generated codes, acceptable options -O0, -O1, -O2, -O3
HIPRTC_JIT_TARGET_FROM_HIPCONTEXT, ///< CUDA Only The target context, which is the default
HIPRTC_JIT_TARGET, ///< CUDA Only JIT target
HIPRTC_JIT_FALLBACK_STRATEGY, ///< CUDA Only Fallback strategy
HIPRTC_JIT_GENERATE_DEBUG_INFO, ///< CUDA Only Generate debug information
HIPRTC_JIT_LOG_VERBOSE, ///< CUDA Only Generate log verbose
HIPRTC_JIT_GENERATE_LINE_INFO, ///< CUDA Only Generate line number information
HIPRTC_JIT_CACHE_MODE, ///< CUDA Only Set cache mode
HIPRTC_JIT_NEW_SM3X_OPT, ///< @deprecated CUDA Only New SM3X option.
HIPRTC_JIT_FAST_COMPILE, ///< CUDA Only Set fast compile
HIPRTC_JIT_GLOBAL_SYMBOL_NAMES, ///< CUDA Only Array of device symbol names to be relocated to the host
HIPRTC_JIT_GLOBAL_SYMBOL_ADDRESS, ///< CUDA Only Array of host addresses to be relocated to the device
HIPRTC_JIT_GLOBAL_SYMBOL_COUNT, ///< CUDA Only Number of symbol count.
HIPRTC_JIT_LTO, ///< @deprecated CUDA Only Enable link-time optimization for device code
HIPRTC_JIT_FTZ, ///< @deprecated CUDA Only Set single-precision denormals.
HIPRTC_JIT_PREC_DIV, ///< @deprecated CUDA Only Set single-precision floating-point division and
///< reciprocals
HIPRTC_JIT_PREC_SQRT, ///< @deprecated CUDA Only Set single-precision floating-point square root
HIPRTC_JIT_FMA, ///< @deprecated CUDA Only Enable floating-point multiplies and adds/subtracts operations
HIPRTC_JIT_NUM_OPTIONS, ///< Number of options
HIPRTC_JIT_IR_TO_ISA_OPT_EXT = 10000, ///< Linker options to be passed on to compiler
/// @note Only supported for the AMD platform.
HIPRTC_JIT_IR_TO_ISA_OPT_COUNT_EXT, ///< Count of linker options to be passed on to
///< compiler @note Only supported for the AMD platform
} hiprtcJIT_option;
/**
* hiprtc JIT input type
*/
typedef enum hiprtcJITInputType {
HIPRTC_JIT_INPUT_CUBIN = 0, ///< Input cubin
HIPRTC_JIT_INPUT_PTX, ///< Input PTX
HIPRTC_JIT_INPUT_FATBINARY, ///< Input fat binary
HIPRTC_JIT_INPUT_OBJECT, ///< Input object
HIPRTC_JIT_INPUT_LIBRARY, ///< Input library
HIPRTC_JIT_INPUT_NVVM, ///< Input NVVM
HIPRTC_JIT_NUM_LEGACY_INPUT_TYPES, ///< Number of legacy input type
HIPRTC_JIT_INPUT_LLVM_BITCODE = 100, ///< LLVM bitcode or IR assembly
HIPRTC_JIT_INPUT_LLVM_BUNDLED_BITCODE = 101, ///< LLVM bundled bitcode
HIPRTC_JIT_INPUT_LLVM_ARCHIVES_OF_BUNDLED_BITCODE = 102, ///< LLVM archives of boundled bitcode
HIPRTC_JIT_NUM_INPUT_TYPES = (HIPRTC_JIT_NUM_LEGACY_INPUT_TYPES + 3)
} hiprtcJITInputType;
/**
* @}
*/
/**
* hiprtc link state
*
*/
typedef struct ihiprtcLinkState* hiprtcLinkState;
/**
* @ingroup Runtime
*
* @brief Returns text string message to explain the error which occurred
*
* @param [in] result code to convert to string.
* @returns const char pointer to the NULL-terminated error string
*
* @warning In HIP, this function returns the name of the error,
* if the hiprtc result is defined, it will return "Invalid HIPRTC error code"
*
* @see hiprtcResult
*/
const char* hiprtcGetErrorString(hiprtcResult result);
/**
* @ingroup Runtime
* @brief Sets the parameters as major and minor version.
*
* @param [out] major HIP Runtime Compilation major version.
* @param [out] minor HIP Runtime Compilation minor version.
*
* @returns #HIPRTC_ERROR_INVALID_INPUT, #HIPRTC_SUCCESS
*
*/
hiprtcResult hiprtcVersion(int* major, int* minor);
/**
* hiprtc program
*
*/
typedef struct _hiprtcProgram* hiprtcProgram;
/**
* @ingroup Runtime
* @brief Adds the given name exprssion to the runtime compilation program.
*
* @param [in] prog runtime compilation program instance.
* @param [in] name_expression const char pointer to the name expression.
* @returns #HIPRTC_SUCCESS
*
* If const char pointer is NULL, it will return #HIPRTC_ERROR_INVALID_INPUT.
*
* @see hiprtcResult
*/
hiprtcResult hiprtcAddNameExpression(hiprtcProgram prog,
const char* name_expression);
/**
* @ingroup Runtime
* @brief Compiles the given runtime compilation program.
*
* @param [in] prog runtime compilation program instance.
* @param [in] numOptions number of compiler options.
* @param [in] options compiler options as const array of strins.
* @returns #HIPRTC_SUCCESS
*
* If the compiler failed to build the runtime compilation program,
* it will return #HIPRTC_ERROR_COMPILATION.
*
* @see hiprtcResult
*/
hiprtcResult hiprtcCompileProgram(hiprtcProgram prog,
int numOptions,
const char** options);
/**
* @ingroup Runtime
* @brief Creates an instance of hiprtcProgram with the given input parameters,
* and sets the output hiprtcProgram prog with it.
*
* @param [in, out] prog runtime compilation program instance.
* @param [in] src const char pointer to the program source.
* @param [in] name const char pointer to the program name.
* @param [in] numHeaders number of headers.
* @param [in] headers array of strings pointing to headers.
* @param [in] includeNames array of strings pointing to names included in program source.
* @returns #HIPRTC_SUCCESS
*
* Any invalide input parameter, it will return #HIPRTC_ERROR_INVALID_INPUT
* or #HIPRTC_ERROR_INVALID_PROGRAM.
*
* If failed to create the program, it will return #HIPRTC_ERROR_PROGRAM_CREATION_FAILURE.
*
* @see hiprtcResult
*/
hiprtcResult hiprtcCreateProgram(hiprtcProgram* prog,
const char* src,
const char* name,
int numHeaders,
const char** headers,
const char** includeNames);
/**
* @brief Destroys an instance of given hiprtcProgram.
* @ingroup Runtime
* @param [in] prog runtime compilation program instance.
* @returns #HIPRTC_SUCCESS
*
* If prog is NULL, it will return #HIPRTC_ERROR_INVALID_INPUT.
*
* @see hiprtcResult
*/
hiprtcResult hiprtcDestroyProgram(hiprtcProgram* prog);
/**
* @brief Gets the lowered (mangled) name from an instance of hiprtcProgram with the given input parameters,
* and sets the output lowered_name with it.
* @ingroup Runtime
* @param [in] prog runtime compilation program instance.
* @param [in] name_expression const char pointer to the name expression.
* @param [in, out] lowered_name const char array to the lowered (mangled) name.
* @returns #HIPRTC_SUCCESS
*
* If any invalide nullptr input parameters, it will return #HIPRTC_ERROR_INVALID_INPUT
*
* If name_expression is not found, it will return #HIPRTC_ERROR_NAME_EXPRESSION_NOT_VALID
*
* If failed to get lowered_name from the program, it will return #HIPRTC_ERROR_COMPILATION.
*
* @see hiprtcResult
*/
hiprtcResult hiprtcGetLoweredName(hiprtcProgram prog,
const char* name_expression,
const char** lowered_name);
/**
* @brief Gets the log generated by the runtime compilation program instance.
* @ingroup Runtime
* @param [in] prog runtime compilation program instance.
* @param [out] log memory pointer to the generated log.
* @returns #HIPRTC_SUCCESS
*
* @see hiprtcResult
*/
hiprtcResult hiprtcGetProgramLog(hiprtcProgram prog, char* log);
/**
* @brief Gets the size of log generated by the runtime compilation program instance.
*
* @param [in] prog runtime compilation program instance.
* @param [out] logSizeRet size of generated log.
* @returns #HIPRTC_SUCCESS
*
* @see hiprtcResult
*/
hiprtcResult hiprtcGetProgramLogSize(hiprtcProgram prog,
size_t* logSizeRet);
/**
* @brief Gets the pointer of compilation binary by the runtime compilation program instance.
* @ingroup Runtime
* @param [in] prog runtime compilation program instance.
* @param [out] code char pointer to binary.
* @returns #HIPRTC_SUCCESS
*
* @see hiprtcResult
*/
hiprtcResult hiprtcGetCode(hiprtcProgram prog, char* code);
/**
* @brief Gets the size of compilation binary by the runtime compilation program instance.
* @ingroup Runtime
* @param [in] prog runtime compilation program instance.
* @param [out] codeSizeRet the size of binary.
* @returns #HIPRTC_SUCCESS
*
* @see hiprtcResult
*/
hiprtcResult hiprtcGetCodeSize(hiprtcProgram prog, size_t* codeSizeRet);
/**
* @brief Gets the pointer of compiled bitcode by the runtime compilation program instance.
*
* @param [in] prog runtime compilation program instance.
* @param [out] bitcode char pointer to bitcode.
* @return HIPRTC_SUCCESS
*
* @see hiprtcResult
*/
hiprtcResult hiprtcGetBitcode(hiprtcProgram prog, char* bitcode);
/**
* @brief Gets the size of compiled bitcode by the runtime compilation program instance.
* @ingroup Runtime
*
* @param [in] prog runtime compilation program instance.
* @param [out] bitcode_size the size of bitcode.
* @returns #HIPRTC_SUCCESS
*
* @see hiprtcResult
*/
hiprtcResult hiprtcGetBitcodeSize(hiprtcProgram prog, size_t* bitcode_size);
/**
* @brief Creates the link instance via hiprtc APIs.
* @ingroup Runtime
* @param [in] num_options Number of options
* @param [in] option_ptr Array of options
* @param [in] option_vals_pptr Array of option values cast to void*
* @param [out] hip_link_state_ptr hiprtc link state created upon success
*
* @returns #HIPRTC_SUCCESS, #HIPRTC_ERROR_INVALID_INPUT, #HIPRTC_ERROR_INVALID_OPTION
*
* @see hiprtcResult
*/
hiprtcResult hiprtcLinkCreate(unsigned int num_options, hiprtcJIT_option* option_ptr,
void** option_vals_pptr, hiprtcLinkState* hip_link_state_ptr);
/**
* @brief Adds a file with bit code to be linked with options
* @ingroup Runtime
* @param [in] hip_link_state hiprtc link state
* @param [in] input_type Type of the input data or bitcode
* @param [in] file_path Path to the input file where bitcode is present
* @param [in] num_options Size of the options
* @param [in] options_ptr Array of options applied to this input
* @param [in] option_values Array of option values cast to void*
*
* @returns #HIPRTC_SUCCESS
*
* If input values are invalid, it will
* @return #HIPRTC_ERROR_INVALID_INPUT
*
* @see hiprtcResult
*/
hiprtcResult hiprtcLinkAddFile(hiprtcLinkState hip_link_state, hiprtcJITInputType input_type,
const char* file_path, unsigned int num_options,
hiprtcJIT_option* options_ptr, void** option_values);
/**
* @brief Completes the linking of the given program.
* @ingroup Runtime
* @param [in] hip_link_state hiprtc link state
* @param [in] input_type Type of the input data or bitcode
* @param [in] image Input data which is null terminated
* @param [in] image_size Size of the input data
* @param [in] name Optional name for this input
* @param [in] num_options Size of the options
* @param [in] options_ptr Array of options applied to this input
* @param [in] option_values Array of option values cast to void*
*
* @returns #HIPRTC_SUCCESS, #HIPRTC_ERROR_INVALID_INPUT
*
* If adding the file fails, it will
* @return #HIPRTC_ERROR_PROGRAM_CREATION_FAILURE
*
* @see hiprtcResult
*/
hiprtcResult hiprtcLinkAddData(hiprtcLinkState hip_link_state, hiprtcJITInputType input_type,
void* image, size_t image_size, const char* name,
unsigned int num_options, hiprtcJIT_option* options_ptr,
void** option_values);
/**
* @brief Completes the linking of the given program.
* @ingroup Runtime
* @param [in] hip_link_state hiprtc link state
* @param [out] bin_out Upon success, points to the output binary
* @param [out] size_out Size of the binary is stored (optional)
*
* @returns #HIPRTC_SUCCESS
*
* If adding the data fails, it will
* @return #HIPRTC_ERROR_LINKING
*
* @see hiprtcResult
*/
hiprtcResult hiprtcLinkComplete(hiprtcLinkState hip_link_state, void** bin_out, size_t* size_out);
/**
* @brief Deletes the link instance via hiprtc APIs.
* @ingroup Runtime
* @param [in] hip_link_state link state instance
*
* @returns #HIPRTC_SUCCESS
*
* @see hiprtcResult
*/
hiprtcResult hiprtcLinkDestroy(hiprtcLinkState hip_link_state);
#if !defined(_WIN32)
#pragma GCC visibility pop
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#else
#error("Must define exactly one of __HIP_PLATFORM_AMD__ or __HIP_PLATFORM_NVIDIA__");
#endif