@@ -0,0 +1,75 @@
1+{ stdenv, fetchurl, gfortran, opencl-headers, clblas, ocl-icd, mkl, intel-ocl }:
2+
3+with stdenv.lib;
4+
5+let
6+ version = "1.3.0";
7+ incfile = builtins.toFile "make.inc.custom" ''
8+ CC = g++
9+ FORT = gfortran
10+
11+ ARCH = ar
12+ ARCHFLAGS = cr
13+ RANLIB = ranlib
14+
15+ OPTS = -fPIC -O3 -DADD_ -Wall
16+ FOPTS = -fPIC -O3 -DADD_ -Wall -x f95-cpp-input
17+ F77OPTS = -fPIC -O3 -DADD_ -Wall
18+ LDOPTS = -fPIC
19+
20+ -include make.check-mkl
21+ -include make.check-clblas
22+
23+ # Gnu mkl is not available I guess?
24+ #LIB = -lmkl_gf_lp64 -lmkl_gnu_thread -lmkl_core -lpthread -lm -fopenmp
25+ LIB = -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -liomp5 -lm -fopenmp
26+ LIB += -lclBLAS -lOpenCL
27+
28+ LIBDIR = -L$(MKLROOT)/lib/intel64 \
29+ -L$(MKLROOT)/../compiler/lib/intel64 \
30+ -L$(clBLAS)/lib64
31+
32+ INC = -I$(clBLAS)/include
33+ #-I$(AMDAPP)/include
34+ '';
35+in stdenv.mkDerivation {
36+ name = "clmagma-${version}";
37+ src = fetchurl {
38+ url = "http://icl.cs.utk.edu/projectsfiles/magma/cl/clmagma-${version}.tar.gz";
39+ sha256 = "1n27ny0xhwirw2ydn46pfcwy53gzia9zbam4irx44fd4d7f9ydv7";
40+ name = "clmagma-${version}.tar.gz";
41+ };
42+
43+ buildInputs = [
44+ gfortran
45+ clblas
46+ opencl-headers
47+ ocl-icd
48+ mkl
49+ intel-ocl
50+ ];
51+
52+ enableParallelBuilding=true;
53+
54+ MKLROOT = "${mkl}";
55+ clBLAS = "${clblas}";
56+
57+ # Otherwise build looks for it in /run/opengl-driver/etc/OpenCL/vendors,
58+ # which is not available.
59+ OPENCL_VENDOR_PATH="${intel-ocl}/etc/OpenCL/vendors";
60+
61+ preBuild = ''
62+ # By default it tries to use GPU, and thus fails for CPUs
63+ sed -i "s/CL_DEVICE_TYPE_GPU/CL_DEVICE_TYPE_DEFAULT/" interface_opencl/clmagma_runtime.cpp
64+ sed -i "s%/usr/local/clmagma%/$out%" Makefile.internal
65+ cp ${incfile} make.inc
66+ '';
67+
68+ meta = with stdenv.lib; {
69+ description = "Matrix Algebra on GPU and Multicore Architectures, OpenCL port";
70+ license = licenses.bsd3;
71+ homepage = http://icl.cs.utk.edu/magma/index.html;
72+ platforms = platforms.linux;
73+ maintainers = with maintainers; [ volhovm ];
74+ };
75+}