Skip to content

Commit bc3ec2c

Browse files
authored
flake : support nix build '.#opencl' (#2337)
1 parent a940458 commit bc3ec2c

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

flake.nix

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
flake-utils.lib.eachDefaultSystem (system:
88
let
99
inherit (pkgs.stdenv) isAarch32 isAarch64 isDarwin;
10-
osSpecific = with pkgs; [ openmpi ] ++
10+
buildInputs = with pkgs; [ openmpi ];
11+
osSpecific = with pkgs; buildInputs ++
1112
(
1213
if isAarch64 && isDarwin then
1314
with pkgs.darwin.apple_sdk_11_0.frameworks; [
@@ -29,29 +30,44 @@
2930
nativeBuildInputs = with pkgs; [ cmake pkgconfig ];
3031
llama-python =
3132
pkgs.python3.withPackages (ps: with ps; [ numpy sentencepiece ]);
33+
postPatch = ''
34+
substituteInPlace ./ggml-metal.m \
35+
--replace '[bundle pathForResource:@"ggml-metal" ofType:@"metal"];' "@\"$out/bin/ggml-metal.metal\";"
36+
substituteInPlace ./*.py --replace '/usr/bin/env python' '${llama-python}/bin/python'
37+
'';
38+
postInstall = ''
39+
mv $out/bin/main $out/bin/llama
40+
mv $out/bin/server $out/bin/llama-server
41+
'';
42+
cmakeFlags = [ "-DLLAMA_BUILD_SERVER=ON" "-DLLAMA_MPI=ON" "-DBUILD_SHARED_LIBS=ON" "-DCMAKE_SKIP_BUILD_RPATH=ON" ];
3243
in {
3344
packages.default = pkgs.stdenv.mkDerivation {
3445
name = "llama.cpp";
3546
src = ./.;
36-
postPatch = ''
37-
substituteInPlace ./ggml-metal.m \
38-
--replace '[bundle pathForResource:@"ggml-metal" ofType:@"metal"];' "@\"$out/bin/ggml-metal.metal\";"
39-
substituteInPlace ./*.py --replace '/usr/bin/env python' '${llama-python}/bin/python'
40-
'';
47+
postPatch = postPatch;
4148
nativeBuildInputs = nativeBuildInputs;
4249
buildInputs = osSpecific;
43-
cmakeFlags = [ "-DLLAMA_BUILD_SERVER=ON" "-DLLAMA_MPI=ON" "-DBUILD_SHARED_LIBS=ON" "-DCMAKE_SKIP_BUILD_RPATH=ON" ]
50+
cmakeFlags = cmakeFlags
4451
++ (if isAarch64 && isDarwin then [
4552
"-DCMAKE_C_FLAGS=-D__ARM_FEATURE_DOTPROD=1"
4653
"-DLLAMA_METAL=ON"
4754
] else [
4855
"-DLLAMA_BLAS=ON"
4956
"-DLLAMA_BLAS_VENDOR=OpenBLAS"
5057
]);
51-
postInstall = ''
52-
mv $out/bin/main $out/bin/llama
53-
mv $out/bin/server $out/bin/llama-server
54-
'';
58+
postInstall = postInstall;
59+
meta.mainProgram = "llama";
60+
};
61+
packages.opencl = pkgs.stdenv.mkDerivation {
62+
name = "llama.cpp";
63+
src = ./.;
64+
postPatch = postPatch;
65+
nativeBuildInputs = nativeBuildInputs;
66+
buildInputs = with pkgs; buildInputs ++ [ clblast ];
67+
cmakeFlags = cmakeFlags ++ [
68+
"-DLLAMA_CLBLAST=ON"
69+
];
70+
postInstall = postInstall;
5571
meta.mainProgram = "llama";
5672
};
5773
apps.llama-server = {

0 commit comments

Comments
 (0)