Skip to content

Commit 4af8feb

Browse files
committed
Revert "Revert "SWDEV-489106 - Hip changes for Linker APIs""
This reverts commit ba14651. Reason for revert: Resubmitting with the fixed patches Change-Id: I505cf48b6f12e7b1abd2ea8c7adca96050b31bc9
1 parent ba14651 commit 4af8feb

File tree

3 files changed

+288
-74
lines changed

3 files changed

+288
-74
lines changed

include/hip/hip_runtime_api.h

Lines changed: 82 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ THE SOFTWARE.
3333
#include <string.h> // for getDeviceProp
3434
#include <hip/hip_version.h>
3535
#include <hip/hip_common.h>
36+
#include <hip/linker_types.h>
3637

3738
enum {
3839
HIP_SUCCESS = 0,
@@ -625,6 +626,7 @@ typedef struct hipIpcEventHandle_st {
625626
} hipIpcEventHandle_t;
626627
typedef struct ihipModule_t* hipModule_t;
627628
typedef struct ihipModuleSymbol_t* hipFunction_t;
629+
typedef struct ihipLinkState_t* hipLinkState_t;
628630
/**
629631
* HIP memory pool
630632
*/
@@ -1137,29 +1139,6 @@ typedef struct hipMemPoolPtrExportData {
11371139
unsigned char reserved[64];
11381140
} hipMemPoolPtrExportData;
11391141

1140-
/**
1141-
* hipJitOption
1142-
*/
1143-
typedef enum hipJitOption {
1144-
hipJitOptionMaxRegisters = 0,
1145-
hipJitOptionThreadsPerBlock,
1146-
hipJitOptionWallTime,
1147-
hipJitOptionInfoLogBuffer,
1148-
hipJitOptionInfoLogBufferSizeBytes,
1149-
hipJitOptionErrorLogBuffer,
1150-
hipJitOptionErrorLogBufferSizeBytes,
1151-
hipJitOptionOptimizationLevel,
1152-
hipJitOptionTargetFromContext,
1153-
hipJitOptionTarget,
1154-
hipJitOptionFallbackStrategy,
1155-
hipJitOptionGenerateDebugInfo,
1156-
hipJitOptionLogVerbose,
1157-
hipJitOptionGenerateLineInfo,
1158-
hipJitOptionCacheMode,
1159-
hipJitOptionSm3xOpt,
1160-
hipJitOptionFastCompile,
1161-
hipJitOptionNumOptions
1162-
} hipJitOption;
11631142
/**
11641143
* @warning On AMD devices and some Nvidia devices, these hints and controls are ignored.
11651144
*/
@@ -5898,6 +5877,86 @@ hipError_t hipModuleLoadData(hipModule_t* module, const void* image);
58985877
*/
58995878
hipError_t hipModuleLoadDataEx(hipModule_t* module, const void* image, unsigned int numOptions,
59005879
hipJitOption* options, void** optionValues);
5880+
/**
5881+
* @brief Completes the linking of the given program.
5882+
* @param [in] state hip link state
5883+
* @param [in] type Type of the input data or bitcode
5884+
* @param [in] data Input data which is null terminated
5885+
* @param [in] size Size of the input data
5886+
* @param [in] name Optional name for this input
5887+
* @param [in] numOptions Size of the options
5888+
* @param [in] options Array of options applied to this input
5889+
* @param [in] optionValues Array of option values cast to void*
5890+
*
5891+
* @returns #hipSuccess, #hipErrorInvalidValue, #hipErrorInvalidHandle
5892+
*
5893+
* If adding the file fails, it will
5894+
* @return #hipErrorInvalidConfiguration
5895+
*
5896+
* @see hipError_t
5897+
*/
5898+
hipError_t hipLinkAddData(hipLinkState_t state, hipJitInputType type, void* data, size_t size,
5899+
const char* name, unsigned int numOptions, hipJitOption* options,
5900+
void** optionValues);
5901+
5902+
/**
5903+
* @brief Adds a file with bit code to be linked with options
5904+
* @param [in] state hip link state
5905+
* @param [in] type Type of the input data or bitcode
5906+
* @param [in] path Path to the input file where bitcode is present
5907+
* @param [in] numOptions Size of the options
5908+
* @param [in] options Array of options applied to this input
5909+
* @param [in] optionValues Array of option values cast to void*
5910+
*
5911+
* @returns #hipSuccess, #hipErrorInvalidValue
5912+
*
5913+
* If adding the file fails, it will
5914+
* @return #hipErrorInvalidConfiguration
5915+
*
5916+
* @see hipError_t
5917+
*/
5918+
hipError_t hipLinkAddFile(hipLinkState_t state, hipJitInputType type, const char* path, unsigned int numOptions,
5919+
hipJitOption* options, void** optionValues);
5920+
5921+
/**
5922+
* @brief Completes the linking of the given program.
5923+
* @param [in] state hip link state
5924+
* @param [out] hipBinOut Upon success, points to the output binary
5925+
* @param [out] sizeOut Size of the binary is stored (optional)
5926+
*
5927+
* @returns #hipSuccess #hipErrorInvalidValue
5928+
*
5929+
* If adding the data fails, it will
5930+
* @return #hipErrorInvalidConfiguration
5931+
*
5932+
* @see hipError_t
5933+
*/
5934+
5935+
hipError_t hipLinkComplete(hipLinkState_t state, void** hipBinOut, size_t* sizeOut);
5936+
5937+
/**
5938+
* @brief Creates the link instance via hip APIs.
5939+
* @param [in] numOptions Number of options
5940+
* @param [in] option Array of options
5941+
* @param [in] optionValues Array of option values cast to void*
5942+
* @param [out] stateOut hip link state created upon success
5943+
*
5944+
* @returns #hipSuccess #hipErrorInvalidValue #hipErrorInvalidConfiguration
5945+
*
5946+
* @see hipSuccess
5947+
*/
5948+
hipError_t hipLinkCreate(unsigned int numOptions, hipJitOption* options,
5949+
void** optionValues, hipLinkState_t* stateOut);
5950+
/**
5951+
* @brief Deletes the link instance via hip APIs.
5952+
* @param [in] state link state instance
5953+
*
5954+
* @returns #hipSuccess #hipErrorInvalidValue
5955+
*
5956+
* @see hipSuccess
5957+
*/
5958+
hipError_t hipLinkDestroy(hipLinkState_t state);
5959+
59015960
/**
59025961
* @brief launches kernel f with launch parameters and shared memory on stream with arguments passed
59035962
* to kernelparams or extra

include/hip/hiprtc.h

Lines changed: 76 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ THE SOFTWARE.
2222
#pragma once
2323

2424
#include <hip/hip_common.h>
25+
#include <hip/linker_types.h>
2526

2627
#if !defined(__HIP_PLATFORM_AMD__) && defined(__HIP_PLATFORM_NVIDIA__)
2728
#include <hip/nvidia_detail/nvidia_hiprtc.h>
@@ -41,7 +42,7 @@ extern "C" {
4142
*
4243
* @addtogroup GlobalDefs
4344
* @{
44-
*
45+
*
4546
*/
4647
/**
4748
* hiprtc error code
@@ -56,66 +57,90 @@ typedef enum hiprtcResult {
5657
HIPRTC_ERROR_COMPILATION = 6, ///< Compilation error
5758
HIPRTC_ERROR_BUILTIN_OPERATION_FAILURE = 7, ///< Failed in builtin operation
5859
HIPRTC_ERROR_NO_NAME_EXPRESSIONS_AFTER_COMPILATION = 8, ///< No name expression after compilation
59-
HIPRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION = 9, ///< No lowered names before compilation
60+
HIPRTC_ERROR_NO_LOWERED_NAMES_BEFORE_COMPILATION = 9, ///< No lowered names before compilation
6061
HIPRTC_ERROR_NAME_EXPRESSION_NOT_VALID = 10, ///< Invalid name expression
6162
HIPRTC_ERROR_INTERNAL_ERROR = 11, ///< Internal error
6263
HIPRTC_ERROR_LINKING = 100 ///< Error in linking
6364
} hiprtcResult;
64-
6565
/**
6666
* hiprtc JIT option
6767
*/
68-
69-
typedef enum hiprtcJIT_option {
70-
HIPRTC_JIT_MAX_REGISTERS = 0, ///< CUDA Only Maximum registers may be used in a thread, passed to compiler
71-
HIPRTC_JIT_THREADS_PER_BLOCK, ///< CUDA Only Number of thread per block
72-
HIPRTC_JIT_WALL_TIME, ///< CUDA Only Value for total wall clock time
73-
HIPRTC_JIT_INFO_LOG_BUFFER, ///< CUDA Only Pointer to the buffer with logged information
74-
HIPRTC_JIT_INFO_LOG_BUFFER_SIZE_BYTES, ///< CUDA Only Size of the buffer in bytes for logged info
75-
HIPRTC_JIT_ERROR_LOG_BUFFER, ///< CUDA Only Pointer to the buffer with logged error(s)
76-
HIPRTC_JIT_ERROR_LOG_BUFFER_SIZE_BYTES, ///< CUDA Only Size of the buffer in bytes for logged error(s)
77-
HIPRTC_JIT_OPTIMIZATION_LEVEL, ///< Value of optimization level for generated codes, acceptable options -O0, -O1, -O2, -O3
78-
HIPRTC_JIT_TARGET_FROM_HIPCONTEXT, ///< CUDA Only The target context, which is the default
79-
HIPRTC_JIT_TARGET, ///< CUDA Only JIT target
80-
HIPRTC_JIT_FALLBACK_STRATEGY, ///< CUDA Only Fallback strategy
81-
HIPRTC_JIT_GENERATE_DEBUG_INFO, ///< CUDA Only Generate debug information
82-
HIPRTC_JIT_LOG_VERBOSE, ///< CUDA Only Generate log verbose
83-
HIPRTC_JIT_GENERATE_LINE_INFO, ///< CUDA Only Generate line number information
84-
HIPRTC_JIT_CACHE_MODE, ///< CUDA Only Set cache mode
85-
HIPRTC_JIT_NEW_SM3X_OPT, ///< @deprecated CUDA Only New SM3X option.
86-
HIPRTC_JIT_FAST_COMPILE, ///< CUDA Only Set fast compile
87-
HIPRTC_JIT_GLOBAL_SYMBOL_NAMES, ///< CUDA Only Array of device symbol names to be relocated to the host
88-
HIPRTC_JIT_GLOBAL_SYMBOL_ADDRESS, ///< CUDA Only Array of host addresses to be relocated to the device
89-
HIPRTC_JIT_GLOBAL_SYMBOL_COUNT, ///< CUDA Only Number of symbol count.
90-
HIPRTC_JIT_LTO, ///< @deprecated CUDA Only Enable link-time optimization for device code
91-
HIPRTC_JIT_FTZ, ///< @deprecated CUDA Only Set single-precision denormals.
92-
HIPRTC_JIT_PREC_DIV, ///< @deprecated CUDA Only Set single-precision floating-point division and
93-
///< reciprocals
94-
HIPRTC_JIT_PREC_SQRT, ///< @deprecated CUDA Only Set single-precision floating-point square root
95-
HIPRTC_JIT_FMA, ///< @deprecated CUDA Only Enable floating-point multiplies and adds/subtracts operations
96-
HIPRTC_JIT_NUM_OPTIONS, ///< Number of options
97-
HIPRTC_JIT_IR_TO_ISA_OPT_EXT = 10000, ///< Linker options to be passed on to compiler
98-
/// @note Only supported for the AMD platform.
99-
HIPRTC_JIT_IR_TO_ISA_OPT_COUNT_EXT, ///< Count of linker options to be passed on to
100-
///< compiler @note Only supported for the AMD platform
101-
} hiprtcJIT_option;
102-
68+
#define hiprtcJIT_option hipJitOption
69+
#define HIPRTC_JIT_MAX_REGISTERS hipJitOptionMaxRegisters ///< CUDA Only Maximum registers may be used in a
70+
///< thread, passed to compiler
71+
#define HIPRTC_JIT_THREADS_PER_BLOCK hipJitOptionThreadsPerBlock ///< CUDA Only Number of thread per block
72+
#define HIPRTC_JIT_WALL_TIME hipJitOptionWallTime ///< CUDA Only Value for total wall clock time
73+
#define HIPRTC_JIT_INFO_LOG_BUFFER hipJitOptionInfoLogBuffer ///< CUDA Only Pointer to the buffer with
74+
///< logged information
75+
#define HIPRTC_JIT_INFO_LOG_BUFFER_SIZE_BYTES hipJitOptionInfoLogBufferSizeBytes ///< CUDA Only Size of the buffer
76+
///< in bytes for logged info
77+
#define HIPRTC_JIT_ERROR_LOG_BUFFER hipJitOptionErrorLogBuffer ///< CUDA Only Pointer to the buffer
78+
///< with logged error(s)
79+
#define HIPRTC_JIT_ERROR_LOG_BUFFER_SIZE_BYTES hipJitOptionErrorLogBufferSizeBytes ///< CUDA Only Size of the buffer in
80+
///< bytes for logged error(s)
81+
#define HIPRTC_JIT_OPTIMIZATION_LEVEL hipJitOptionOptimizationLevel ///< Value of optimization level for
82+
///< generated codes, acceptable
83+
///< options -O0, -O1, -O2, -O3
84+
#define HIPRTC_JIT_TARGET_FROM_HIPCONTEXT hipJitOptionTargetFromContext ///< CUDA Only The target context,
85+
///< which is the default
86+
#define HIPRTC_JIT_TARGET hipJitOptionTarget ///< CUDA Only JIT target
87+
#define HIPRTC_JIT_FALLBACK_STRATEGY hipJitOptionFallbackStrategy ///< CUDA Only Fallback strategy
88+
#define HIPRTC_JIT_GENERATE_DEBUG_INFO hipJitOptionGenerateDebugInfo ///< CUDA Only Generate debug information
89+
#define HIPRTC_JIT_LOG_VERBOSE hipJitOptionLogVerbose ///< CUDA Only Generate log verbose
90+
#define HIPRTC_JIT_GENERATE_LINE_INFO hipJitOptionGenerateLineInfo ///< CUDA Only Generate line number information
91+
#define HIPRTC_JIT_CACHE_MODE hipJitOptionCacheMode ///< CUDA Only Set cache mode
92+
#define HIPRTC_JIT_NEW_SM3X_OPT hipJitOptionSm3xOpt ///< @deprecated CUDA Only New SM3X option.
93+
#define HIPRTC_JIT_FAST_COMPILE hipJitOptionFastCompile ///< CUDA Only Set fast compile
94+
#define HIPRTC_JIT_GLOBAL_SYMBOL_NAMES hipJitOptionGlobalSymbolNames ///< CUDA Only Array of device symbol names to be
95+
///< relocated to the host
96+
#define HIPRTC_JIT_GLOBAL_SYMBOL_ADDRESS hipJitOptionGlobalSymbolAddresses ///< CUDA Only Array of host addresses to be
97+
///< relocated to the device
98+
#define HIPRTC_JIT_GLOBAL_SYMBOL_COUNT hipJitOptionGlobalSymbolCount ///< CUDA Only Number of symbol count.
99+
#define HIPRTC_JIT_LTO hipJitOptionLto ///< @deprecated CUDA Only Enable link-time
100+
///< optimization for device code
101+
#define HIPRTC_JIT_FTZ hipJitOptionFtz ///< @deprecated CUDA Only Set
102+
///< single-precision denormals.
103+
#define HIPRTC_JIT_PREC_DIV hipJitOptionPrecDiv ///< @deprecated CUDA Only Set
104+
///< single-precision floating-point division
105+
///< and reciprocals
106+
#define HIPRTC_JIT_PREC_SQRT hipJitOptionPrecSqrt ///< @deprecated CUDA Only Set
107+
///< single-precision floating-point
108+
///< square root
109+
#define HIPRTC_JIT_FMA hipJitOptionFma ///< @deprecated CUDA Only Enable
110+
///< floating-point multiplies and
111+
///< adds/subtracts operations
112+
#define HIPRTC_JIT_POSITION_INDEPENDENT_CODE hipJitOptionPositionIndependentCode ///< CUDA Only Generates
113+
///< Position Independent code
114+
#define HIPRTC_JIT_MIN_CTA_PER_SM hipJitOptionMinCTAPerSM ///< CUDA Only Hints to JIT compiler
115+
///< the minimum number of CTAs frin
116+
///< kernel's grid to be mapped to SM
117+
#define HIPRTC_JIT_MAX_THREADS_PER_BLOCK hipJitOptionMaxThreadsPerBlock ///< CUDA only Maximum number of
118+
///< threads in a thread block
119+
#define HIPRTC_JIT_OVERRIDE_DIRECT_VALUES hipJitOptionOverrideDirectiveValues ///< CUDA only Override Directive
120+
///< Values
121+
#define HIPRTC_JIT_NUM_OPTIONS hipJitOptionNumOptions ///< Number of options
122+
#define HIPRTC_JIT_IR_TO_ISA_OPT_EXT hipJitOptionIRtoISAOptExt ///< HIP Only Linker options to be
123+
///< passed on to compiler
124+
#define HIPRTC_JIT_IR_TO_ISA_OPT_COUNT_EXT hipJitOptionIRtoISAOptCountExt ///< HIP Only Count of linker options
125+
///< to be passed on to
103126
/**
104127
* hiprtc JIT input type
105128
*/
106-
typedef enum hiprtcJITInputType {
107-
HIPRTC_JIT_INPUT_CUBIN = 0, ///< Input cubin
108-
HIPRTC_JIT_INPUT_PTX, ///< Input PTX
109-
HIPRTC_JIT_INPUT_FATBINARY, ///< Input fat binary
110-
HIPRTC_JIT_INPUT_OBJECT, ///< Input object
111-
HIPRTC_JIT_INPUT_LIBRARY, ///< Input library
112-
HIPRTC_JIT_INPUT_NVVM, ///< Input NVVM
113-
HIPRTC_JIT_NUM_LEGACY_INPUT_TYPES, ///< Number of legacy input type
114-
HIPRTC_JIT_INPUT_LLVM_BITCODE = 100, ///< LLVM bitcode or IR assembly
115-
HIPRTC_JIT_INPUT_LLVM_BUNDLED_BITCODE = 101, ///< LLVM bundled bitcode
116-
HIPRTC_JIT_INPUT_LLVM_ARCHIVES_OF_BUNDLED_BITCODE = 102, ///< LLVM archives of boundled bitcode
117-
HIPRTC_JIT_NUM_INPUT_TYPES = (HIPRTC_JIT_NUM_LEGACY_INPUT_TYPES + 3)
118-
} hiprtcJITInputType;
129+
#define hiprtcJITInputType hipJitInputType
130+
#define HIPRTC_JIT_INPUT_CUBIN hipJitInputCubin ///< Cuda only Input Cubin
131+
#define HIPRTC_JIT_INPUT_PTX hipJitInputPtx ///< Cuda only Input PTX
132+
#define HIPRTC_JIT_INPUT_FATBINARY hipJitInputFatBinary ///< Cuda Only Input FAT Binary
133+
#define HIPRTC_JIT_INPUT_OBJECT hipJitInputObject ///< Cuda Only Host Object with embedded device code
134+
#define HIPRTC_JIT_INPUT_LIBRARY hipJitInputLibrary ///< Cuda Only Archive of Host Objects with embedded device code
135+
#define HIPRTC_JIT_INPUT_NVVM hipJitInputNvvm ///< @deprecated CUDA only High Level intermediate code for LTO
136+
#define HIPRTC_JIT_NUM_LEGACY_INPUT_TYPES hipJitNumLegacyInputTypes ///< Count of Legacy Input Types
137+
#define HIPRTC_JIT_INPUT_LLVM_BITCODE hipJitInputLLVMBitcode ///< HIP Only LLVM Bitcode or IR assembly
138+
#define HIPRTC_JIT_INPUT_LLVM_BUNDLED_BITCODE hipJitInputLLVMBundledBitcode ///< HIP Only LLVM Clang Bundled Code
139+
#define HIPRTC_JIT_INPUT_LLVM_ARCHIVES_OF_BUNDLED_BITCODE hipJitInputLLVMArchivesOfBundledBitcode ///< HIP Only LLVM
140+
///< Archives of
141+
///< Bundled Bitcode
142+
#define HIPRTC_JIT_INPUT_SPIRV hipJitInputSpirv ///< HIP Only SPIRV Code Object
143+
#define HIPRTC_JIT_NUM_INPUT_TYPES hipJitNumInputTypes ///< Count of Input Types
119144
/**
120145
* @}
121146
*/

0 commit comments

Comments
 (0)