Skip to content

Commit e38cef8

Browse files
committed
flake.nix: add rocm support and cleanup
1 parent bae5c5f commit e38cef8

File tree

2 files changed

+44
-41
lines changed

2 files changed

+44
-41
lines changed

flake.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,29 @@
66
outputs = { self, nixpkgs, flake-utils }:
77
flake-utils.lib.eachDefaultSystem (system:
88
let
9+
name = "llama.cpp";
10+
src = ./.;
11+
meta.mainProgram = "llama";
912
inherit (pkgs.stdenv) isAarch32 isAarch64 isDarwin;
1013
buildInputs = with pkgs; [ openmpi ];
1114
osSpecific = with pkgs; buildInputs ++
12-
(
13-
if isAarch64 && isDarwin then
14-
with pkgs.darwin.apple_sdk_11_0.frameworks; [
15-
Accelerate
16-
MetalKit
17-
]
18-
else if isAarch32 && isDarwin then
19-
with pkgs.darwin.apple_sdk.frameworks; [
20-
Accelerate
21-
CoreGraphics
22-
CoreVideo
23-
]
24-
else
25-
with pkgs; [ openblas ]
26-
);
15+
(
16+
if isAarch64 && isDarwin then
17+
with pkgs.darwin.apple_sdk_11_0.frameworks; [
18+
Accelerate
19+
MetalKit
20+
]
21+
else if isAarch32 && isDarwin then
22+
with pkgs.darwin.apple_sdk.frameworks; [
23+
Accelerate
24+
CoreGraphics
25+
CoreVideo
26+
]
27+
else
28+
with pkgs; [ openblas ]
29+
);
2730
pkgs = import nixpkgs { inherit system; };
28-
nativeBuildInputs = with pkgs; [ cmake pkgconfig ];
31+
nativeBuildInputs = with pkgs; [ cmake ninja pkgconfig ];
2932
llama-python =
3033
pkgs.python3.withPackages (ps: with ps; [ numpy sentencepiece ]);
3134
postPatch = ''
@@ -38,35 +41,35 @@
3841
mv $out/bin/server $out/bin/llama-server
3942
'';
4043
cmakeFlags = [ "-DLLAMA_BUILD_SERVER=ON" "-DLLAMA_MPI=ON" "-DBUILD_SHARED_LIBS=ON" "-DCMAKE_SKIP_BUILD_RPATH=ON" ];
41-
in {
44+
in
45+
{
4246
packages.default = pkgs.stdenv.mkDerivation {
43-
name = "llama.cpp";
44-
src = ./.;
45-
postPatch = postPatch;
46-
nativeBuildInputs = nativeBuildInputs;
47-
buildInputs = osSpecific;
47+
inherit name src meta postPatch nativeBuildInputs buildInputs postInstall;
4848
cmakeFlags = cmakeFlags
4949
++ (if isAarch64 && isDarwin then [
50-
"-DCMAKE_C_FLAGS=-D__ARM_FEATURE_DOTPROD=1"
51-
"-DLLAMA_METAL=ON"
52-
] else [
53-
"-DLLAMA_BLAS=ON"
54-
"-DLLAMA_BLAS_VENDOR=OpenBLAS"
50+
"-DCMAKE_C_FLAGS=-D__ARM_FEATURE_DOTPROD=1"
51+
"-DLLAMA_METAL=ON"
52+
] else [
53+
"-DLLAMA_BLAS=ON"
54+
"-DLLAMA_BLAS_VENDOR=OpenBLAS"
5555
]);
56-
postInstall = postInstall;
57-
meta.mainProgram = "llama";
5856
};
5957
packages.opencl = pkgs.stdenv.mkDerivation {
60-
name = "llama.cpp";
61-
src = ./.;
62-
postPatch = postPatch;
63-
nativeBuildInputs = nativeBuildInputs;
58+
inherit name src meta postPatch nativeBuildInputs postInstall;
6459
buildInputs = with pkgs; buildInputs ++ [ clblast ];
6560
cmakeFlags = cmakeFlags ++ [
6661
"-DLLAMA_CLBLAST=ON"
6762
];
68-
postInstall = postInstall;
69-
meta.mainProgram = "llama";
63+
};
64+
packages.rocm = pkgs.stdenv.mkDerivation {
65+
inherit name src meta postPatch nativeBuildInputs postInstall;
66+
buildInputs = with pkgs; buildInputs ++ [ hip hipblas rocblas ];
67+
cmakeFlags = cmakeFlags ++ [
68+
"-DLLAMA_HIPBLAS=1"
69+
"-DCMAKE_C_COMPILER=hipcc"
70+
"-DCMAKE_CXX_COMPILER=hipcc"
71+
"-DCMAKE_POSITION_INDEPENDENT_CODE=ON"
72+
];
7073
};
7174
apps.llama-server = {
7275
type = "app";

0 commit comments

Comments
 (0)