summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: a4ac15369af926138aa6858a1457b6838431ad53 (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# Maintainer: Jakub Klinkovský <lahwaacz at archlinux dot org>

_pkgname=ginkgo
pkgbase=ginkgo-hpc-git
pkgname=(ginkgo-hpc{,-docs,-cuda,-hip}-git)
pkgver=r8256.abe9ecf7f9
pkgrel=1
pkgdesc="Numerical linear algebra software package"
arch=(x86_64)
url=https://ginkgo-project.github.io/
license=(BSD-3-Clause)
depends=(
  gcc-libs
  glibc
  hwloc
  openmpi
)
# FIXME: system 'rapidjson' does not work due to some C++ issues
# (see the 'declared protected here' error in https://github.com/Tencent/rapidjson/issues/1338#issuecomment-449849215 )
makedepends=(
  git
  cmake
  ninja
  nlohmann-json
  gflags  # for benchmarks (not installed yet)
  gtest
  numactl
  doxygen
  graphviz
  texlive-bin
  texlive-latexextra
  # -cuda
  cuda
  # -hip
  hip-runtime-amd
  hipblas
  hipfft
  hiprand
  hipsparse
  rocthrust
  roctracer
)
source=(
  "git+https://github.com/ginkgo-project/$_pkgname.git"
  split_cuda_library.patch
)
b2sums=('SKIP'
        '3dd2558f399a4e9e7176021415b53e8f06e41c328df920ed254890ffc4c2a430344162c5054bb8d8f4ef2c53ae4029084fd85f89f46a047ebf5707a70fb6d7fe')

pkgver() {
  cd $_pkgname
  printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  # Ginkgo is too big to build all CUDA archs into a single library, we need to split it
  # https://github.com/ginkgo-project/ginkgo/issues/1734#issuecomment-2517784197
  patch --directory=$_pkgname -Np1 < split_cuda_library.patch
}

build() {
  local common_cmake_flags=(
    -S $_pkgname -G Ninja
    -DCMAKE_BUILD_TYPE=None
    -DCMAKE_INSTALL_PREFIX=/usr
    -DGINKGO_BUILD_REFERENCE=ON
    -DGINKGO_BUILD_OMP=ON
    -DGINKGO_BUILD_MPI=ON
    -DGINKGO_HAVE_GPU_AWARE_MPI=ON
    -DGINKGO_BUILD_BENCHMARKS=ON
    -DGINKGO_BUILD_EXAMPLES=ON
    -DGINKGO_BUILD_DOC=ON
    -DGINKGO_BUILD_TESTS=ON
  )
  # In general, we want to list all real archs (sm_XX) and the latest virtual arch (compute_XX) for future PTX compatibility.
  # Valid values can be discovered from nvcc --help
  local _cuda_archs="50;52;53;60;61;62;70;72;75;80;86;87;89;90;90a;90a-virtual"
  # archs gfx1010;gfx1012;gfx1030;gfx1100;gfx1101;gfx1102 are not supported: https://github.com/ginkgo-project/ginkgo/issues/1429
  local _amdgpu_archs="gfx906;gfx908;gfx90a;gfx940;gfx941;gfx942"

  # base package
  cmake -B build "${common_cmake_flags[@]}" \
    -DGINKGO_BUILD_CUDA=OFF \
    -DGINKGO_BUILD_HIP=OFF \
    -DGINKGO_BUILD_SYCL=OFF
  cmake --build build

  # -cuda package
  cmake -B build-cuda "${common_cmake_flags[@]}" \
    -DCMAKE_CUDA_ARCHITECTURES="$_cuda_archs" \
    -DGINKGO_BUILD_CUDA=ON \
    -DGINKGO_BUILD_HIP=OFF \
    -DGINKGO_BUILD_SYCL=OFF
  cmake --build build-cuda

  # -hip package
  # LTO does not work with HIP
  local _hip_flags="${CXXFLAGS/-flto=auto/}"
  local _cxx_flags="${CXXFLAGS/-flto=auto/}"
  # HIP does not support -fcf-protection
  _hip_flags="${_hip_flags/-fcf-protection/}"
  # Ginkgo does not support _GLIBCXX_ASSERTIONS for device builds https://github.com/ginkgo-project/ginkgo/issues/1143#issuecomment-2036957897
  _hip_flags="${_hip_flags/-Wp,-D_GLIBCXX_ASSERTIONS/}"
  cmake -B build-hip "${common_cmake_flags[@]}" \
    -DCMAKE_CXX_COMPILER=/opt/rocm/lib/llvm/bin/amdclang++ \
    -DCMAKE_CXX_FLAGS="$_cxx_flags" \
    -DCMAKE_HIP_FLAGS="$_hip_flags" \
    -DCMAKE_HIP_ARCHITECTURES="$_amdgpu_archs" \
    -DGINKGO_BUILD_CUDA=OFF \
    -DGINKGO_BUILD_HIP=ON \
    -DGINKGO_BUILD_SYCL=OFF
  cmake --build build-hip
}

check() {
  # some tests fail due to capturing stderr and getting different number of mpirun warnings
  # see https://github.com/ginkgo-project/ginkgo/issues/1567
  local excluded_tests="benchmark_.*_distributed"

  # limit parallel execution of tests to 4 threads and 8 processes
  # note that without a GPU we cannot run tests for -cuda and -hip
  (
    export OMP_NUM_THREADS=4
    export CTEST_PARALLEL_LEVEL=8
    export CTEST_OUTPUT_ON_FAILURE=1
    ctest --test-dir build --exclude-regex "$excluded_tests"
  )
}

_package() {
  DESTDIR="$pkgdir" cmake --install build"$1"

  # install the license
  install -vDm 644 $_pkgname/LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"

  # TODO: install the benchmarks and examples: https://github.com/ginkgo-project/ginkgo/issues/1144
}

package_ginkgo-hpc-git() {
  optdepends=(
    'ginkgo-hpc-docs: for documentation'
  )
  conflicts=(ginkgo-hpc)
  provides=(ginkgo-hpc)

  _package ""
}

package_ginkgo-hpc-docs-git() {
  pkgdesc+=" - documentation"
  depends=()
  conflicts=(ginkgo-hpc-docs)
  provides=(ginkgo-hpc-docs)

  # install the documentation
  install -vdm755 "$pkgdir/usr/share/doc/$pkgbase"
  cp -r build/doc/usr "$pkgdir/usr/share/doc/$pkgbase/html"

  # install the license
  install -vDm 644 $_pkgname/LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}

package_ginkgo-hpc-cuda-git() {
  pkgdesc+=" (with CUDA)"
  depends+=(cuda)
  optdepends=(
    'ginkgo-hpc-docs: for documentation'
  )
  conflicts=(ginkgo-hpc)
  provides=(ginkgo-hpc)

  _package -cuda
}

package_ginkgo-hpc-hip-git() {
  pkgdesc+=" (with ROCm/HIP)"
  depends+=(
    hip-runtime-amd
    hipblas
    hipfft
    hiprand
    hipsparse
    roctracer
  )
  optdepends=(
    'ginkgo-hpc-docs: for documentation'
  )
  conflicts=(ginkgo-hpc)
  provides=(ginkgo-hpc)

  _package -hip
}

# vim:set ts=2 sw=2 et: