include/hip/hiprtc.h Source File

include/hip/hiprtc.h Source File#

HIP Runtime API Reference: include/hip/hiprtc.h Source File
hiprtc.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2015 - 2023 Advanced Micro Devices, Inc. All rights reserved.
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 */
22 #pragma once
23 
24 #include <hip/hip_common.h>
25 #include <hip/linker_types.h>
26 
27 #if !defined(__HIP_PLATFORM_AMD__) && defined(__HIP_PLATFORM_NVIDIA__)
28 #include <hip/nvidia_detail/nvidia_hiprtc.h>
29 #elif defined(__HIP_PLATFORM_AMD__) && !defined(__HIP_PLATFORM_NVIDIA__)
30 
31 #ifdef __cplusplus
32 #include <cstdlib>
33 #else
34 #include <stdlib.h>
35 #endif
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif /* __cplusplus */
40 
41 #if !defined(_WIN32)
42 #pragma GCC visibility push(default)
43 #endif
44 
54 typedef enum hiprtcResult {
72 #define hiprtcJIT_option hipJitOption
73 #define HIPRTC_JIT_MAX_REGISTERS \
74  hipJitOptionMaxRegisters
76 #define HIPRTC_JIT_THREADS_PER_BLOCK \
77  hipJitOptionThreadsPerBlock
78 #define HIPRTC_JIT_WALL_TIME hipJitOptionWallTime
79 #define HIPRTC_JIT_INFO_LOG_BUFFER \
80  hipJitOptionInfoLogBuffer
82 #define HIPRTC_JIT_INFO_LOG_BUFFER_SIZE_BYTES \
83  hipJitOptionInfoLogBufferSizeBytes
85 #define HIPRTC_JIT_ERROR_LOG_BUFFER \
86  hipJitOptionErrorLogBuffer
88 #define HIPRTC_JIT_ERROR_LOG_BUFFER_SIZE_BYTES \
89  hipJitOptionErrorLogBufferSizeBytes
91 #define HIPRTC_JIT_OPTIMIZATION_LEVEL \
92  hipJitOptionOptimizationLevel
95 #define HIPRTC_JIT_TARGET_FROM_HIPCONTEXT \
96  hipJitOptionTargetFromContext
98 #define HIPRTC_JIT_TARGET hipJitOptionTarget
99 #define HIPRTC_JIT_FALLBACK_STRATEGY hipJitOptionFallbackStrategy
100 #define HIPRTC_JIT_GENERATE_DEBUG_INFO \
101  hipJitOptionGenerateDebugInfo
102 #define HIPRTC_JIT_LOG_VERBOSE hipJitOptionLogVerbose
103 #define HIPRTC_JIT_GENERATE_LINE_INFO \
104  hipJitOptionGenerateLineInfo
105 #define HIPRTC_JIT_CACHE_MODE hipJitOptionCacheMode
106 #define HIPRTC_JIT_NEW_SM3X_OPT hipJitOptionSm3xOpt
107 #define HIPRTC_JIT_FAST_COMPILE hipJitOptionFastCompile
108 #define HIPRTC_JIT_GLOBAL_SYMBOL_NAMES \
109  hipJitOptionGlobalSymbolNames
111 #define HIPRTC_JIT_GLOBAL_SYMBOL_ADDRESS \
112  hipJitOptionGlobalSymbolAddresses
114 #define HIPRTC_JIT_GLOBAL_SYMBOL_COUNT \
115  hipJitOptionGlobalSymbolCount
116 #define HIPRTC_JIT_LTO \
117  hipJitOptionLto
119 #define HIPRTC_JIT_FTZ \
120  hipJitOptionFtz
122 #define HIPRTC_JIT_PREC_DIV \
123  hipJitOptionPrecDiv
126 #define HIPRTC_JIT_PREC_SQRT \
127  hipJitOptionPrecSqrt
130 #define HIPRTC_JIT_FMA \
131  hipJitOptionFma
134 #define HIPRTC_JIT_POSITION_INDEPENDENT_CODE \
135  hipJitOptionPositionIndependentCode
137 #define HIPRTC_JIT_MIN_CTA_PER_SM \
138  hipJitOptionMinCTAPerSM
141 #define HIPRTC_JIT_MAX_THREADS_PER_BLOCK \
142  hipJitOptionMaxThreadsPerBlock
144 #define HIPRTC_JIT_OVERRIDE_DIRECT_VALUES \
145  hipJitOptionOverrideDirectiveValues
147 #define HIPRTC_JIT_NUM_OPTIONS hipJitOptionNumOptions
148 #define HIPRTC_JIT_IR_TO_ISA_OPT_EXT \
149  hipJitOptionIRtoISAOptExt
151 #define HIPRTC_JIT_IR_TO_ISA_OPT_COUNT_EXT \
152  hipJitOptionIRtoISAOptCountExt
154 
157 #define hiprtcJITInputType hipJitInputType
158 #define HIPRTC_JIT_INPUT_CUBIN hipJitInputCubin
159 #define HIPRTC_JIT_INPUT_PTX hipJitInputPtx
160 #define HIPRTC_JIT_INPUT_FATBINARY hipJitInputFatBinary
161 #define HIPRTC_JIT_INPUT_OBJECT \
162  hipJitInputObject
163 #define HIPRTC_JIT_INPUT_LIBRARY \
164  hipJitInputLibrary
165 #define HIPRTC_JIT_INPUT_NVVM \
166  hipJitInputNvvm
167 #define HIPRTC_JIT_NUM_LEGACY_INPUT_TYPES \
168  hipJitNumLegacyInputTypes
169 #define HIPRTC_JIT_INPUT_LLVM_BITCODE \
170  hipJitInputLLVMBitcode
171 #define HIPRTC_JIT_INPUT_LLVM_BUNDLED_BITCODE \
172  hipJitInputLLVMBundledBitcode
173 #define HIPRTC_JIT_INPUT_LLVM_ARCHIVES_OF_BUNDLED_BITCODE \
174  hipJitInputLLVMArchivesOfBundledBitcode
177 #define HIPRTC_JIT_INPUT_SPIRV hipJitInputSpirv
178 #define HIPRTC_JIT_NUM_INPUT_TYPES hipJitNumInputTypes
187 typedef struct ihiprtcLinkState* hiprtcLinkState;
201 const char* hiprtcGetErrorString(hiprtcResult result);
202 
213 hiprtcResult hiprtcVersion(int* major, int* minor);
214 
219 typedef struct _hiprtcProgram* hiprtcProgram;
220 
233 hiprtcResult hiprtcAddNameExpression(hiprtcProgram prog, const char* name_expression);
234 
249 hiprtcResult hiprtcCompileProgram(hiprtcProgram prog, int numOptions, const char* const* options);
250 
271 hiprtcResult hiprtcCreateProgram(hiprtcProgram* prog, const char* src, const char* name,
272  int numHeaders, const char* const* headers,
273  const char* const* includeNames);
274 
286 
304 hiprtcResult hiprtcGetLoweredName(hiprtcProgram prog, const char* name_expression,
305  const char** lowered_name);
306 
317 
328 
339 
349 hiprtcResult hiprtcGetCodeSize(hiprtcProgram prog, size_t* codeSizeRet);
350 
361 
372 hiprtcResult hiprtcGetBitcodeSize(hiprtcProgram prog, size_t* bitcode_size);
373 
386 hiprtcResult hiprtcLinkCreate(unsigned int num_options, hiprtcJIT_option* option_ptr,
387  void** option_vals_pptr, hiprtcLinkState* hip_link_state_ptr);
388 
408  const char* file_path, unsigned int num_options,
409  hiprtcJIT_option* options_ptr, void** option_values);
410 
432  void* image, size_t image_size, const char* name,
433  unsigned int num_options, hiprtcJIT_option* options_ptr,
434  void** option_values);
435 
450 hiprtcResult hiprtcLinkComplete(hiprtcLinkState hip_link_state, void** bin_out, size_t* size_out);
451 
462 
463 #if !defined(_WIN32)
464 #pragma GCC visibility pop
465 #endif
466 
467 #ifdef __cplusplus
468 }
469 #endif /* __cplusplus */
470 
471 #else
472 #error ("Must define exactly one of __HIP_PLATFORM_AMD__ or __HIP_PLATFORM_NVIDIA__");
473 #endif
#define hiprtcJIT_option
Definition: hiprtc.h:72
#define hiprtcJITInputType
Definition: hiprtc.h:157
hiprtcResult
Definition: hiprtc.h:54
@ HIPRTC_ERROR_PROGRAM_CREATION_FAILURE
Failed to create program.
Definition: hiprtc.h:57
@ HIPRTC_ERROR_INVALID_PROGRAM
Invalid program.
Definition: hiprtc.h:59
@ HIPRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION
No name expression after compilation.
Definition: hiprtc.h:63
@ HIPRTC_ERROR_INVALID_OPTION
Invalid option.
Definition: hiprtc.h:60
@ HIPRTC_ERROR_INVALID_INPUT
Invalid input.
Definition: hiprtc.h:58
@ HIPRTC_ERROR_NAME_EXPRESSION_NOT_VALID
Invalid name expression.
Definition: hiprtc.h:65
@ HIPRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION
No lowered names before compilation.
Definition: hiprtc.h:64
@ HIPRTC_SUCCESS
Success.
Definition: hiprtc.h:55
@ HIPRTC_ERROR_BUILTIN_OPERATION_FAILURE
Failed in builtin operation.
Definition: hiprtc.h:62
@ HIPRTC_ERROR_INTERNAL_ERROR
Internal error.
Definition: hiprtc.h:66
@ HIPRTC_ERROR_COMPILATION
Compilation error.
Definition: hiprtc.h:61
@ HIPRTC_ERROR_OUT_OF_MEMORY
Out of memory.
Definition: hiprtc.h:56
@ HIPRTC_ERROR_LINKING
Error in linking.
Definition: hiprtc.h:67
hiprtcResult hiprtcAddNameExpression(hiprtcProgram prog, const char *name_expression)
Adds the given name exprssion to the runtime compilation program.
hiprtcResult hiprtcLinkComplete(hiprtcLinkState hip_link_state, void **bin_out, size_t *size_out)
Completes the linking of the given program.
hiprtcResult hiprtcLinkAddFile(hiprtcLinkState hip_link_state, hiprtcJITInputType input_type, const char *file_path, unsigned int num_options, hiprtcJIT_option *options_ptr, void **option_values)
Adds a file with bit code to be linked with options.
hiprtcResult hiprtcGetLoweredName(hiprtcProgram prog, const char *name_expression, const char **lowered_name)
Gets the lowered (mangled) name from an instance of hiprtcProgram with the given input parameters,...
const char * hiprtcGetErrorString(hiprtcResult result)
Returns text string message to explain the error which occurred.
hiprtcResult hiprtcLinkCreate(unsigned int num_options, hiprtcJIT_option *option_ptr, void **option_vals_pptr, hiprtcLinkState *hip_link_state_ptr)
Creates the link instance via hiprtc APIs.
hiprtcResult hiprtcGetCodeSize(hiprtcProgram prog, size_t *codeSizeRet)
Gets the size of compilation binary by the runtime compilation program instance.
hiprtcResult hiprtcLinkDestroy(hiprtcLinkState hip_link_state)
Deletes the link instance via hiprtc APIs.
hiprtcResult hiprtcGetProgramLog(hiprtcProgram prog, char *log)
Gets the log generated by the runtime compilation program instance.
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)
Completes the linking of the given program.
hiprtcResult hiprtcGetBitcodeSize(hiprtcProgram prog, size_t *bitcode_size)
Gets the size of compiled bitcode by the runtime compilation program instance.
hiprtcResult hiprtcCompileProgram(hiprtcProgram prog, int numOptions, const char *const *options)
Compiles the given runtime compilation program.
hiprtcResult hiprtcDestroyProgram(hiprtcProgram *prog)
Destroys an instance of given hiprtcProgram.
hiprtcResult hiprtcGetCode(hiprtcProgram prog, char *code)
Gets the pointer of compilation binary by the runtime compilation program instance.
hiprtcResult hiprtcCreateProgram(hiprtcProgram *prog, const char *src, const char *name, int numHeaders, const char *const *headers, const char *const *includeNames)
Creates an instance of hiprtcProgram with the given input parameters, and sets the output hiprtcProgr...
hiprtcResult hiprtcVersion(int *major, int *minor)
Sets the parameters as major and minor version.
hiprtcResult hiprtcGetProgramLogSize(hiprtcProgram prog, size_t *logSizeRet)
Gets the size of log generated by the runtime compilation program instance.
hiprtcResult hiprtcGetBitcode(hiprtcProgram prog, char *bitcode)
Gets the pointer of compiled bitcode by the runtime compilation program instance.
struct ihiprtcLinkState * hiprtcLinkState
Definition: hiprtc.h:187
struct _hiprtcProgram * hiprtcProgram
Definition: hiprtc.h:219