Skip to content

Cuda interop #517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Closed

Cuda interop #517

wants to merge 14 commits into from

Conversation

devshgraphicsprogramming
Copy link
Member

Description

Testing

TODO list:

Comment on lines 121 to 124
void chainPreDestroyCleanup(std::unique_ptr<ICleanup> first)
{
ICleanup::chain(m_cachedCreationParams.preDestroyCleanup, std::move(first));
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the cleanups are not meant to be dynamic, all the cleanups you'll ever need are required to be specified in the SCreationParams

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fact you've added this method tells me one thing, you're attempting to use the system to make the Nabla object hold onto something after it has already been created, probably the CUDA resource that you've created from it. Esp because you're hooking into the pre-destroy cleanup.

Whereas the intended use is for Nabla object to hold onto some external resoruce it has been created from.

In the case where you have a Nabla object, owned and created by Nabla, being exported, which created an object in some other API that needs to be destroyed before the Nabla object...

The correct way is for the other API object wrapper to hold a smart_Refctd_ptr to the Nabla object it was imported from.

Comment on lines 17 to 24
std::unique_ptr<ICleanup> next;

static void chain(std::unique_ptr<ICleanup>& first, std::unique_ptr<ICleanup>&& next)
{
if (first)
return chain(first->next, std::move(next));
first = std::move(next);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't like it being the default, if you want to chain up cleanups the proper way would be to either:

  • have a "metacleanup" that inherits from multiple cleanups (and each of them virtually from ICleanup)
  • have this same chain, but in a CLinkedListCleanup final

Anyway this is probably not needed for anything due to what I think is the misuse of the API https://github.com/Devsh-Graphics-Programming/Nabla/pull/517/files#r1264588641

@@ -423,6 +423,8 @@ class NBL_API2 ILogicalDevice : public core::IReferenceCounted, public IDeviceMe
//
virtual void unmapMemory(IDeviceMemoryAllocation* memory) = 0;

virtual void* getExternalMemoryHandle(IDeviceMemoryBacked* obj) const = 0;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need it though?

We already have getExternalMemoryHandle on the IDeviceMemoryBacked itself

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDeviceMemoryBacked calls this one and caches the returned handle. This could be removed. Also, I think these handles need to be released by platform specific functions such as CloseHandle on win32 so we might be needing to track them.

Comment on lines +414 to 415
const char* nvrtc64_versions[] = { "nvrtc64_120", "nvrtc64_111","nvrtc64_110","nvrtc64_102","nvrtc64_101","nvrtc64_100","nvrtc64_92","nvrtc64_91","nvrtc64_90","nvrtc64_80","nvrtc64_75","nvrtc64_70",nullptr };
const char* nvrtc64_suffices[] = {"","_","_0","_1","_2",nullptr};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw CUDA 11 had 8 minor versions, and 12 has 3 minor versions, so you're probably missing a few in the version table

Comment on lines 780 to 786
VkMemoryGetWin32HandleInfoKHR getHandleInfo = {
.sType = VK_STRUCTURE_TYPE_MEMORY_GET_WIN32_HANDLE_INFO_KHR,
.memory = vkHandle,
.handleType = VkExternalMemoryHandleTypeFlagBits(obj->getCachedCreationParams().externalHandleType.value),
};
void* handle = 0;
if(VK_SUCCESS == m_devf.vk.vkGetMemoryWin32HandleKHR(m_vkdev, &getHandleInfo, &handle))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please guard Windows specific code with the appropriate #ifdef NBL_....._PLATFORM_....

.semaphore = semaphore,
.handleType = static_cast<VkExternalSemaphoreHandleTypeFlagBits>(params.externalHandleType.value),
};
if (VK_SUCCESS != m_devf.vk.vkGetSemaphoreWin32HandleKHR(m_vkdev, &props, &params.externalHandle))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd make sure you follow the same pattern as you do with Buffers/Images, which is not to hotpatch the creation parameters (because we can no longer tell if the thing was created from an import or created for export)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm aware this broke the pattern with the external resources. Although atm CUDA can only import semaphores so we don't need to deal with imports on nabla side.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with refcounted osHandles we will no longer need to know/care if object was created from import or to export

Comment on lines 902 to 903
bufferMemoryReqs.prefersDedicatedAllocation = vk_dedicatedMemoryRequirements.prefersDedicatedAllocation;
bufferMemoryReqs.requiresDedicatedAllocation = vk_dedicatedMemoryRequirements.requiresDedicatedAllocation;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

override these two with true if external or assert that they were true, unless your requirements are not true here
https://github.com/Devsh-Graphics-Programming/Nabla/pull/517/files#r1264590615

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make it clear, unlike textures it is not required for external buffers to have dedicated allocations. It's just easier for us to make them dedicated.

@devshgraphicsprogramming devshgraphicsprogramming changed the base branch from master to vulkan_1_3 January 4, 2024 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants