summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 416545c1d23c7f4a3ea180c6ed6239c05e466836 (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
# Maintainer: robertfoster

_name=stable-diffusion.cpp
pkgbase="${_name}-git"
pkgname=(
  "${pkgbase}"
  "${_name}-cublas-git"
  "${_name}-hipblas-git"
)
pkgver=r108.48bcce4
pkgrel=1
pkgdesc="Stable Diffusion in pure C/C++"
arch=('armv7h' 'aarch64' 'x86_64')
url="https://github.com/leejet/stable-diffusion.cpp"
license=("MIT")
makedepends=(
  'ccache'
  'cmake'
  'cuda'
  'git'
  'rocm-hip-sdk'
  'openblas'
)
conflicts=("${_name}")
provides=("${_name}")
source=("${_name}::git+${url}"
  "git+https://github.com/ggerganov/ggml.git")

prepare() {
  cd "${srcdir}/${_name}"
  git submodule init
  git config submodule.ggml.url "${srcdir}/ggml"
  git -c protocol.file.allow=always submodule update

  if [ ! -d "${srcdir}/${_name}-cublas" ]; then
    cp -r "${srcdir}/${_name}" "${srcdir}/${_name}-cublas"
    cp -r "${srcdir}/${_name}" "${srcdir}/${_name}-openblas"
    cp -r "${srcdir}/${_name}" "${srcdir}/${_name}-hipblas"
  fi
}

pkgver() {
  cd "${srcdir}/${_name}"
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short=7 HEAD)"
}

build() {
  local _cmake_args=(
    -B build
    -S .
    -DCMAKE_INSTALL_PREFIX=/usr
    -DCMAKE_BUILD_TYPE=Release
  )

  local _cmake_cublas_args=(
    "${_cmake_args[@]}"
    -DSD_CUBLAS=ON
  )

  local _cmake_hipblas_args=(
    "${_cmake_args[@]}"
    -DCMAKE_C_COMPILER=clang
    -DCMAKE_CXX_COMPILER=clang++
    -DSD_HIPBLAS=ON
    -DAMDGPU_TARGETS=gfx1100
  )

  local _cmake_openblas_args=(
    "${_cmake_args[@]}"
    -DGGML_OPENBLAS=ON
  )

  echo "Build ${pkgbase} with OPENBlas"
  cd "${srcdir}/${_name}-openblas"
  cmake "${_cmake_openblas_args[@]}"
  cmake --build build

  echo "Build ${pkgbase} with CUBlas (NVIDIA CUDA)"
  export CUDA_PATH=/opt/cuda
  export PATH+=":/opt/cuda/bin:/opt/cuda/nsight_compute:/opt/cuda/nsight_systems/bin"
  export LD_LIBRARY_PATH+=":/opt/cuda/lib:/opt/cuda/lib64"
  export NVCC_PREPEND_FLAGS='-ccbin /opt/cuda/bin'
  cd "${srcdir}/${_name}-cublas"
  cmake "${_cmake_cublas_args[@]}"
  cmake --build build

  echo "Build ${pkgbase} with HIPBlas (AMD ROCm)"
  cd "${srcdir}/${_name}-hipblas"
  export CXXFLAGS+="$CXXFLAGS -fcf-protection=none"
  export PATH+=":/opt/rocm/lib/llvm/bin"
  CC="/opt/rocm/llvm/bin/clang" CXX="/opt/rocm/llvm/bin/clang++" \
    cmake "${_cmake_hipblas_args[@]}"
  cmake --build build

}

package_stable-diffusion.cpp-git() {
  pkgdesc="$pkgdesc (with OPENBlas CPU optimizations)"
  depends+=('openblas')
  provides=("${pkgbase}=${pkgver}")

  cd "${_name}-openblas"
  DESTDIR="${pkgdir}" cmake --install build
}

package_stable-diffusion.cpp-cublas-git() {
  pkgdesc="$pkgdesc (with NVIDIA CUDA optimizations)"
  depends+=('cuda')
  provides=("${pkgbase}=${pkgver}")
  conflicts=("${pkgbase}")

  cd "${_name}-cublas"
  DESTDIR="${pkgdir}" cmake --install build
}

package_stable-diffusion.cpp-hipblas-git() {
  pkgdesc="$pkgdesc (with AMD ROCm optimizations)"
  depends+=('rocm-hip-runtime')
  provides=("${pkgbase}=${pkgver}")
  conflicts=("${pkgbase}")

  cd "${_name}-hipblas"
  DESTDIR="${pkgdir}" cmake --install build
}

sha256sums=('SKIP'
  'SKIP')