nixpkgs/pkgs/development/libraries/nvidia-thrust/default.nix

103 lines
2.7 KiB
Nix
Raw Normal View History

2022-04-12 15:57:03 +02:00
{ lib
, config
2022-04-12 15:57:03 +02:00
, fetchFromGitHub
, stdenv
, cmake
, pkg-config
, cudaPackages ? { }
2022-04-12 15:57:03 +02:00
, symlinkJoin
, tbb
, hostSystem ? "CPP"
, deviceSystem ? if config.cudaSupport or false then "CUDA" else "OMP"
2022-04-12 15:57:03 +02:00
}:
# Policy for device_vector<T>
assert builtins.elem deviceSystem [
"CPP" # Serial on CPU
"OMP" # Parallel with OpenMP
"TBB" # Parallel with Intel TBB
"CUDA" # Parallel on GPU
];
# Policy for host_vector<T>
# Always lives on CPU, but execution can be made parallel
assert builtins.elem hostSystem [ "CPP" "OMP" "TBB" ];
2022-04-12 15:57:03 +02:00
let
pname = "nvidia-thrust";
version = "1.16.0";
inherit (cudaPackages) backendStdenv cudaFlags;
cudaCapabilities = map cudaFlags.dropDot cudaFlags.cudaCapabilities;
2022-04-13 01:37:57 +02:00
tbbSupport = builtins.elem "TBB" [ deviceSystem hostSystem ];
cudaSupport = deviceSystem == "CUDA";
2022-04-12 15:57:03 +02:00
# TODO: Would like to use this:
cudaJoined = symlinkJoin {
name = "cuda-packages-unsplit";
paths = with cudaPackages; [
cuda_nvcc
cuda_nvrtc # symbols: cudaLaunchDevice, &c; notice postBuild
2022-04-12 15:57:03 +02:00
cuda_cudart # cuda_runtime.h
libcublas
];
postBuild = ''
ln -s $out/lib $out/lib64
'';
2022-04-12 15:57:03 +02:00
};
in
stdenv.mkDerivation {
inherit pname version;
src = fetchFromGitHub {
owner = "NVIDIA";
repo = "thrust";
rev = version;
fetchSubmodules = true;
hash = "sha256-/EyznxWKuHuvHNjq+SQg27IaRbtkjXR2zlo2YgCWmUQ=";
};
# NVIDIA's "compiler hacks" seem like work-arounds for legacy toolchains and
# cause us errors such as:
# > Thrust's test harness uses CMAKE_CXX_COMPILER for the CUDA host compiler.
# > Refusing to overwrite specified CMAKE_CUDA_HOST_COMPILER
# So we un-fix cmake after them:
postPatch = ''
echo > cmake/ThrustCompilerHacks.cmake
'';
2022-04-13 01:37:57 +02:00
buildInputs = lib.optionals tbbSupport [ tbb ];
2022-04-12 15:57:03 +02:00
nativeBuildInputs = [
cmake
pkg-config
] ++ lib.optionals cudaSupport [
2022-04-13 01:37:57 +02:00
# Goes in native build inputs because thrust looks for headers
2022-04-12 15:57:03 +02:00
# in a path relative to nvcc...
cudaJoined
2022-04-12 15:57:03 +02:00
];
cmakeFlags = [
"-DTHRUST_INCLUDE_CUB_CMAKE=${if cudaSupport then "ON" else "OFF"}"
"-DTHRUST_DEVICE_SYSTEM=${deviceSystem}"
"-DTHRUST_HOST_SYSTEM=${hostSystem}"
"-DTHRUST_AUTO_DETECT_COMPUTE_ARCHS=OFF"
"-DTHRUST_DISABLE_ARCH_BY_DEFAULT=ON"
] ++ lib.optionals cudaFlags.enableForwardCompat [
"-DTHRUST_ENABLE_COMPUTE_FUTURE=ON"
] ++ map (sm: "THRUST_ENABLE_COMPUTE_${sm}") cudaCapabilities;
2022-04-12 15:57:03 +02:00
passthru = {
inherit cudaSupport cudaPackages cudaJoined;
};
2022-04-12 15:57:03 +02:00
meta = with lib; {
description = "A high-level C++ parallel algorithms library that builds on top of CUDA, TBB, OpenMP, etc";
2022-04-12 15:57:03 +02:00
homepage = "https://github.com/NVIDIA/thrust";
license = licenses.asl20;
platforms = platforms.unix;
maintainers = with maintainers; [ SomeoneSerge ];
};
}