SWDEV-245532 - HIP - Vulkan interop

Change-Id: Iba1ef8112e318b4f099da5a4a4602e0dae7de9e3


[ROCm/hip commit: a1b321bba4]
This commit is contained in:
pghafari
2021-03-19 18:36:13 -04:00
committed by Payam Ghafari
parent 362629f2e8
commit 5242decbc0
4 changed files with 128 additions and 3 deletions
+53
View File
@@ -25,6 +25,7 @@
#include "platform/context.hpp"
#include "platform/command.hpp"
#include "platform/memory.hpp"
#include "amdocl/cl_vk_amd.hpp"
// ================================================================================================
amd::Memory* getMemoryObject(const void* ptr, size_t& offset) {
@@ -105,6 +106,58 @@ hipError_t ihipFree(void *ptr)
return hipErrorInvalidValue;
}
hipError_t hipImportExternalMemory(hipExternalMemory_t* extMem_out, const hipExternalMemoryHandleDesc* memHandleDesc) {
HIP_INIT_API(hipImportExternalMemory, extMem_out, memHandleDesc);
size_t sizeBytes = memHandleDesc->size;
amd::Context& amdContext = *hip::getCurrentDevice()->asContext();
amd::BufferVk* pBufferVk = nullptr;
#ifdef _WIN32
pBufferVk = new (amdContext) amd::BufferVk(amdContext, sizeBytes, memHandleDesc->handle.win32.handle);
#else
pBufferVk = new (amdContext) amd::BufferVk(amdContext, sizeBytes, memHandleDesc->handle.fd);
#endif
if (!pBufferVk) {
HIP_RETURN(hipErrorOutOfMemory);
}
if (!pBufferVk->create()) {
pBufferVk->release();
HIP_RETURN(hipErrorOutOfMemory);
}
*extMem_out = pBufferVk;
HIP_RETURN(hipSuccess);
}
hipError_t hipExternalMemoryGetMappedBuffer(void **devPtr, hipExternalMemory_t extMem, const hipExternalMemoryBufferDesc *bufferDesc) {
HIP_INIT_API(hipExternalMemoryGetMappedBuffer, devPtr, extMem, bufferDesc);
if (extMem == nullptr) {
HIP_RETURN(hipErrorInvalidValue);
}
amd::BufferVk *buf = reinterpret_cast<amd::BufferVk*>(extMem);
const device::Memory* devMem = buf->getDeviceMemory(*hip::getCurrentDevice()->devices()[0]);
if (devMem != nullptr) {
*devPtr = reinterpret_cast<void*>(devMem->virtualAddress());
}
HIP_RETURN(hipSuccess);
}
hipError_t hipDestroyExternalMemory(hipExternalMemory_t extMem) {
HIP_INIT_API(hipDestroyExternalMemory, extMem);
if (extMem == nullptr) {
HIP_RETURN(hipErrorInvalidValue);
}
reinterpret_cast<amd::BufferVk*>(extMem)->release();
HIP_RETURN(hipSuccess);
}
// ================================================================================================
hipError_t ihipMalloc(void** ptr, size_t sizeBytes, unsigned int flags)
{