【发布时间】:2021-11-29 08:45:11
【问题描述】:
我正在尝试使用 VK_EXT_external_memory_host 扩展 https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VK_EXT_external_memory_host.html。我不确定vk::ExternalMemoryHandleTypeFlagBits::eHostAllocationEXT 和eHostMappedForeignMemoryEXT 之间的区别是什么,但我一直无法工作。 (我正在使用 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 );
当DeviceMemory 的构造函数调用vkAllocateMemory 如果EXTERNAL_MEMORY_TYPE = eHostAllocationEXT 和内存中的零如果EXTERNAL_MEMORY_TYPE = eHostMappedForeignMemoryEXT 时我得到Result::eErrorOutOfDeviceMemory(我已经检查了我要导入的py/libtorch 张量是非-zero,并且我的代码成功地复制和回读了不同的缓冲区)。
MEMORY_TYPE_INDEX 的所有值都会产生相同的行为(MEMORY_TYPE_INDEX 溢出时除外)。
getMemoryHostPointerPropertiesEXT 返回的位掩码的设置位假定为MEMORY_TYPE_INDEX 提供有效值。
auto pointerProperties = device.getMemoryHostPointerPropertiesEXT(
EXTERNAL_MEMORY_TYPE,
data_ptr);
std::cout << "memoryTypeBits " << std::bitset<32>(pointerProperties.memoryTypeBits) << std::endl;
}
但如果EXTERNAL_MEMORY_TYPE = eHostMappedForeignMemoryEXT,则vkGetMemoryHostPointerPropertiesEXT 返回Result::eErrorInitializationFailed,如果EXTERNAL_MEMORY_TYPE = eHostAllocationEXT,则设置第8 位和第9 位。但是不管data_ptr是cuda指针0x7ffecf400000还是cpu指针0x2be7c80都是一样的,所以我感觉出了点问题。
我也无法获得VK_KHR_external_memory 所需的扩展名VK_KHR_external_memory_capabilities,这是我们使用的扩展名VK_EXT_external_memory_host 的要求。我正在使用 vulkan 版本 1.2.162.0。
eErrorOutOfDeviceMemory 很奇怪,因为我们不应该分配任何内存,如果有人能推测一下,我会很高兴。
【问题讨论】:
标签: memory-management cuda gpu interop vulkan