Skip to content

Commit d174f5a

Browse files
committed
find_nvidia_headers.py initial version (untested).
1 parent 1e5097c commit d174f5a

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2025 NVIDIA Corporation. All rights reserved.
2+
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
3+
4+
import functools
5+
import glob
6+
import os
7+
8+
from cuda.bindings._path_finder.find_sub_dirs import find_sub_dirs_all_sitepackages
9+
from cuda.bindings._path_finder.supported_libs import IS_WINDOWS
10+
11+
12+
@functools.cache
13+
def find_nvidia_header_directory(libname: str) -> str:
14+
assert libname == "nvshmem"
15+
assert not IS_WINDOWS
16+
17+
# Installed from a wheel
18+
nvidia_sub_dirs = ("nvidia", "nvshmem", "include")
19+
for hdr_dir in find_sub_dirs_all_sitepackages(nvidia_sub_dirs):
20+
nvshmem_h_path = os.path.join(hdr_dir, "nvshmem.h")
21+
if os.path.isfile(nvshmem_h_path):
22+
return hdr_dir
23+
24+
conda_prefix = os.environ.get("CONDA_PREFIX")
25+
if conda_prefix and os.path.isdir(conda_prefix):
26+
hdr_dir = os.path.join(conda_prefix, "include")
27+
if os.path.isdir(hdr_dir):
28+
nvshmem_h_path = os.path.join(hdr_dir, "nvshmem.h")
29+
if os.path.isfile(nvshmem_h_path):
30+
return hdr_dir
31+
32+
for hdr_dir in sorted(glob.glob("/usr/include/nvshmem_*")):
33+
if os.path.isdir(hdr_dir):
34+
nvshmem_h_path = os.path.join(hdr_dir, "nvshmem.h")
35+
if os.path.isfile(nvshmem_h_path):
36+
return hdr_dir
37+
38+
return None

0 commit comments

Comments
 (0)