Skip to content

fix: add missing CUDA error check + correct Vulkan enum type mismatch - #414

Open
Scottcjn wants to merge 1 commit into
NVIDIA:masterfrom
Scottcjn:fix/cuda-error-check-and-vulkan-enum
Open

fix: add missing CUDA error check + correct Vulkan enum type mismatch#414
Scottcjn wants to merge 1 commit into
NVIDIA:masterfrom
Scottcjn:fix/cuda-error-check-and-vulkan-enum

Conversation

@Scottcjn

@Scottcjn Scottcjn commented Mar 26, 2026

Copy link
Copy Markdown

Summary

Two small fixes.

1. Missing error check on cuDeviceGetName (#413)

File: cpp/7_libNVVM/simple/simple.c:72

cuDeviceGetName() is called without checkCudaErrors(), so on failure the sample prints an uninitialised name buffer. Every other driver API call in cudaDeviceInit() is wrapped, so this just brings it in line.

2. Wrong Vulkan enum family in external memory import (#409)

File: cpp/5_Domain_Specific/simpleVulkan/main.cpp:331-337

importCudaExternalMemory() takes a VkExternalMemoryHandleTypeFlagBits handleType, but tests it against VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_* constants, which belong to VkExternalSemaphoreHandleTypeFlagBits. Replaced with the matching VK_EXTERNAL_MEMORY_HANDLE_TYPE_* constants.

This is a type correctness fix with no behavioural change, because the two enums use the same bit values:

memory semaphore
OPAQUE_FD_BIT 0x00000001 0x00000001
OPAQUE_WIN32_BIT 0x00000002 0x00000002
OPAQUE_WIN32_KMT_BIT 0x00000004 0x00000004

(An earlier version of this description said VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT was 0x00000001. That was wrong, it is 0x00000002. The values above are from vulkan_core.h in KhronosGroup/Vulkan-Headers.)

The other two VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_* sites in this file, at lines 369 and 379, are inside importCudaExternalSemaphore(), whose parameter really is VkExternalSemaphoreHandleTypeFlagBits. Those are correct and are deliberately left alone.

Fixes #413, Fixes #409

1. simple.c: Wrap cuDeviceGetName() with checkCudaErrors() to catch
   failures instead of silently using uninitialized device name.
   Fixes NVIDIA#413

2. simpleVulkan/main.cpp: Replace VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_*
   with VK_EXTERNAL_MEMORY_HANDLE_TYPE_* when checking memory handle
   type. The parameter is VkExternalMemoryHandleTypeFlagBits, not
   semaphore flags. Works by coincidence (same bit values) but is
   incorrect per the Vulkan spec.
   Fixes NVIDIA#409
@Scottcjn
Scottcjn force-pushed the fix/cuda-error-check-and-vulkan-enum branch from 9732801 to d474bc4 Compare May 15, 2026 16:51
@Scottcjn

Copy link
Copy Markdown
Author

Rebased against current upstream master. Ready for re-review.

@Scottcjn

Copy link
Copy Markdown
Author

Checking in on this. The added CUDA error check and Vulkan external-memory fix are small and self-contained. Happy to adjust if a maintainer has a preferred style.

@jnbntz

jnbntz commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Hi @Scottcjn we are in the process of reworking the CUDA Samples repo, so we'll take a look at this in due time, thanks.

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.

Missing check for CUDA failure in example Potential bug in simpleVulkan example

2 participants