2024-06-05 15:53:02 +00:00
|
|
|
{
|
|
|
|
lib,
|
|
|
|
stdenv,
|
|
|
|
pythonAtLeast,
|
|
|
|
pythonOlder,
|
|
|
|
fetchFromGitHub,
|
|
|
|
python,
|
|
|
|
buildPythonPackage,
|
|
|
|
setuptools,
|
|
|
|
numpy,
|
2024-07-27 06:49:29 +00:00
|
|
|
numpy_2,
|
2024-06-05 15:53:02 +00:00
|
|
|
llvmlite,
|
|
|
|
libcxx,
|
|
|
|
importlib-metadata,
|
|
|
|
substituteAll,
|
|
|
|
runCommand,
|
|
|
|
symlinkJoin,
|
|
|
|
writers,
|
|
|
|
numba,
|
|
|
|
|
|
|
|
config,
|
|
|
|
|
|
|
|
# CUDA-only dependencies:
|
|
|
|
addDriverRunpath,
|
|
|
|
autoAddDriverRunpath,
|
|
|
|
cudaPackages,
|
|
|
|
|
|
|
|
# CUDA flags:
|
|
|
|
cudaSupport ? config.cudaSupport,
|
2020-04-24 23:36:52 +00:00
|
|
|
}:
|
|
|
|
|
2022-04-15 01:41:22 +00:00
|
|
|
let
|
2024-04-21 15:54:59 +00:00
|
|
|
cudatoolkit = cudaPackages.cuda_nvcc;
|
2024-06-05 15:53:02 +00:00
|
|
|
in
|
|
|
|
buildPythonPackage rec {
|
2024-07-27 06:49:29 +00:00
|
|
|
version = "0.60.0";
|
2020-04-24 23:36:52 +00:00
|
|
|
pname = "numba";
|
2023-11-16 04:20:00 +00:00
|
|
|
pyproject = true;
|
|
|
|
|
2024-02-29 20:09:43 +00:00
|
|
|
disabled = pythonOlder "3.8" || pythonAtLeast "3.13";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-08-10 07:59:29 +00:00
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "numba";
|
|
|
|
repo = "numba";
|
2023-11-16 04:20:00 +00:00
|
|
|
rev = "refs/tags/${version}";
|
2023-08-10 07:59:29 +00:00
|
|
|
# Upstream uses .gitattributes to inject information about the revision
|
|
|
|
# hash and the refname into `numba/_version.py`, see:
|
|
|
|
#
|
|
|
|
# - https://git-scm.com/docs/gitattributes#_export_subst and
|
|
|
|
# - https://github.com/numba/numba/blame/5ef7c86f76a6e8cc90e9486487294e0c34024797/numba/_version.py#L25-L31
|
|
|
|
#
|
|
|
|
# Hence this hash may change if GitHub / Git will change it's behavior.
|
|
|
|
# Hopefully this will not happen until the next release. We are fairly sure
|
|
|
|
# that upstream relies on those strings to be valid, that's why we don't
|
|
|
|
# use `forceFetchGit = true;`.` If in the future we'll observe the hash
|
|
|
|
# changes too often, we can always use forceFetchGit, and inject the
|
|
|
|
# relevant strings ourselves, using `sed` commands, in extraPostFetch.
|
2024-07-27 06:49:29 +00:00
|
|
|
hash = "sha256-hUL281wHLA7wo8umzBNhiGJikyIF2loCzjLECuC+pO0=";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2024-04-21 15:54:59 +00:00
|
|
|
|
|
|
|
postPatch = ''
|
|
|
|
substituteInPlace numba/cuda/cudadrv/driver.py \
|
|
|
|
--replace-fail \
|
|
|
|
"dldir = [" \
|
|
|
|
"dldir = [ '${addDriverRunpath.driverLink}/lib', "
|
|
|
|
'';
|
|
|
|
|
2023-03-04 12:14:45 +00:00
|
|
|
env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-I${lib.getDev libcxx}/include/c++/v1";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-07-27 06:49:29 +00:00
|
|
|
build-system = [
|
|
|
|
setuptools
|
|
|
|
numpy_2
|
|
|
|
];
|
|
|
|
|
|
|
|
nativeBuildInputs = lib.optionals cudaSupport [
|
|
|
|
autoAddDriverRunpath
|
|
|
|
cudaPackages.cuda_nvcc
|
|
|
|
];
|
2024-04-21 15:54:59 +00:00
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
buildInputs = lib.optionals cudaSupport [ cudaPackages.cuda_cudart ];
|
2022-09-30 11:47:45 +00:00
|
|
|
|
2024-07-27 06:49:29 +00:00
|
|
|
dependencies = [
|
2022-06-16 17:23:12 +00:00
|
|
|
numpy
|
|
|
|
llvmlite
|
|
|
|
setuptools
|
2024-06-05 15:53:02 +00:00
|
|
|
] ++ lib.optionals (pythonOlder "3.9") [ importlib-metadata ];
|
2022-04-15 01:41:22 +00:00
|
|
|
|
2023-08-10 07:59:29 +00:00
|
|
|
patches = lib.optionals cudaSupport [
|
2022-04-15 01:41:22 +00:00
|
|
|
(substituteAll {
|
|
|
|
src = ./cuda_path.patch;
|
|
|
|
cuda_toolkit_path = cudatoolkit;
|
2024-04-21 15:54:59 +00:00
|
|
|
cuda_toolkit_lib_path = lib.getLib cudatoolkit;
|
2022-04-15 01:41:22 +00:00
|
|
|
})
|
|
|
|
];
|
|
|
|
|
2022-11-21 17:40:18 +00:00
|
|
|
# run a smoke test in a temporary directory so that
|
|
|
|
# a) Python picks up the installed library in $out instead of the build files
|
|
|
|
# b) we have somewhere to put $HOME so some caching tests work
|
|
|
|
# c) it doesn't take 6 CPU hours for the full suite
|
2020-04-24 23:36:52 +00:00
|
|
|
checkPhase = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
runHook preCheck
|
2021-09-18 10:52:07 +00:00
|
|
|
|
2022-11-21 17:40:18 +00:00
|
|
|
pushd $(mktemp -d)
|
|
|
|
HOME=. ${python.interpreter} -m numba.runtests -m $NIX_BUILD_CORES numba.tests.test_usecases
|
|
|
|
popd
|
|
|
|
|
|
|
|
runHook postCheck
|
|
|
|
'';
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
pythonImportsCheck = [ "numba" ];
|
2021-09-18 10:52:07 +00:00
|
|
|
|
2024-04-21 15:54:59 +00:00
|
|
|
passthru.testers.cuda-detect =
|
|
|
|
writers.writePython3Bin "numba-cuda-detect"
|
|
|
|
{ libraries = [ (numba.override { cudaSupport = true; }) ]; }
|
|
|
|
''
|
|
|
|
from numba import cuda
|
|
|
|
cuda.detect()
|
|
|
|
'';
|
2022-11-21 17:40:18 +00:00
|
|
|
passthru.tests = {
|
|
|
|
# CONTRIBUTOR NOTE: numba also contains CUDA tests, though these cannot be run in
|
|
|
|
# this sandbox environment. Consider running similar commands to those below outside the
|
|
|
|
# sandbox manually if you have the appropriate hardware; support will be detected
|
|
|
|
# and the corresponding tests enabled automatically.
|
|
|
|
# Also, the full suite currently does not complete on anything but x86_64-linux.
|
2024-06-05 15:53:02 +00:00
|
|
|
fullSuite = runCommand "${pname}-test" { } ''
|
2022-11-21 17:40:18 +00:00
|
|
|
pushd $(mktemp -d)
|
|
|
|
# pip and python in $PATH is needed for the test suite to pass fully
|
2024-06-05 15:53:02 +00:00
|
|
|
PATH=${
|
|
|
|
python.withPackages (p: [
|
|
|
|
p.numba
|
|
|
|
p.pip
|
|
|
|
])
|
|
|
|
}/bin:$PATH
|
2022-11-21 17:40:18 +00:00
|
|
|
HOME=$PWD python -m numba.runtests -m $NIX_BUILD_CORES
|
|
|
|
popd
|
|
|
|
touch $out # stop Nix from complaining no output was generated and failing the build
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
meta = with lib; {
|
2022-06-16 17:23:12 +00:00
|
|
|
description = "Compiling Python code using LLVM";
|
2021-09-18 10:52:07 +00:00
|
|
|
homepage = "https://numba.pydata.org/";
|
2021-02-05 17:12:51 +00:00
|
|
|
license = licenses.bsd2;
|
2023-08-22 20:05:09 +00:00
|
|
|
mainProgram = "numba";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|