Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions nanovdb/nanovdb/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,17 @@ nanovdb_example(NAME "ex_coarsen_nanovdb_cuda" OPENVDB)
nanovdb_example(NAME "ex_mesh_to_grid_cuda" OPENVDB)

if(CUDAToolkit_FOUND)
nanovdb_example(NAME "ex_make_mgpu_nanovdb") # requires cuRAND
target_link_libraries(ex_make_mgpu_nanovdb PRIVATE CUDA::curand)
# ex_make_mgpu_nanovdb uses TF32 WMMA which requires SM_80+ (Ampere or newer)
execute_process(
COMMAND bash -c "nvidia-smi --query-gpu=compute_cap --format=csv,noheader 2>/dev/null | sort -n | tail -1 | tr -d '.'"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What if you're building on a machine that doesn't have a GPU and going to run it on an SM >=8.0 machine? Or are we assuming all examples are built/run on the same machine and/or they're not used as CI tests (which might have this behaviour)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For Windows, assuming availability of bash is a hard requirement. Can we rely on something like CMAKE_CUDA_ARCHITECTURES (see, e.g. this) instead of probing the local machine with bash and nvidia-smi?

@apradhana apradhana Aug 5, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I asked Codex to scan CMAKE_CUDA_ARCHITECTURES and only add target if at least one architecture is >=80

if(CUDAToolkit_FOUND)
  set(_nanovdb_has_sm80 OFF)

  foreach(_cuda_arch IN LISTS CMAKE_CUDA_ARCHITECTURES)
    string(REGEX MATCH "^[0-9]+" _cuda_arch_number "${_cuda_arch}")
    if(_cuda_arch_number GREATER_EQUAL 80)
      set(_nanovdb_has_sm80 ON)
    endif()
  endforeach()

  if(_nanovdb_has_sm80)
    nanovdb_example(NAME "ex_make_mgpu_nanovdb") # requires cuRAND and SM_80+ (TF32 WMMA)
    target_link_libraries(ex_make_mgpu_nanovdb PRIVATE CUDA::curand)
  else()
    message(STATUS "Skipping ex_make_mgpu_nanovdb: requires CUDA architecture 80 or newer")
  endif()

  unset(_nanovdb_has_sm80)
  unset(_cuda_arch_number)
  unset(_cuda_arch)
endif()

OUTPUT_VARIABLE _max_cuda_arch OUTPUT_STRIP_TRAILING_WHITESPACE)
if(_max_cuda_arch GREATER_EQUAL 80)
nanovdb_example(NAME "ex_make_mgpu_nanovdb") # requires cuRAND and SM_80+ (TF32 WMMA)
target_link_libraries(ex_make_mgpu_nanovdb PRIVATE CUDA::curand)
else()
message(STATUS "Skipping ex_make_mgpu_nanovdb: requires SM_80+ (TF32), detected SM_${_max_cuda_arch}")
endif()
unset(_max_cuda_arch)
endif()

if(NANOVDB_USE_MAGICAVOXEL)
Expand Down
Loading