Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# based on LLVM style (matches the brace/indent conventions in src/), with a
# generous column limit to keep churn on existing code minimal
BasedOnStyle: LLVM
Language: Cpp
ColumnLimit: 120
IndentWidth: 4
TabWidth: 4
UseTab: Never
PointerAlignment: Right
DerivePointerAlignment: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
SortIncludes: Never
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveDeclarations: Consecutive
IncludeBlocks: Preserve
InsertBraces: true
FixNamespaceComments: true
14 changes: 14 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# conservative starter config; warnings are not errors
Checks: >
bugprone-*,
performance-*,
readability-*,
-bugprone-easily-swappable-parameters,
-readability-magic-numbers,
-readability-identifier-length,
-readability-function-cognitive-complexity,
-readability-implicit-bool-conversion

WarningsAsErrors: ''
HeaderFilterRegex: '^(src|tests)/.*\.h$'
FormatStyle: file
85 changes: 85 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: build

on:
pull_request:
push:
branches-ignore:
- master

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install ninja and ccache
run: |
sudo apt-get update
sudo apt-get install -y ninja-build ccache

- name: ccache
uses: ggml-org/ccache-action@v1.2.21
with:
max-size: 500MB
evict-old-files: 7d
save: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}

- name: Configure
run: >-
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_COMPILER_LAUNCHER=ccache
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
-DCMAKE_INSTALL_RPATH='$ORIGIN'
-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON

- name: Build
run: cmake --build build -j"$(nproc)"

sanitize:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Install ninja
run: |
sudo apt-get update
sudo apt-get install -y ninja-build

- name: Configure (ASan + UBSan)
run: >-
cmake -B build-sanitize -G Ninja
-DCMAKE_BUILD_TYPE=Debug
-DCMAKE_CXX_FLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer -g"
-DCMAKE_C_FLAGS="-fsanitize=address,undefined -fno-omit-frame-pointer -g"

- name: Build
run: cmake --build build-sanitize -j"$(nproc)"

- name: Test
run: ctest --test-dir build-sanitize --output-on-failure

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install clang-format
run: sudo apt-get update && sudo apt-get install -y clang-format-18

- name: clang-format check
run: >-
clang-format-18 --dry-run --Werror
src/image.cpp src/image.h
inference.cpp dinov2.cpp dinov2.h quantize.cpp
tests/test_image.cpp
228 changes: 228 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
name: release

on:
push:
tags:
- "v*"

concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false

permissions:
contents: write

jobs:
ubuntu-x64:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Cache apt packages
uses: actions/cache@v4
with:
path: /var/cache/apt/archives
key: apt-${{ runner.os }}-x64-${{ hashFiles('.github/workflows/release.yml') }}
restore-keys: apt-${{ runner.os }}-x64-

- name: Install build packages
run: |
sudo apt-get update
sudo apt-get install -y ninja-build ccache cmake
dpkg-query -W -f='${Package} ${Version}\n' ninja-build ccache cmake > /tmp/apt-fingerprint.txt

- name: ccache
uses: ggml-org/ccache-action@v1.2.21
with:
max-size: 500MB
evict-old-files: 7d

- name: Configure
run: >-
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_COMPILER_LAUNCHER=ccache
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
-DCMAKE_INSTALL_RPATH='$ORIGIN'
-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON
-DBUILD_SHARED_LIBS=OFF

- name: Build
run: cmake --build build -j"$(nproc)"

- name: Package
run: |
mkdir -p stage/bin
cp build/bin/inference build/bin/quantize stage/bin/
tar -czf "dinov2-${{ github.ref_name }}-bin-ubuntu-x64.tar.gz" -C stage bin

- uses: actions/upload-artifact@v4
with:
name: dinov2-bin-linux-x64
path: dinov2-*-bin-ubuntu-x64.tar.gz
if-no-files-found: error

ubuntu-arm64:
runs-on: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Cache apt packages
uses: actions/cache@v4
with:
path: /var/cache/apt/archives
key: apt-${{ runner.os }}-arm64-${{ hashFiles('.github/workflows/release.yml') }}
restore-keys: apt-${{ runner.os }}-arm64-

- name: Install build packages
run: |
sudo apt-get update
sudo apt-get install -y ninja-build ccache cmake
dpkg-query -W -f='${Package} ${Version}\n' ninja-build ccache cmake > /tmp/apt-fingerprint.txt

- name: ccache
uses: ggml-org/ccache-action@v1.2.21
with:
max-size: 500MB
evict-old-files: 7d

- name: Configure
run: >-
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_COMPILER_LAUNCHER=ccache
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
-DCMAKE_INSTALL_RPATH='$ORIGIN'
-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON
-DBUILD_SHARED_LIBS=OFF

- name: Build
run: cmake --build build -j"$(nproc)"

- name: Package
run: |
mkdir -p stage/bin
cp build/bin/inference build/bin/quantize stage/bin/
tar -czf "dinov2-${{ github.ref_name }}-bin-ubuntu-arm64.tar.gz" -C stage bin

- uses: actions/upload-artifact@v4
with:
name: dinov2-bin-linux-arm64
path: dinov2-*-bin-ubuntu-arm64.tar.gz
if-no-files-found: error

macos-arm64:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Cache brew formulas
uses: actions/cache@v4
with:
path: |
/usr/local/Cellar/ninja
/usr/local/Cellar/ccache
/opt/homebrew/Cellar/ninja
/opt/homebrew/Cellar/ccache
key: brew-${{ runner.os }}-${{ runner.arch }}-ninja-ccache
restore-keys: brew-${{ runner.os }}-${{ runner.arch }}-

- name: Install build packages
run: |
brew install ninja ccache
brew link --overwrite ninja ccache

- name: ccache
uses: ggml-org/ccache-action@v1.2.21
with:
max-size: 500MB
evict-old-files: 7d

- name: Configure
run: >-
cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
-DCMAKE_C_COMPILER_LAUNCHER=ccache
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
-DCMAKE_BUILD_RPATH='@loader_path'
-DCMAKE_OSX_DEPLOYMENT_TARGET=13.3
-DBUILD_SHARED_LIBS=OFF

- name: Build
run: cmake --build build -j"$(sysctl -n hw.logicalcpu)"

- name: Package
run: |
mkdir -p stage/bin
cp build/bin/inference build/bin/quantize stage/bin/
tar -czf "dinov2-${{ github.ref_name }}-bin-macos-arm64.tar.gz" -C stage bin

- uses: actions/upload-artifact@v4
with:
name: dinov2-bin-macos-arm64
path: dinov2-*-bin-macos-arm64.tar.gz
if-no-files-found: error

windows-x64:
runs-on: windows-latest
env:
SCCACHE_GHA_ENABLED: "true"
SCCACHE_CACHE_SIZE: 500MB
CMAKE_C_COMPILER_LAUNCHER: sccache
CMAKE_CXX_COMPILER_LAUNCHER: sccache
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: sccache
uses: Mozilla-Actions/sccache-action@v0.0.9

- name: Configure
shell: pwsh
run: >-
cmake -B build -G "Ninja Multi-Config"
-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
-DCMAKE_BUILD_TYPE=Release
-DBUILD_SHARED_LIBS=OFF

- name: Build
shell: pwsh
run: cmake --build build --config Release

- name: Package
shell: pwsh
run: |
New-Item -ItemType Directory -Force -Path stage/bin | Out-Null
Copy-Item build/bin/Release/inference.exe,build/bin/Release/quantize.exe stage/bin/
Compress-Archive -Path stage/bin -DestinationPath dinov2-bin-win-cpu-x64.zip

- uses: actions/upload-artifact@v4
with:
name: dinov2-bin-win-cpu-x64
path: dinov2-bin-win-cpu-x64.zip
if-no-files-found: error

release:
needs: [ubuntu-x64, ubuntu-arm64, macos-arm64, windows-x64]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
merge-multiple: true
path: dist

- name: Generate checksums
run: |
cd dist
sha256sum * > SHA256SUMS.txt

- name: Publish release
uses: softprops/action-gh-release@v2
with:
files: |
dist/**
generate_release_notes: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,5 @@ cmake-build-debug/

.vs/
.vscode/

build*
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "ggml"]
path = ggml
url = git@github.com:ggml-org/ggml.git
url = https://github.com/ggml-org/ggml.git
branch = master
Loading
Loading