From ceea495693949eba86cab2caf6cd28169fb7de61 Mon Sep 17 00:00:00 2001 From: David Coles Date: Fri, 23 Feb 2024 00:12:21 -0800 Subject: [PATCH] Add CMakePresets and update README instructions Using a `CMakePresets.json` file makes it much easier to manage several alternate build configurations, such as the "ClangCL" build for Windows. This also makes it easier for tools like VSCode to run CMake-based builds. --- CMakePresets.json | 59 +++++++++++++++++++++++++++++++++++++++++++++++ README.md | 41 ++++++++++++++++++++++++-------- 2 files changed, 90 insertions(+), 10 deletions(-) create mode 100644 CMakePresets.json diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..5fe13c8 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,59 @@ +{ + "version": 3, + "cmakeMinimumRequired": { + "major": 3, + "minor": 11, + "patch": 0 + }, + "configurePresets": [ + { + "name": "__defaults__", + "hidden": true, + "binaryDir": "${sourceDir}/build" + }, + { + "name": "make", + "inherits": "__defaults__", + "displayName": "Make", + "description": "Unix Makefiles", + "generator": "Unix Makefiles", + "binaryDir": "${sourceDir}/build" + }, + { + "name": "windows", + "inherits": "__defaults__", + "displayName": "Windows", + "description": "Visual Studio 2022 with Clang/LLVM frontend", + "generator": "Visual Studio 17 2022", + "toolset": "ClangCL", + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + } + ], + "buildPresets": [ + { + "name": "__defaults__", + "hidden": true, + "targets": [ + "gemma", + "libgemma" + ] + }, + { + "name": "make", + "inherits": "__defaults__", + "displayName": "Unix Makefiles", + "configurePreset": "make" + }, + { + "name": "windows", + "inherits": "__defaults__", + "displayName": "Windows", + "configuration": "Release", + "configurePreset": "windows" + } + ] + } diff --git a/README.md b/README.md index ab7bf2d..ee53551 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,16 @@ Before starting, you should have installed: least C++17. - `tar` for extracting archives from Kaggle. +Building natively on Windows requires the Visual Studio 2012 Build Tools with the +optional Clang/LLVM C++ frontend (`clang-cl`). This can be installed from the +command line with +[`winget`](https://learn.microsoft.com/en-us/windows/package-manager/winget/): + +```sh +winget install --id Kitware.CMake +winget install --id Microsoft.VisualStudio.2022.BuildTools --force --override "--passive --wait --add Microsoft.VisualStudio.Workload.VCTools;installRecommended --add Microsoft.VisualStudio.Component.VC.Llvm.Clang --add Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset" +``` + ### Step 1: Obtain model weights and tokenizer from Kaggle Visit [the Gemma model page on @@ -104,25 +114,36 @@ The build system uses [CMake](https://cmake.org/). To build the gemma inference runtime, create a build directory and generate the build files using `cmake` from the top-level project directory: -```sh -cmake -B build -``` - -Then run `make` to build the `./gemma` executable: +#### Unix-like Platforms ```sh -cd build -make -j [number of parallel threads to use] gemma +# Configure `build` directory +cmake --preset make + +# Build project using make +cmake --build --preset make -j [number of parallel threads to use] ``` -For example, `make -j4 gemma` will build using 4 threads. If this is successful, -you should now have a `gemma` executable in the `build/` directory. If the -`nproc` command is available, you can use `make -j$(nproc) gemma`. +If the `nproc` command is available, you can use `-j $(nproc)`. + +If this is successful, you should now have a `gemma` executable in the `build/` directory. > [!NOTE] > On Windows Subsystem for Linux (WSL) users should set the number of > parallel threads to 1. Using a larger number may result in errors. +#### Windows + +```sh +# Configure `build` directory +cmake --preset windows + +# Build project using Visual Studio Build Tools +cmake --build --preset windows -j [number of parallel threads to use] +``` + +If this is successful, you should now have a `gemma.exe` executable in the `build/` directory. + ### Step 4: Run You can now run `gemma` from inside the `build/` directory.