1{ lib
2, stdenv
3, fetchFromGitHub
4, cmake
5, pkg-config
6, opencl-clhpp
7, ocl-icd
8, fftw
9, fftwFloat
10, blas
11, lapack
12, boost
13, mesa
14, libGLU
15, libGL
16, freeimage
17, python3
18, clfft
19, clblas
20, doxygen
21, buildDocs ? false
22, config
23, cudaSupport ? config.cudaSupport
24, cudatoolkit
25, darwin
26}:
27
28stdenv.mkDerivation rec {
29 pname = "arrayfire";
30 version = "3.7.3";
31
32 src = fetchFromGitHub {
33 owner = pname;
34 repo = pname;
35 rev = "v${version}";
36 sha256 = "0gcbg6b6gs38xhks5pp0vkcqs89zl7rh9982jqlzsd0h724qddw0";
37 fetchSubmodules = true;
38 };
39
40 cmakeFlags = [
41 "-DAF_BUILD_OPENCL=OFF"
42 "-DAF_BUILD_EXAMPLES=OFF"
43 "-DBUILD_TESTING=OFF"
44 ] ++ lib.optional cudaSupport "-DCMAKE_LIBRARY_PATH=${cudatoolkit}/lib/stubs";
45
46 patches = [ ./no-download.patch ];
47
48 postPatch = ''
49 mkdir -p ./build/third_party/clFFT/src
50 cp -R --no-preserve=mode,ownership ${clfft.src}/ ./build/third_party/clFFT/src/clFFT-ext/
51 mkdir -p ./build/third_party/clBLAS/src
52 cp -R --no-preserve=mode,ownership ${clblas.src}/ ./build/third_party/clBLAS/src/clBLAS-ext/
53 mkdir -p ./build/include/CL
54 cp -R --no-preserve=mode,ownership ${opencl-clhpp}/include/CL/cl2.hpp ./build/include/CL/cl2.hpp
55 '';
56
57 preBuild = lib.optionalString cudaSupport ''
58 export CUDA_PATH="${cudatoolkit}"
59 '';
60
61 nativeBuildInputs = [
62 cmake
63 pkg-config
64 python3
65 ];
66
67 strictDeps = true;
68
69 buildInputs = [
70 opencl-clhpp
71 fftw
72 fftwFloat
73 blas
74 lapack
75 libGLU
76 libGL
77 mesa
78 freeimage
79 boost.out
80 boost.dev
81 ] ++ lib.optionals stdenv.isLinux [
82 ocl-icd
83 ] ++ lib.optionals cudaSupport [
84 cudatoolkit
85 ] ++ lib.optionals buildDocs [
86 doxygen
87 ] ++ lib.optionals stdenv.isDarwin [
88 darwin.apple_sdk_11_0.frameworks.Accelerate
89 ];
90
91 meta = with lib; {
92 description = "A general-purpose library for parallel and massively-parallel computations";
93 longDescription = ''
94 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.";
95 '';
96 license = licenses.bsd3;
97 homepage = "https://arrayfire.com/";
98 platforms = platforms.linux ++ platforms.darwin;
99 maintainers = with maintainers; [ chessai ];
100 };
101}