-
Notifications
You must be signed in to change notification settings - Fork 240
Add Nvfatbin Bindings #1467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add Nvfatbin Bindings #1467
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
2d8c99a
initial localized test
isVoid 9b1a559
add rest of APIs
isVoid a979dd0
remove local skips
isVoid fc4203e
regenerate for CUDA 13.1 and with tile IR API
isVoid 344f735
Merge branch 'main' of github.com:NVIDIA/cuda-python into wangm/nvfat…
isVoid e7ace35
nvfatbinError -> nvFatbinError
isVoid d962f61
regenerate for get_error_string
isVoid bd868bd
enable object creation and testing
isVoid d11cf02
remove the LTOIR mismatching arch failure test
isVoid d995809
encode a legal tileIR into test
isVoid 8e75d8a
update the license year
isVoid 22bf2ce
add an embedded tile program for re-generation
isVoid cda0e29
license date: 2026
isVoid 2e53f46
cdef const char *
isVoid d7dfdb8
add dependency for CI
isVoid ff8f6a2
add TODO to locate nvcc file
isVoid 965c53b
add documentation and release notes
isVoid 2b54279
skip tileIR test for <13.1 installation
isVoid 4baeecd
add an nvcc smoke test to better determine compiler usability
isVoid 4c2f3f3
fix typo
isVoid 3e071e2
add nvfatbin.rst
isVoid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE | ||
| # | ||
| # This code was automatically generated across versions from 12.4.1 to 13.1.0. Do not modify it directly. | ||
|
|
||
| from ..cynvfatbin cimport * | ||
|
|
||
|
|
||
| ############################################################################### | ||
| # Wrapper functions | ||
| ############################################################################### | ||
|
|
||
| cdef const char* _nvFatbinGetErrorString(nvFatbinResult result) except?NULL nogil | ||
| cdef nvFatbinResult _nvFatbinCreate(nvFatbinHandle* handle_indirect, const char** options, size_t optionsCount) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil | ||
| cdef nvFatbinResult _nvFatbinDestroy(nvFatbinHandle* handle_indirect) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil | ||
| cdef nvFatbinResult _nvFatbinAddPTX(nvFatbinHandle handle, const char* code, size_t size, const char* arch, const char* identifier, const char* optionsCmdLine) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil | ||
| cdef nvFatbinResult _nvFatbinAddCubin(nvFatbinHandle handle, const void* code, size_t size, const char* arch, const char* identifier) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil | ||
| cdef nvFatbinResult _nvFatbinAddLTOIR(nvFatbinHandle handle, const void* code, size_t size, const char* arch, const char* identifier, const char* optionsCmdLine) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil | ||
| cdef nvFatbinResult _nvFatbinSize(nvFatbinHandle handle, size_t* size) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil | ||
| cdef nvFatbinResult _nvFatbinGet(nvFatbinHandle handle, void* buffer) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil | ||
| cdef nvFatbinResult _nvFatbinVersion(unsigned int* major, unsigned int* minor) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil | ||
| cdef nvFatbinResult _nvFatbinAddReloc(nvFatbinHandle handle, const void* code, size_t size) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil | ||
| cdef nvFatbinResult _nvFatbinAddTileIR(nvFatbinHandle handle, const void* code, size_t size, const char* identifier, const char* optionsCmdLine) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil | ||
344 changes: 344 additions & 0 deletions
344
cuda_bindings/cuda/bindings/_internal/nvfatbin_linux.pyx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,344 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE | ||
| # | ||
| # This code was automatically generated across versions from 12.4.1 to 13.1.0. Do not modify it directly. | ||
|
|
||
| from libc.stdint cimport intptr_t, uintptr_t | ||
|
|
||
| import threading | ||
| from .utils import FunctionNotFoundError, NotSupportedError | ||
|
|
||
| from cuda.pathfinder import load_nvidia_dynamic_lib | ||
|
|
||
|
|
||
| ############################################################################### | ||
| # Extern | ||
| ############################################################################### | ||
|
|
||
| # You must 'from .utils import NotSupportedError' before using this template | ||
|
|
||
| cdef extern from "<dlfcn.h>" nogil: | ||
| void* dlopen(const char*, int) | ||
| char* dlerror() | ||
| void* dlsym(void*, const char*) | ||
| int dlclose(void*) | ||
|
|
||
| enum: | ||
| RTLD_LAZY | ||
| RTLD_NOW | ||
| RTLD_GLOBAL | ||
| RTLD_LOCAL | ||
|
|
||
| const void* RTLD_DEFAULT 'RTLD_DEFAULT' | ||
|
|
||
| cdef int get_cuda_version(): | ||
| cdef void* handle = NULL | ||
| cdef int err, driver_ver = 0 | ||
|
|
||
| # Load driver to check version | ||
| handle = dlopen('libcuda.so.1', RTLD_NOW | RTLD_GLOBAL) | ||
| if handle == NULL: | ||
| err_msg = dlerror() | ||
| raise NotSupportedError(f'CUDA driver is not found ({err_msg.decode()})') | ||
| cuDriverGetVersion = dlsym(handle, "cuDriverGetVersion") | ||
| if cuDriverGetVersion == NULL: | ||
| raise RuntimeError('Did not find cuDriverGetVersion symbol in libcuda.so.1') | ||
| err = (<int (*)(int*) noexcept nogil>cuDriverGetVersion)(&driver_ver) | ||
| if err != 0: | ||
| raise RuntimeError(f'cuDriverGetVersion returned error code {err}') | ||
|
|
||
| return driver_ver | ||
|
|
||
|
|
||
|
|
||
| ############################################################################### | ||
| # Wrapper init | ||
| ############################################################################### | ||
|
|
||
| cdef object __symbol_lock = threading.Lock() | ||
| cdef bint __py_nvfatbin_init = False | ||
|
|
||
| cdef void* __nvFatbinGetErrorString = NULL | ||
| cdef void* __nvFatbinCreate = NULL | ||
| cdef void* __nvFatbinDestroy = NULL | ||
| cdef void* __nvFatbinAddPTX = NULL | ||
| cdef void* __nvFatbinAddCubin = NULL | ||
| cdef void* __nvFatbinAddLTOIR = NULL | ||
| cdef void* __nvFatbinSize = NULL | ||
| cdef void* __nvFatbinGet = NULL | ||
| cdef void* __nvFatbinVersion = NULL | ||
| cdef void* __nvFatbinAddReloc = NULL | ||
| cdef void* __nvFatbinAddTileIR = NULL | ||
|
|
||
|
|
||
| cdef void* load_library() except* with gil: | ||
| cdef uintptr_t handle = load_nvidia_dynamic_lib("nvfatbin")._handle_uint | ||
| return <void*>handle | ||
|
|
||
|
|
||
| cdef int _init_nvfatbin() except -1 nogil: | ||
| global __py_nvfatbin_init | ||
|
|
||
| cdef void* handle = NULL | ||
|
|
||
leofang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| with gil, __symbol_lock: | ||
| # Recheck the flag after obtaining the locks | ||
| if __py_nvfatbin_init: | ||
| return 0 | ||
|
|
||
| # Load function | ||
| global __nvFatbinGetErrorString | ||
| __nvFatbinGetErrorString = dlsym(RTLD_DEFAULT, 'nvFatbinGetErrorString') | ||
| if __nvFatbinGetErrorString == NULL: | ||
| if handle == NULL: | ||
| handle = load_library() | ||
| __nvFatbinGetErrorString = dlsym(handle, 'nvFatbinGetErrorString') | ||
|
|
||
| global __nvFatbinCreate | ||
leofang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| __nvFatbinCreate = dlsym(RTLD_DEFAULT, 'nvFatbinCreate') | ||
| if __nvFatbinCreate == NULL: | ||
| if handle == NULL: | ||
| handle = load_library() | ||
| __nvFatbinCreate = dlsym(handle, 'nvFatbinCreate') | ||
|
|
||
| global __nvFatbinDestroy | ||
| __nvFatbinDestroy = dlsym(RTLD_DEFAULT, 'nvFatbinDestroy') | ||
| if __nvFatbinDestroy == NULL: | ||
| if handle == NULL: | ||
| handle = load_library() | ||
| __nvFatbinDestroy = dlsym(handle, 'nvFatbinDestroy') | ||
|
|
||
| global __nvFatbinAddPTX | ||
| __nvFatbinAddPTX = dlsym(RTLD_DEFAULT, 'nvFatbinAddPTX') | ||
| if __nvFatbinAddPTX == NULL: | ||
| if handle == NULL: | ||
| handle = load_library() | ||
| __nvFatbinAddPTX = dlsym(handle, 'nvFatbinAddPTX') | ||
|
|
||
| global __nvFatbinAddCubin | ||
| __nvFatbinAddCubin = dlsym(RTLD_DEFAULT, 'nvFatbinAddCubin') | ||
| if __nvFatbinAddCubin == NULL: | ||
| if handle == NULL: | ||
| handle = load_library() | ||
| __nvFatbinAddCubin = dlsym(handle, 'nvFatbinAddCubin') | ||
|
|
||
| global __nvFatbinAddLTOIR | ||
| __nvFatbinAddLTOIR = dlsym(RTLD_DEFAULT, 'nvFatbinAddLTOIR') | ||
| if __nvFatbinAddLTOIR == NULL: | ||
| if handle == NULL: | ||
| handle = load_library() | ||
| __nvFatbinAddLTOIR = dlsym(handle, 'nvFatbinAddLTOIR') | ||
|
|
||
| global __nvFatbinSize | ||
| __nvFatbinSize = dlsym(RTLD_DEFAULT, 'nvFatbinSize') | ||
| if __nvFatbinSize == NULL: | ||
| if handle == NULL: | ||
| handle = load_library() | ||
| __nvFatbinSize = dlsym(handle, 'nvFatbinSize') | ||
|
|
||
| global __nvFatbinGet | ||
| __nvFatbinGet = dlsym(RTLD_DEFAULT, 'nvFatbinGet') | ||
| if __nvFatbinGet == NULL: | ||
| if handle == NULL: | ||
| handle = load_library() | ||
| __nvFatbinGet = dlsym(handle, 'nvFatbinGet') | ||
|
|
||
| global __nvFatbinVersion | ||
| __nvFatbinVersion = dlsym(RTLD_DEFAULT, 'nvFatbinVersion') | ||
| if __nvFatbinVersion == NULL: | ||
| if handle == NULL: | ||
| handle = load_library() | ||
| __nvFatbinVersion = dlsym(handle, 'nvFatbinVersion') | ||
|
|
||
| global __nvFatbinAddReloc | ||
| __nvFatbinAddReloc = dlsym(RTLD_DEFAULT, 'nvFatbinAddReloc') | ||
| if __nvFatbinAddReloc == NULL: | ||
| if handle == NULL: | ||
| handle = load_library() | ||
| __nvFatbinAddReloc = dlsym(handle, 'nvFatbinAddReloc') | ||
|
|
||
| global __nvFatbinAddTileIR | ||
| __nvFatbinAddTileIR = dlsym(RTLD_DEFAULT, 'nvFatbinAddTileIR') | ||
| if __nvFatbinAddTileIR == NULL: | ||
| if handle == NULL: | ||
| handle = load_library() | ||
| __nvFatbinAddTileIR = dlsym(handle, 'nvFatbinAddTileIR') | ||
|
|
||
| __py_nvfatbin_init = True | ||
| return 0 | ||
|
|
||
|
|
||
| cdef inline int _check_or_init_nvfatbin() except -1 nogil: | ||
| if __py_nvfatbin_init: | ||
| return 0 | ||
|
|
||
| return _init_nvfatbin() | ||
|
|
||
| cdef dict func_ptrs = None | ||
|
|
||
|
|
||
| cpdef dict _inspect_function_pointers(): | ||
| global func_ptrs | ||
| if func_ptrs is not None: | ||
| return func_ptrs | ||
|
|
||
| _check_or_init_nvfatbin() | ||
| cdef dict data = {} | ||
|
|
||
| global __nvFatbinGetErrorString | ||
| data["__nvFatbinGetErrorString"] = <intptr_t>__nvFatbinGetErrorString | ||
|
|
||
| global __nvFatbinCreate | ||
| data["__nvFatbinCreate"] = <intptr_t>__nvFatbinCreate | ||
|
|
||
| global __nvFatbinDestroy | ||
| data["__nvFatbinDestroy"] = <intptr_t>__nvFatbinDestroy | ||
|
|
||
| global __nvFatbinAddPTX | ||
| data["__nvFatbinAddPTX"] = <intptr_t>__nvFatbinAddPTX | ||
|
|
||
| global __nvFatbinAddCubin | ||
| data["__nvFatbinAddCubin"] = <intptr_t>__nvFatbinAddCubin | ||
|
|
||
| global __nvFatbinAddLTOIR | ||
| data["__nvFatbinAddLTOIR"] = <intptr_t>__nvFatbinAddLTOIR | ||
|
|
||
| global __nvFatbinSize | ||
| data["__nvFatbinSize"] = <intptr_t>__nvFatbinSize | ||
|
|
||
| global __nvFatbinGet | ||
| data["__nvFatbinGet"] = <intptr_t>__nvFatbinGet | ||
|
|
||
| global __nvFatbinVersion | ||
| data["__nvFatbinVersion"] = <intptr_t>__nvFatbinVersion | ||
|
|
||
| global __nvFatbinAddReloc | ||
| data["__nvFatbinAddReloc"] = <intptr_t>__nvFatbinAddReloc | ||
|
|
||
| global __nvFatbinAddTileIR | ||
| data["__nvFatbinAddTileIR"] = <intptr_t>__nvFatbinAddTileIR | ||
|
|
||
| func_ptrs = data | ||
| return data | ||
|
|
||
|
|
||
| cpdef _inspect_function_pointer(str name): | ||
| global func_ptrs | ||
| if func_ptrs is None: | ||
| func_ptrs = _inspect_function_pointers() | ||
| return func_ptrs[name] | ||
|
|
||
|
|
||
| ############################################################################### | ||
| # Wrapper functions | ||
| ############################################################################### | ||
|
|
||
| cdef const char* _nvFatbinGetErrorString(nvFatbinResult result) except?NULL nogil: | ||
| global __nvFatbinGetErrorString | ||
| _check_or_init_nvfatbin() | ||
| if __nvFatbinGetErrorString == NULL: | ||
| with gil: | ||
| raise FunctionNotFoundError("function nvFatbinGetErrorString is not found") | ||
| return (<const char* (*)(nvFatbinResult) noexcept nogil>__nvFatbinGetErrorString)( | ||
| result) | ||
|
|
||
|
|
||
| cdef nvFatbinResult _nvFatbinCreate(nvFatbinHandle* handle_indirect, const char** options, size_t optionsCount) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: | ||
| global __nvFatbinCreate | ||
| _check_or_init_nvfatbin() | ||
| if __nvFatbinCreate == NULL: | ||
| with gil: | ||
| raise FunctionNotFoundError("function nvFatbinCreate is not found") | ||
| return (<nvFatbinResult (*)(nvFatbinHandle*, const char**, size_t) noexcept nogil>__nvFatbinCreate)( | ||
| handle_indirect, options, optionsCount) | ||
|
|
||
|
|
||
| cdef nvFatbinResult _nvFatbinDestroy(nvFatbinHandle* handle_indirect) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: | ||
| global __nvFatbinDestroy | ||
| _check_or_init_nvfatbin() | ||
| if __nvFatbinDestroy == NULL: | ||
| with gil: | ||
| raise FunctionNotFoundError("function nvFatbinDestroy is not found") | ||
| return (<nvFatbinResult (*)(nvFatbinHandle*) noexcept nogil>__nvFatbinDestroy)( | ||
| handle_indirect) | ||
|
|
||
|
|
||
| cdef nvFatbinResult _nvFatbinAddPTX(nvFatbinHandle handle, const char* code, size_t size, const char* arch, const char* identifier, const char* optionsCmdLine) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: | ||
| global __nvFatbinAddPTX | ||
| _check_or_init_nvfatbin() | ||
| if __nvFatbinAddPTX == NULL: | ||
| with gil: | ||
| raise FunctionNotFoundError("function nvFatbinAddPTX is not found") | ||
| return (<nvFatbinResult (*)(nvFatbinHandle, const char*, size_t, const char*, const char*, const char*) noexcept nogil>__nvFatbinAddPTX)( | ||
| handle, code, size, arch, identifier, optionsCmdLine) | ||
|
|
||
|
|
||
| cdef nvFatbinResult _nvFatbinAddCubin(nvFatbinHandle handle, const void* code, size_t size, const char* arch, const char* identifier) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: | ||
| global __nvFatbinAddCubin | ||
| _check_or_init_nvfatbin() | ||
| if __nvFatbinAddCubin == NULL: | ||
| with gil: | ||
| raise FunctionNotFoundError("function nvFatbinAddCubin is not found") | ||
| return (<nvFatbinResult (*)(nvFatbinHandle, const void*, size_t, const char*, const char*) noexcept nogil>__nvFatbinAddCubin)( | ||
| handle, code, size, arch, identifier) | ||
|
|
||
|
|
||
| cdef nvFatbinResult _nvFatbinAddLTOIR(nvFatbinHandle handle, const void* code, size_t size, const char* arch, const char* identifier, const char* optionsCmdLine) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: | ||
| global __nvFatbinAddLTOIR | ||
| _check_or_init_nvfatbin() | ||
| if __nvFatbinAddLTOIR == NULL: | ||
| with gil: | ||
| raise FunctionNotFoundError("function nvFatbinAddLTOIR is not found") | ||
| return (<nvFatbinResult (*)(nvFatbinHandle, const void*, size_t, const char*, const char*, const char*) noexcept nogil>__nvFatbinAddLTOIR)( | ||
| handle, code, size, arch, identifier, optionsCmdLine) | ||
|
|
||
|
|
||
| cdef nvFatbinResult _nvFatbinSize(nvFatbinHandle handle, size_t* size) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: | ||
| global __nvFatbinSize | ||
| _check_or_init_nvfatbin() | ||
| if __nvFatbinSize == NULL: | ||
| with gil: | ||
| raise FunctionNotFoundError("function nvFatbinSize is not found") | ||
| return (<nvFatbinResult (*)(nvFatbinHandle, size_t*) noexcept nogil>__nvFatbinSize)( | ||
| handle, size) | ||
|
|
||
|
|
||
| cdef nvFatbinResult _nvFatbinGet(nvFatbinHandle handle, void* buffer) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: | ||
| global __nvFatbinGet | ||
| _check_or_init_nvfatbin() | ||
| if __nvFatbinGet == NULL: | ||
| with gil: | ||
| raise FunctionNotFoundError("function nvFatbinGet is not found") | ||
| return (<nvFatbinResult (*)(nvFatbinHandle, void*) noexcept nogil>__nvFatbinGet)( | ||
| handle, buffer) | ||
|
|
||
|
|
||
| cdef nvFatbinResult _nvFatbinVersion(unsigned int* major, unsigned int* minor) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: | ||
| global __nvFatbinVersion | ||
| _check_or_init_nvfatbin() | ||
| if __nvFatbinVersion == NULL: | ||
| with gil: | ||
| raise FunctionNotFoundError("function nvFatbinVersion is not found") | ||
| return (<nvFatbinResult (*)(unsigned int*, unsigned int*) noexcept nogil>__nvFatbinVersion)( | ||
| major, minor) | ||
|
|
||
|
|
||
| cdef nvFatbinResult _nvFatbinAddReloc(nvFatbinHandle handle, const void* code, size_t size) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: | ||
| global __nvFatbinAddReloc | ||
| _check_or_init_nvfatbin() | ||
| if __nvFatbinAddReloc == NULL: | ||
| with gil: | ||
| raise FunctionNotFoundError("function nvFatbinAddReloc is not found") | ||
| return (<nvFatbinResult (*)(nvFatbinHandle, const void*, size_t) noexcept nogil>__nvFatbinAddReloc)( | ||
| handle, code, size) | ||
|
|
||
|
|
||
| cdef nvFatbinResult _nvFatbinAddTileIR(nvFatbinHandle handle, const void* code, size_t size, const char* identifier, const char* optionsCmdLine) except?_NVFATBINRESULT_INTERNAL_LOADING_ERROR nogil: | ||
| global __nvFatbinAddTileIR | ||
| _check_or_init_nvfatbin() | ||
| if __nvFatbinAddTileIR == NULL: | ||
| with gil: | ||
| raise FunctionNotFoundError("function nvFatbinAddTileIR is not found") | ||
| return (<nvFatbinResult (*)(nvFatbinHandle, const void*, size_t, const char*, const char*) noexcept nogil>__nvFatbinAddTileIR)( | ||
| handle, code, size, identifier, optionsCmdLine) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.