Skip to content

Commit c788f13

Browse files
committed
add precompileMetalShaders flag (defaults to false) to disable precompilation of metal shader
Precompilation requires Xcode to be installed and requires disable sandbox on nix-darwin
1 parent f625a7a commit c788f13

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

.devops/nix/package.nix

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
# It's necessary to consistently use backendStdenv when building with CUDA support,
3737
# otherwise we get libstdc++ errors downstream.
3838
effectiveStdenv ? if useCuda then cudaPackages.backendStdenv else stdenv,
39-
enableStatic ? effectiveStdenv.hostPlatform.isStatic
39+
enableStatic ? effectiveStdenv.hostPlatform.isStatic,
40+
precompileMetalShaders ? false
4041
}@inputs:
4142

4243
let
@@ -166,12 +167,12 @@ effectiveStdenv.mkDerivation (
166167
'';
167168

168169
# With PR#6015 https://github.com/ggerganov/llama.cpp/pull/6015,
169-
# `default.metallib` is compiled with Metal compiler from XCode
170+
# `default.metallib` may be compiled with Metal compiler from XCode
170171
# and we need to escape sandbox on MacOS to access Metal compiler.
171172
# `xcrun` is used find the path of the Metal compiler, which is varible
172173
# and not on $PATH
173174
# see https://github.com/ggerganov/llama.cpp/pull/6118 for discussion
174-
__noChroot = effectiveStdenv.isDarwin && useMetalKit;
175+
__noChroot = effectiveStdenv.isDarwin && useMetalKit && precompileMetalShaders;
175176

176177
nativeBuildInputs =
177178
[
@@ -189,7 +190,7 @@ effectiveStdenv.mkDerivation (
189190
]
190191
++ optionals (effectiveStdenv.hostPlatform.isGnu && enableStatic) [
191192
glibc.static
192-
] ++ optionals (effectiveStdenv.isDarwin && useMetalKit) [
193+
] ++ optionals (effectiveStdenv.isDarwin && useMetalKit && precompileMetalShaders) [
193194
xcrunHost
194195
];
195196

@@ -234,7 +235,10 @@ effectiveStdenv.mkDerivation (
234235
# Should likely use `rocmPackages.clr.gpuTargets`.
235236
"-DAMDGPU_TARGETS=gfx803;gfx900;gfx906:xnack-;gfx908:xnack-;gfx90a:xnack+;gfx90a:xnack-;gfx940;gfx941;gfx942;gfx1010;gfx1012;gfx1030;gfx1100;gfx1101;gfx1102"
236237
]
237-
++ optionals useMetalKit [ (lib.cmakeFeature "CMAKE_C_FLAGS" "-D__ARM_FEATURE_DOTPROD=1") ]
238+
++ optionals useMetalKit [
239+
(lib.cmakeFeature "CMAKE_C_FLAGS" "-D__ARM_FEATURE_DOTPROD=1")
240+
(cmakeBool "LLAMA_METAL_EMBED_LIBRARY" (!precompileMetalShaders))
241+
]
238242
++ optionals useBlas [ (lib.cmakeFeature "LLAMA_BLAS_VENDOR" "OpenBLAS") ];
239243

240244
# TODO(SomeoneSerge): It's better to add proper install targets at the CMake level,

0 commit comments

Comments
 (0)