-
Notifications
You must be signed in to change notification settings - Fork 103
/
shared.nix
177 lines (162 loc) · 7.69 KB
/
shared.nix
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
{ compiler ? "ghc865" }:
let
libtorch_src = pkgs:
let src = pkgs.fetchFromGitHub {
owner = "stites";
repo = "pytorch-world";
rev = "44a1795d253b37d4fa3a0d2f52ff718181599fb3";
sha256 = "1i012ld8j0j3x152g2ra4bqyy6sial6hwbai4z7na8ac1hbpicn8";
};
in (pkgs.callPackage "${src}/libtorch/release.nix" { });
overlayShared = pkgsNew: pkgsOld: {
inherit (libtorch_src pkgsOld)
libtorch_cpu
libtorch_cudatoolkit_9_2
libtorch_cudatoolkit_10_1
;
haskell = pkgsOld.haskell // {
packages = pkgsOld.haskell.packages // {
"${compiler}" = pkgsOld.haskell.packages."${compiler}".override (old: {
overrides =
let
appendConfigureFlag = pkgsNew.haskell.lib.appendConfigureFlag;
dontCheck = pkgsNew.haskell.lib.dontCheck;
failOnAllWarnings = pkgsNew.haskell.lib.failOnAllWarnings;
overrideCabal = pkgsNew.haskell.lib.overrideCabal;
optionalString = pkgsNew.stdenv.lib.optionalString;
isDarwin = pkgsNew.stdenv.isDarwin;
enableLibraryProfiling = pkgsNew.stdenv.lib.enableLibraryProfiling;
mkHasktorchExtension = postfix:
haskellPackagesNew: haskellPackagesOld: {
"libtorch-ffi_${postfix}" =
appendConfigureFlag
(overrideCabal
(haskellPackagesOld.callCabal2nix
"libtorch-ffi"
../libtorch-ffi
{ c10 = pkgsNew."libtorch_${postfix}"
; torch = pkgsNew."libtorch_${postfix}"
; }
)
(old: {
preConfigure = (old.preConfigure or "") + optionalString isDarwin ''
sed -i -e 's/-optc-std=c++11 -optc-xc++/-optc-xc++/g' ../libtorch-ffi/libtorch-ffi.cabal;
'';
}
)
)
"--extra-include-dirs=${pkgsNew."libtorch_${postfix}"}/include/torch/csrc/api/include";
"hasktorch_${postfix}" =
overrideCabal
(haskellPackagesOld.callCabal2nix
"hasktorch"
../hasktorch
{ libtorch-ffi = haskellPackagesNew."libtorch-ffi_${postfix}"; }
)
(old: {
preConfigure = (old.preConfigure or "") + optionalString (!isDarwin) ''
export LD_PRELOAD=${pkgs.mkl}/lib/libmkl_rt.so
'';
}
);
"hasktorch-examples_${postfix}" =
# failOnAllWarnings
(haskellPackagesOld.callCabal2nix
"examples"
../examples
{ libtorch-ffi = haskellPackagesNew."libtorch-ffi_${postfix}"
; hasktorch = haskellPackagesNew."hasktorch_${postfix}"
; }
);
};
extension =
haskellPackagesNew: haskellPackagesOld: {
hasktorch-codegen =
# failOnAllWarnings
(haskellPackagesNew.callCabal2nix
"codegen"
../codegen
{ }
);
inline-c =
# failOnAllWarnings
(haskellPackagesNew.callCabal2nix
"inline-c"
../inline-c/inline-c
{ }
);
inline-c-cpp =
# failOnAllWarnings
(haskellPackagesNew.callCabal2nix
"inline-c-cpp"
../inline-c/inline-c-cpp
{ }
);
};
in
pkgsNew.lib.fold
pkgsNew.lib.composeExtensions
(old.overrides or (_: _: {}))
[ (pkgsNew.haskell.lib.packagesFromDirectory { directory = ./haskellExtensions/.; })
extension
(mkHasktorchExtension "cpu")
(mkHasktorchExtension "cudatoolkit_9_2")
(mkHasktorchExtension "cudatoolkit_10_1")
];
}
);
};
};
};
bootstrap = import <nixpkgs> { };
nixpkgs = builtins.fromJSON (builtins.readFile ./nixpkgs.json);
src = bootstrap.fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs";
inherit (nixpkgs) rev sha256;
};
pkgs = import src {
config = { allowUnsupportedSystem = true; allowUnfree = true; };
overlays = [ overlayShared ];
};
nullIfDarwin = arg: if pkgs.stdenv.hostPlatform.system == "x86_64-darwin" then null else arg;
fixmkl = old: old // {
shellHook = ''
export LD_PRELOAD=${pkgs.mkl}/lib/libmkl_rt.so
'';
};
fixcpath = libtorch: old: old // {
shellHook = ''
export CPATH=${libtorch}/include/torch/csrc/api/include
'';
};
in
rec {
inherit nullIfDarwin;
inherit (pkgs.haskell.packages."${compiler}")
hasktorch-codegen
inline-c
inline-c-cpp
libtorch-ffi_cpu
libtorch-ffi_cudatoolkit_9_2
libtorch-ffi_cudatoolkit_10_1
hasktorch_cpu
hasktorch_cudatoolkit_9_2
hasktorch_cudatoolkit_10_1
hasktorch-examples_cpu
hasktorch-examples_cudatoolkit_9_2
hasktorch-examples_cudatoolkit_10_1
;
shell-hasktorch-codegen = (pkgs.haskell.lib.doBenchmark pkgs.haskell.packages."${compiler}".hasktorch-codegen).env;
shell-inline-c = (pkgs.haskell.lib.doBenchmark pkgs.haskell.packages."${compiler}".inline-c).env;
shell-inline-c-cpp = (pkgs.haskell.lib.doBenchmark pkgs.haskell.packages."${compiler}".inline-c-cpp).env;
shell-libtorch-ffi_cpu = (pkgs.haskell.lib.doBenchmark pkgs.haskell.packages."${compiler}".libtorch-ffi_cpu).env.overrideAttrs (fixcpath pkgs.libtorch_cpu);
shell-libtorch-ffi_cudatoolkit_9_2 = (pkgs.haskell.lib.doBenchmark pkgs.haskell.packages."${compiler}".libtorch-ffi_cudatoolkit_9_2).env.overrideAttrs (fixcpath pkgs.libtorch_cudatoolkit_9_2);
shell-libtorch-ffi_cudatoolkit_10_1 = (pkgs.haskell.lib.doBenchmark pkgs.haskell.packages."${compiler}".libtorch-ffi_cudatoolkit_10_1).env.overrideAttrs (fixcpath pkgs.libtorch_cudatoolkit_10_1);
shell-hasktorch_cpu = (pkgs.haskell.lib.doBenchmark pkgs.haskell.packages."${compiler}".hasktorch_cpu).env.overrideAttrs fixmkl;
shell-hasktorch_cudatoolkit_9_2 = (pkgs.haskell.lib.doBenchmark pkgs.haskell.packages."${compiler}".hasktorch_cudatoolkit_9_2).env.overrideAttrs fixmkl;
shell-hasktorch_cudatoolkit_10_1 = (pkgs.haskell.lib.doBenchmark pkgs.haskell.packages."${compiler}".hasktorch_cudatoolkit_10_1).env.overrideAttrs fixmkl;
shell-hasktorch-examples_cpu = (pkgs.haskell.lib.doBenchmark pkgs.haskell.packages."${compiler}".hasktorch-examples_cpu).env.overrideAttrs fixmkl;
shell-hasktorch-examples_cudatoolkit_9_2 = (pkgs.haskell.lib.doBenchmark pkgs.haskell.packages."${compiler}".hasktorch-examples_cudatoolkit_9_2).env.overrideAttrs fixmkl;
shell-hasktorch-examples_cudatoolkit_10_1 = (pkgs.haskell.lib.doBenchmark pkgs.haskell.packages."${compiler}".hasktorch-examples_cudatoolkit_10_1).env.overrideAttrs fixmkl;
}