From 1bc5af684ce2fd70eea3f5895086136ea79924bb Mon Sep 17 00:00:00 2001 From: Flora Cui Date: Thu, 23 Oct 2025 10:09:23 +0800 Subject: [PATCH] update hsa header Signed-off-by: Flora Cui --- hsa/hsa_amd_tool.h | 6 ++ hsa/hsa_api_trace.h | 2 + hsa/hsa_api_trace_version.h | 2 +- hsa/hsa_ext_amd.h | 123 +++++++++++++++++++++++++++++++++--- 4 files changed, 124 insertions(+), 9 deletions(-) diff --git a/hsa/hsa_amd_tool.h b/hsa/hsa_amd_tool.h index fa9cac804a..22847a8a44 100644 --- a/hsa/hsa_amd_tool.h +++ b/hsa/hsa_amd_tool.h @@ -1,3 +1,9 @@ +/* + * Copyright © Advanced Micro Devices, Inc., or its affiliates. + * + * SPDX-License-Identifier: MIT + */ + #ifndef HSA_RUNTIME_AMD_TOOL_EVENTS_H_ #define HSA_RUNTIME_AMD_TOOL_EVENTS_H_ diff --git a/hsa/hsa_api_trace.h b/hsa/hsa_api_trace.h index 6515b19700..cc33320269 100644 --- a/hsa/hsa_api_trace.h +++ b/hsa/hsa_api_trace.h @@ -271,6 +271,8 @@ struct AmdExtTable { decltype(hsa_amd_signal_wait_all)* hsa_amd_signal_wait_all_fn; decltype(hsa_amd_memory_get_preferred_copy_engine)* hsa_amd_memory_get_preferred_copy_engine_fn; decltype(hsa_amd_portable_export_dmabuf_v2)* hsa_amd_portable_export_dmabuf_v2_fn; + decltype(hsa_amd_ais_file_write)* hsa_amd_ais_file_write_fn; + decltype(hsa_amd_ais_file_read)* hsa_amd_ais_file_read_fn; }; // Table to export HSA Core Runtime Apis diff --git a/hsa/hsa_api_trace_version.h b/hsa/hsa_api_trace_version.h index befd1e26e3..6cf1054823 100644 --- a/hsa/hsa_api_trace_version.h +++ b/hsa/hsa_api_trace_version.h @@ -58,7 +58,7 @@ // Step Ids of the Api tables exported by Hsa Core Runtime #define HSA_API_TABLE_STEP_VERSION 0x01 #define HSA_CORE_API_TABLE_STEP_VERSION 0x00 -#define HSA_AMD_EXT_API_TABLE_STEP_VERSION 0x07 +#define HSA_AMD_EXT_API_TABLE_STEP_VERSION 0x08 #define HSA_FINALIZER_API_TABLE_STEP_VERSION 0x00 #define HSA_IMAGE_API_TABLE_STEP_VERSION 0x01 // Rocprofiler just checks HSA_MAGE_EXT_API_TABLE_STEP_VERSION diff --git a/hsa/hsa_ext_amd.h b/hsa/hsa_ext_amd.h index c402a51264..3fd1f9348e 100644 --- a/hsa/hsa_ext_amd.h +++ b/hsa/hsa_ext_amd.h @@ -62,9 +62,12 @@ * - 1.9 - hsa_amd_portable_export_dmabuf_v2 * - 1.10 - hsa_amd_vmem_address_reserve: HSA_AMD_VMEM_ADDRESS_NO_REGISTER * - 1.11 - hsa_amd_agent_info_t: HSA_AMD_AGENT_INFO_CLOCK_COUNTERS + * - 1.12 - hsa_amd_pointer_info: HSA_EXT_POINTER_TYPE_HSA_VMEM and HSA_EXT_POINTER_TYPE_RESERVED_ADDR + * - 1.13 - hsa_amd_pointer_info: Added new registered field to hsa_amd_pointer_info_t + * - 1.14 - hsa_amd_ais_file_write, hsa_amd_ais_file_read */ #define HSA_AMD_INTERFACE_VERSION_MAJOR 1 -#define HSA_AMD_INTERFACE_VERSION_MINOR 11 +#define HSA_AMD_INTERFACE_VERSION_MINOR 14 #ifdef __cplusplus extern "C" { @@ -1578,7 +1581,10 @@ typedef enum hsa_amd_memory_pool_flag_s { * Allocates executable memory */ HSA_AMD_MEMORY_POOL_EXECUTABLE_FLAG = (1 << 2), - + /** + * Allocates uncached memory + */ + HSA_AMD_MEMORY_POOL_UNCACHED_FLAG = (1 << 3), } hsa_amd_memory_pool_flag_t; /** @@ -1806,8 +1812,6 @@ hsa_status_t HSA_API * * @retval ::HSA_STATUS_ERROR_OUT_OF_RESOURCES Agent does not have available SDMA engines. * - * @retval ::HSA_STATUS_ERROR_INVALID_AGENT dst_agent and src_agent are the same as - * dst_agent == src_agent is generally used for shader copies. */ hsa_status_t HSA_API hsa_amd_memory_copy_engine_status(hsa_agent_t dst_agent, hsa_agent_t src_agent, @@ -1824,8 +1828,6 @@ hsa_amd_memory_copy_engine_status(hsa_agent_t dst_agent, hsa_agent_t src_agent, * * @retval ::HSA_STATUS_SUCCESS For mask returned * - * @retval ::HSA_STATUS_ERROR_INVALID_AGENT dst_agent and src_agent are the same as - * dst_agent == src_agent is generally used for shader copies. */ hsa_status_t HSA_API hsa_amd_memory_get_preferred_copy_engine(hsa_agent_t dst_agent, hsa_agent_t src_agent, @@ -2362,7 +2364,11 @@ typedef enum { /* No backend memory but virtual address */ - HSA_EXT_POINTER_TYPE_RESERVED_ADDR = 5 + HSA_EXT_POINTER_TYPE_RESERVED_ADDR = 5, + /* + Memory was allocated with an HSA virtual memory allocator + */ + HSA_EXT_POINTER_TYPE_HSA_VMEM = 6 } hsa_amd_pointer_type_t; /** @@ -2417,6 +2423,13 @@ typedef struct hsa_amd_pointer_info_s { meaningful if the type of the allocation is HSA_EXT_POINTER_TYPE_UNKNOWN. */ uint32_t global_flags; + + /* + Set to true if this allocation was registered with the underlying driver + This field is not meaningful if the type of the allocation is + HSA_EXT_POINTER_TYPE_UNKNOWN. + */ + bool registered; } hsa_amd_pointer_info_t; /** @@ -3642,12 +3655,106 @@ typedef enum { hsa_status_t hsa_amd_queue_get_info(hsa_queue_t* queue, hsa_queue_info_attribute_t attribute, void* value); +typedef struct hsa_amd_ais_file_handle_s { + /* + * file handle for AIS read & write. Linux will use fd. + * pad is keep the size consistent accross different platforms. + */ + union { + void* handle; + int fd; + uint8_t pad[8]; + }; +} hsa_amd_ais_file_handle_t; + +/** + * @brief Write data from device memory to a file + * + * Writes data from device memory buffer to a file at the specified offset. + * The device memory pointer must be accessible from the host and point to + * a valid allocation. + * + * EXPERIMENTAL: AIS read and write calls are currently in experimental phase and + * APIs may be modified + * + * @param[in] handle Handle of the file to write to. + * + * @param[in] devicePtr Device memory buffer pointer containing data to write. + * + * @param[in] size Size in bytes of the data to write. + * + * @param[in] file_offset Offset in bytes into the file where data will be written. + * + * @param[in/out] size_copied Actual number of bytes copied + * + * @param[in/out] status Additional status if any + * + * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. + * + * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been + * initialized. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p fd is invalid, @p devicePtr + * is NULL, or @p size is 0. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ALLOCATION @p devicePtr does not refer to + * a valid allocation. + * + * @retval ::HSA_STATUS_ERROR An error occurred during the write operation. + */ +hsa_status_t HSA_API hsa_amd_ais_file_write(hsa_amd_ais_file_handle_t handle, void *devicePtr, + uint64_t size, int64_t file_offset, + uint64_t *size_copied, int32_t *status); + +/** + * @brief Read data from a file to device memory + * + * Reads data from a file at the specified offset into a device memory buffer. + * The device memory pointer must be accessible from the host and point to + * a valid allocation. + * + * EXPERIMENTAL: AIS read and write calls are currently in experimental phase and + * APIs may be modified + * @param[in] hanlde Handle of the file to read from. + * + * @param[in] devicePtr Device memory buffer pointer to store the read data. + * + * @param[in] size Size in bytes of the data to read. + * + * @param[in] file_offset Offset in bytes into the file where data will be read from. + * + * @param[in/out] size_copied Actual number of bytes copied + * + * @param[in/out] status Additional status if any + * + * @retval ::HSA_STATUS_SUCCESS The function has been executed successfully. + * + * @retval ::HSA_STATUS_ERROR_NOT_INITIALIZED The HSA runtime has not been + * initialized. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ARGUMENT @p fd is invalid, @p devicePtr + * is NULL, or @p size is 0. + * + * @retval ::HSA_STATUS_ERROR_INVALID_ALLOCATION @p devicePtr does not refer to + * a valid allocation. + * + * @retval ::HSA_STATUS_ERROR An error occurred during the read operation. + */ +hsa_status_t HSA_API hsa_amd_ais_file_read(hsa_amd_ais_file_handle_t handle, void *devicePtr, + uint64_t size, int64_t file_offset, + uint64_t *size_copied, int32_t *status); + /** * @brief logging types */ typedef enum hsa_amd_log_flag_s { - /* Log AQL packets internally enqueued by HSA for Blit Kernels */ + /* Log AQL packets internally enqueued by ROCr */ HSA_AMD_LOG_FLAG_BLIT_KERNEL_PKTS = 0, + HSA_AMD_LOG_FLAG_AQL = 0, + /* Log SDMA packets */ + HSA_AMD_LOG_FLAG_SDMA = 1, + /* Log INFO */ + HSA_AMD_LOG_FLAG_INFO = 2, } hsa_amd_log_flag_t; /**