Skip to content

Commit 0a38a2d

Browse files
ochafikcebtenzzreNeoZhangJianyu
authored andcommitted
build(cmake): simplify instructions (cmake -B build && cmake --build build ...) (ggml-org#6964)
* readme: cmake . -B build && cmake --build build * build: fix typo Co-authored-by: Jared Van Bortel <[email protected]> * build: drop implicit . from cmake config command * build: remove another superfluous . * build: update MinGW cmake commands * Update README-sycl.md Co-authored-by: Neo Zhang Jianyu <[email protected]> * build: reinstate --config Release as not the default w/ some generators + document how to build Debug * build: revert more --config Release * build: nit / remove -H from cmake example * build: reword debug instructions around single/multi config split --------- Co-authored-by: Jared Van Bortel <[email protected]> Co-authored-by: Neo Zhang Jianyu <[email protected]>
1 parent f94194a commit 0a38a2d

File tree

10 files changed

+91
-110
lines changed

10 files changed

+91
-110
lines changed

.devops/main-intel.Dockerfile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ WORKDIR /app
1010

1111
COPY . .
1212

13-
RUN mkdir build && \
14-
cd build && \
15-
if [ "${LLAMA_SYCL_F16}" = "ON" ]; then \
13+
RUN if [ "${LLAMA_SYCL_F16}" = "ON" ]; then \
1614
echo "LLAMA_SYCL_F16 is set" && \
1715
export OPT_SYCL_F16="-DLLAMA_SYCL_F16=ON"; \
1816
fi && \
19-
cmake .. -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx ${OPT_SYCL_F16} && \
20-
cmake --build . --config Release --target main
17+
cmake -B build -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx ${OPT_SYCL_F16} && \
18+
cmake --build build --config Release --target main
2119

2220
FROM intel/oneapi-basekit:$ONEAPI_VERSION as runtime
2321

.devops/main-vulkan.Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ RUN wget -qO - https://packages.lunarg.com/lunarg-signing-key-pub.asc | apt-key
1414
# Build it
1515
WORKDIR /app
1616
COPY . .
17-
RUN mkdir build && \
18-
cd build && \
19-
cmake .. -DLLAMA_VULKAN=1 && \
20-
cmake --build . --config Release --target main
17+
RUN cmake -B build -DLLAMA_VULKAN=1 && \
18+
cmake --build build --config Release --target main
2119

2220
# Clean up
2321
WORKDIR /

.devops/server-intel.Dockerfile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ WORKDIR /app
1010

1111
COPY . .
1212

13-
RUN mkdir build && \
14-
cd build && \
15-
if [ "${LLAMA_SYCL_F16}" = "ON" ]; then \
13+
RUN if [ "${LLAMA_SYCL_F16}" = "ON" ]; then \
1614
echo "LLAMA_SYCL_F16 is set" && \
1715
export OPT_SYCL_F16="-DLLAMA_SYCL_F16=ON"; \
1816
fi && \
19-
cmake .. -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DLLAMA_CURL=ON ${OPT_SYCL_F16} && \
20-
cmake --build . --config Release --target server
17+
cmake -B build -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DLLAMA_CURL=ON ${OPT_SYCL_F16} && \
18+
cmake --build build --config Release --target server
2119

2220
FROM intel/oneapi-basekit:$ONEAPI_VERSION as runtime
2321

.devops/server-vulkan.Dockerfile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ RUN apt-get update && \
1818
# Build it
1919
WORKDIR /app
2020
COPY . .
21-
RUN mkdir build && \
22-
cd build && \
23-
cmake .. -DLLAMA_VULKAN=1 -DLLAMA_CURL=1 && \
24-
cmake --build . --config Release --target server
21+
RUN cmake -B build -DLLAMA_VULKAN=1 -DLLAMA_CURL=1 && \
22+
cmake --build build --config Release --target server
2523

2624
# Clean up
2725
WORKDIR /

.github/workflows/bench.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ jobs:
9696
id: cmake_build
9797
run: |
9898
set -eux
99-
mkdir build
100-
cd build
101-
cmake .. \
99+
cmake -B build \
102100
-DLLAMA_NATIVE=OFF \
103101
-DLLAMA_BUILD_SERVER=ON \
104102
-DLLAMA_CURL=ON \
@@ -109,7 +107,7 @@ jobs:
109107
-DLLAMA_FATAL_WARNINGS=OFF \
110108
-DLLAMA_ALL_WARNINGS=OFF \
111109
-DCMAKE_BUILD_TYPE=Release;
112-
cmake --build . --config Release -j $(nproc) --target server
110+
cmake --build build --config Release -j $(nproc) --target server
113111
114112
- name: Download the dataset
115113
id: download_dataset

.github/workflows/server.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,13 @@ jobs:
9494
- name: Build
9595
id: cmake_build
9696
run: |
97-
mkdir build
98-
cd build
99-
cmake .. \
97+
cmake -B build \
10098
-DLLAMA_NATIVE=OFF \
10199
-DLLAMA_BUILD_SERVER=ON \
102100
-DLLAMA_CURL=ON \
103101
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
104102
-DLLAMA_SANITIZE_${{ matrix.sanitizer }}=ON ;
105-
cmake --build . --config ${{ matrix.build_type }} -j $(nproc) --target server
103+
cmake --build build --config ${{ matrix.build_type }} -j $(nproc) --target server
106104
107105
108106
- name: Tests
@@ -143,10 +141,8 @@ jobs:
143141
- name: Build
144142
id: cmake_build
145143
run: |
146-
mkdir build
147-
cd build
148-
cmake .. -DLLAMA_CURL=ON -DCURL_LIBRARY="$env:RUNNER_TEMP/libcurl/lib/libcurl.dll.a" -DCURL_INCLUDE_DIR="$env:RUNNER_TEMP/libcurl/include"
149-
cmake --build . --config Release -j ${env:NUMBER_OF_PROCESSORS} --target server
144+
cmake -B build -DLLAMA_CURL=ON -DCURL_LIBRARY="$env:RUNNER_TEMP/libcurl/lib/libcurl.dll.a" -DCURL_INCLUDE_DIR="$env:RUNNER_TEMP/libcurl/include"
145+
cmake --build build --config Release -j ${env:NUMBER_OF_PROCESSORS} --target server
150146
151147
- name: Python setup
152148
id: setup_python

README-sycl.md

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,8 @@ Upon a successful installation, SYCL is enabled for the available intel devices,
185185
```sh
186186
git clone https://github.com/oneapi-src/oneMKL
187187
cd oneMKL
188-
mkdir -p buildWithCublas && cd buildWithCublas
189-
cmake ../ -DCMAKE_CXX_COMPILER=icpx -DCMAKE_C_COMPILER=icx -DENABLE_MKLGPU_BACKEND=OFF -DENABLE_MKLCPU_BACKEND=OFF -DENABLE_CUBLAS_BACKEND=ON -DTARGET_DOMAINS=blas
190-
make
188+
cmake -B buildWithCublas -DCMAKE_CXX_COMPILER=icpx -DCMAKE_C_COMPILER=icx -DENABLE_MKLGPU_BACKEND=OFF -DENABLE_MKLCPU_BACKEND=OFF -DENABLE_CUBLAS_BACKEND=ON -DTARGET_DOMAINS=blas
189+
cmake --build buildWithCublas --config Release
191190
```
192191

193192

@@ -227,16 +226,15 @@ Similarly, user targeting Nvidia GPUs should expect at least one SYCL-CUDA devic
227226
source /opt/intel/oneapi/setvars.sh
228227

229228
# Build LLAMA with MKL BLAS acceleration for intel GPU
230-
mkdir -p build && cd build
231229

232230
# Option 1: Use FP32 (recommended for better performance in most cases)
233-
cmake .. -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
231+
cmake -B build -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
234232

235233
# Option 2: Use FP16
236-
cmake .. -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DLLAMA_SYCL_F16=ON
234+
cmake -B build -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DLLAMA_SYCL_F16=ON
237235

238-
#build all binary
239-
cmake --build . --config Release -j -v
236+
# build all binary
237+
cmake --build build --config Release -j -v
240238
```
241239

242240
#### Nvidia GPU
@@ -248,16 +246,15 @@ export CPLUS_INCLUDE_DIR=/path/to/oneMKL/buildWithCublas/include:$CPLUS_INCLUDE_
248246
export CPLUS_INCLUDE_DIR=/path/to/oneMKL/include:$CPLUS_INCLUDE_DIR
249247

250248
# Build LLAMA with Nvidia BLAS acceleration through SYCL
251-
mkdir -p build && cd build
252249

253250
# Option 1: Use FP32 (recommended for better performance in most cases)
254-
cmake .. -DLLAMA_SYCL=ON -DLLAMA_SYCL_TARGET=NVIDIA -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
251+
cmake -B build -DLLAMA_SYCL=ON -DLLAMA_SYCL_TARGET=NVIDIA -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
255252

256253
# Option 2: Use FP16
257-
cmake .. -DLLAMA_SYCL=ON -DLLAMA_SYCL_TARGET=NVIDIA -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DLLAMA_SYCL_F16=ON
254+
cmake -B build -DLLAMA_SYCL=ON -DLLAMA_SYCL_TARGET=NVIDIA -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DLLAMA_SYCL_F16=ON
258255

259-
#build all binary
260-
cmake --build . --config Release -j -v
256+
# build all binary
257+
cmake --build build --config Release -j -v
261258

262259
```
263260

@@ -412,17 +409,15 @@ b. Download & install mingw-w64 make for Windows provided by w64devkit
412409
On the oneAPI command line window, step into the llama.cpp main directory and run the following:
413410

414411
```
415-
mkdir -p build
416-
cd build
417412
@call "C:\Program Files (x86)\Intel\oneAPI\setvars.bat" intel64 --force
418413
419414
# Option 1: Use FP32 (recommended for better performance in most cases)
420-
cmake -G "MinGW Makefiles" .. -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icx -DCMAKE_BUILD_TYPE=Release
415+
cmake -B build -G "MinGW Makefiles" -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icx -DCMAKE_BUILD_TYPE=Release
421416
422417
# Option 2: Or FP16
423-
cmake -G "MinGW Makefiles" .. -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icx -DCMAKE_BUILD_TYPE=Release -DLLAMA_SYCL_F16=ON
418+
cmake -B build -G "MinGW Makefiles" -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icx -DCMAKE_BUILD_TYPE=Release -DLLAMA_SYCL_F16=ON
424419
425-
make -j
420+
cmake --build build --config Release -j
426421
```
427422

428423
Otherwise, run the `win-build-sycl.bat` wrapper which encapsulates the former instructions:

README.md

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ In order to build llama.cpp you have three different options.
308308
make
309309
```
310310

311+
**Note**: for `Debug` builds, run `make LLAMA_DEBUG=1`
312+
311313
- On Windows:
312314

313315
1. Download the latest fortran version of [w64devkit](https://github.com/skeeto/w64devkit/releases).
@@ -322,12 +324,26 @@ In order to build llama.cpp you have three different options.
322324
- Using `CMake`:
323325

324326
```bash
325-
mkdir build
326-
cd build
327-
cmake ..
328-
cmake --build . --config Release
327+
cmake -B build
328+
cmake --build build --config Release
329329
```
330330

331+
**Note**: for `Debug` builds, there are two cases:
332+
333+
- Single-config generators (e.g. default = `Unix Makefiles`; note that they just ignore the `--config` flag):
334+
335+
```bash
336+
cmake -B build -DCMAKE_BUILD_TYPE=Debug
337+
cmake --build build
338+
```
339+
340+
- Multi-config generators (`-G` param set to Visual Studio, XCode...):
341+
342+
```bash
343+
cmake -B build -G "Xcode"
344+
cmake --build build --config Debug
345+
```
346+
331347
- Using `Zig` (version 0.11 or later):
332348

333349
Building for optimization levels and CPU features can be accomplished using standard build arguments, for example AVX2, FMA, F16C,
@@ -439,10 +455,8 @@ Building the program with BLAS support may lead to some performance improvements
439455
- Using `CMake` on Linux:
440456

441457
```bash
442-
mkdir build
443-
cd build
444-
cmake .. -DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS
445-
cmake --build . --config Release
458+
cmake -B build -DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=OpenBLAS
459+
cmake --build build --config Release
446460
```
447461

448462
- #### BLIS
@@ -462,11 +476,9 @@ Building the program with BLAS support may lead to some performance improvements
462476
- Using manual oneAPI installation:
463477
By default, `LLAMA_BLAS_VENDOR` is set to `Generic`, so if you already sourced intel environment script and assign `-DLLAMA_BLAS=ON` in cmake, the mkl version of Blas will automatically been selected. Otherwise please install oneAPI and follow the below steps:
464478
```bash
465-
mkdir build
466-
cd build
467479
source /opt/intel/oneapi/setvars.sh # You can skip this step if in oneapi-basekit docker image, only required for manual installation
468-
cmake .. -DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=Intel10_64lp -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DLLAMA_NATIVE=ON
469-
cmake --build . --config Release
480+
cmake -B build -DLLAMA_BLAS=ON -DLLAMA_BLAS_VENDOR=Intel10_64lp -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DLLAMA_NATIVE=ON
481+
cmake --build build --config Release
470482
```
471483

472484
- Using oneAPI docker image:
@@ -487,10 +499,8 @@ Building the program with BLAS support may lead to some performance improvements
487499
- Using `CMake`:
488500
489501
```bash
490-
mkdir build
491-
cd build
492-
cmake .. -DLLAMA_CUDA=ON
493-
cmake --build . --config Release
502+
cmake -B build -DLLAMA_CUDA=ON
503+
cmake --build build --config Release
494504
```
495505
496506
The environment variable [`CUDA_VISIBLE_DEVICES`](https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#env-vars) can be used to specify which GPU(s) will be used. The following compilation options are also available to tweak performance:
@@ -517,8 +527,8 @@ Building the program with BLAS support may lead to some performance improvements
517527
- Using `CMake` for Linux (assuming a gfx1030-compatible AMD GPU):
518528
```bash
519529
CC=/opt/rocm/llvm/bin/clang CXX=/opt/rocm/llvm/bin/clang++ \
520-
cmake -H. -Bbuild -DLLAMA_HIPBLAS=ON -DAMDGPU_TARGETS=gfx1030 -DCMAKE_BUILD_TYPE=Release \
521-
&& cmake --build build -- -j 16
530+
cmake -B build -DLLAMA_HIPBLAS=ON -DAMDGPU_TARGETS=gfx1030 -DCMAKE_BUILD_TYPE=Release \
531+
&& cmake --build build --config Release -- -j 16
522532
```
523533
On Linux it is also possible to use unified memory architecture (UMA) to share main memory between the CPU and integrated GPU by setting `-DLLAMA_HIP_UMA=ON"`.
524534
However, this hurts performance for non-integrated GPUs (but enables working with integrated GPUs).
@@ -564,15 +574,14 @@ Building the program with BLAS support may lead to some performance improvements
564574
565575
```sh
566576
git clone --recurse-submodules https://github.com/KhronosGroup/OpenCL-SDK.git
567-
mkdir OpenCL-SDK/build
568-
cd OpenCL-SDK/build
569-
cmake .. -DBUILD_DOCS=OFF \
577+
cd OpenCL-SDK
578+
cmake -B build -DBUILD_DOCS=OFF \
570579
-DBUILD_EXAMPLES=OFF \
571580
-DBUILD_TESTING=OFF \
572581
-DOPENCL_SDK_BUILD_SAMPLES=OFF \
573582
-DOPENCL_SDK_TEST_SAMPLES=OFF
574-
cmake --build . --config Release
575-
cmake --install . --prefix /some/path
583+
cmake --build build
584+
cmake --install build --prefix /some/path
576585
```
577586
</details>
578587
@@ -594,23 +603,23 @@ Building the program with BLAS support may lead to some performance improvements
594603
```cmd
595604
set OPENCL_SDK_ROOT="C:/OpenCL-SDK-v2023.04.17-Win-x64"
596605
git clone https://github.com/CNugteren/CLBlast.git
597-
mkdir CLBlast\build
598-
cd CLBlast\build
599-
cmake .. -DBUILD_SHARED_LIBS=OFF -DOVERRIDE_MSVC_FLAGS_TO_MT=OFF -DTUNERS=OFF -DOPENCL_ROOT=%OPENCL_SDK_ROOT% -G "Visual Studio 17 2022" -A x64
600-
cmake --build . --config Release
601-
cmake --install . --prefix C:/CLBlast
606+
cd CLBlast
607+
cmake -B build -DBUILD_SHARED_LIBS=OFF -DOVERRIDE_MSVC_FLAGS_TO_MT=OFF -DTUNERS=OFF -DOPENCL_ROOT=%OPENCL_SDK_ROOT% -G "Visual Studio 17 2022" -A x64
608+
cmake --build build --config Release
609+
cmake --install build --prefix C:/CLBlast
602610
```
603611
612+
(note: `--config Release` at build time is the default and only relevant for Visual Studio builds - or multi-config Ninja builds)
613+
604614
- <details>
605615
<summary>Unix:</summary>
606616
607617
```sh
608618
git clone https://github.com/CNugteren/CLBlast.git
609-
mkdir CLBlast/build
610-
cd CLBlast/build
611-
cmake .. -DBUILD_SHARED_LIBS=OFF -DTUNERS=OFF
612-
cmake --build . --config Release
613-
cmake --install . --prefix /some/path
619+
cd CLBlast
620+
cmake -B build -DBUILD_SHARED_LIBS=OFF -DTUNERS=OFF
621+
cmake --build build --config Release
622+
cmake --install build --prefix /some/path
614623
```
615624
616625
Where `/some/path` is where the built library will be installed (default is `/usr/local`).
@@ -624,21 +633,17 @@ Building the program with BLAS support may lead to some performance improvements
624633
```
625634
- CMake (Unix):
626635
```sh
627-
mkdir build
628-
cd build
629-
cmake .. -DLLAMA_CLBLAST=ON -DCLBlast_DIR=/some/path
630-
cmake --build . --config Release
636+
cmake -B build -DLLAMA_CLBLAST=ON -DCLBlast_DIR=/some/path
637+
cmake --build build --config Release
631638
```
632639
- CMake (Windows):
633640
```cmd
634641
set CL_BLAST_CMAKE_PKG="C:/CLBlast/lib/cmake/CLBlast"
635642
git clone https://github.com/ggerganov/llama.cpp
636643
cd llama.cpp
637-
mkdir build
638-
cd build
639-
cmake .. -DBUILD_SHARED_LIBS=OFF -DLLAMA_CLBLAST=ON -DCMAKE_PREFIX_PATH=%CL_BLAST_CMAKE_PKG% -G "Visual Studio 17 2022" -A x64
640-
cmake --build . --config Release
641-
cmake --install . --prefix C:/LlamaCPP
644+
cmake -B build -DBUILD_SHARED_LIBS=OFF -DLLAMA_CLBLAST=ON -DCMAKE_PREFIX_PATH=%CL_BLAST_CMAKE_PKG% -G "Visual Studio 17 2022" -A x64
645+
cmake --build build --config Release
646+
cmake --install build --prefix C:/LlamaCPP
642647
```
643648
644649
##### Running Llama with CLBlast
@@ -694,10 +699,8 @@ Building the program with BLAS support may lead to some performance improvements
694699
Then, build llama.cpp using the cmake command below:
695700
696701
```bash
697-
mkdir -p build
698-
cd build
699-
cmake .. -DLLAMA_VULKAN=1
700-
cmake --build . --config Release
702+
cmake -B build -DLLAMA_VULKAN=1
703+
cmake --build build --config Release
701704
# Test the output binary (with "-ngl 33" to offload all layers to GPU)
702705
./bin/main -m "PATH_TO_MODEL" -p "Hi you how are you" -n 50 -e -ngl 33 -t 4
703706

0 commit comments

Comments
 (0)