Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
matyas-streamhpc committed Nov 12, 2024
1 parent cc65cc2 commit 43a781b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions docs/tools/example_codes/external_interop.hip
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ VkBuffer create_buffer(const graphics_context& ctx,
return buffer;
}

// [Sphinx external descriptor start]
/// \brief This function converts a Vulkan memory handle to its equivalent HIP handle. The
/// VkDeviceMemory passed to this function and the returned HIP memory represents the same
/// physical area of GPU memory, through the handles of each respective API. Writing to the
Expand All @@ -431,6 +430,7 @@ VkBuffer create_buffer(const graphics_context& ctx,
hipExternalMemory_t
memory_to_hip(const graphics_context& ctx, const VkDeviceMemory memory, const VkDeviceSize size)
{
// [Sphinx external descriptor start]
// Prepare the HIP external semaphore descriptor with the platform-specific
// handle type that we wish to import. This value should correspond to the
// handleTypes field set in VkExportMemoryAllocateInfoKHR while creating the
Expand Down Expand Up @@ -468,8 +468,8 @@ hipExternalMemory_t
hipExternalMemory_t hip_memory;
HIP_CHECK(hipImportExternalMemory(&hip_memory, &desc));
return hip_memory;
// [Sphinx external descriptor end]
}
// [Sphinx external descriptor end]

/// \brief Utility function to create a Vulkan semaphore.
/// \param external - If true, this semaphore is created so that it can later be exported
Expand Down Expand Up @@ -501,7 +501,6 @@ VkSemaphore create_semaphore(const graphics_context& ctx, const bool external =
return sema;
}

// [Sphinx semaphore use in kernel start]
/// \brief This function converts a Vulkan semaphore to its equivalent HIP handle. The passed
/// semaphore and the returned HIP semaphore represent the same backing semaphore, though the
/// handles of the respective API. Signaling on the semaphore in one API will allow the other
Expand All @@ -512,6 +511,7 @@ VkSemaphore create_semaphore(const graphics_context& ctx, const bool external =
/// \see create_semaphore for creating such a semaphore.
hipExternalSemaphore_t semaphore_to_hip(const graphics_context& ctx, const VkSemaphore sema)
{
// [Sphinx semaphore use in kernel start]
// Prepare the HIP external semaphore descriptor with the platform-specific handle type
// that we wish to import. This value should correspond to the handleTypes field set in
// the VkExportSemaphoreCreateInfoKHR structure that was passed to Vulkan when creating
Expand Down Expand Up @@ -547,26 +547,26 @@ hipExternalSemaphore_t semaphore_to_hip(const graphics_context& ctx, const VkSem
// Import the native semaphore to HIP to create a HIP external semaphore.
hipExternalSemaphore_t hip_sema;
HIP_CHECK(hipImportExternalSemaphore(&hip_sema, &desc));
// [Sphinx semaphore use in kernel end]
return hip_sema;
}
// [Sphinx semaphore use in kernel end]

// [Sphinx external memory use in kernel start]
/// \brief When the HIP external memory is exported from Vulkan and imported to HIP, it
/// is not yet ready for use. To actually use the memory, we need to map it to a pointer
/// so that we may pass it to the kernel so that it can be read from and written to.
void* map_hip_external_memory(const hipExternalMemory_t mem, const VkDeviceSize size)
{
// [Sphinx external memory use in kernel start]
hipExternalMemoryBufferDesc desc = {};
desc.offset = 0;
desc.size = size;
desc.flags = 0;

void* ptr;
HIP_CHECK(hipExternalMemoryGetMappedBuffer(&ptr, mem, &desc));
// [Sphinx external memory use in kernel end]
return ptr;
}
// [Sphinx external memory use in kernel end]

/// \brief The main HIP kernel for this example - computes a simple sine wave over a
/// 2-dimensional grid of points.
Expand Down

0 comments on commit 43a781b

Please sign in to comment.