at master 248 lines 8.0 kB view raw
1{ 2 blas, 3 boost, 4 clblast, 5 cmake, 6 config, 7 cudaPackages, 8 fetchFromGitHub, 9 fftw, 10 fftwFloat, 11 fmt_9, 12 forge, 13 freeimage, 14 gtest, 15 lapack, 16 lib, 17 libGL, 18 mesa, 19 ocl-icd, 20 opencl-clhpp, 21 pkg-config, 22 python3, 23 span-lite, 24 stdenv, 25 # NOTE: We disable tests by default, because they cannot be run easily on 26 # non-NixOS systems when either CUDA or OpenCL support is enabled (CUDA and 27 # OpenCL need access to drivers that are installed outside of Nix on 28 # non-NixOS systems). 29 doCheck ? false, 30 cpuSupport ? true, 31 cudaSupport ? config.cudaSupport, 32 # OpenCL needs mesa which is broken on Darwin 33 openclSupport ? !stdenv.hostPlatform.isDarwin, 34 # This argument lets one run CUDA & OpenCL tests on non-NixOS systems by 35 # telling Nix where to find the drivers. If you know the version of the 36 # Nvidia driver that is installed on your system, you can do: 37 # 38 # arrayfire.override { 39 # nvidiaComputeDrivers = 40 # callPackage 41 # (prev.linuxPackages.nvidiaPackages.mkDriver { 42 # version = cudaVersion; # our driver version 43 # sha256_64bit = cudaHash; # sha256 of the .run binary 44 # useGLVND = false; 45 # useProfiles = false; 46 # useSettings = false; 47 # usePersistenced = false; 48 # ... 49 # }) 50 # { libsOnly = true; }; 51 # } 52 nvidiaComputeDrivers ? null, 53 fetchpatch, 54}: 55 56# ArrayFire compiles with 64-bit BLAS, but some tests segfault or throw 57# exceptions, which means that it isn't really supported yet... 58assert blas.isILP64 == false; 59 60stdenv.mkDerivation rec { 61 pname = "arrayfire"; 62 version = "3.9.0"; 63 64 src = fetchFromGitHub { 65 owner = "arrayfire"; 66 repo = "arrayfire"; 67 rev = "v3.9.0"; 68 hash = "sha256-80fxdkaeAQ5u0X/UGPaI/900cdkZ/vXNcOn5tkZ+C3Y="; 69 }; 70 71 # We cannot use the clfft from Nixpkgs because ArrayFire maintain a fork 72 # of clfft where they've modified the CMake build system, and the 73 # CMakeLists.txt of ArrayFire assumes that we're using that fork. 74 # 75 # This can be removed once ArrayFire upstream their changes. 76 clfft = fetchFromGitHub { 77 owner = "arrayfire"; 78 repo = "clfft"; 79 rev = "760096b37dcc4f18ccd1aac53f3501a83b83449c"; 80 sha256 = "sha256-vJo1YfC2AJIbbRj/zTfcOUmi0Oj9v64NfA9MfK8ecoY="; 81 }; 82 glad = fetchFromGitHub { 83 owner = "arrayfire"; 84 repo = "glad"; 85 rev = "ef8c5508e72456b714820c98e034d9a55b970650"; 86 sha256 = "sha256-u9Vec7XLhE3xW9vzM7uuf+b18wZsh/VMtGbB6nMVlno="; 87 }; 88 threads = fetchFromGitHub { 89 owner = "arrayfire"; 90 repo = "threads"; 91 rev = "4d4a4f0384d1ac2f25b2c4fc1d57b9e25f4d6818"; 92 sha256 = "sha256-qqsT9woJDtQvzuV323OYXm68pExygYs/+zZNmg2sN34="; 93 }; 94 test-data = fetchFromGitHub { 95 owner = "arrayfire"; 96 repo = "arrayfire-data"; 97 rev = "a5f533d7b864a4d8f0dd7c9aaad5ff06018c4867"; 98 sha256 = "sha256-AWzhsrDXyZrQN2bd0Ng/XlE8v02x7QWTiFTyaAuRXSw="; 99 }; 100 # ArrayFire fails to compile with newer versions of spdlog, so we can't use 101 # the one in Nixpkgs. Once they upgrade, we can switch to using spdlog from 102 # Nixpkgs. 103 spdlog = fetchFromGitHub { 104 owner = "gabime"; 105 repo = "spdlog"; 106 rev = "v1.9.2"; 107 hash = "sha256-GSUdHtvV/97RyDKy8i+ticnSlQCubGGWHg4Oo+YAr8Y="; 108 }; 109 110 cmakeFlags = [ 111 "-DBUILD_TESTING=ON" 112 # We do not build examples, because building tests already takes long enough... 113 "-DAF_BUILD_EXAMPLES=OFF" 114 # No need to build forge, because it's a separate package 115 "-DAF_BUILD_FORGE=OFF" 116 "-DAF_COMPUTE_LIBRARY='FFTW/LAPACK/BLAS'" 117 # Prevent ArrayFire from trying to download some matrices from the Internet 118 "-DAF_TEST_WITH_MTX_FILES=OFF" 119 # Have to use the header-only version, because we're not using the version 120 # from Nixpkgs. Otherwise, libaf.so won't be able to find the shared 121 # library, because ArrayFire's CMake files do not run the install step of 122 # spdlog. 123 "-DAF_WITH_SPDLOG_HEADER_ONLY=ON" 124 (if cpuSupport then "-DAF_BUILD_CPU=ON" else "-DAF_BUILD_CPU=OFF") 125 (if openclSupport then "-DAF_BUILD_OPENCL=ON" else "-DAF_BUILD_OPENCL=OFF") 126 (if cudaSupport then "-DAF_BUILD_CUDA=ON" else "-DAF_BUILD_CUDA=OFF") 127 ] 128 ++ lib.optionals cudaSupport [ 129 # ArrayFire use deprecated FindCUDA in their CMake files, so we help CMake 130 # locate cudatoolkit. 131 "-DCUDA_LIBRARIES_PATH=${cudaPackages.cudatoolkit}/lib" 132 ]; 133 134 # ArrayFire have a repo with assets for the examples. Since we don't build 135 # the examples anyway, remove the dependency on assets. 136 patches = [ 137 ./no-assets.patch 138 ./no-download.patch 139 # Fix for newer opencl-clhpp. Remove with the next release. 140 (fetchpatch { 141 url = "https://github.com/arrayfire/arrayfire/pull/3562.patch"; 142 hash = "sha256-AdWlpcRTn9waNAaVpZfK6sJ/xBQLiBC4nBeEYiGNN50"; 143 }) 144 ]; 145 146 postPatch = '' 147 mkdir -p ./extern/af_glad-src 148 mkdir -p ./extern/af_threads-src 149 mkdir -p ./extern/af_test_data-src 150 mkdir -p ./extern/ocl_clfft-src 151 mkdir -p ./extern/spdlog-src 152 cp -R --no-preserve=mode,ownership ${glad}/* ./extern/af_glad-src/ 153 cp -R --no-preserve=mode,ownership ${threads}/* ./extern/af_threads-src/ 154 cp -R --no-preserve=mode,ownership ${test-data}/* ./extern/af_test_data-src/ 155 cp -R --no-preserve=mode,ownership ${clfft}/* ./extern/ocl_clfft-src/ 156 cp -R --no-preserve=mode,ownership ${spdlog}/* ./extern/spdlog-src/ 157 158 # libaf.so (the unified backend) tries to load the right shared library at 159 # runtime, and the search paths are hard-coded... We tweak them to point to 160 # the installation directory in the Nix store. 161 substituteInPlace src/api/unified/symbol_manager.cpp \ 162 --replace '"/opt/arrayfire-3/lib/",' \ 163 "\"$out/lib/\", \"/opt/arrayfire-3/lib/\"," 164 ''; 165 166 inherit doCheck; 167 checkPhase = 168 let 169 LD_LIBRARY_PATH = builtins.concatStringsSep ":" ( 170 [ 171 "${forge}/lib" 172 "${freeimage}/lib" 173 ] 174 ++ lib.optional cudaSupport "${cudaPackages.cudatoolkit}/lib64" 175 # On non-NixOS systems, help the tests find Nvidia drivers 176 ++ lib.optional (nvidiaComputeDrivers != null) "${nvidiaComputeDrivers}/lib" 177 ); 178 ctestFlags = builtins.concatStringsSep " " ( 179 # We have to run with "-j1" otherwise various segfaults occur on non-NixOS systems. 180 [ 181 "--output-on-errors" 182 "-j1" 183 ] 184 # See https://github.com/arrayfire/arrayfire/issues/3484 185 ++ lib.optional openclSupport "-E '(inverse_dense|cholesky_dense)'" 186 ); 187 in 188 '' 189 export LD_LIBRARY_PATH=${LD_LIBRARY_PATH} 190 '' 191 + 192 # On non-NixOS systems, help the tests find Nvidia drivers 193 lib.optionalString (openclSupport && nvidiaComputeDrivers != null) '' 194 export OCL_ICD_VENDORS=${nvidiaComputeDrivers}/etc/OpenCL/vendors 195 '' 196 + '' 197 # Note: for debugging, enable AF_TRACE=all 198 AF_PRINT_ERRORS=1 ctest ${ctestFlags} 199 ''; 200 201 buildInputs = [ 202 blas 203 boost.dev 204 boost.out 205 clblast 206 fftw 207 fftwFloat 208 # We need fmt_9 because ArrayFire fails to compile with newer versions. 209 fmt_9 210 forge 211 freeimage 212 gtest 213 lapack 214 libGL 215 ocl-icd 216 opencl-clhpp 217 span-lite 218 ] 219 ++ lib.optionals cudaSupport [ 220 cudaPackages.cudatoolkit 221 cudaPackages.cudnn 222 cudaPackages.cuda_cccl 223 ] 224 ++ lib.optionals openclSupport [ 225 mesa 226 ]; 227 228 nativeBuildInputs = [ 229 cmake 230 pkg-config 231 python3 232 ]; 233 234 meta = with lib; { 235 description = "General-purpose library for parallel and massively-parallel computations"; 236 longDescription = '' 237 A general-purpose library that simplifies the process of developing software that targets parallel and massively-parallel architectures including CPUs, GPUs, and other hardware acceleration devices."; 238 ''; 239 license = licenses.bsd3; 240 homepage = "https://arrayfire.com/"; 241 platforms = platforms.linux; 242 maintainers = with maintainers; [ 243 chessai 244 twesterhout 245 ]; 246 broken = true; 247 }; 248}