summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 8d75e45e526656d95cb9e71a11a5a615dd501c67 (plain)
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
# Maintainer: Bink
: ${aur_llamacpp_build_universal:=false}
pkgname=llama.cpp-cuda-git
_pkgname="${pkgname%-cuda-git}"
pkgver=b8895.r7.550d684bd1
pkgrel=1
_build_number=0
_commit_id=
pkgdesc="Port of Facebook's LLaMA model in C/C++ (with NVIDIA CUDA optimizations)"
arch=(x86_64 aarch64)
url='https://github.com/ggml-org/llama.cpp'
license=('MIT')
backup=('etc/conf.d/llama.cpp')
depends=(
  cuda
  curl
  gcc-libs
  glibc  
  nvidia-utils
  openssl
)
makedepends=(  
  cmake
  cudnn
  git
  ninja
)
optdepends=(
'ccache: greatly reduce package re-build time'
'nccl: needed for multi-GPU parallelism'
'python-numpy: needed for convert_hf_to_gguf.py'
'python-safetensors: needed for convert_hf_to_gguf.py'
'python-sentencepiece: needed for convert_hf_to_gguf.py'
'python-pytorch: needed for convert_hf_to_gguf.py'
'python-transformers: needed for convert_hf_to_gguf.py'
'rdma-core: RDMA transport for RPC backend'
)
# Note: This package provides libggml (with CUDA) and libggml-cuda-git to support
# downstream packages like whisper.cpp-cuda that require CUDA-enabled GGML backends.
provides=(
  "${_pkgname}"
  libggml-cuda-git
  libggml
  libggml.so
  ggml
)
conflicts=(
  "${_pkgname}"
  libggml
  ggml
)
source=(
"git+https://github.com/ggml-org/llama.cpp.git"
llama.cpp.conf
llama.cpp.service
)
sha256sums=('SKIP'
            '53fa70cfe40cb8a3ca432590e4f76561df0f129a31b121c9b4b34af0da7c4d87'
            '0377d08a07bda056785981d3352ccd2dbc0387c4836f91fb73e6b790d836620d')
b2sums=('SKIP'
        '088e6b702e42bf1af019f69c8a85b0cd1196599e12f196e086ea1271e1800540947d1b51e3500821ec4556386f8e3c8217c0ad03570b764b85016827648939e7'
        '56e8e6e99c37f9baa1db5e3f8956f48a59bdbdc48797ae9b41292f0d1cdc3e41e5174bd7d721f3db84587ca271b11b480525e8c32cdb0f17f689b5537623c0a7')

pkgver() {
  cd "${_pkgname}" || exit
  printf "%s" "$(git describe --long --tags | sed 's/\([^-]*-\)g/r\1/;s/-/./g')"
}

prepare() {
  cd "${_pkgname}" || exit
  # Get the latest commit hash
  _commit_id=$(git rev-parse HEAD)
  _build_number=$(git rev-list --count HEAD)
  cd ..
}

build() {
  # Ensure CUDA environment is set up
  if [[ -z "${NVCC_CCBIN}" ]]; then
    export NVCC_CCBIN=/usr/bin/g++
  fi
  if ! type -P nvcc &>/dev/null && [[ -d /opt/cuda/bin ]]; then
    export PATH="/opt/cuda/bin:$PATH"
  fi

  local _cmake_options=(
    -G Ninja
    -B build
    -S "${_pkgname}"
    -DCMAKE_BUILD_TYPE=Release
    -DCMAKE_INSTALL_PREFIX='/usr'
    -DBUILD_SHARED_LIBS=ON
    -DLLAMA_BUILD_TESTS=OFF
    -DLLAMA_USE_SYSTEM_GGML=OFF
    -DGGML_ALL_WARNINGS=OFF
    -DGGML_ALL_WARNINGS_3RD_PARTY=OFF
    -DGGML_BUILD_EXAMPLES=OFF
    -DGGML_BUILD_TESTS=OFF
    -DGGML_OPENMP=ON
    -DGGML_LTO=ON
    -DGGML_RPC=ON
    -DGGML_CUDA=ON
    -DGGML_CUDA_FA_ALL_QUANTS=ON
    -DGGML_CUDNN=ON
    -DGGML_CUDA_COMPRESSION_MODE=speed
    -DLLAMA_BUILD_SERVER=ON
    -DLLAMA_BUILD_NUMBER="${_build_number}"
    -DLLAMA_BUILD_COMMIT="${_commit_id}"
    -DLLAMA_OPENSSL=ON
    -Wno-dev
  )

  if [[ ${aur_llamacpp_build_universal} == true ]]; then
    echo "Building universal binary [aur_llamacpp_build_universal == true]"
    _cmake_options+=(
      -DGGML_BACKEND_DL=ON
      -DGGML_NATIVE=OFF
      -DGGML_CPU_ALL_VARIANTS=ON
    )
  else
    # we lose GGML_NATIVE_DEFAULT due to how makepkg includes
    # $SOURCE_DATE_EPOCH in ENV
    _cmake_options+=(
      -DGGML_NATIVE=ON
    )
  fi

  # Allow user-specified additional flags
  if [[ -n "${aur_llamacpp_cmakeopts:-}" ]]; then
    echo "Applying custom CMake options: ${aur_llamacpp_cmakeopts}"
    # shellcheck disable=SC2206 # intentional word splitting
    _cmake_options+=(${aur_llamacpp_cmakeopts})
  fi

  cmake "${_cmake_options[@]}"
  cmake --build build
}

package() {
  DESTDIR="${pkgdir}" cmake --install build
  install -Dm644 "${_pkgname}/LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
  install -Dm644 "llama.cpp.conf" "${pkgdir}/etc/conf.d/llama.cpp"
  install -Dm644 "llama.cpp.service" "${pkgdir}/usr/lib/systemd/system/llama.cpp.service"
}