From 4bae839601caced8e01a4b7a087655574a201188 Mon Sep 17 00:00:00 2001 From: Marko Arandjelovic Date: Mon, 23 Dec 2024 22:24:41 +0530 Subject: [PATCH] SWDEV-499927 - Fix param handling in hipMemAccess APIs Change-Id: If7c168e28fc94137abf33e4083b7af9515f24298 [ROCm/hipother commit: 011c022e70199af6cf5663e2540345a1cdd25943] --- .../nvidia_detail/nvidia_hip_runtime_api.h | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/projects/hipother/hipnv/include/hip/nvidia_detail/nvidia_hip_runtime_api.h b/projects/hipother/hipnv/include/hip/nvidia_detail/nvidia_hip_runtime_api.h index 769f4f9d56..1169bd5ea1 100644 --- a/projects/hipother/hipnv/include/hip/nvidia_detail/nvidia_hip_runtime_api.h +++ b/projects/hipother/hipnv/include/hip/nvidia_detail/nvidia_hip_runtime_api.h @@ -2844,11 +2844,14 @@ inline static CUmemLocation hipMemLocationToCUmemLocation(const hipMemLocation* cuLoc.type = (CUmemLocationType)loc->type; return cuLoc; } -inline static CUmemAccessDesc hipMemAccessDescToCUmemAccessDesc(const hipMemAccessDesc* desc) { - CUmemAccessDesc cuDesc; - cuDesc.flags = (CUmemAccess_flags)desc->flags; - cuDesc.location.id = (desc->location).id; - cuDesc.location.type = (CUmemLocationType)((desc->location).type); +inline static CUmemAccessDesc* hipMemAccessDescToCUmemAccessDesc(const hipMemAccessDesc* desc, + size_t count) { + CUmemAccessDesc* cuDesc = (CUmemAccessDesc*)malloc(sizeof(CUmemAccessDesc) * count); + for (int i = 0; i < count; i++) { + cuDesc[i].flags = (CUmemAccess_flags)desc[i].flags; + cuDesc[i].location.id = (desc[i].location).id; + cuDesc[i].location.type = (CUmemLocationType)((desc[i].location).type); + } return cuDesc; } inline static hipError_t hipMemGetAllocationGranularity(size_t* granularity, @@ -2925,8 +2928,14 @@ inline static hipError_t hipMemRetainAllocationHandle(hipMemGenericAllocationHan inline static hipError_t hipMemSetAccess(hipDeviceptr_t ptr, size_t size, const hipMemAccessDesc* desc, size_t count) { - CUmemAccessDesc cuDesc = hipMemAccessDescToCUmemAccessDesc(desc); - return hipCUResultTohipError(cuMemSetAccess(ptr, size, &cuDesc, count)); + if (desc == NULL) { + return hipCUResultTohipError(cuMemSetAccess(ptr, size, NULL, count)); + } else { + CUmemAccessDesc* cuDesc = hipMemAccessDescToCUmemAccessDesc(desc, count); + auto status = hipCUResultTohipError(cuMemSetAccess(ptr, size, cuDesc, count)); + free(cuDesc); + return status; + } } inline static hipError_t hipMemUnmap(hipDeviceptr_t ptr, size_t size) { return hipCUResultTohipError(cuMemUnmap(ptr, size));