xref: /llvm-project/offload/plugins-nextgen/amdgpu/dynamic_hsa/hsa_ext_amd.h (revision 330d8983d25d08580fc1642fea48b2473f47a9da)
1 //===--- amdgpu/dynamic_hsa/hsa_ext_amd.h ------------------------- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // The parts of the hsa api that are presently in use by the amdgpu plugin
10 //
11 //===----------------------------------------------------------------------===//
12 #ifndef HSA_RUNTIME_EXT_AMD_H_
13 #define HSA_RUNTIME_EXT_AMD_H_
14 
15 #include "hsa.h"
16 
17 /* Using this header means we do not know what version library will be linked.
18    Until such point as a CMake level override is requested, default to the
19    minimum. */
20 /*
21  * - 1.0 - initial version
22  */
23 #define HSA_AMD_INTERFACE_VERSION_MAJOR 1
24 #define HSA_AMD_INTERFACE_VERSION_MINOR 0
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 typedef struct hsa_amd_memory_pool_s {
31   uint64_t handle;
32 } hsa_amd_memory_pool_t;
33 
34 typedef enum hsa_amd_memory_pool_global_flag_s {
35   HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_KERNARG_INIT = 1,
36   HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_FINE_GRAINED = 2,
37   HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_COARSE_GRAINED = 4
38 } hsa_amd_memory_pool_global_flag_t;
39 
40 typedef enum {
41   HSA_AMD_SEGMENT_GLOBAL = 0,
42   HSA_AMD_SEGMENT_READONLY = 1,
43   HSA_AMD_SEGMENT_PRIVATE = 2,
44   HSA_AMD_SEGMENT_GROUP = 3,
45 } hsa_amd_segment_t;
46 
47 typedef enum {
48   HSA_AMD_MEMORY_POOL_INFO_SEGMENT = 0,
49   HSA_AMD_MEMORY_POOL_INFO_GLOBAL_FLAGS = 1,
50   HSA_AMD_MEMORY_POOL_INFO_SIZE = 2,
51   HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALLOWED = 5,
52   HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_GRANULE = 6,
53   HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALIGNMENT = 7,
54   HSA_AMD_MEMORY_POOL_INFO_ACCESSIBLE_BY_ALL = 15,
55 } hsa_amd_memory_pool_info_t;
56 
57 typedef enum {
58   HSA_AMD_AGENT_MEMORY_POOL_INFO_ACCESS = 0,
59 } hsa_amd_agent_memory_pool_info_t;
60 
61 typedef enum {
62   HSA_AMD_MEMORY_POOL_ACCESS_NEVER_ALLOWED = 0,
63 } hsa_amd_memory_pool_access_t;
64 
65 typedef enum hsa_amd_agent_info_s {
66   HSA_AMD_AGENT_INFO_CHIP_ID = 0xA000,
67   HSA_AMD_AGENT_INFO_CACHELINE_SIZE = 0xA001,
68   HSA_AMD_AGENT_INFO_COMPUTE_UNIT_COUNT = 0xA002,
69   HSA_AMD_AGENT_INFO_MAX_CLOCK_FREQUENCY = 0xA003,
70   HSA_AMD_AGENT_INFO_PRODUCT_NAME = 0xA009,
71   HSA_AMD_AGENT_INFO_MAX_WAVES_PER_CU = 0xA00A,
72   HSA_AMD_AGENT_INFO_NUM_SIMDS_PER_CU = 0xA00B,
73   HSA_AMD_AGENT_INFO_COOPERATIVE_QUEUES = 0xA010,
74   HSA_AMD_AGENT_INFO_TIMESTAMP_FREQUENCY = 0xA016,
75 } hsa_amd_agent_info_t;
76 
77 hsa_status_t hsa_amd_memory_pool_get_info(hsa_amd_memory_pool_t memory_pool,
78                                           hsa_amd_memory_pool_info_t attribute,
79                                           void *value);
80 
81 hsa_status_t hsa_amd_agent_iterate_memory_pools(
82     hsa_agent_t agent,
83     hsa_status_t (*callback)(hsa_amd_memory_pool_t memory_pool, void *data),
84     void *data);
85 
86 hsa_status_t hsa_amd_memory_pool_allocate(hsa_amd_memory_pool_t memory_pool,
87                                           size_t size, uint32_t flags,
88                                           void **ptr);
89 
90 hsa_status_t hsa_amd_memory_pool_free(void *ptr);
91 
92 hsa_status_t hsa_amd_memory_async_copy(void *dst, hsa_agent_t dst_agent,
93                                        const void *src, hsa_agent_t src_agent,
94                                        size_t size, uint32_t num_dep_signals,
95                                        const hsa_signal_t *dep_signals,
96                                        hsa_signal_t completion_signal);
97 
98 hsa_status_t hsa_amd_agent_memory_pool_get_info(
99     hsa_agent_t agent, hsa_amd_memory_pool_t memory_pool,
100     hsa_amd_agent_memory_pool_info_t attribute, void *value);
101 
102 hsa_status_t hsa_amd_agents_allow_access(uint32_t num_agents,
103                                          const hsa_agent_t *agents,
104                                          const uint32_t *flags,
105                                          const void *ptr);
106 
107 hsa_status_t hsa_amd_memory_lock(void* host_ptr, size_t size,
108                                 hsa_agent_t* agents, int num_agent,
109                                 void** agent_ptr);
110 
111 hsa_status_t hsa_amd_memory_unlock(void* host_ptr);
112 
113 hsa_status_t hsa_amd_memory_fill(void *ptr, uint32_t value, size_t count);
114 
115 typedef enum hsa_amd_event_type_s {
116   HSA_AMD_GPU_MEMORY_FAULT_EVENT = 0,
117 } hsa_amd_event_type_t;
118 
119 typedef struct hsa_amd_gpu_memory_fault_info_s {
120   hsa_agent_t agent;
121   uint64_t virtual_address;
122   uint32_t fault_reason_mask;
123 } hsa_amd_gpu_memory_fault_info_t;
124 
125 typedef struct hsa_amd_event_s {
126   hsa_amd_event_type_t event_type;
127   union {
128     hsa_amd_gpu_memory_fault_info_t memory_fault;
129   };
130 } hsa_amd_event_t;
131 
132 typedef hsa_status_t (*hsa_amd_system_event_callback_t)(
133     const hsa_amd_event_t *event, void *data);
134 
135 hsa_status_t
136 hsa_amd_register_system_event_handler(hsa_amd_system_event_callback_t callback,
137                                       void *data);
138 
139 typedef enum {
140   HSA_AMD_MEMORY_FAULT_PAGE_NOT_PRESENT = 1 << 0,
141   HSA_AMD_MEMORY_FAULT_READ_ONLY = 1 << 1,
142   HSA_AMD_MEMORY_FAULT_NX = 1 << 2,
143   HSA_AMD_MEMORY_FAULT_HOST_ONLY = 1 << 3,
144   HSA_AMD_MEMORY_FAULT_DRAMECC = 1 << 4,
145   HSA_AMD_MEMORY_FAULT_IMPRECISE = 1 << 5,
146   HSA_AMD_MEMORY_FAULT_SRAMECC = 1 << 6,
147   HSA_AMD_MEMORY_FAULT_HANG = 1 << 31
148 } hsa_amd_memory_fault_reason_t;
149 
150 typedef enum {
151   HSA_EXT_POINTER_TYPE_UNKNOWN = 0,
152   HSA_EXT_POINTER_TYPE_HSA = 1,
153   HSA_EXT_POINTER_TYPE_LOCKED = 2
154 } hsa_amd_pointer_type_t;
155 
156 typedef struct hsa_amd_pointer_info_s {
157   uint32_t size;
158   hsa_amd_pointer_type_t type;
159   void* agentBaseAddress;
160   void* hostBaseAddress;
161   size_t sizeInBytes;
162 } hsa_amd_pointer_info_t;
163 
164 hsa_status_t hsa_amd_pointer_info(const void* ptr,
165                                           hsa_amd_pointer_info_t* info,
166                                           void* (*alloc)(size_t),
167                                           uint32_t* num_agents_accessible,
168                                           hsa_agent_t** accessible);
169 
170 #ifdef __cplusplus
171 }
172 #endif
173 
174 #endif
175