From ffb380a710cba31f8285e0c79f8cf4a1fba93c77 Mon Sep 17 00:00:00 2001 From: "systems-assistant[bot]" <221163467+systems-assistant[bot]@users.noreply.github.com> Date: Fri, 17 Oct 2025 16:32:00 -0700 Subject: [PATCH] SWDEV-491279 - add stream capture test for ExternalMemory APIs (#570) Co-authored-by: Li, Todd tiantuo --- .../hipDestroyExternalMemory.cc | 28 ++++++++++ .../hipExternalMemoryGetMappedBuffer.cc | 38 ++++++++++++++ ...ipExternalMemoryGetMappedMipmappedArray.cc | 52 +++++++++++++++++++ .../vulkan_interop/hipImportExternalMemory.cc | 32 ++++++++++++ 4 files changed, 150 insertions(+) diff --git a/projects/hip-tests/catch/unit/vulkan_interop/hipDestroyExternalMemory.cc b/projects/hip-tests/catch/unit/vulkan_interop/hipDestroyExternalMemory.cc index cb1b0766cd..85c78316f8 100644 --- a/projects/hip-tests/catch/unit/vulkan_interop/hipDestroyExternalMemory.cc +++ b/projects/hip-tests/catch/unit/vulkan_interop/hipDestroyExternalMemory.cc @@ -45,3 +45,31 @@ TEST_CASE("Unit_hipDestroyExternalMemory_Vulkan_Negative_Parameters") { } #endif } + +/** + * Test Description + * ------------------------ + * - Test hipDestroyExternalMemory while stream is capturing. + * Test source + * ------------------------ + * - unit/vulkan_interop/hipDestroyExternalMemory.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 6.0 + */ +TEST_CASE("Unit_hipDestroyExternalMemory_Vulkan_Capture") { +// Segfaults in CUDA +// Disabled on AMD due to defect - EXSWHTEC-187 +#if HT_AMD && 0 + VulkanTest vkt(enable_validation); + const auto storage = vkt.CreateMappedStorage(1, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true); + auto desc = vkt.BuildMemoryDescriptor(storage.memory, sizeof(*storage.host_ptr)); + hipExternalMemory_t ext_memory; + HIP_CHECK(hipImportExternalMemory(&ext_memory, &desc)); + + hipError_t memcpy_err = hipSuccess; + BEGIN_CAPTURE_SYNC(memcpy_err, true); + HIP_CHECK_ERROR(hipDestroyExternalMemory(ext_memory), memcpy_err); + END_CAPTURE_SYNC(memcpy_err); +#endif +} \ No newline at end of file diff --git a/projects/hip-tests/catch/unit/vulkan_interop/hipExternalMemoryGetMappedBuffer.cc b/projects/hip-tests/catch/unit/vulkan_interop/hipExternalMemoryGetMappedBuffer.cc index a2f4dc0b68..2dfaedc588 100644 --- a/projects/hip-tests/catch/unit/vulkan_interop/hipExternalMemoryGetMappedBuffer.cc +++ b/projects/hip-tests/catch/unit/vulkan_interop/hipExternalMemoryGetMappedBuffer.cc @@ -157,3 +157,41 @@ TEST_CASE("Unit_hipExternalMemoryGetMappedBuffer_Vulkan_Negative_Parameters") { } #endif } + +/** + * Test Description + * ------------------------ + * - Test hipExternalMemoryGetMappedBuffer while stream is capturing. + * Test source + * ------------------------ + * - unit/vulkan_interop/hipExternalMemoryGetMappedBuffer.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 6.0 + */ +TEST_CASE("Unit_hipExternalMemoryGetMappedBuffer_Vulkan_Capture") { + VulkanTest vkt(enable_validation); + using type = uint8_t; + constexpr uint32_t count = 3; + + const auto vk_storage = + vkt.CreateMappedStorage(count, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true); + if (vk_storage.memory == nullptr) { + return; + } + const auto hip_ext_mem_desc = vkt.BuildMemoryDescriptor(vk_storage.memory, vk_storage.size); + hipExternalMemory_t hip_ext_memory; + HIP_CHECK(hipImportExternalMemory(&hip_ext_memory, &hip_ext_mem_desc)); + + hipExternalMemoryBufferDesc external_mem_buffer_desc = {}; + external_mem_buffer_desc.size = vk_storage.size; + type* hip_dev_ptr = nullptr; + + hipError_t memcpy_err = hipSuccess; + BEGIN_CAPTURE_SYNC(memcpy_err, true); + HIP_CHECK_ERROR(hipExternalMemoryGetMappedBuffer(reinterpret_cast(&hip_dev_ptr), + hip_ext_memory, &external_mem_buffer_desc), + memcpy_err); + END_CAPTURE_SYNC(memcpy_err); + REQUIRE(nullptr != hip_dev_ptr); +} \ No newline at end of file diff --git a/projects/hip-tests/catch/unit/vulkan_interop/hipExternalMemoryGetMappedMipmappedArray.cc b/projects/hip-tests/catch/unit/vulkan_interop/hipExternalMemoryGetMappedMipmappedArray.cc index 5487c38f1d..3d8e340eec 100644 --- a/projects/hip-tests/catch/unit/vulkan_interop/hipExternalMemoryGetMappedMipmappedArray.cc +++ b/projects/hip-tests/catch/unit/vulkan_interop/hipExternalMemoryGetMappedMipmappedArray.cc @@ -212,3 +212,55 @@ TEST_CASE("Unit_hipExternalMemoryGetMappedMipmappedArray_Vulkan_Negative_Paramet HIP_CHECK(hipDestroyExternalMemory(ext_memory)); } + +/** + * Test Description + * ------------------------ + * - Test hipExternalMemoryGetMappedMipmappedArray while stream is capturing. + * Test source + * ------------------------ + * - unit/vulkan_interop/hipExternalMemoryGetMappedMipmappedArray.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 6.0 + */ +TEST_CASE("Unit_hipExternalMemoryGetMappedMipmappedArray_Vulkan_Capture") { + VulkanTest vkt(enable_validation); + using type = uint8_t; + // cubemap HIP array is allocated if all three extents are non-zero and the hipArrayCubemap + // flag is set. Width must be equal to height, and depth must be six + constexpr uint32_t cube_size = 32; + constexpr uint32_t depth = 6; + constexpr uint32_t ext_mem_size = cube_size * cube_size * depth; + + const auto vk_storage = + vkt.CreateMappedStorage(ext_mem_size, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true); + if (vk_storage.memory == nullptr) { + return; + } + + const auto ext_mem_desc = vkt.BuildMemoryDescriptor(vk_storage.memory, vk_storage.size); + hipExternalMemory_t ext_memory; + HIP_CHECK(hipImportExternalMemory(&ext_memory, &ext_mem_desc)); + + hipExternalMemoryMipmappedArrayDesc mipmapped_arr_desc = {}; + mipmapped_arr_desc.extent = {}; + mipmapped_arr_desc.extent.width = cube_size; + mipmapped_arr_desc.extent.height = cube_size; + mipmapped_arr_desc.extent.depth = depth; + mipmapped_arr_desc.flags = hipArrayCubemap; + mipmapped_arr_desc.formatDesc = hipCreateChannelDesc(); + mipmapped_arr_desc.numLevels = GENERATE(1, 2, 4); + mipmapped_arr_desc.offset = 0; + hipMipmappedArray_t mipmapped_arr = nullptr; + + hipError_t memcpy_err = hipSuccess; + BEGIN_CAPTURE_SYNC(memcpy_err, true); + HIP_CHECK_ERROR( + hipExternalMemoryGetMappedMipmappedArray(&mipmapped_arr, ext_memory, &mipmapped_arr_desc), + memcpy_err); + END_CAPTURE_SYNC(memcpy_err); + + HIP_CHECK(hipFreeMipmappedArray(mipmapped_arr)); + HIP_CHECK(hipDestroyExternalMemory(ext_memory)); +} \ No newline at end of file diff --git a/projects/hip-tests/catch/unit/vulkan_interop/hipImportExternalMemory.cc b/projects/hip-tests/catch/unit/vulkan_interop/hipImportExternalMemory.cc index db541ea287..10cb9697cb 100644 --- a/projects/hip-tests/catch/unit/vulkan_interop/hipImportExternalMemory.cc +++ b/projects/hip-tests/catch/unit/vulkan_interop/hipImportExternalMemory.cc @@ -78,3 +78,35 @@ TEST_CASE("Unit_hipImportExternalMemory_Vulkan_Negative_Parameters") { } #endif } + +/** + * Test Description + * ------------------------ + * - Test hipImportExternalMemory while stream is capturing. + * Test source + * ------------------------ + * - unit/vulkan_interop/hipImportExternalMemory.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 6.0 + */ +TEST_CASE("Unit_hipImportExternalMemory_Vulkan_Capture") { + VulkanTest vkt(enable_validation); + using type = uint8_t; + constexpr uint32_t count = 2; + + const auto vk_storage = + vkt.CreateMappedStorage(count, VK_BUFFER_USAGE_TRANSFER_DST_BIT, true); + if (vk_storage.memory == nullptr) { + return; + } + + const auto hip_ext_mem_desc = vkt.BuildMemoryDescriptor(vk_storage.memory, vk_storage.size); + hipExternalMemory_t hip_ext_memory; + + hipError_t memcpy_err = hipSuccess; + BEGIN_CAPTURE_SYNC(memcpy_err, true); + HIP_CHECK_ERROR(hipImportExternalMemory(&hip_ext_memory, &hip_ext_mem_desc), + memcpy_err); + END_CAPTURE_SYNC(memcpy_err); +} \ No newline at end of file