1 //===--- amdgpu/dynamic_hsa/hsa.h --------------------------------- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // The parts of the hsa api that are presently in use by the amdgpu plugin
11 //===----------------------------------------------------------------------===//
12 #ifndef HSA_RUNTIME_INC_HSA_H_
13 #define HSA_RUNTIME_INC_HSA_H_
18 // Detect and set large model builds.
19 #undef HSA_LARGE_MODEL
20 #if defined(__LP64__) || defined(_M_X64)
21 #define HSA_LARGE_MODEL
29 HSA_STATUS_SUCCESS
= 0x0,
30 HSA_STATUS_INFO_BREAK
= 0x1,
31 HSA_STATUS_ERROR
= 0x1000,
32 HSA_STATUS_ERROR_INVALID_CODE_OBJECT
= 0x1010,
33 HSA_STATUS_ERROR_NOT_INITIALIZED
= 0x100B,
36 hsa_status_t
hsa_status_string(hsa_status_t status
, const char **status_string
);
38 typedef struct hsa_dim3_s
{
44 hsa_status_t
hsa_init();
46 hsa_status_t
hsa_shut_down();
48 typedef struct hsa_agent_s
{
53 HSA_DEVICE_TYPE_CPU
= 0,
54 HSA_DEVICE_TYPE_GPU
= 1,
55 HSA_DEVICE_TYPE_DSP
= 2
59 HSA_ISA_INFO_NAME_LENGTH
= 0,
64 HSA_AGENT_INFO_NAME
= 0,
65 HSA_AGENT_INFO_VENDOR_NAME
= 1,
66 HSA_AGENT_INFO_FEATURE
= 2,
67 HSA_AGENT_INFO_PROFILE
= 4,
68 HSA_AGENT_INFO_WAVEFRONT_SIZE
= 6,
69 HSA_AGENT_INFO_WORKGROUP_MAX_DIM
= 7,
70 HSA_AGENT_INFO_WORKGROUP_MAX_SIZE
= 8,
71 HSA_AGENT_INFO_GRID_MAX_DIM
= 9,
72 HSA_AGENT_INFO_GRID_MAX_SIZE
= 10,
73 HSA_AGENT_INFO_FBARRIER_MAX_SIZE
= 11,
74 HSA_AGENT_INFO_QUEUES_MAX
= 12,
75 HSA_AGENT_INFO_QUEUE_MIN_SIZE
= 13,
76 HSA_AGENT_INFO_QUEUE_MAX_SIZE
= 14,
77 HSA_AGENT_INFO_NODE
= 16,
78 HSA_AGENT_INFO_DEVICE
= 17,
79 HSA_AGENT_INFO_CACHE_SIZE
= 18,
80 HSA_AGENT_INFO_FAST_F16_OPERATION
= 24,
84 HSA_SYSTEM_INFO_VERSION_MAJOR
= 0,
85 HSA_SYSTEM_INFO_VERSION_MINOR
= 1,
89 HSA_AGENT_FEATURE_KERNEL_DISPATCH
= 1,
90 HSA_AGENT_FEATURE_AGENT_DISPATCH
= 2,
91 } hsa_agent_feature_t
;
93 typedef struct hsa_region_s
{
97 typedef struct hsa_isa_s
{
101 hsa_status_t
hsa_system_get_info(hsa_system_info_t attribute
, void *value
);
103 hsa_status_t
hsa_agent_get_info(hsa_agent_t agent
, hsa_agent_info_t attribute
,
106 hsa_status_t
hsa_isa_get_info_alt(hsa_isa_t isa
, hsa_isa_info_t attribute
,
109 hsa_status_t
hsa_iterate_agents(hsa_status_t (*callback
)(hsa_agent_t agent
,
113 hsa_status_t
hsa_agent_iterate_isas(hsa_agent_t agent
,
114 hsa_status_t (*callback
)(hsa_isa_t isa
,
118 typedef struct hsa_signal_s
{
122 #ifdef HSA_LARGE_MODEL
123 typedef int64_t hsa_signal_value_t
;
125 typedef int32_t hsa_signal_value_t
;
128 hsa_status_t
hsa_signal_create(hsa_signal_value_t initial_value
,
129 uint32_t num_consumers
,
130 const hsa_agent_t
*consumers
,
131 hsa_signal_t
*signal
);
133 hsa_status_t
hsa_amd_signal_create(hsa_signal_value_t initial_value
,
134 uint32_t num_consumers
,
135 const hsa_agent_t
*consumers
,
136 uint64_t attributes
, hsa_signal_t
*signal
);
138 hsa_status_t
hsa_signal_destroy(hsa_signal_t signal
);
140 void hsa_signal_store_relaxed(hsa_signal_t signal
, hsa_signal_value_t value
);
142 void hsa_signal_store_screlease(hsa_signal_t signal
, hsa_signal_value_t value
);
144 hsa_signal_value_t
hsa_signal_load_scacquire(hsa_signal_t signal
);
146 void hsa_signal_subtract_screlease(hsa_signal_t signal
,
147 hsa_signal_value_t value
);
150 HSA_SIGNAL_CONDITION_EQ
= 0,
151 HSA_SIGNAL_CONDITION_NE
= 1,
152 } hsa_signal_condition_t
;
155 HSA_WAIT_STATE_BLOCKED
= 0,
156 HSA_WAIT_STATE_ACTIVE
= 1
159 hsa_signal_value_t
hsa_signal_wait_scacquire(hsa_signal_t signal
,
160 hsa_signal_condition_t condition
,
161 hsa_signal_value_t compare_value
,
162 uint64_t timeout_hint
,
163 hsa_wait_state_t wait_state_hint
);
166 HSA_QUEUE_TYPE_MULTI
= 0,
167 HSA_QUEUE_TYPE_SINGLE
= 1,
171 HSA_QUEUE_FEATURE_KERNEL_DISPATCH
= 1,
172 HSA_QUEUE_FEATURE_AGENT_DISPATCH
= 2
173 } hsa_queue_feature_t
;
175 typedef uint32_t hsa_queue_type32_t
;
177 typedef struct hsa_queue_s
{
178 hsa_queue_type32_t type
;
181 #ifdef HSA_LARGE_MODEL
183 #elif defined HSA_LITTLE_ENDIAN
190 hsa_signal_t doorbell_signal
;
196 hsa_status_t
hsa_queue_create(hsa_agent_t agent
, uint32_t size
,
197 hsa_queue_type32_t type
,
198 void (*callback
)(hsa_status_t status
,
199 hsa_queue_t
*source
, void *data
),
200 void *data
, uint32_t private_segment_size
,
201 uint32_t group_segment_size
, hsa_queue_t
**queue
);
203 hsa_status_t
hsa_queue_destroy(hsa_queue_t
*queue
);
205 uint64_t hsa_queue_load_read_index_scacquire(const hsa_queue_t
*queue
);
207 uint64_t hsa_queue_add_write_index_relaxed(const hsa_queue_t
*queue
,
211 HSA_PACKET_TYPE_KERNEL_DISPATCH
= 2,
212 HSA_PACKET_TYPE_BARRIER_AND
= 3,
215 typedef enum { HSA_FENCE_SCOPE_SYSTEM
= 2 } hsa_fence_scope_t
;
218 HSA_PACKET_HEADER_TYPE
= 0,
219 HSA_PACKET_HEADER_ACQUIRE_FENCE_SCOPE
= 9,
220 HSA_PACKET_HEADER_RELEASE_FENCE_SCOPE
= 11
221 } hsa_packet_header_t
;
224 HSA_KERNEL_DISPATCH_PACKET_SETUP_DIMENSIONS
= 0
225 } hsa_kernel_dispatch_packet_setup_t
;
228 HSA_KERNEL_DISPATCH_PACKET_SETUP_WIDTH_DIMENSIONS
= 2
229 } hsa_kernel_dispatch_packet_setup_width_t
;
231 typedef struct hsa_kernel_dispatch_packet_s
{
234 uint16_t workgroup_size_x
;
235 uint16_t workgroup_size_y
;
236 uint16_t workgroup_size_z
;
238 uint32_t grid_size_x
;
239 uint32_t grid_size_y
;
240 uint32_t grid_size_z
;
241 uint32_t private_segment_size
;
242 uint32_t group_segment_size
;
243 uint64_t kernel_object
;
244 #ifdef HSA_LARGE_MODEL
245 void *kernarg_address
;
246 #elif defined HSA_LITTLE_ENDIAN
247 void *kernarg_address
;
251 void *kernarg_address
;
254 hsa_signal_t completion_signal
;
255 } hsa_kernel_dispatch_packet_t
;
257 typedef struct hsa_barrier_and_packet_s
{
261 hsa_signal_t dep_signal
[5];
263 hsa_signal_t completion_signal
;
264 } hsa_barrier_and_packet_t
;
266 typedef enum { HSA_PROFILE_BASE
= 0, HSA_PROFILE_FULL
= 1 } hsa_profile_t
;
269 HSA_EXECUTABLE_STATE_UNFROZEN
= 0,
270 HSA_EXECUTABLE_STATE_FROZEN
= 1
271 } hsa_executable_state_t
;
273 typedef struct hsa_executable_s
{
277 typedef struct hsa_executable_symbol_s
{
279 } hsa_executable_symbol_t
;
282 HSA_EXECUTABLE_SYMBOL_INFO_TYPE
= 0,
283 HSA_EXECUTABLE_SYMBOL_INFO_NAME_LENGTH
= 1,
284 HSA_EXECUTABLE_SYMBOL_INFO_NAME
= 2,
285 HSA_EXECUTABLE_SYMBOL_INFO_VARIABLE_ADDRESS
= 21,
286 HSA_EXECUTABLE_SYMBOL_INFO_VARIABLE_SIZE
= 9,
287 HSA_EXECUTABLE_SYMBOL_INFO_KERNEL_OBJECT
= 22,
288 HSA_EXECUTABLE_SYMBOL_INFO_KERNEL_KERNARG_SEGMENT_SIZE
= 11,
289 HSA_EXECUTABLE_SYMBOL_INFO_KERNEL_GROUP_SEGMENT_SIZE
= 13,
290 HSA_EXECUTABLE_SYMBOL_INFO_KERNEL_PRIVATE_SEGMENT_SIZE
= 14,
291 } hsa_executable_symbol_info_t
;
293 typedef struct hsa_code_object_s
{
298 HSA_SYMBOL_KIND_VARIABLE
= 0,
299 HSA_SYMBOL_KIND_KERNEL
= 1,
300 HSA_SYMBOL_KIND_INDIRECT_FUNCTION
= 2
304 HSA_DEFAULT_FLOAT_ROUNDING_MODE_DEFAULT
= 0,
305 HSA_DEFAULT_FLOAT_ROUNDING_MODE_ZERO
= 1,
306 HSA_DEFAULT_FLOAT_ROUNDING_MODE_NEAR
= 2,
307 } hsa_default_float_rounding_mode_t
;
309 hsa_status_t
hsa_memory_copy(void *dst
, const void *src
, size_t size
);
311 hsa_status_t
hsa_executable_create(hsa_profile_t profile
,
312 hsa_executable_state_t executable_state
,
314 hsa_executable_t
*executable
);
316 hsa_status_t
hsa_executable_create_alt(
317 hsa_profile_t profile
,
318 hsa_default_float_rounding_mode_t default_float_rounding_mode
,
319 const char *options
, hsa_executable_t
*executable
);
321 hsa_status_t
hsa_executable_destroy(hsa_executable_t executable
);
323 hsa_status_t
hsa_executable_freeze(hsa_executable_t executable
,
324 const char *options
);
326 hsa_status_t
hsa_executable_validate(hsa_executable_t executable
,
330 hsa_executable_symbol_get_info(hsa_executable_symbol_t executable_symbol
,
331 hsa_executable_symbol_info_t attribute
,
334 hsa_status_t
hsa_executable_iterate_symbols(
335 hsa_executable_t executable
,
336 hsa_status_t (*callback
)(hsa_executable_t exec
,
337 hsa_executable_symbol_t symbol
, void *data
),
340 hsa_status_t
hsa_executable_get_symbol_by_name(hsa_executable_t executable
,
341 const char *symbol_name
,
342 const hsa_agent_t
*agent
,
343 hsa_executable_symbol_t
*symbol
);
345 hsa_status_t
hsa_code_object_deserialize(void *serialized_code_object
,
346 size_t serialized_code_object_size
,
348 hsa_code_object_t
*code_object
);
350 hsa_status_t
hsa_executable_load_code_object(hsa_executable_t executable
,
352 hsa_code_object_t code_object
,
353 const char *options
);
355 hsa_status_t
hsa_code_object_destroy(hsa_code_object_t code_object
);
357 typedef bool (*hsa_amd_signal_handler
)(hsa_signal_value_t value
, void *arg
);
359 hsa_status_t
hsa_amd_signal_async_handler(hsa_signal_t signal
,
360 hsa_signal_condition_t cond
,
361 hsa_signal_value_t value
,
362 hsa_amd_signal_handler handler
,