-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
python3Packages.pycuda: add maintainer and clean up #465047
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
Open
ConnorBaker
wants to merge
2
commits into
NixOS:master
Choose a base branch
from
ConnorBaker:fix/pycuda-cleanup
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 was deleted.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -1,81 +1,233 @@ | ||
| { | ||
| _cuda, | ||
| boost, | ||
| buildPythonPackage, | ||
| addDriverRunpath, | ||
| fetchPypi, | ||
| cudaPackages, | ||
| fetchFromGitHub, | ||
| lib, | ||
| mako, | ||
| boost, | ||
| numpy, | ||
| pytools, | ||
| pytest, | ||
| decorator, | ||
| appdirs, | ||
| six, | ||
| cudaPackages, | ||
| platformdirs, | ||
| python, | ||
| mkDerivation, | ||
| lib, | ||
| pytools, | ||
| setuptools, | ||
| wheel, | ||
| writableTmpDirAsHomeHook, | ||
| writeShellApplication, | ||
| stdenvNoCC, | ||
| }: | ||
| let | ||
| compyte = import ./compyte.nix { inherit mkDerivation fetchFromGitHub; }; | ||
|
|
||
| inherit (cudaPackages) cudatoolkit; | ||
| inherit (_cuda.lib) dropDots; | ||
| inherit (cudaPackages) | ||
| backendStdenv | ||
| cuda_cudart | ||
| cuda_cccl | ||
| cuda_nvcc | ||
| cuda_profiler_api | ||
| libcurand | ||
| ; | ||
| inherit (lib) | ||
| getBin | ||
| getFirstOutput | ||
| getInclude | ||
| getLib | ||
| licenses | ||
| maintainers | ||
| teams | ||
| ; | ||
| in | ||
| buildPythonPackage rec { | ||
| buildPythonPackage { | ||
| __structuredAttrs = true; | ||
|
|
||
| pname = "pycuda"; | ||
| version = "2025.1.2"; | ||
| format = "setuptools"; | ||
|
|
||
| src = fetchPypi { | ||
| inherit pname version; | ||
| hash = "sha256-DdgpEdctjgPGMSiuROmc+3tGiQlKumzFGT2OlEcXqvo="; | ||
| pyproject = true; | ||
|
|
||
| stdenv = backendStdenv; | ||
|
|
||
| src = fetchFromGitHub { | ||
| owner = "inducer"; | ||
| repo = "pycuda"; | ||
| tag = "v2025.1.2"; | ||
| hash = "sha256-JMGVNjiKCAno29df8Zk3njvpgvz9JE8mb0HeJMVTnCQ="; | ||
| # Use the vendored compyte source rather than tracking it as a separate dependency. | ||
| # As an added bonus, this should unbreak the update script added by buildPythonPackage. | ||
| fetchSubmodules = true; | ||
| }; | ||
|
|
||
| preConfigure = with lib.versions; '' | ||
| ${python.pythonOnBuildForHost.interpreter} configure.py --boost-inc-dir=${boost.dev}/include \ | ||
| --boost-lib-dir=${boost}/lib \ | ||
| --no-use-shipped-boost \ | ||
| --boost-python-libname=boost_python${major python.version}${minor python.version} \ | ||
| --cuda-root=${cudatoolkit} | ||
| ''; | ||
| build-system = [ | ||
| setuptools | ||
| wheel | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be able to get rid of |
||
| ]; | ||
|
|
||
| postInstall = '' | ||
| ln -s ${compyte} $out/${python.sitePackages}/pycuda/compyte | ||
| ''; | ||
| nativeBuildInputs = [ | ||
| cuda_nvcc | ||
| ]; | ||
|
|
||
| postFixup = '' | ||
| find $out/lib -type f \( -name '*.so' -or -name '*.so.*' \) | while read lib; do | ||
| echo "setting opengl runpath for $lib..." | ||
| addDriverRunpath "$lib" | ||
| done | ||
| ''; | ||
| prePatch = '' | ||
| nixLog "removing vendored boost source" | ||
| rm -rf "$PWD/bpl-subset" | ||
|
|
||
| # Requires access to libcuda.so.1 which is provided by the driver | ||
| doCheck = false; | ||
| nixLog "patching $PWD/pycuda/compiler.py::compile to fix CUDA include paths" | ||
| substituteInPlace "$PWD/pycuda/compiler.py" \ | ||
| --replace-fail \ | ||
| 'include_dirs = [*include_dirs, _find_pycuda_include_path()]' \ | ||
| 'include_dirs = [ | ||
| *include_dirs, | ||
| "${getInclude cuda_nvcc}/include", | ||
| "${getInclude cuda_cudart}/include", | ||
| "${getInclude cuda_cccl}/include", | ||
| "${getInclude cuda_profiler_api}/include", | ||
| "${getInclude libcurand}/include", | ||
| _find_pycuda_include_path(), | ||
| ]' | ||
|
|
||
| checkPhase = '' | ||
| py.test | ||
| ''; | ||
| nixLog "patching $PWD/pycuda/compiler.py::compile to fix NVCC path" | ||
| substituteInPlace "$PWD/pycuda/compiler.py" \ | ||
| --replace-fail \ | ||
| 'nvcc="nvcc"' \ | ||
| 'nvcc="${getBin cuda_nvcc}/bin/nvcc"' | ||
|
|
||
| nativeBuildInputs = [ addDriverRunpath ]; | ||
| nixLog "patching $PWD/pycuda/compiler.py::DynamicModule.__init__ to fix CUDA runtime library path" | ||
| substituteInPlace "$PWD/pycuda/compiler.py" \ | ||
| --replace-fail \ | ||
| 'cuda_libdir=None,' \ | ||
| 'cuda_libdir="${getLib cuda_cudart}/lib",' | ||
| ''; | ||
|
|
||
| propagatedBuildInputs = [ | ||
| dependencies = [ | ||
| boost | ||
| mako | ||
| numpy | ||
| platformdirs | ||
| pytools | ||
| pytest | ||
| decorator | ||
| appdirs | ||
| six | ||
| cudatoolkit | ||
| compyte | ||
| python | ||
| mako | ||
| ]; | ||
|
|
||
| meta = with lib; { | ||
| homepage = "https://github.com/inducer/pycuda/"; | ||
| buildInputs = [ | ||
| cuda_cccl | ||
| cuda_cudart | ||
| cuda_nvcc | ||
| cuda_profiler_api | ||
| libcurand | ||
| ]; | ||
|
|
||
| configureScript = "./configure.py"; | ||
|
|
||
| # configure.py doesn't support the installation directory arguments _multioutConfig sets. | ||
| # The other argument provided by configurePhase, like --prefix, --enable-shared, and --disable-static are ignored. | ||
| setOutputFlags = false; | ||
|
|
||
| configureFlags = [ | ||
| # The expected boost python library name is something like boost_python-py313, but our library name doesn't have a | ||
| # hyphen. The pythonVersion is already a major-minor version, so we just need to remove the dot. | ||
| "--no-use-shipped-boost" | ||
| "--boost-python-libname=boost_python${dropDots python.pythonVersion}" | ||
| # Provide paths to our CUDA libraries. | ||
| "--cudadrv-lib-dir=${getFirstOutput [ "stubs" "lib" ] cuda_cudart}/lib/stubs" | ||
| ]; | ||
|
|
||
| # Requires access to libcuda.so.1 which is provided by the driver | ||
| doCheck = false; | ||
|
|
||
| # From setup.py | ||
| pythonImportsCheck = [ | ||
| "pycuda" | ||
| # "pycuda.gl" # Requires the CUDA driver | ||
| "pycuda.sparse" | ||
| "pycuda.compyte" | ||
| ]; | ||
|
|
||
| # TODO: Split into testers and tests. | ||
| # NOTE: Tests take 23m to run on a 4090 and require 18GB of VRAM. | ||
| passthru = { | ||
| testers.tester = writeShellApplication { | ||
| derivationArgs = { | ||
| __structuredAttrs = true; | ||
| strictDeps = true; | ||
| }; | ||
| name = "pycuda-tester"; | ||
| runtimeInputs = [ | ||
| (python.withPackages (ps: [ | ||
| ps.pycuda | ||
| ps.pytest | ||
| ])) | ||
| ]; | ||
| text = '' | ||
| echo "Copying pycuda test sources to $PWD/pycuda_test_sources" | ||
| mkdir -p "$PWD/pycuda_test_sources" | ||
| cp -r "${python.pkgs.pycuda.src}"/test "$PWD/pycuda_test_sources" | ||
| chmod -R u+w "$PWD/pycuda_test_sources" | ||
|
|
||
| pushd "$PWD/pycuda_test_sources" | ||
| pytest "$@" | ||
| popd | ||
| ''; | ||
| }; | ||
| tests = | ||
| let | ||
| makeTest = | ||
| name: testArgs: | ||
| stdenvNoCC.mkDerivation { | ||
| __structuredAttrs = true; | ||
| strictDeps = true; | ||
|
|
||
| inherit name testArgs; | ||
|
|
||
| dontUnpack = true; | ||
|
|
||
| nativeBuildInputs = [ | ||
| # cuda_nvcc | ||
| python.pkgs.pycuda.passthru.testers.tester | ||
| writableTmpDirAsHomeHook | ||
| ]; | ||
|
|
||
| dontConfigure = true; | ||
|
|
||
| buildPhase = '' | ||
| nixLog "using testArgs: ''${testArgs[*]@Q}" | ||
| pycuda-tester "''${testArgs[@]}" || { | ||
| nixErrorLog "pycuda-tester finished with non-zero exit code: $?" | ||
| exit 1 | ||
| } | ||
| ''; | ||
|
|
||
| postInstall = '' | ||
| touch $out | ||
| ''; | ||
|
|
||
| requiredSystemFeatures = [ "cuda" ]; | ||
| }; | ||
| in | ||
| { | ||
| # Fast: ~10s on a 4090 | ||
| driver = makeTest "pycuda-driver-tests" [ "test/test_driver.py" ]; | ||
| # Fast: ~16s on a 4090 | ||
| cumath = makeTest "pycuda-cumath-tests" [ "test/test_cumath.py" ]; | ||
| # Fast: ~3m on a 4090 | ||
| gpuarray-fast = makeTest "pycuda-gpuarray-fast-tests" [ | ||
| "test/test_gpuarray.py" | ||
| "-k" | ||
| "not test_curand_wrappers" | ||
| ]; | ||
| # EXTREMELY SLOW: ~20m on a 4090 | ||
| gpuarray-slow = makeTest "pycuda-gpuarray-slow-tests" [ | ||
| "test/test_gpuarray.py" | ||
| "-k" | ||
| "test_curand_wrappers" | ||
| ]; | ||
| }; | ||
| }; | ||
|
|
||
| meta = { | ||
| description = "CUDA integration for Python"; | ||
| homepage = "https://github.com/inducer/pycuda/"; | ||
| license = licenses.mit; | ||
| maintainers = [ ]; | ||
| platforms = [ | ||
| "aarch64-linux" | ||
| "x86_64-linux" | ||
| ]; | ||
| maintainers = with maintainers; [ connorbaker ]; | ||
| teams = [ teams.cuda ]; | ||
| }; | ||
| } | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using
wrapProgramhere?