Users/hkasivis/add ais support v2.1 (#928)

* libhsakmt: Update hsakmt_fmm_get_handle to support address range

Currently, hsakmt_fmm_get_handle works only if the address is allocated
(staring) value. Update it so it can find the handle if address falls in
the valid allocated range. This is useful for AMD infinity storage
feature where data needs to be transferred to any memory within in the
allocated range

Signed-off-by: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>

* libhsakmt: Introduce AMD Infinity Storage (AIS) API

Add hsaKmtAisReadWriteFile() API to support AMD Infinity Storage. The
API moves data directly from GPU VRAM to a file.

v2: Add in/out ioctl arguments to provide more status information to
user space. Modify hsaKmt API also accordingly.

Signed-off-by: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>

* rocr: Initial implementation of AMD Infinity Storage (AIS)

Implement first two API: hsa_amd_ais_file_write and hsa_amd_ais_file_read

v2: Change API from hsa_amd_ to hsa_amd_ais_
    Change API to take in handle instead of fd for compatibility accross
     different platforms

Original Author: Chris Freehill <Chris.Freehill@amd.com>
Signed-off-by: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>

---------

Signed-off-by: Harish Kasiviswanathan <Harish.Kasiviswanathan@amd.com>
This commit is contained in:
hkasivis
2025-09-20 11:30:05 -04:00
committed by GitHub
parent 7137c7f3d8
commit 5e7210980e
19 changed files with 376 additions and 10 deletions
@@ -87,7 +87,7 @@ void HsaApiTable::Init() {
// they can add preprocessor macros on the new functions
constexpr size_t expected_core_api_table_size = 1016;
constexpr size_t expected_amd_ext_table_size = 608;
constexpr size_t expected_amd_ext_table_size = 624;
constexpr size_t expected_image_ext_table_size = 128;
constexpr size_t expected_finalizer_ext_table_size = 64;
constexpr size_t expected_tools_table_size = 64;
@@ -474,6 +474,8 @@ void HsaApiTable::UpdateAmdExts() {
amd_ext_api.hsa_amd_agent_set_async_scratch_limit_fn = AMD::hsa_amd_agent_set_async_scratch_limit;
amd_ext_api.hsa_amd_queue_get_info_fn = AMD::hsa_amd_queue_get_info;
amd_ext_api.hsa_amd_enable_logging_fn = AMD::hsa_amd_enable_logging;
amd_ext_api.hsa_amd_ais_file_write_fn = AMD::hsa_amd_ais_file_write;
amd_ext_api.hsa_amd_ais_file_read_fn = AMD::hsa_amd_ais_file_read;
amd_ext_api.hsa_amd_signal_wait_all_fn = AMD::hsa_amd_signal_wait_all;
amd_ext_api.hsa_amd_memory_get_preferred_copy_engine_fn = AMD::hsa_amd_memory_get_preferred_copy_engine;
amd_ext_api.hsa_amd_portable_export_dmabuf_v2_fn = AMD::hsa_amd_portable_export_dmabuf_v2;
@@ -1537,6 +1537,45 @@ hsa_status_t HSA_API hsa_amd_queue_get_info(hsa_queue_t* _queue,
CATCH;
}
hsa_status_t 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) {
TRY;
IS_OPEN();
if (devicePtr == nullptr || size == 0) {
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
}
// Call the kernel module function through the thunk layer
HSAKMT_STATUS ret = HSAKMT_CALL(hsaKmtAisReadWriteFile)(devicePtr, size, handle.fd,
file_offset, HSA_AIS_WRITE,
size_copied, status);
return (ret == HSAKMT_STATUS_SUCCESS) ?
HSA_STATUS_SUCCESS : HSA_STATUS_ERROR;
CATCH;
}
hsa_status_t 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) {
TRY;
IS_OPEN();
if (devicePtr == nullptr || size == 0) {
return HSA_STATUS_ERROR_INVALID_ARGUMENT;
}
// Call the kernel module function through the thunk layer
HSAKMT_STATUS ret = HSAKMT_CALL(hsaKmtAisReadWriteFile)(devicePtr, size, handle.fd,
file_offset, HSA_AIS_READ,
size_copied, status);
return (ret == HSAKMT_STATUS_SUCCESS) ? HSA_STATUS_SUCCESS : HSA_STATUS_ERROR;
CATCH;
}
hsa_status_t hsa_amd_enable_logging(uint8_t* flags, void *file) {
TRY;
return core::Runtime::runtime_singleton_->EnableLogging(flags, file);
@@ -387,6 +387,9 @@ namespace core {
DRM_PFN(amdgpu_device_initialize) = (DRM_DEF(amdgpu_device_initialize)*)dlsym(thunk_handle, "amdgpu_device_initialize");
if (DRM_PFN(amdgpu_device_initialize) == NULL) goto ERROR;
HSAKMT_PFN(hsaKmtAisReadWriteFile) = (HSAKMT_DEF(hsaKmtAisReadWriteFile)*)dlsym(thunk_handle, "hsaKmtAisReadWriteFile");
if (HSAKMT_PFN(hsaKmtAisReadWriteFile) == NULL) goto ERROR;
DRM_PFN(amdgpu_device_deinitialize) = (DRM_DEF(amdgpu_device_deinitialize)*)dlsym(thunk_handle, "amdgpu_device_deinitialize");
if (DRM_PFN(amdgpu_device_deinitialize) == NULL) goto ERROR;
@@ -511,6 +514,7 @@ ERROR:
HSAKMT_PFN(hsaKmtQueueRingDoorbell) = (HSAKMT_DEF(hsaKmtQueueRingDoorbell)*)(&hsaKmtQueueRingDoorbell);
#endif
HSAKMT_PFN(hsaKmtModelEnabled) = (HSAKMT_DEF(hsaKmtModelEnabled)*)(&hsaKmtModelEnabled);
HSAKMT_PFN(hsaKmtAisReadWriteFile) = (HSAKMT_DEF(hsaKmtAisReadWriteFile)*)(&hsaKmtAisReadWriteFile);
DRM_PFN(amdgpu_device_initialize) = (DRM_DEF(amdgpu_device_initialize)*)(&amdgpu_device_initialize);
DRM_PFN(amdgpu_device_deinitialize) = (DRM_DEF(amdgpu_device_deinitialize)*)(&amdgpu_device_deinitialize);