Implement hipMemAllocationTypeUncached in hipMemCreate (#747)

* Revert "SWDEV-547589 - Add hipDeviceMallocUncached to hipMemCreate (#815)"

This reverts commit 5ce7103555.

* Revert "SWDEV-547589 - comment for flag hipDeviceMallocUncached in hipMemcreate (#339)"

This reverts commit 04dac5eae3.

* SWDEV-551942 - implement hipMemAllocationTypeUncached in hipMemCreate
This commit is contained in:
Jimbo
2025-08-26 11:34:49 -04:00
committad av GitHub
förälder 202aa7ff8c
incheckning c03048d68e
3 ändrade filer med 16 tillägg och 15 borttagningar
+11 -13
Visa fil
@@ -85,12 +85,9 @@ hipError_t hipMemCreate(hipMemGenericAllocationHandle_t* handle, size_t size,
HIP_INIT_API(hipMemCreate, handle, size, prop, flags);
// Currently we do not support Pinned memory
if (handle == nullptr || size == 0 || prop == nullptr ||
prop->type != hipMemAllocationTypePinned || prop->location.type != hipMemLocationTypeDevice) {
HIP_RETURN(hipErrorInvalidValue);
}
if (flags != hipDeviceMallocUncached && flags != 0) {
if (handle == nullptr || size == 0 || flags != 0 || prop == nullptr ||
(prop->type != hipMemAllocationTypePinned && prop->type != hipMemAllocationTypeUncached) ||
prop->location.type != hipMemLocationTypeDevice) {
HIP_RETURN(hipErrorInvalidValue);
}
@@ -103,6 +100,12 @@ hipError_t hipMemCreate(hipMemGenericAllocationHandle_t* handle, size_t size,
HIP_RETURN(hipErrorNotSupported);
}
// When ROCCLR_MEM_PHYMEM is set, ROCr impl gets and stores unique hsa handle. Flag no-op on PAL.
unsigned int ihipFlags = ROCCLR_MEM_PHYMEM;
if (prop->type == hipMemAllocationTypeUncached) {
ihipFlags |= CL_MEM_SVM_ATOMICS | ROCCLR_MEM_HSA_UNCACHED;
}
// Device info validation
const auto& dev_info = g_devices[prop->location.id]->devices()[0]->info();
@@ -115,13 +118,8 @@ hipError_t hipMemCreate(hipMemGenericAllocationHandle_t* handle, size_t size,
amd::Context* amdContext = g_devices[prop->location.id]->asContext();
// When ROCCLR_MEM_PHYMEM is set, ROCr impl gets and stores unique hsa handle. Flag no-op on PAL.
uint64_t ihipFlags = ROCCLR_MEM_PHYMEM;
if (flags == hipDeviceMallocUncached) {
ihipFlags |= ROCCLR_MEM_HSA_UNCACHED | CL_MEM_SVM_ATOMICS;
}
void* ptr =
amd::SvmBuffer::malloc(*amdContext, ihipFlags, size, dev_info.memBaseAddrAlign_, nullptr);
void* ptr = amd::SvmBuffer::malloc(*amdContext, ihipFlags, size,
dev_info.memBaseAddrAlign_, nullptr);
// Handle out of memory cases,
if (ptr == nullptr) {