Initial support for HIP managed memory
- Call the new ROCclr interfaces for HMM
Change-Id: I2cd1bf438f712a9e9e328340e7d0c025257ca6c1
[ROCm/hip commit: f4211c3905]
This commit is contained in:
@@ -105,6 +105,7 @@ hipError_t ihipMalloc(void** ptr, size_t sizeBytes, unsigned int flags)
|
||||
return hipSuccess;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
hipError_t ihipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind kind,
|
||||
amd::HostQueue& queue, bool isAsync = false) {
|
||||
if (sizeBytes == 0) {
|
||||
@@ -154,36 +155,26 @@ hipError_t ihipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKin
|
||||
*srcMemory->asBuffer(), sOffset, sizeBytes, dst);
|
||||
isAsync = false;
|
||||
} else if ((srcMemory != nullptr) && (dstMemory != nullptr)) {
|
||||
if (queueDevice != srcMemory->getContext().devices()[0]) {
|
||||
amd::Coord3D srcOffset(sOffset, 0, 0);
|
||||
amd::Coord3D dstOffset(dOffset, 0, 0);
|
||||
amd::Coord3D copySize(sizeBytes, 1, 1);
|
||||
if ((kind == hipMemcpyDeviceToDevice) &&
|
||||
// Check if the queue device doesn't match the device on any memory object. Hence
|
||||
// it's a P2P transfer, because the app has requested access to another GPU
|
||||
(srcMemory->getContext().devices()[0] != dstMemory->getContext().devices()[0])) {
|
||||
command = new amd::CopyMemoryP2PCommand(queue, CL_COMMAND_COPY_BUFFER, waitList,
|
||||
*srcMemory->asBuffer(),*dstMemory->asBuffer(), srcOffset, dstOffset, copySize);
|
||||
command->enqueue();
|
||||
if (!isAsync) {
|
||||
command->awaitCompletion();
|
||||
*srcMemory->asBuffer(), *dstMemory->asBuffer(), sOffset, dOffset, sizeBytes);
|
||||
if (command == nullptr) {
|
||||
return hipErrorOutOfMemory;
|
||||
}
|
||||
command->release();
|
||||
return hipSuccess;
|
||||
}
|
||||
if (queueDevice != dstMemory->getContext().devices()[0]) {
|
||||
amd::Coord3D srcOffset(sOffset, 0, 0);
|
||||
amd::Coord3D dstOffset(dOffset, 0, 0);
|
||||
amd::Coord3D copySize(sizeBytes, 1, 1);
|
||||
command = new amd::CopyMemoryP2PCommand(queue, CL_COMMAND_COPY_BUFFER, waitList,
|
||||
*srcMemory->asBuffer(),*dstMemory->asBuffer(), srcOffset, dstOffset, copySize);
|
||||
command->enqueue();
|
||||
if (!isAsync) {
|
||||
command->awaitCompletion();
|
||||
// Make sure runtime has valid memory for the command execution. P2P access
|
||||
// requires page table mapping on the current device to another GPU memory
|
||||
if (!static_cast<amd::CopyMemoryP2PCommand*>(command)->validateMemory()) {
|
||||
delete command;
|
||||
return hipErrorInvalidValue;
|
||||
}
|
||||
command->release();
|
||||
return hipSuccess;
|
||||
} else {
|
||||
command = new amd::CopyMemoryCommand(queue, CL_COMMAND_COPY_BUFFER, waitList,
|
||||
*srcMemory->asBuffer(), *dstMemory->asBuffer(), sOffset, dOffset, sizeBytes);
|
||||
}
|
||||
command = new amd::CopyMemoryCommand(queue, CL_COMMAND_COPY_BUFFER, waitList,
|
||||
*srcMemory->asBuffer(),*dstMemory->asBuffer(), sOffset, dOffset, sizeBytes);
|
||||
}
|
||||
|
||||
if (command == nullptr) {
|
||||
return hipErrorOutOfMemory;
|
||||
}
|
||||
@@ -201,6 +192,7 @@ hipError_t ihipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKin
|
||||
return hipSuccess;
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
hipError_t hipExtMallocWithFlags(void** ptr, size_t sizeBytes, unsigned int flags) {
|
||||
HIP_INIT_API(hipExtMallocWithFlags, ptr, sizeBytes, flags);
|
||||
|
||||
@@ -245,17 +237,6 @@ hipError_t hipHostMalloc(void** ptr, size_t sizeBytes, unsigned int flags) {
|
||||
HIP_RETURN(ihipMalloc(ptr, sizeBytes, ihipFlags), *ptr);
|
||||
}
|
||||
|
||||
hipError_t hipMallocManaged(void** devPtr, size_t size,
|
||||
unsigned int flags) {
|
||||
HIP_INIT_API(hipMallocManaged, devPtr, size, flags);
|
||||
|
||||
if (flags != hipMemAttachGlobal) {
|
||||
HIP_RETURN(hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
HIP_RETURN(ihipMalloc(devPtr, size, CL_MEM_SVM_FINE_GRAIN_BUFFER), *devPtr);
|
||||
}
|
||||
|
||||
hipError_t hipFree(void* ptr) {
|
||||
HIP_INIT_API(hipFree, ptr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user