I'm trying to use the VK_EXT_external_memory_host extension https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VK_EXT_external_memory_host.html. I'm not sure what the difference is between vk::ExternalMemoryHandleTypeFlagBits::eHostAllocationEXT
and eHostMappedForeignMemoryEXT
but I've been failing to get either to work. (I'm using VulkanHpp).
void* data_ptr = getTorchDataPtr();
uint32_t MEMORY_TYPE_INDEX;
auto EXTERNAL_MEMORY_TYPE = vk::ExternalMemoryHandleTypeFlagBits::eHostAllocationEXT;
// or vk::ExternalMemoryHandleTypeFlagBits::eHostMappedForeignMemoryEXT;
vk::MemoryAllocateInfo memoryAllocateInfo(SIZE_BYTES, MEMORY_TYPE_INDEX);
vk::ImportMemoryHostPointerInfoEXT importMemoryHostPointerInfoEXT(
MEMORY_FLAG,
data_ptr);
memoryAllocateInfo.pNext = &importMemoryHostPointerInfoEXT;
vk::raii::DeviceMemory deviceMemory( device, memoryAllocateInfo );
I'm getting Result::eErrorOutOfDeviceMemory
when the constructor of DeviceMemory
calls vkAllocateMemory
if EXTERNAL_MEMORY_TYPE = eHostAllocationEXT
and zeros in the memory if EXTERNAL_MEMORY_TYPE = eHostMappedForeignMemoryEXT
(I've checked the py/libtorch tensor I'm importing is non-zero, and that my code successfully copies and readbacks a different buffer).
All values of MEMORY_TYPE_INDEX
produce the same behaviour (except when MEMORY_TYPE_INDEX overflows).
The set bits of the bitmask returned by getMemoryHostPointerPropertiesEXT
is suppose to give the valid values for MEMORY_TYPE_INDEX
.
auto pointerProperties = device.getMemoryHostPointerPropertiesEXT(
EXTERNAL_MEMORY_TYPE,
data_ptr);
std::cout << "memoryTypeBits " << std::bitset<32>(pointerProperties.memoryTypeBits) << std::endl;
}
But if EXTERNAL_MEMORY_TYPE = eHostMappedForeignMemoryEXT
then vkGetMemoryHostPointerPropertiesEXT
returns Result::eErrorInitializationFailed
, and if EXTERNAL_MEMORY_TYPE = eHostAllocationEXT
, then the 8th and 9th bits are set. But this is the same regardless of whether data_ptr
is a cuda pointer 0x7ffecf400000
or a cpu pointer 0x2be7c80
so I'm feeling something has gone wrong.
I'm also unable to get the extension VK_KHR_external_memory_capabilities
which is required by VK_KHR_external_memory
which is a requirement of the extension we are using VK_EXT_external_memory_host
. I'm using vulkan version 1.2.162.0.
The eErrorOutOfDeviceMemory
is strange as we are not supposed to be allocating any memory, I'd be glad if someone could speculate about this.