Skip to content

Commit ab29f67

Browse files
leofangclaude
andauthored
Replace nvrtc Tempita templates with pre-generated Cython files (#1900)
* [DRAFT] Replace nvrtc Tempita templates with pre-generated Cython files Replace .pyx.in / .pxd.in Tempita templates with plain .pyx / .pxd files generated by the refactored cython-gen (cybind leof/cybind\!369). Changes: - Remove 6 Tempita template files (.pyx.in / .pxd.in) for nvrtc - Add 7 pre-generated Cython files with zero Tempita - Move internal layer from _bindings/ to _internal/ following cybind convention - Split platform-specific code into nvrtc_linux.pyx / nvrtc_windows.pyx - Internal layer now uses cybind-style loading (RTLD_DEFAULT + fallback, FunctionNotFoundError, _init_nvrtc/_check_or_init_nvrtc naming) This is a companion PR to cybind leof/cybind\!369. Build system changes (build_hooks.py, pyproject.toml) to remove pyclibrary are not yet included — this PR shows the generated output for review. Part of https://gitlab-master.nvidia.com/leof/cybind/-/issues/173 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Regenerate nvrtc files with template-based generation Update generated artifacts to use cybind-style templates: - Fix excessive blank lines from Tempita stripping - Internal layer files now generated from template files under cybind/assets/templates/ via string.Template.substitute() - Proper license headers from templates Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Update cynvrtc.pyx to use _internal cimport (cybind convention) - cynvrtc.pyx now uses "from ._internal cimport nvrtc as _nvrtc" instead of the legacy "cimport _bindings.cynvrtc as cynvrtc" - Function wrappers reference _nvrtc._funcName() matching cybind style - cynvrtc.pxd gets proper template header Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Update build system: skip pyclibrary for nvrtc, fix cynvrtc source path - Remove nvrtc from _REQUIRED_HEADERS (no pyclibrary parsing needed; nvrtc .pyx/.pxd files are now pre-generated by cybind) - Update sources_list: cynvrtc.pyx moved from _bindings/ to bindings/ - _rename_architecture_specific_files already handles _internal/nvrtc_linux.pyx -> _internal/nvrtc.pyx Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Restore generator version in headers, remove duplicate cynvrtc source entry - Regenerate files with generator version in header comments - Remove explicit cynvrtc.pyx from sources_list (already covered by cuda_bindings_files glob) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix pre-commit: strip trailing whitespace and ensure final newline Regenerated from latest cybind which now cleans up trailing whitespace and ensures files end with exactly one newline. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 6ec277e commit ab29f67

File tree

9 files changed

+1194
-1192
lines changed

9 files changed

+1194
-1192
lines changed

cuda_bindings/build_hooks.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ def _get_cuda_path() -> str:
9494
"driver_functions.h",
9595
"cuda_profiler_api.h",
9696
],
97-
"nvrtc": [
98-
"nvrtc.h",
99-
],
97+
# nvrtc: headers no longer parsed at build time (pre-generated by cybind).
10098
# During compilation, Cython will reference C headers that are not
10199
# explicitly parsed above. These are the known dependencies:
102100
#
@@ -423,7 +421,8 @@ def _cleanup_dst_files():
423421
sources_list = [
424422
# private
425423
(["cuda/bindings/_bindings/cydriver.pyx", "cuda/bindings/_bindings/loader.cpp"], None),
426-
(["cuda/bindings/_bindings/cynvrtc.pyx"], None),
424+
# cynvrtc.pyx is now in cuda/bindings/ (pre-generated by cybind),
425+
# picked up by the cuda_bindings_files glob below.
427426
(["cuda/bindings/_bindings/cyruntime.pyx"], static_runtime_libraries),
428427
(["cuda/bindings/_bindings/cyruntime_ptds.pyx"], static_runtime_libraries),
429428
# utils

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

Lines changed: 0 additions & 789 deletions
This file was deleted.
Lines changed: 7 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,63 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2021-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
#
23
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
4+
#
5+
# This code was automatically generated with version 13.2.0, generator version 0.3.1.dev1364+ged01d643e. Do not modify it directly.
36

4-
# This code was automatically generated with version 13.2.0, generator version 0.3.1.dev1422+gf4812259e.d20260318. Do not modify it directly.
5-
from cuda.bindings.cynvrtc cimport *
7+
from ..cynvrtc cimport *
68

7-
{{if 'nvrtcGetErrorString' in found_functions}}
9+
###############################################################################
10+
# Wrapper functions
11+
###############################################################################
812

913
cdef const char* _nvrtcGetErrorString(nvrtcResult result) except ?NULL nogil
10-
{{endif}}
11-
12-
{{if 'nvrtcVersion' in found_functions}}
1314

1415
cdef nvrtcResult _nvrtcVersion(int* major, int* minor) except ?NVRTC_ERROR_INVALID_INPUT nogil
15-
{{endif}}
16-
17-
{{if 'nvrtcGetNumSupportedArchs' in found_functions}}
1816

1917
cdef nvrtcResult _nvrtcGetNumSupportedArchs(int* numArchs) except ?NVRTC_ERROR_INVALID_INPUT nogil
20-
{{endif}}
21-
22-
{{if 'nvrtcGetSupportedArchs' in found_functions}}
2318

2419
cdef nvrtcResult _nvrtcGetSupportedArchs(int* supportedArchs) except ?NVRTC_ERROR_INVALID_INPUT nogil
25-
{{endif}}
26-
27-
{{if 'nvrtcCreateProgram' in found_functions}}
2820

2921
cdef nvrtcResult _nvrtcCreateProgram(nvrtcProgram* prog, const char* src, const char* name, int numHeaders, const char** headers, const char** includeNames) except ?NVRTC_ERROR_INVALID_INPUT nogil
30-
{{endif}}
31-
32-
{{if 'nvrtcDestroyProgram' in found_functions}}
3322

3423
cdef nvrtcResult _nvrtcDestroyProgram(nvrtcProgram* prog) except ?NVRTC_ERROR_INVALID_INPUT nogil
35-
{{endif}}
36-
37-
{{if 'nvrtcCompileProgram' in found_functions}}
3824

3925
cdef nvrtcResult _nvrtcCompileProgram(nvrtcProgram prog, int numOptions, const char** options) except ?NVRTC_ERROR_INVALID_INPUT nogil
40-
{{endif}}
41-
42-
{{if 'nvrtcGetPTXSize' in found_functions}}
4326

4427
cdef nvrtcResult _nvrtcGetPTXSize(nvrtcProgram prog, size_t* ptxSizeRet) except ?NVRTC_ERROR_INVALID_INPUT nogil
45-
{{endif}}
46-
47-
{{if 'nvrtcGetPTX' in found_functions}}
4828

4929
cdef nvrtcResult _nvrtcGetPTX(nvrtcProgram prog, char* ptx) except ?NVRTC_ERROR_INVALID_INPUT nogil
50-
{{endif}}
51-
52-
{{if 'nvrtcGetCUBINSize' in found_functions}}
5330

5431
cdef nvrtcResult _nvrtcGetCUBINSize(nvrtcProgram prog, size_t* cubinSizeRet) except ?NVRTC_ERROR_INVALID_INPUT nogil
55-
{{endif}}
56-
57-
{{if 'nvrtcGetCUBIN' in found_functions}}
5832

5933
cdef nvrtcResult _nvrtcGetCUBIN(nvrtcProgram prog, char* cubin) except ?NVRTC_ERROR_INVALID_INPUT nogil
60-
{{endif}}
61-
62-
{{if 'nvrtcGetLTOIRSize' in found_functions}}
6334

6435
cdef nvrtcResult _nvrtcGetLTOIRSize(nvrtcProgram prog, size_t* LTOIRSizeRet) except ?NVRTC_ERROR_INVALID_INPUT nogil
65-
{{endif}}
66-
67-
{{if 'nvrtcGetLTOIR' in found_functions}}
6836

6937
cdef nvrtcResult _nvrtcGetLTOIR(nvrtcProgram prog, char* LTOIR) except ?NVRTC_ERROR_INVALID_INPUT nogil
70-
{{endif}}
71-
72-
{{if 'nvrtcGetOptiXIRSize' in found_functions}}
7338

7439
cdef nvrtcResult _nvrtcGetOptiXIRSize(nvrtcProgram prog, size_t* optixirSizeRet) except ?NVRTC_ERROR_INVALID_INPUT nogil
75-
{{endif}}
76-
77-
{{if 'nvrtcGetOptiXIR' in found_functions}}
7840

7941
cdef nvrtcResult _nvrtcGetOptiXIR(nvrtcProgram prog, char* optixir) except ?NVRTC_ERROR_INVALID_INPUT nogil
80-
{{endif}}
81-
82-
{{if 'nvrtcGetProgramLogSize' in found_functions}}
8342

8443
cdef nvrtcResult _nvrtcGetProgramLogSize(nvrtcProgram prog, size_t* logSizeRet) except ?NVRTC_ERROR_INVALID_INPUT nogil
85-
{{endif}}
86-
87-
{{if 'nvrtcGetProgramLog' in found_functions}}
8844

8945
cdef nvrtcResult _nvrtcGetProgramLog(nvrtcProgram prog, char* log) except ?NVRTC_ERROR_INVALID_INPUT nogil
90-
{{endif}}
91-
92-
{{if 'nvrtcAddNameExpression' in found_functions}}
9346

9447
cdef nvrtcResult _nvrtcAddNameExpression(nvrtcProgram prog, const char* name_expression) except ?NVRTC_ERROR_INVALID_INPUT nogil
95-
{{endif}}
96-
97-
{{if 'nvrtcGetLoweredName' in found_functions}}
9848

9949
cdef nvrtcResult _nvrtcGetLoweredName(nvrtcProgram prog, const char* name_expression, const char** lowered_name) except ?NVRTC_ERROR_INVALID_INPUT nogil
100-
{{endif}}
101-
102-
{{if 'nvrtcGetPCHHeapSize' in found_functions}}
10350

10451
cdef nvrtcResult _nvrtcGetPCHHeapSize(size_t* ret) except ?NVRTC_ERROR_INVALID_INPUT nogil
105-
{{endif}}
106-
107-
{{if 'nvrtcSetPCHHeapSize' in found_functions}}
10852

10953
cdef nvrtcResult _nvrtcSetPCHHeapSize(size_t size) except ?NVRTC_ERROR_INVALID_INPUT nogil
110-
{{endif}}
111-
112-
{{if 'nvrtcGetPCHCreateStatus' in found_functions}}
11354

11455
cdef nvrtcResult _nvrtcGetPCHCreateStatus(nvrtcProgram prog) except ?NVRTC_ERROR_INVALID_INPUT nogil
115-
{{endif}}
116-
117-
{{if 'nvrtcGetPCHHeapSizeRequired' in found_functions}}
11856

11957
cdef nvrtcResult _nvrtcGetPCHHeapSizeRequired(nvrtcProgram prog, size_t* size) except ?NVRTC_ERROR_INVALID_INPUT nogil
120-
{{endif}}
121-
122-
{{if 'nvrtcSetFlowCallback' in found_functions}}
12358

12459
cdef nvrtcResult _nvrtcSetFlowCallback(nvrtcProgram prog, void* callback, void* payload) except ?NVRTC_ERROR_INVALID_INPUT nogil
125-
{{endif}}
126-
127-
{{if 'nvrtcGetTileIRSize' in found_functions}}
12860

12961
cdef nvrtcResult _nvrtcGetTileIRSize(nvrtcProgram prog, size_t* TileIRSizeRet) except ?NVRTC_ERROR_INVALID_INPUT nogil
130-
{{endif}}
131-
132-
{{if 'nvrtcGetTileIR' in found_functions}}
13362

13463
cdef nvrtcResult _nvrtcGetTileIR(nvrtcProgram prog, char* TileIR) except ?NVRTC_ERROR_INVALID_INPUT nogil
135-
{{endif}}
136-

0 commit comments

Comments
 (0)