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 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 typedef struct hsa_amd_memory_pool_s { 22 uint64_t handle; 23 } hsa_amd_memory_pool_t; 24 25 typedef enum hsa_amd_memory_pool_global_flag_s { 26 HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_KERNARG_INIT = 1, 27 HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_FINE_GRAINED = 2, 28 HSA_AMD_MEMORY_POOL_GLOBAL_FLAG_COARSE_GRAINED = 4 29 } hsa_amd_memory_pool_global_flag_t; 30 31 typedef enum { 32 HSA_AMD_SEGMENT_GLOBAL = 0, 33 HSA_AMD_SEGMENT_READONLY = 1, 34 HSA_AMD_SEGMENT_PRIVATE = 2, 35 HSA_AMD_SEGMENT_GROUP = 3, 36 } hsa_amd_segment_t; 37 38 typedef enum { 39 HSA_AMD_MEMORY_POOL_INFO_SEGMENT = 0, 40 HSA_AMD_MEMORY_POOL_INFO_GLOBAL_FLAGS = 1, 41 HSA_AMD_MEMORY_POOL_INFO_SIZE = 2, 42 HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALLOWED = 5, 43 HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_GRANULE = 6, 44 HSA_AMD_MEMORY_POOL_INFO_RUNTIME_ALLOC_ALIGNMENT = 7, 45 HSA_AMD_MEMORY_POOL_INFO_ACCESSIBLE_BY_ALL = 15, 46 } hsa_amd_memory_pool_info_t; 47 48 typedef enum { 49 HSA_AMD_AGENT_MEMORY_POOL_INFO_ACCESS = 0, 50 } hsa_amd_agent_memory_pool_info_t; 51 52 typedef enum { 53 HSA_AMD_MEMORY_POOL_ACCESS_NEVER_ALLOWED = 0, 54 } hsa_amd_memory_pool_access_t; 55 56 typedef enum hsa_amd_agent_info_s { 57 HSA_AMD_AGENT_INFO_CACHELINE_SIZE = 0xA001, 58 HSA_AMD_AGENT_INFO_COMPUTE_UNIT_COUNT = 0xA002, 59 HSA_AMD_AGENT_INFO_MAX_CLOCK_FREQUENCY = 0xA003, 60 HSA_AMD_AGENT_INFO_PRODUCT_NAME = 0xA009, 61 HSA_AMD_AGENT_INFO_MAX_WAVES_PER_CU = 0xA00A, 62 HSA_AMD_AGENT_INFO_NUM_SIMDS_PER_CU = 0xA00B, 63 HSA_AMD_AGENT_INFO_COOPERATIVE_QUEUES = 0xA010 64 } hsa_amd_agent_info_t; 65 66 hsa_status_t hsa_amd_memory_pool_get_info(hsa_amd_memory_pool_t memory_pool, 67 hsa_amd_memory_pool_info_t attribute, 68 void *value); 69 70 hsa_status_t hsa_amd_agent_iterate_memory_pools( 71 hsa_agent_t agent, 72 hsa_status_t (*callback)(hsa_amd_memory_pool_t memory_pool, void *data), 73 void *data); 74 75 hsa_status_t hsa_amd_memory_pool_allocate(hsa_amd_memory_pool_t memory_pool, 76 size_t size, uint32_t flags, 77 void **ptr); 78 79 hsa_status_t hsa_amd_memory_pool_free(void *ptr); 80 81 hsa_status_t hsa_amd_memory_async_copy(void *dst, hsa_agent_t dst_agent, 82 const void *src, hsa_agent_t src_agent, 83 size_t size, uint32_t num_dep_signals, 84 const hsa_signal_t *dep_signals, 85 hsa_signal_t completion_signal); 86 87 hsa_status_t hsa_amd_agent_memory_pool_get_info( 88 hsa_agent_t agent, hsa_amd_memory_pool_t memory_pool, 89 hsa_amd_agent_memory_pool_info_t attribute, void *value); 90 91 hsa_status_t hsa_amd_agents_allow_access(uint32_t num_agents, 92 const hsa_agent_t *agents, 93 const uint32_t *flags, 94 const void *ptr); 95 96 hsa_status_t hsa_amd_memory_lock(void* host_ptr, size_t size, 97 hsa_agent_t* agents, int num_agent, 98 void** agent_ptr); 99 100 hsa_status_t hsa_amd_memory_unlock(void* host_ptr); 101 102 hsa_status_t hsa_amd_memory_fill(void *ptr, uint32_t value, size_t count); 103 104 typedef enum hsa_amd_event_type_s { 105 HSA_AMD_GPU_MEMORY_FAULT_EVENT = 0, 106 } hsa_amd_event_type_t; 107 108 typedef struct hsa_amd_gpu_memory_fault_info_s { 109 hsa_agent_t agent; 110 uint64_t virtual_address; 111 uint32_t fault_reason_mask; 112 } hsa_amd_gpu_memory_fault_info_t; 113 114 typedef struct hsa_amd_event_s { 115 hsa_amd_event_type_t event_type; 116 union { 117 hsa_amd_gpu_memory_fault_info_t memory_fault; 118 }; 119 } hsa_amd_event_t; 120 121 typedef hsa_status_t (*hsa_amd_system_event_callback_t)( 122 const hsa_amd_event_t *event, void *data); 123 124 hsa_status_t 125 hsa_amd_register_system_event_handler(hsa_amd_system_event_callback_t callback, 126 void *data); 127 128 #ifdef __cplusplus 129 } 130 #endif 131 132 #endif 133