Skip to content

Adds path for the CUDA static library based on CUDA_HOME - #837

Merged
Andy-Jost merged 3 commits into
NVIDIA:mainfrom
Andy-Jost:fix/add-library-path-check
Aug 19, 2025
Merged

Adds path for the CUDA static library based on CUDA_HOME#837
Andy-Jost merged 3 commits into
NVIDIA:mainfrom
Andy-Jost:fix/add-library-path-check

Conversation

@Andy-Jost

Copy link
Copy Markdown
Contributor

Both CUDA_HOME (or CUDA_PATH) and LIBRARY_PATH are required to be set in the environment during installation. There was already a check for CUDA_HOME in setup.py, but no check for LIBRARY_PATH. This change adds a check to make sure LIBRARY_PATH is set.

When LIBRARY_PATH is not set, the installation fails at link time and indicates that cudart_static could not be found.

@copy-pr-bot

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

kkraus14
kkraus14 previously approved these changes Aug 14, 2025
@github-project-automationgithub-project-automationBot moved this from Todo to In Review in CCCLAug 14, 2025
@kkraus14

Copy link
Copy Markdown
Collaborator

@Andy-Jost to trigger CI to run you need to comment "/ok to test". More info here: https://docs.gha-runners.nvidia.com/platform/apps/copy-pr-bot/faqs

@Andy-Jost

Copy link
Copy Markdown
ContributorAuthor

/ok to test 6b178c1a24971ef7811dc4571cb08295a3956b7b

@Andy-Jost

Copy link
Copy Markdown
ContributorAuthor

This breaks Windows builds because LIBRARY_PATH is specific to Linux. While I could place a guard around the check, it's probably better to close this PR without merging.

@github-project-automationgithub-project-automationBot moved this from In Review to Done in CCCLAug 14, 2025
@rwgk

rwgk commented Aug 15, 2025

Copy link
Copy Markdown
Contributor

This breaks Windows builds because LIBRARY_PATH is specific to Linux. While I could place a guard around the check, it's probably better to close this PR without merging.

I think it'd be lovely to complete this PR, I stumbled over this many times.

Under Windows, we need LIB to be set.

This is a good way to test for Windows (we use that in cuda_pathfinder):

IS_WINDOWS = sys.platform == "win32"

@Andy-JostAndy-Jost reopened this Aug 18, 2025
@github-project-automationgithub-project-automationBot moved this from Done to Needs Triage in CCCLAug 18, 2025
@Andy-Jost

Copy link
Copy Markdown
ContributorAuthor

This breaks Windows builds because LIBRARY_PATH is specific to Linux. While I could place a guard around the check, it's probably better to close this PR without merging.

I think it'd be lovely to complete this PR, I stumbled over this many times.

Under Windows, we need LIB to be set.

This is a good way to test for Windows (we use that in cuda_pathfinder):

IS_WINDOWS = sys.platform == "win32"

I am looking into a solution that works for Windows as well as Linux.

@leofangleofang added this to the cuda-python parking lot milestone Aug 18, 2025
@leofangleofang linked an issue Aug 18, 2025 that may be closed by this pull request
@leofang

Copy link
Copy Markdown
Member

Probably just update library_dirs that's passed to setup() in setup.py?

@leofangleofang added enhancement Any code-related improvements P1 Medium priority - Should do cuda.bindings Everything related to the cuda.bindings module labels Aug 18, 2025
@Andy-Jost
Andy-Jostforce-pushed the fix/add-library-path-check branch from 37e877d to 44579bcCompareAugust 18, 2025 21:34
@Andy-Jost

Andy-Jost commented Aug 18, 2025

Copy link
Copy Markdown
ContributorAuthor

The latest changes eliminate the need to set either LIBRARY_PATH or LIB and should resolve issue #608.

Where can I find the source for the installation instructions? I.e., https://nvidia.github.io/cuda-python/cuda-bindings/latest/install.html.

Those can be updated now.

@Andy-Jost

Copy link
Copy Markdown
ContributorAuthor

Probably just update library_dirs that's passed to setup() in setup.py?

This did the trick.

@Andy-Jost
Andy-Jostforce-pushed the fix/add-library-path-check branch 2 times, most recently from d62461d to 96f3514CompareAugust 18, 2025 21:52
@Andy-Jost

Copy link
Copy Markdown
ContributorAuthor

/ok to test 96f3514f3ace9fdc505165add1f65ac52cbc970b

@github-actions

This comment has been minimized.

@Andy-Jost
Andy-Jostforce-pushed the fix/add-library-path-check branch from 96f3514 to 49ec36dCompareAugust 18, 2025 23:10
@Andy-JostAndy-Jost changed the title Adds a check to make sure LIBRARY_PATH is set in setup.py.Adds path for the CUDA static library based on CUDA_HOMEAug 19, 2025
@leofang

Copy link
Copy Markdown
Member

Thanks, @Andy-Jost! The diff is clean now.

I think to test this properly in the CI, we should delete these two lines

LIBRARY_PATH=/host/${{ env.CUDA_PATH }}/lib

LIB="${CUDA_HOME}\\lib\\x64;${LIB}"

Not sure if I miss any. I hope not 🤔

Comment threadcuda_bindings/setup.py Outdated
os.path.dirname(sysconfig.get_path("include")),
] + include_path_list
library_dirs = [sysconfig.get_path("platlib"), os.path.join(os.sys.prefix, "lib")]
cudalib_subdir = r"lib\x64" if sys.platform == "win32" else "lib64"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On the Linux side, one annoying thing is that depending on how CUDA is installed, this could be lib or lib64:

$ ls -l /usr/local/cuda-13.0/lib64/libcudart_static.a -rw-r--r-- 1 root root 1361104 Aug 5 09:32 /usr/local/cuda-13.0/lib64/libcudart_static.a
$ ls -l /usr/local/cuda-13.0/targets/x86_64-linux/lib/libcudart_static.a -rw-r--r-- 1 root root 1361104 Aug 5 09:32 /usr/local/cuda-13.0/targets/x86_64-linux/lib/libcudart_static.a

https://github.com/conda-forge/cuda-cudart-feedstock/blob/38fb08899691fa53fce33960ef37d48ab58584b0/recipe/meta.yaml#L220

https://github.com/conda-forge/cuda-cudart-feedstock/blob/38fb08899691fa53fce33960ef37d48ab58584b0/recipe/meta.yaml#L251

We probably should support both.

@Andy-Jost

Copy link
Copy Markdown
ContributorAuthor

/ok to test 19aaca9358742cb4913c6e138b0f9c28c6b0744d

@Andy-Jost

Copy link
Copy Markdown
ContributorAuthor

I see a failure in pre-commit.ci due to "ruff format" creating diffs. I think I get the general idea, but I don't see how to get more information (e.g., see the diffs, or run the ruff format locally). I can probably fix the formatting issue by guessing, but in general how can I get the details?

@Andy-Jost

Copy link
Copy Markdown
ContributorAuthor

/ok to test 19aaca9358742cb4913c6e138b0f9c28c6b0744d

@Andy-Jost

Copy link
Copy Markdown
ContributorAuthor

/ok to test 26da853a3bb600112694a26248c5399a9347446e

@Andy-Jost
Andy-Jostforce-pushed the fix/add-library-path-check branch from 26da853 to 73acddfCompareAugust 19, 2025 21:42
@Andy-Jost

Copy link
Copy Markdown
ContributorAuthor

/ok to test 73acddf

@github-project-automationgithub-project-automationBot moved this from Needs Triage to In Review in CCCLAug 19, 2025
@Andy-Jost
Andy-Jost merged commit 72e7791 into NVIDIA:mainAug 19, 2025
48 checks passed
@github-project-automationgithub-project-automationBot moved this from In Review to Done in CCCLAug 19, 2025
@Andy-Jost
Andy-Jost deleted the fix/add-library-path-check branch August 19, 2025 22:24
@github-actions

Copy link
Copy Markdown
Doc Preview CI
Preview removed because the pull request was closed or merged.

@leofang

Copy link
Copy Markdown
Member

@copilot please backport this PR to the 12.9.x branch. (Since this PR touched some files in the .github folder, the backport bot does not work.)

@leofangleofang mentioned this pull request Aug 20, 2025
@leofangleofang added to-be-backported Trigger the bot to raise a backport PR upon merge and removed enhancement Any code-related improvements labels Aug 20, 2025
@github-actions

Copy link
Copy Markdown

Git push to origin failed for 12.9.x with exitcode 1

@leofangleofang added the enhancement Any code-related improvements label Aug 20, 2025
@github-actions

Copy link
Copy Markdown

Git push to origin failed for 12.9.x with exitcode 1

CopilotAI added a commit that referenced this pull request Aug 21, 2025
Co-authored-by: leofang <5534781+leofang@users.noreply.github.com>
Andy-Jost added a commit that referenced this pull request Aug 21, 2025
…bc-85a8c5353e08
Backport PR #837: Add path for CUDA static library based on CUDA_HOME
@cpcloudcpcloud mentioned this pull request Oct 8, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.bindingsEverything related to the cuda.bindings moduleenhancementAny code-related improvementsP1Medium priority - Should doto-be-backportedTrigger the bot to raise a backport PR upon merge

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Ensure cuda_static's directory is passed to setuptools

4 participants

@Andy-Jost@kkraus14@rwgk@leofang