summary refs log tree commit diff
path: root/pkgs/os-specific/linux/intel-ocl/default.nix
blob: 06cb18b2377429a17bf2fa80f91a8fd67580a8de (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{ lib, stdenv, fetchzip, rpmextract, ncurses5, numactl, zlib }:

stdenv.mkDerivation rec {
  pname = "intel-ocl";
  version = "5.0-63503";

  src = fetchzip {
    url = "https://registrationcenter-download.intel.com/akdlm/irc_nas/11396/SRB5.0_linux64.zip";
    sha256 = "0qbp63l74s0i80ysh9ya8x7r79xkddbbz4378nms9i7a0kprg9p2";
    stripRoot = false;
  };

  buildInputs = [ rpmextract ];

  sourceRoot = ".";

  libPath = lib.makeLibraryPath [
    stdenv.cc.cc.lib
    ncurses5
    numactl
    zlib
  ];

  postUnpack = ''
    # Extract the RPMs contained within the source ZIP.
    rpmextract source/intel-opencl-r${version}.x86_64.rpm
    rpmextract source/intel-opencl-cpu-r${version}.x86_64.rpm
  '';

  patchPhase = ''
    runHook prePatch

    # Remove libOpenCL.so, since we use ocl-icd's libOpenCL.so instead and this would cause a clash.
    rm opt/intel/opencl/libOpenCL.so*

    # Patch shared libraries.
    for lib in opt/intel/opencl/*.so; do
      patchelf --set-rpath "${libPath}:$out/lib/intel-ocl" $lib || true
    done

    runHook postPatch
  '';

  buildPhase = ''
    runHook preBuild

    # Create ICD file, which just contains the path of the corresponding shared library.
    echo "$out/lib/intel-ocl/libintelocl.so" > intel.icd

    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall

    install -D -m 0755 opt/intel/opencl/*.so* -t $out/lib/intel-ocl
    install -D -m 0644 opt/intel/opencl/*.{o,rtl,bin} -t $out/lib/intel-ocl
    install -D -m 0644 opt/intel/opencl/{LICENSE,NOTICES} -t $out/share/doc/intel-ocl
    install -D -m 0644 intel.icd -t $out/etc/OpenCL/vendors

    runHook postInstall
  '';

  dontStrip = true;

  meta = {
    description = "Official OpenCL runtime for Intel CPUs";
    homepage    = "https://software.intel.com/en-us/articles/opencl-drivers";
    license     = lib.licenses.unfree;
    platforms   = [ "x86_64-linux" ];
    maintainers = [ lib.maintainers.kierdavis ];
  };
}