Skip to content

Commit 18ecca6

Browse files
authored
Merge branch 'main' into dching/event-timing-message
2 parents 9f530b6 + c71ed39 commit 18ecca6

36 files changed

+1215
-148
lines changed

.bandit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[bandit]
2+
skips = B101,B311

.github/actions/fetch_ctk/action.yml

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,22 @@ inputs:
99
cuda-version:
1010
required: true
1111
type: string
12+
cuda-components:
13+
description: "A list of the CTK components to install as a comma-separated list. e.g. 'cuda_nvcc,cuda_nvrtc,cuda_cudart'"
14+
required: false
15+
type: string
16+
default: "cuda_nvcc,cuda_cudart,cuda_nvrtc,cuda_profiler_api,cuda_cccl,cuda_sanitizer_api,libnvjitlink"
1217

1318
runs:
1419
using: composite
1520
steps:
1621
- name: Set up CTK cache variable
1722
shell: bash --noprofile --norc -xeuo pipefail {0}
1823
run: |
19-
echo "CTK_CACHE_KEY=mini-ctk-${{ inputs.cuda-version }}-${{ inputs.host-platform }}" >> $GITHUB_ENV
20-
echo "CTK_CACHE_FILENAME=mini-ctk-${{ inputs.cuda-version }}-${{ inputs.host-platform }}.tar.gz" >> $GITHUB_ENV
24+
HASH=$(echo -n "${{ inputs.cuda-components }}" | sha256sum | awk '{print $1}')
25+
echo "CTK_CACHE_KEY=mini-ctk-${{ inputs.cuda-version }}-${{ inputs.host-platform }}-$HASH" >> $GITHUB_ENV
26+
echo "CTK_CACHE_FILENAME=mini-ctk-${{ inputs.cuda-version }}-${{ inputs.host-platform }}-$HASH.tar.gz" >> $GITHUB_ENV
27+
echo "CTK_CACHE_COMPONENTS=${{ inputs.cuda-components }}" >> $GITHUB_ENV
2128
2229
- name: Install dependencies
2330
uses: ./.github/actions/install_unix_deps
@@ -78,18 +85,16 @@ runs:
7885
rm $CTK_COMPONENT_COMPONENT_FILENAME
7986
}
8087
81-
# Get headers and shared libraries in place
82-
# Note: the existing artifact would need to be manually deleted (ex: through web UI)
83-
# if this list is changed, as the artifact actions do not offer any option for us to
84-
# invalidate the artifact.
85-
populate_cuda_path cuda_nvcc
86-
populate_cuda_path cuda_cudart
87-
populate_cuda_path cuda_nvrtc
88-
populate_cuda_path cuda_profiler_api
89-
populate_cuda_path cuda_cccl
90-
if [[ "$(cut -d '.' -f 1 <<< ${{ inputs.cuda-version }})" -ge 12 ]]; then
91-
populate_cuda_path libnvjitlink
88+
# Conditionally strip out libnvjitlink for CUDA versions < 12
89+
if [[ "$(cut -d '.' -f 1 <<< ${{ inputs.cuda-version }})" -lt 12 ]]; then
90+
CTK_CACHE_COMPONENTS="${CTK_CACHE_COMPONENTS//libnvjitlink/}"
9291
fi
92+
# Cleanup stray commas after removing components
93+
CTK_CACHE_COMPONENTS="${CTK_CACHE_COMPONENTS//,,/,}"
94+
# Get headers and shared libraries in place
95+
for item in $(echo $CTK_CACHE_COMPONENTS | tr ',' ' '); do
96+
populate_cuda_path "$item"
97+
done
9398
ls -l $CUDA_PATH
9499
95100
# Prepare the cache

.github/workflows/bandit.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: "Static Analysis: Bandit Scan"
2+
3+
on:
4+
push:
5+
branches:
6+
- "pull-request/[0-9]+"
7+
- "main"
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
analyze:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
security-events: write
17+
steps:
18+
- name: Perform Bandit Analysis
19+
uses: PyCQA/bandit-action@8a1b30610f61f3f792fe7556e888c9d7dffa52de # v1.0.0

.github/workflows/codeql.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: "Static Analysis: CodeQL Scan"
2+
3+
on:
4+
push:
5+
branches:
6+
- "pull-request/[0-9]+"
7+
- "main"
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
analyze:
14+
name: Analyze (${{ matrix.language }})
15+
runs-on: ubuntu-latest
16+
permissions:
17+
security-events: write
18+
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
include:
23+
- language: python
24+
build-mode: none
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
29+
- name: Initialize CodeQL
30+
uses: github/codeql-action/init@v3
31+
with:
32+
languages: ${{ matrix.language }}
33+
build-mode: ${{ matrix.build-mode }}
34+
queries: security-extended
35+
36+
- name: Perform CodeQL Analysis
37+
uses: github/codeql-action/analyze@v3
38+
with:
39+
category: "/language:${{matrix.language}}"

.pre-commit-config.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,23 @@ ci:
66
autoupdate_branch: ''
77
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
88
autoupdate_schedule: quarterly
9-
skip: []
9+
skip: [bandit]
1010
submodules: false
1111

1212
repos:
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.11.4
14+
rev: 971923581912ef60a6b70dbf0c3e9a39563c9d47 #v0.11.4
1515
hooks:
1616
- id: ruff
1717
args: [--fix, --show-fixes]
1818
- id: ruff-format
19+
- repo: https://github.com/PyCQA/bandit
20+
rev: 8ff25e07e487f143571cc305e56dd0253c60bc7b #v1.8.3
21+
hooks:
22+
- id: bandit
23+
args:
24+
- --ini
25+
- .bandit
1926

2027
default_language_version:
2128
python: python3

cuda_bindings/cuda/__init__.pxd

Whitespace-only changes.

cuda_bindings/cuda/__init__.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

cuda_bindings/cuda/bindings/_bindings/cynvrtc.pyx.in

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,36 +60,37 @@ cdef int cuPythonInit() except -1 nogil:
6060
except:
6161
handle = None
6262

63-
# Else try default search
64-
if not handle:
65-
LOAD_LIBRARY_SAFE_CURRENT_DIRS = 0x00002000
66-
try:
67-
handle = win32api.LoadLibraryEx("nvrtc64_120_0.dll", 0, LOAD_LIBRARY_SAFE_CURRENT_DIRS)
68-
except:
69-
pass
70-
71-
# Final check if DLLs can be found within pip installations
63+
# Check if DLLs can be found within pip installations
7264
if not handle:
65+
LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 0x00001000
66+
LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR = 0x00000100
7367
site_packages = [site.getusersitepackages()] + site.getsitepackages()
7468
for sp in site_packages:
7569
mod_path = os.path.join(sp, "nvidia", "cuda_nvrtc", "bin")
76-
if not os.path.isdir(mod_path):
77-
continue
78-
os.add_dll_directory(mod_path)
79-
LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 0x00001000
80-
LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR = 0x00000100
81-
try:
82-
handle = win32api.LoadLibraryEx(
83-
# Note: LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR needs an abs path...
84-
os.path.join(mod_path, "nvrtc64_120_0.dll"),
85-
0, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR)
86-
87-
# Note: nvrtc64_120_0.dll calls into nvrtc-builtins64_*.dll which is
88-
# located in the same mod_path.
89-
# Update PATH environ so that the two dlls can find each other
90-
os.environ["PATH"] = os.pathsep.join((os.environ.get("PATH", ""), mod_path))
91-
except:
92-
pass
70+
if os.path.isdir(mod_path):
71+
os.add_dll_directory(mod_path)
72+
try:
73+
handle = win32api.LoadLibraryEx(
74+
# Note: LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR needs an abs path...
75+
os.path.join(mod_path, "nvrtc64_120_0.dll"),
76+
0, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR)
77+
78+
# Note: nvrtc64_120_0.dll calls into nvrtc-builtins64_*.dll which is
79+
# located in the same mod_path.
80+
# Update PATH environ so that the two dlls can find each other
81+
os.environ["PATH"] = os.pathsep.join((os.environ.get("PATH", ""), mod_path))
82+
except:
83+
pass
84+
else:
85+
break
86+
else:
87+
# Else try default search
88+
# Only reached if DLL wasn't found in any site-package path
89+
LOAD_LIBRARY_SAFE_CURRENT_DIRS = 0x00002000
90+
try:
91+
handle = win32api.LoadLibraryEx("nvrtc64_120_0.dll", 0, LOAD_LIBRARY_SAFE_CURRENT_DIRS)
92+
except:
93+
pass
9394

9495
if not handle:
9596
raise RuntimeError('Failed to LoadLibraryEx nvrtc64_120_0.dll')

cuda_bindings/cuda/bindings/_internal/nvjitlink_windows.pyx

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,40 +56,30 @@ cdef load_library(const int driver_ver):
5656

5757
# First check if the DLL has been loaded by 3rd parties
5858
try:
59-
handle = win32api.GetModuleHandle(dll_name)
59+
return win32api.GetModuleHandle(dll_name)
6060
except:
6161
pass
62-
else:
63-
break
6462

6563
# Next, check if DLLs are installed via pip
6664
for sp in get_site_packages():
6765
mod_path = os.path.join(sp, "nvidia", "nvJitLink", "bin")
68-
if not os.path.isdir(mod_path):
69-
continue
70-
os.add_dll_directory(mod_path)
71-
try:
72-
handle = win32api.LoadLibraryEx(
73-
# Note: LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR needs an abs path...
74-
os.path.join(mod_path, dll_name),
75-
0, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR)
76-
except:
77-
pass
78-
else:
79-
break
80-
66+
if os.path.isdir(mod_path):
67+
os.add_dll_directory(mod_path)
68+
try:
69+
return win32api.LoadLibraryEx(
70+
# Note: LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR needs an abs path...
71+
os.path.join(mod_path, dll_name),
72+
0, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR)
73+
except:
74+
pass
8175
# Finally, try default search
76+
# Only reached if DLL wasn't found in any site-package path
8277
try:
83-
handle = win32api.LoadLibrary(dll_name)
78+
return win32api.LoadLibrary(dll_name)
8479
except:
8580
pass
86-
else:
87-
break
88-
else:
89-
raise RuntimeError('Failed to load nvJitLink')
9081

91-
assert handle != 0
92-
return handle
82+
raise RuntimeError('Failed to load nvJitLink')
9383

9484

9585
cdef int _check_or_init_nvjitlink() except -1 nogil:

cuda_bindings/cuda/bindings/_internal/nvvm_windows.pyx

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ cdef void* __nvvmGetProgramLog = NULL
4141

4242

4343
cdef inline list get_site_packages():
44-
return [site.getusersitepackages()] + site.getsitepackages()
44+
return [site.getusersitepackages()] + site.getsitepackages() + ["conda"]
4545

4646

4747
cdef load_library(const int driver_ver):
@@ -50,44 +50,42 @@ cdef load_library(const int driver_ver):
5050
for suffix in get_nvvm_dso_version_suffix(driver_ver):
5151
if len(suffix) == 0:
5252
continue
53-
dll_name = "nvvm64_40_0"
53+
dll_name = "nvvm64_40_0.dll"
5454

5555
# First check if the DLL has been loaded by 3rd parties
5656
try:
57-
handle = win32api.GetModuleHandle(dll_name)
57+
return win32api.GetModuleHandle(dll_name)
5858
except:
5959
pass
60-
else:
61-
break
6260

63-
# Next, check if DLLs are installed via pip
61+
# Next, check if DLLs are installed via pip or conda
6462
for sp in get_site_packages():
65-
mod_path = os.path.join(sp, "nvidia", "cuda_nvcc", "nvvm", "bin")
66-
if not os.path.isdir(mod_path):
67-
continue
68-
os.add_dll_directory(mod_path)
69-
try:
70-
handle = win32api.LoadLibraryEx(
71-
# Note: LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR needs an abs path...
72-
os.path.join(mod_path, dll_name),
73-
0, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR)
74-
except:
75-
pass
76-
else:
77-
break
63+
if sp == "conda":
64+
# nvvm is not under $CONDA_PREFIX/lib, so it's not in the default search path
65+
conda_prefix = os.environ.get("CONDA_PREFIX")
66+
if conda_prefix is None:
67+
continue
68+
mod_path = os.path.join(conda_prefix, "Library", "nvvm", "bin")
69+
else:
70+
mod_path = os.path.join(sp, "nvidia", "cuda_nvcc", "nvvm", "bin")
71+
if os.path.isdir(mod_path):
72+
os.add_dll_directory(mod_path)
73+
try:
74+
return win32api.LoadLibraryEx(
75+
# Note: LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR needs an abs path...
76+
os.path.join(mod_path, dll_name),
77+
0, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR)
78+
except:
79+
pass
7880

7981
# Finally, try default search
82+
# Only reached if DLL wasn't found in any site-package path
8083
try:
81-
handle = win32api.LoadLibrary(dll_name)
84+
return win32api.LoadLibrary(dll_name)
8285
except:
8386
pass
84-
else:
85-
break
86-
else:
87-
raise RuntimeError('Failed to load nvvm')
8887

89-
assert handle != 0
90-
return handle
88+
raise RuntimeError('Failed to load nvvm')
9189

9290

9391
cdef int _check_or_init_nvvm() except -1 nogil:

0 commit comments

Comments
 (0)