SWDEV-539145 - Support extended fine grained system memory pool (#603)
* Add hipHostMalloc() new flag hipHostMallocUncached which will force to allocate pinned host memory on extended fine grained system memory pool. * Add hipHostAlloc() new flag hipHostAllocUncached which will force to allocate pinned host memory on extended fine grained system memory pool. * Add hipHostRegister() new flag hipHostRegisterUncached which will force to map host memory onto extended fine grained system momory pool.
This commit is contained in:
@@ -400,8 +400,19 @@ hipError_t ihipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags)
|
||||
}
|
||||
|
||||
unsigned int ihipFlags = CL_MEM_SVM_FINE_GRAIN_BUFFER;
|
||||
if (flags & hipHostMallocUncached) {
|
||||
if (IS_WINDOWS) {
|
||||
return hipErrorInvalidValue;
|
||||
}
|
||||
if (flags & (hipHostMallocNonCoherent | hipHostMallocCoherent)) {
|
||||
return hipErrorInvalidValue;
|
||||
}
|
||||
ihipFlags |= ROCCLR_MEM_HSA_UNCACHED;
|
||||
}
|
||||
|
||||
if (flags == 0 ||
|
||||
flags & (hipHostMallocCoherent | hipHostMallocMapped | hipHostMallocNumaUser) ||
|
||||
flags & (hipHostMallocCoherent | hipHostMallocMapped | hipHostMallocNumaUser |
|
||||
hipHostMallocUncached) ||
|
||||
(!(flags & hipHostMallocNonCoherent) && HIP_HOST_COHERENT)) {
|
||||
ihipFlags |= CL_MEM_SVM_ATOMICS;
|
||||
}
|
||||
@@ -1332,11 +1343,21 @@ hipError_t hipHostGetFlags(unsigned int* flagsPtr, void* hostPtr) {
|
||||
}
|
||||
|
||||
hipError_t ihipHostRegister(void* hostPtr, size_t sizeBytes, unsigned int flags) {
|
||||
if (hostPtr == nullptr || sizeBytes == 0 || flags > 15) {
|
||||
if (hostPtr == nullptr || sizeBytes == 0 ||
|
||||
flags & ~(hipHostRegisterPortable | hipHostRegisterMapped |
|
||||
hipExtHostRegisterCoarseGrained | hipExtHostRegisterUncached)) {
|
||||
return hipErrorInvalidValue;
|
||||
} else {
|
||||
unsigned int memFlags = CL_MEM_USE_HOST_PTR | CL_MEM_SVM_ATOMICS;
|
||||
if (flags & hipExtHostRegisterUncached) {
|
||||
if (IS_WINDOWS) {
|
||||
return hipErrorInvalidValue;
|
||||
}
|
||||
memFlags |= ROCCLR_MEM_HSA_UNCACHED;
|
||||
}
|
||||
|
||||
amd::Memory* mem = new (*hip::host_context) amd::Buffer(*hip::host_context,
|
||||
CL_MEM_USE_HOST_PTR | CL_MEM_SVM_ATOMICS, sizeBytes);
|
||||
memFlags, sizeBytes);
|
||||
|
||||
constexpr bool sysMemAlloc = false;
|
||||
constexpr bool skipAlloc = false;
|
||||
@@ -1358,6 +1379,7 @@ hipError_t ihipHostRegister(void* hostPtr, size_t sizeBytes, unsigned int flags)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (mem != nullptr) {
|
||||
mem->getUserData().deviceId = hip::getCurrentDevice()->deviceId();
|
||||
// Save the HIP memory flags so that they can be accessed later
|
||||
@@ -1416,8 +1438,8 @@ hipError_t hipHostAlloc(void** ptr, size_t sizeBytes, unsigned int flags) {
|
||||
if (ptr == nullptr) {
|
||||
HIP_RETURN(hipErrorInvalidValue);
|
||||
}
|
||||
if (flags > (hipHostAllocPortable | hipHostAllocMapped |
|
||||
hipHostAllocWriteCombined)) {
|
||||
if (flags & ~(hipHostAllocPortable | hipHostAllocMapped |
|
||||
hipHostAllocWriteCombined | hipHostAllocUncached)) {
|
||||
HIP_RETURN(hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
@@ -4300,4 +4322,4 @@ hipError_t hipMemGetHandleForAddressRange(void* handle, hipDeviceptr_t dptr, siz
|
||||
HIP_RETURN(hipSuccess);
|
||||
}
|
||||
|
||||
} // namespace hip
|
||||
} // namespace hip
|
||||
|
||||
Reference in New Issue
Block a user