From 2789ea429a8f0f32ff68e21858a21f4b04be9e82 Mon Sep 17 00:00:00 2001 From: Shadi Dashmiz <94885391+shadidashmiz@users.noreply.github.com> Date: Mon, 5 Jan 2026 11:33:11 -0500 Subject: [PATCH] SWDEV-565300: Fix coherency range mode in mem pool pointers (#2296) Signed-off-by: sdashmiz --- projects/clr/rocclr/device/rocm/rocdevice.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/projects/clr/rocclr/device/rocm/rocdevice.cpp b/projects/clr/rocclr/device/rocm/rocdevice.cpp index 2c907e2f19..ad1f993578 100644 --- a/projects/clr/rocclr/device/rocm/rocdevice.cpp +++ b/projects/clr/rocclr/device/rocm/rocdevice.cpp @@ -2514,8 +2514,8 @@ bool Device::SetSvmAttributes(const void* dev_ptr, size_t count, amd::MemoryAdvi // ================================================================================================ bool Device::GetSvmAttributes(void** data, size_t* data_sizes, int* attributes, size_t num_attributes, const void* dev_ptr, size_t count) const { + amd::Memory* svm_mem = amd::MemObjMap::FindMemObj(dev_ptr); if (settings().hmmFlags_ & Settings::Hmm::EnableSvmTracking) { - amd::Memory* svm_mem = amd::MemObjMap::FindMemObj(dev_ptr); if ((nullptr == svm_mem) || ((svm_mem->getMemFlags() & CL_MEM_ALLOC_HOST_PTR) == 0) || // Validate the range of provided memory ((svm_mem->getSize() - (reinterpret_cast(dev_ptr) - @@ -2548,6 +2548,14 @@ bool Device::GetSvmAttributes(void** data, size_t* data_sizes, int* attributes, *reinterpret_cast(data[i]) = HSA_AMD_SVM_GLOBAL_FLAG_FINE_GRAINED; } } + // If coherency is still indeterminate + if (ptr_info.type == HSA_EXT_POINTER_TYPE_HSA_VMEM) { + if (svm_mem != nullptr && (svm_mem->getMemFlags() & CL_MEM_SVM_FINE_GRAIN_BUFFER)) { + *reinterpret_cast(data[i]) = HSA_AMD_SVM_GLOBAL_FLAG_FINE_GRAINED; + } else { + *reinterpret_cast(data[i]) = HSA_AMD_SVM_GLOBAL_FLAG_COARSE_GRAINED; + } + } } } @@ -2588,7 +2596,10 @@ bool Device::GetSvmAttributes(void** data, size_t* data_sizes, int* attributes, break; } } - + // Only call svm_attributes_get if there are SVM attributes to query + if (attr.empty()) { + return true; + } hsa_status_t status = Hsa::svm_attributes_get(const_cast(dev_ptr), count, attr.data(), attr.size()); if (status != HSA_STATUS_SUCCESS) {