rocr: Add hsa_amd_portable_export_dmabuf_v2

The original version of hsa_amd_portable_export_dmabuf() did not
consider the conditions under which a dmabuf could be shared.
In the new version (hsa_amd_portable_export_dmabuf_v2()), the caller
can specify the flag HSA_AMD_DMABUF_MAPPING_TYPE_PCIE, which means they
want to share the dmabuf over PCIe. In that case, the new code will check
that if it is a PCIe GPU and it is not in a XGMI Hive then if
large-BAR is not supported, we will return an error.
Ta zmiana jest zawarta w:
Chris Freehill authored and Freehill, Chris committed 2025-06-09 15:42:58 -05:00
1 rodzic dce52be686
złożenie 3a9d14bb66
11 plików zmienionych
+114 -23

Żadne pliki nie pasują do Twojego wyszukiwania

+2 -1
Wyświetl plik
@@ -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 = 600;
constexpr size_t expected_amd_ext_table_size = 608;
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;
@@ -476,6 +476,7 @@ void HsaApiTable::UpdateAmdExts() {
amd_ext_api.hsa_amd_enable_logging_fn = AMD::hsa_amd_enable_logging;
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;
}
void HsaApiTable::UpdateTools() {
+16 -2
Wyświetl plik
@@ -1307,14 +1307,28 @@ hsa_status_t hsa_amd_spm_set_dest_buffer(hsa_agent_t preferred_agent, size_t siz
}
hsa_status_t hsa_amd_portable_export_dmabuf(const void* ptr, size_t size, int* dmabuf,
uint64_t* offset) {
uint64_t* offset) {
TRY;
IS_OPEN();
IS_BAD_PTR(ptr);
IS_BAD_PTR(dmabuf);
IS_BAD_PTR(offset);
IS_ZERO(size);
return core::Runtime::runtime_singleton_->DmaBufExport(ptr, size, dmabuf,
offset, HSA_AMD_DMABUF_MAPPING_TYPE_NONE);
CATCH;
}
hsa_status_t hsa_amd_portable_export_dmabuf_v2(const void* ptr, size_t size,
int* dmabuf, uint64_t* offset, uint64_t flags) {
TRY;
IS_OPEN();
IS_BAD_PTR(ptr);
IS_BAD_PTR(dmabuf);
IS_BAD_PTR(offset);
IS_ZERO(size);
return core::Runtime::runtime_singleton_->DmaBufExport(ptr, size, dmabuf, offset);
return core::Runtime::runtime_singleton_->DmaBufExport(ptr, size,
dmabuf, offset, flags);
CATCH;
}
+10 -2
Wyświetl plik
@@ -3078,7 +3078,8 @@ Agent* Runtime::GetSVMPrefetchAgent(void* ptr, size_t size) {
return agents_by_node_[prefetch_node][0];
}
hsa_status_t Runtime::DmaBufExport(const void* ptr, size_t size, int* dmabuf, uint64_t* offset) {
hsa_status_t Runtime::DmaBufExport(const void* ptr, size_t size, int* dmabuf,
uint64_t* offset, uint64_t flags) {
#ifdef __linux__
ScopedAcquire<KernelSharedMutex::Shared> lock(memory_lock_.shared());
// Lookup containing allocation.
@@ -3093,6 +3094,14 @@ hsa_status_t Runtime::DmaBufExport(const void* ptr, size_t size, int* dmabuf, ui
if (mem->second.region->owner()->device_type() != Agent::kAmdGpuDevice)
return HSA_STATUS_ERROR_INVALID_AGENT;
rocr::AMD::GpuAgent* owner =
static_cast<AMD::GpuAgent*>(mem->second.region->owner());
if (flags & HSA_AMD_DMABUF_MAPPING_TYPE_PCIE &&
!owner->is_xgmi_cpu_gpu() &&
!owner->LargeBarEnabled()) {
return (hsa_status_t)HSA_STATUS_ERROR_NOT_SUPPORTED;
}
int fd;
uint64_t off;
HSAKMT_STATUS err = HSAKMT_CALL(hsaKmtExportDMABufHandle(const_cast<void*>(ptr), size, &fd, &off));
@@ -3319,7 +3328,6 @@ hsa_status_t Runtime::VMemoryHandleUnmap(void* va, size_t size) {
if (va_chunk != va_ptr + size) {
return HSA_STATUS_ERROR_INVALID_ALLOCATION;
}
hsa_status_t status;
for (auto mappedHandleIt : mappedHandles) {
// Remove access from all agents that were allowed access