From 3e6721df9f61d4cc6c4fd77ea2e466d671f25d4d Mon Sep 17 00:00:00 2001 From: David Yat Sin Date: Wed, 9 Nov 2022 14:57:11 +0000 Subject: [PATCH] Allow page-aligned len for ipc_memory_create Previous versions of HIP will call hsa_amd_ipc_memory_create with then len aligned to granularity. Temporarily allow this so that we go not break backward compability. Will remove this after 2 releaes Change-Id: I6b5ac2cad5d32d62c803637cf1a2c6deebc03169 [ROCm/ROCR-Runtime commit: cb71e2d715332bc6836e50c6e586a47e5e644645] --- .../runtime/hsa-runtime/core/runtime/runtime.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp index 50eac54c0b..39e2ba8e97 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp @@ -913,6 +913,9 @@ hsa_status_t Runtime::SetPtrInfoData(const void* ptr, void* userptr) { hsa_status_t Runtime::IPCCreate(void* ptr, size_t len, hsa_amd_ipc_memory_t* handle) { static_assert(sizeof(hsa_amd_ipc_memory_t) == sizeof(HsaSharedMemoryHandle), "Thunk IPC mismatch."); + + static const size_t pageSize = 4096; + // Reject sharing allocations larger than ~8TB due to thunk limitations. if (len > 0x7FFFFFFF000ull) return HSA_STATUS_ERROR_INVALID_ARGUMENT; @@ -922,8 +925,14 @@ hsa_status_t Runtime::IPCCreate(void* ptr, size_t len, hsa_amd_ipc_memory_t* han info.size = sizeof(info); if (PtrInfo(ptr, &info, nullptr, nullptr, nullptr, &block) != HSA_STATUS_SUCCESS) return HSA_STATUS_ERROR_INVALID_ARGUMENT; - if ((info.agentBaseAddress != ptr) || (info.sizeInBytes != len)) + + // Temporary: Previous versions of HIP will call hsa_amd_ipc_memory_create with the len aligned to + // granularity. We need to maintain backward compatibility for 2 releases so we temporarily allow + // this. After 2 releases, we will only allow info.sizeInBytes != len. + if ((info.agentBaseAddress != ptr) || + (info.sizeInBytes != len && AlignUp(info.sizeInBytes, pageSize) != len)) { return HSA_STATUS_ERROR_INVALID_ARGUMENT; + } if ((block.base != ptr) || (block.length != len)) { if (!IsMultipleOf(block.base, 2 * 1024 * 1024)) { assert(false && "Fragment's block not aligned to 2MB!");