Debian Codegraph @

offload/plugins-nextgen/amdgpu/dynamic_hsa/hsa_ext_amd.h

raw
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_MEMORY_MAX_FREQUENCY = 0xA008,
71 HSA_AMD_AGENT_INFO_PRODUCT_NAME = 0xA009,
72 HSA_AMD_AGENT_INFO_MAX_WAVES_PER_CU = 0xA00A,
73 HSA_AMD_AGENT_INFO_NUM_SIMDS_PER_CU = 0xA00B,
74 HSA_AMD_AGENT_INFO_COOPERATIVE_QUEUES = 0xA010,
75 HSA_AMD_AGENT_INFO_UUID = 0xA011,
76 HSA_AMD_AGENT_INFO_TIMESTAMP_FREQUENCY = 0xA016,
77 } hsa_amd_agent_info_t;
78
79 hsa_status_t hsa_amd_memory_pool_get_info(hsa_amd_memory_pool_t memory_pool,
80 hsa_amd_memory_pool_info_t attribute,
81 void *value);
82
83 hsa_status_t hsa_amd_agent_iterate_memory_pools(
84 hsa_agent_t agent,
85 hsa_status_t (*callback)(hsa_amd_memory_pool_t memory_pool, void *data),
86 void *data);
87
88 hsa_status_t hsa_amd_memory_pool_allocate(hsa_amd_memory_pool_t memory_pool,
89 size_t size, uint32_t flags,
90 void **ptr);
91
92 hsa_status_t hsa_amd_memory_pool_free(void *ptr);
93
94 hsa_status_t hsa_amd_memory_async_copy(void *dst, hsa_agent_t dst_agent,
95 const void *src, hsa_agent_t src_agent,
96 size_t size, uint32_t num_dep_signals,
97 const hsa_signal_t *dep_signals,
98 hsa_signal_t completion_signal);
99
100 hsa_status_t hsa_amd_agent_memory_pool_get_info(
101 hsa_agent_t agent, hsa_amd_memory_pool_t memory_pool,
102 hsa_amd_agent_memory_pool_info_t attribute, void *value);
103
104 hsa_status_t hsa_amd_agents_allow_access(uint32_t num_agents,
105 const hsa_agent_t *agents,
106 const uint32_t *flags,
107 const void *ptr);
108
109 hsa_status_t hsa_amd_memory_lock(void* host_ptr, size_t size,
110 hsa_agent_t* agents, int num_agent,
111 void** agent_ptr);
112
113 hsa_status_t hsa_amd_memory_unlock(void* host_ptr);
114
115 hsa_status_t hsa_amd_memory_fill(void *ptr, uint32_t value, size_t count);
116
117 typedef enum hsa_amd_event_type_s {
118 HSA_AMD_GPU_MEMORY_FAULT_EVENT = 0,
119 } hsa_amd_event_type_t;
120
121 typedef struct hsa_amd_gpu_memory_fault_info_s {
122 hsa_agent_t agent;
123 uint64_t virtual_address;
124 uint32_t fault_reason_mask;
125 } hsa_amd_gpu_memory_fault_info_t;
126
127 typedef struct hsa_amd_event_s {
128 hsa_amd_event_type_t event_type;
129 union {
130 hsa_amd_gpu_memory_fault_info_t memory_fault;
131 };
132 } hsa_amd_event_t;
133
134 typedef hsa_status_t (*hsa_amd_system_event_callback_t)(
135 const hsa_amd_event_t *event, void *data);
136
137 hsa_status_t
138 hsa_amd_register_system_event_handler(hsa_amd_system_event_callback_t callback,
139 void *data);
140
141 typedef enum {
142 HSA_AMD_MEMORY_FAULT_PAGE_NOT_PRESENT = 1 << 0,
143 HSA_AMD_MEMORY_FAULT_READ_ONLY = 1 << 1,
144 HSA_AMD_MEMORY_FAULT_NX = 1 << 2,
145 HSA_AMD_MEMORY_FAULT_HOST_ONLY = 1 << 3,
146 HSA_AMD_MEMORY_FAULT_DRAMECC = 1 << 4,
147 HSA_AMD_MEMORY_FAULT_IMPRECISE = 1 << 5,
148 HSA_AMD_MEMORY_FAULT_SRAMECC = 1 << 6,
149 HSA_AMD_MEMORY_FAULT_HANG = 1 << 31
150 } hsa_amd_memory_fault_reason_t;
151
152 typedef enum {
153 HSA_EXT_POINTER_TYPE_UNKNOWN = 0,
154 HSA_EXT_POINTER_TYPE_HSA = 1,
155 HSA_EXT_POINTER_TYPE_LOCKED = 2
156 } hsa_amd_pointer_type_t;
157
158 typedef struct hsa_amd_pointer_info_s {
159 uint32_t size;
160 hsa_amd_pointer_type_t type;
161 void* agentBaseAddress;
162 void* hostBaseAddress;
163 size_t sizeInBytes;
164 } hsa_amd_pointer_info_t;
165
166 hsa_status_t hsa_amd_pointer_info(const void* ptr,
167 hsa_amd_pointer_info_t* info,
168 void* (*alloc)(size_t),
169 uint32_t* num_agents_accessible,
170 hsa_agent_t** accessible);
171
172 #ifdef __cplusplus
173 }
174 #endif
175
176 #endif