Skip to content

Commit 55d12a3

Browse files
committed
Added nix build
1 parent b7fac0f commit 55d12a3

File tree

9 files changed

+161
-25
lines changed

9 files changed

+161
-25
lines changed

.ghci

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
:set prompt "\x03BB> "
22
:seti -XTypeApplications
33
:load ArrayFire
4+
:m - ArrayFire
5+
import qualified ArrayFire as A
46
:set -laf

arrayfire.cabal

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,19 @@ test-suite doctests
170170
main-is:
171171
Main.hs
172172
hs-source-dirs:
173-
doctest
173+
doctests
174174
build-depends:
175-
base, doctest >= 0.8
175+
arrayfire
176+
, base < 5
177+
, doctest >= 0.8
178+
, split
179+
autogen-modules:
180+
Build_doctests
181+
other-modules:
182+
Build_doctests
176183
default-language:
177184
Haskell2010
178185

186+
source-repository head
187+
type: git
188+
location: https://github.com/arrayfire/arrayfire-haskell.git

default.nix

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
{ pkgs ? import <nixpkgs> {} }:
1+
{ pkgs ? import <nixpkgs> { config.allowUnfree = true; } }:
22
# Latest arrayfire is not yet procured w/ nix.
3-
pkgs.haskellPackages.callCabal2nix "arrayfire" ./. { af = null; }
3+
let
4+
af = pkgs.callPackage ./nix {};
5+
pkg = pkgs.haskellPackages.callCabal2nix "arrayfire" ./. { inherit af; };
6+
in
7+
with pkgs.haskell.lib;
8+
enableCabalFlag pkg "disable-default-paths"

doctest/Main.hs

Lines changed: 0 additions & 7 deletions
This file was deleted.

doctests/Main.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module Main (main) where
2+
3+
import ArrayFire
4+
import Build_doctests (flags, pkgs, module_sources)
5+
import System.Environment
6+
import Test.DocTest (doctest)
7+
import Data.List.Split
8+
9+
main :: IO ()
10+
main = do
11+
print $ 1 + (1 :: Array Int)
12+
moreFlags <- drop 1 . splitOn " " <$> getEnv "NIX_TARGET_LDFLAGS"
13+
mapM_ print moreFlags
14+
mapM_ print (flags ++ pkgs ++ module_sources ++ moreFlags)
15+
doctest (moreFlags ++ flags ++ pkgs ++ module_sources)

nix/default.nix

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{ stdenv, fetchurl, fetchFromGitHub, cmake, pkgconfig
2+
, cudatoolkit, opencl-clhpp, ocl-icd, fftw, fftwFloat, mkl
3+
, blas, openblas, boost, mesa_noglu, libGLU_combined
4+
, freeimage, python, lib
5+
}:
6+
7+
let
8+
version = "3.6.4";
9+
10+
clfftSource = fetchFromGitHub {
11+
owner = "arrayfire";
12+
repo = "clFFT";
13+
rev = "16925fb93338b3cac66490b5cf764953d6a5dac7";
14+
sha256 = "0y35nrdz7w4n1l17myhkni3hwm37z775xn6f76xmf1ph7dbkslsc";
15+
fetchSubmodules = true;
16+
};
17+
18+
clblasSource = fetchFromGitHub {
19+
owner = "arrayfire";
20+
repo = "clBLAS";
21+
rev = "1f3de2ae5582972f665c685b18ef0df43c1792bb";
22+
sha256 = "154mz52r5hm0jrp5fqrirzzbki14c1jkacj75flplnykbl36ibjs";
23+
fetchSubmodules = true;
24+
};
25+
26+
cl2hppSource = fetchurl {
27+
url = "https://github.com/KhronosGroup/OpenCL-CLHPP/releases/download/v2.0.10/cl2.hpp";
28+
sha256 = "1v4q0g6b6mwwsi0kn7kbjn749j3qafb9r4ld3zdq1163ln9cwnvw";
29+
};
30+
31+
in stdenv.mkDerivation {
32+
pname = "arrayfire";
33+
inherit version;
34+
35+
src = fetchurl {
36+
url = "http://arrayfire.com/arrayfire_source/arrayfire-full-${version}.tar.bz2";
37+
sha256 = "1fin7a9rliyqic3z83agkpb8zlq663q6gdxsnm156cs8s7f7rc9h";
38+
};
39+
40+
cmakeFlags = [
41+
"-DAF_BUILD_OPENCL=OFF"
42+
"-DAF_BUILD_EXAMPLES=OFF"
43+
"-DBUILD_TESTING=OFF"
44+
] ++ (lib.optional stdenv.isLinux ["-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 ${clfftSource}/ ./build/third_party/clFFT/src/clFFT-ext/
51+
mkdir -p ./build/third_party/clBLAS/src
52+
cp -R --no-preserve=mode,ownership ${clblasSource}/ ./build/third_party/clBLAS/src/clBLAS-ext/
53+
mkdir -p ./build/include/CL
54+
cp -R --no-preserve=mode,ownership ${cl2hppSource} ./build/include/CL/cl2.hpp
55+
'';
56+
57+
preBuild = lib.optionalString stdenv.isLinux ''
58+
export CUDA_PATH="${cudatoolkit}"'
59+
'';
60+
61+
enableParallelBuilding = true;
62+
63+
buildInputs = [
64+
cmake pkgconfig
65+
opencl-clhpp fftw fftwFloat
66+
mkl openblas
67+
libGLU_combined
68+
mesa_noglu freeimage
69+
boost.out boost.dev python
70+
] ++ (lib.optional stdenv.isLinux [ cudatoolkit ocl-icd ]);
71+
72+
meta = with stdenv.lib; {
73+
description = "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";
74+
license = licenses.bsd3;
75+
homepage = https://arrayfire.com/ ;
76+
maintainers = with stdenv.lib.maintainers; [ chessai ];
77+
inherit version;
78+
};
79+
}

nix/no-download.patch

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
diff --git a/CMakeModules/build_clBLAS.cmake b/CMakeModules/build_clBLAS.cmake
2+
index 8de529e8..6361b613 100644
3+
--- a/CMakeModules/build_clBLAS.cmake
4+
+++ b/CMakeModules/build_clBLAS.cmake
5+
@@ -14,8 +14,7 @@ find_package(OpenCL)
6+
7+
ExternalProject_Add(
8+
clBLAS-ext
9+
- GIT_REPOSITORY https://github.com/arrayfire/clBLAS.git
10+
- GIT_TAG arrayfire-release
11+
+ DOWNLOAD_COMMAND true
12+
BUILD_BYPRODUCTS ${clBLAS_location}
13+
PREFIX "${prefix}"
14+
INSTALL_DIR "${prefix}"
15+
diff --git a/CMakeModules/build_clFFT.cmake b/CMakeModules/build_clFFT.cmake
16+
index 28be38a3..85e3915e 100644
17+
--- a/CMakeModules/build_clFFT.cmake
18+
+++ b/CMakeModules/build_clFFT.cmake
19+
@@ -20,8 +20,7 @@ ENDIF()
20+
21+
ExternalProject_Add(
22+
clFFT-ext
23+
- GIT_REPOSITORY https://github.com/arrayfire/clFFT.git
24+
- GIT_TAG arrayfire-release
25+
+ DOWNLOAD_COMMAND true
26+
PREFIX "${prefix}"
27+
INSTALL_DIR "${prefix}"
28+
UPDATE_COMMAND ""

shell.nix

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ in
55
pkgs.lib.overrideDerivation pkg (drv: {
66
shellHook = ''
77
export PATH=$PATH:${pkgs.haskellPackages.doctest}/bin
8+
export PATH=$PATH:${pkgs.haskellPackages.cabal-install}/bin
89
function ghcid () {
910
${pkgs.haskellPackages.ghcid.bin}/bin/ghcid -c 'cabal v1-repl lib:arrayfire'
1011
};
@@ -18,13 +19,13 @@ in
1819
${pkgs.ag}/bin/ag -l | \
1920
${pkgs.entr}/bin/entr sh -c \
2021
'cabal v1-configure --enable-tests && \
21-
cabal v1-build doctests && dist/build/doctests/doctests'
22+
cabal v1-build doctests && dist/build/doctests/doctests src/ArrayFire/Algorithm.hs'
2223
}
2324
function repl () {
24-
${pkgs.cabal-install}/bin/cabal v1-repl lib:arrayfire
25+
cabal v1-repl lib:arrayfire
2526
}
2627
function docs () {
27-
${pkgs.cabal-install}/bin/cabal haddock
28+
cabal haddock
2829
open ./dist-newstyle/*/*/*/*/doc/html/arrayfire/index.html
2930
}
3031
'';

src/ArrayFire/Algorithm.hs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ import Data.Word
3333

3434
-- | Sum all of the elements in 'Array' along the specified dimension
3535
--
36-
-- >>> sum (vector @Double 10 [1..]) 0
37-
-- 33
36+
-- >>> A.sum (A.vector @Double 10 [1..]) 0
37+
-- 55.0
38+
--
39+
-- >>> A.sum (A.matrix @Double (10,10) [[2..],[2..]]) 0
40+
-- 65.0
3841
--
3942
sum
4043
:: AFType a
@@ -48,9 +51,9 @@ sum x (fromIntegral -> n) = getScalar (x `op1` (\p a -> af_sum p a n))
4851

4952
-- | Sum all of the elements in 'Array' along the specified dimension, using a default value for NaN
5053
--
51-
-- @
52-
-- >>> 'sumNaN' ('vector' \@'Double' 10 [1..]) 0 0.0
53-
-- @
54+
-- >>> A.sumNaN (A.vector @Double 10 [1..]) 0 0.0
55+
-- 55
56+
--
5457
sumNaN
5558
:: (Fractional a, AFType a)
5659
=> Array a
@@ -65,9 +68,9 @@ sumNaN n (fromIntegral -> i) d = getScalar (n `op1` (\p a -> af_sum_nan p a i d)
6568

6669
-- | Product all of the elements in 'Array' along the specified dimension
6770
--
68-
-- @
69-
-- >>> 'product' ('vector' \@'Double' 10 [1..]) 0
70-
-- @
71+
-- >>> A.product (A.vector @Double 10 [1..]) 0
72+
-- 3628800.0
73+
--
7174
product
7275
:: AFType a
7376
=> Array a
@@ -80,9 +83,9 @@ product x (fromIntegral -> n) = getScalar (x `op1` (\p a -> af_product p a n))
8083

8184
-- | Product all of the elements in 'Array' along the specified dimension, using a default value for NaN
8285
--
83-
-- @
84-
-- >>> 'productNaN' ('vector' \@'Double' 10 [1..]) 0 0.0
85-
-- @
86+
-- >>> A.productNaN (A.vector @Double 10 [1..]) 0 0.0
87+
-- 3628800.0
88+
--
8689
productNaN
8790
:: (AFType a, Fractional a)
8891
=> Array a

0 commit comments

Comments
 (0)