Skip to content
Closed
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
97 changes: 97 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
strategy:
matrix:
os: [ubuntu-22.04, windows-latest, macos-14]

runs-on: ${{ matrix.os }}

name: Build & Test on ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: recursive

- name: Dependencies (Linux)
if: matrix.os == 'ubuntu-22.04'
run: |
wget -qO - https://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo apt-key add -
sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-jammy.list https://packages.lunarg.com/vulkan/lunarg-vulkan-jammy.list
sudo apt-get update -y
sudo apt-get install -y build-essential cmake g++ ninja-build mesa-vulkan-drivers vulkan-sdk

- name: Dependencies (Windows)
if: matrix.os == 'windows-latest'
uses: microsoft/setup-msbuild@v2

- name: Configure (Linux)
if: matrix.os == 'ubuntu-22.04'
run: >
cmake . -B build -G Ninja
-D CMAKE_BUILD_TYPE=Release
-D VISP_CI=ON
-D VISP_VULKAN=ON
-D VISP_FMT_LIB=ON

- name: Configure (Windows)
if: matrix.os == 'windows-latest'
run: >
cmake . -B build -A x64
-D CMAKE_BUILD_TYPE=Release
-D VISP_CI=ON

- name: Configure (MacOS)
if: matrix.os == 'macos-14'
run: >
cmake . -B build -G Ninja
-D CMAKE_BUILD_TYPE=Release
-D VISP_CI=ON
-D GGML_METAL=OFF
-D GGML_RPC=ON
-D CMAKE_BUILD_RPATH="@loader_path"

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

# tests fail with vulkan/llvmpipe (runs out of memory or just wrong results)
# - name: Test Vulkan
# if: matrix.os == 'ubuntu-22.04'
# working-directory: ./build
# run: |
# export GGML_VK_VISIBLE_DEVICES=0
# ctest --verbose

- name: Test CPU
if: matrix.os != 'ubuntu-22.04'
working-directory: ./build
run: ctest --verbose -C Release

- name: Install
run: cmake --install build --prefix install --config Release

- name: Package
working-directory: ./build
run: cpack

- name: Upload artifacts
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: visioncpp-${{ matrix.os }}
path: |
./build/*.tar.gz
./build/*.zip
./tests/results/*.png
compression-level: 0
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "depend/ggml"]
path = depend/ggml
url = git@github.com:Acly/ggml.git
url = https://github.com/Acly/ggml.git
56 changes: 37 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.22)
cmake_minimum_required(VERSION 3.28)

project(vision.cpp VERSION 0.1.0 LANGUAGES CXX)

Expand All @@ -16,11 +16,16 @@ if(PROJECT_IS_TOP_LEVEL)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()

if(VISP_DEV OR ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
if(VISP_DEV)
set(VISP_ASSERT "VISP_ASSERT_BREAK")
endif()
if(${CMAKE_BUILD_TYPE} STREQUAL "Release")
set(VISP_ASSERT "VISP_ASSERT_DISABLE")
elseif(VISP_CI)
set(VISP_ASSERT "VISP_ASSERT_THROW")
elseif(CMAKE_BUILD_TYPE)
if(${CMAKE_BUILD_TYPE} STREQUAL "Debug")
set(VISP_ASSERT "VISP_ASSERT_BREAK")
elseif(${CMAKE_BUILD_TYPE} STREQUAL "Release")
set(VISP_ASSERT "VISP_ASSERT_DISABLE")
endif()
endif()

if(VISP_ASAN)
Expand Down Expand Up @@ -60,11 +65,15 @@ endif()
set(GGML_VULKAN ${VISP_VULKAN})
set(GGML_LLAMAFILE ON)
if(VISP_CI)
set(GGML_NATIVE OFF)
set(GGML_BACKEND_DL ON)
foreach (feat SSE42 AVX AVX2 F16C BMI2 FMA) # ~haswell and newer
set(GGML_${feat} ON)
endforeach()
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "^(aarch64|arm.*|ARM64)$")
# set default for ARM
else()
set(GGML_NATIVE OFF)
foreach (feat SSE42 AVX AVX2 F16C BMI2 FMA) # ~haswell and newer
set(GGML_${feat} ON)
endforeach()
endif()
endif()
add_subdirectory(depend/ggml)

Expand All @@ -81,7 +90,7 @@ if(VISP_TESTS)
add_subdirectory(models)
endif()

# Installation and packaging
# Installation

install(TARGETS visioncpp
RUNTIME DESTINATION bin
Expand All @@ -92,6 +101,8 @@ if(PROJECT_IS_TOP_LEVEL)
install(FILES README.md LICENSE DESTINATION .)
endif()

install(TARGETS vision-cli RUNTIME DESTINATION bin)

include(CMakePackageConfigHelpers)

set(VISP_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Location of header files")
Expand All @@ -115,12 +126,19 @@ install(
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/visioncpp
)

# if(WIN32)
# set(CPACK_GENERATOR "ZIP")
# set(CPACK_PACKAGE_FILE_NAME visioncpp-windows-x64-${PROJECT_VERSION})
# else()
# set(CPACK_GENERATOR "TGZ")
# set(CPACK_PACKAGE_FILE_NAME visioncpp-linux-x64-${PROJECT_VERSION})
# endif()
# set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
# include(CPack)
# Packaging

if(PROJECT_IS_TOP_LEVEL)
if(WIN32)
set(CPACK_GENERATOR "ZIP")
set(CPACK_PACKAGE_FILE_NAME visioncpp-windows-x64-${PROJECT_VERSION})
elseif(APPLE)
set(CPACK_GENERATOR "TGZ")
set(CPACK_PACKAGE_FILE_NAME visioncpp-macos-x64-${PROJECT_VERSION})
else()
set(CPACK_GENERATOR "TGZ")
set(CPACK_PACKAGE_FILE_NAME visioncpp-linux-x64-${PROJECT_VERSION})
endif()
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
include(CPack)
endif()
31 changes: 16 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ See [Building](#building) to build from source. Binaries can be found in `build/
Let's use MobileSAM to generate a segmentation mask for the <object>
at pixel position (320, 240).

You can download the required model from huggingface: [MobileSAM-F16.gguf]().
You can download the required model from huggingface: [MobileSAM-F16.gguf](https://huggingface.co/Acly/MobileSAM-GGUF/resolve/main/MobileSAM-F16.gguf).

#### CLI

Expand Down Expand Up @@ -93,14 +93,14 @@ vision-cli esrgan -m models/4x_foolhardy_Remacrih-F16.gguf -i input.png -o outpu

### Converting models

Models need to be converted to GGUF before they can be used. This can also
Models need to be converted to GGUF before they can be used. This will also
rearrange or precompute tensors for more optimal inference.

To convert eg. an ESRGAN model, install [uv](https://docs.astral.sh/uv/) and run:
To convert a model, install [uv](https://docs.astral.sh/uv/) and run:
```sh
uv run scripts/convert.py esrgan 4x_NMKD-Superscale-SP_178000_G.pth -q f16
uv run scripts/convert.py <arch> MyModel.pth -q f16
```
This will create `models/4x_NMKD-Superscale-SP_178000_G-F16.gguf`.
where `<arch>` is one of `sam, birefnet, esrgan, ...`. This will create `models/MyModel-F16.gguf`.

See `convert.py --help` for more options.

Expand All @@ -110,35 +110,36 @@ Building requires CMake and a compiler with C++20 support.

**Get the sources**
```sh
git clone --recursive
git clone https://github.com/Acly/vision.cpp.git --recursive
cd vision.cpp
```

**Configure and build**
```sh
cmake . -B build
cmake --build build --config Release
cmake . -B build -D CMAKE_BUILD_TYPE=Release
cmake --build build
```

### Vulkan
### _(Optional)_ Vulkan

Vulkan GPU support requires the [Vulkan SDK](https://www.lunarg.com/vulkan-sdk/) to be installed.

```sh
cmake . -B build -DVISP_VULKAN=ON
cmake --build build --config Release
cmake . -B build -D CMAKE_BUILD_TYPE=Release -D VISP_VULKAN=ON
cmake --build build
```

### Tests
### _(Optional)_ Tests

Run all tests with the following command:
Run all C++ tests with the following command:
```sh
ctest build -C Release
cd build
ctest
```

Some tests require a Python environment. It can be set up with [uv](https://docs.astral.sh/uv/):
```sh
# Setup venv and install dependencies
# Setup venv and install dependencies (once only)
uv sync

# Run only python tests
Expand Down
4 changes: 3 additions & 1 deletion depend/fmt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt
GIT_TAG 40626af88bd7df9a5fb80be7b25ac85b122d6c21) # 11.2.0
GIT_TAG 40626af88bd7df9a5fb80be7b25ac85b122d6c21 # 11.2.0
EXCLUDE_FROM_ALL
)
FetchContent_MakeAvailable(fmt)

set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_OLD})
Expand Down
2 changes: 1 addition & 1 deletion depend/ggml
8 changes: 8 additions & 0 deletions include/visp/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,17 @@ struct flags {
return (lhs.value & uint32_t(rhs)) != 0;
}

friend constexpr bool operator&(flags<E> lhs, flags<E> rhs) {
return (lhs.value & rhs.value) != 0;
}

friend constexpr flags<E> operator|(flags<E> lhs, E rhs) {
return flags<E>(lhs.value | uint32_t(rhs));
}

friend constexpr flags<E> operator|(flags<E> lhs, flags<E> rhs) {
return flags<E>(lhs.value | rhs.value);
}
};

} // namespace visp
1 change: 1 addition & 0 deletions include/visp/vision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ struct esrgan_params {
};

VISP_API esrgan_params esrgan_detect_params(model_ref);
VISP_API int esrgan_estimate_graph_size(esrgan_params const&);

VISP_API tensor esrgan_generate(model_ref, tensor image, esrgan_params const&);

Expand Down
11 changes: 8 additions & 3 deletions models/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Download models used in tests
# (this is disabled unless VISP_TESTS is enabled)
# Download models used in tests (happens only if VISP_TESTS is enabled)

message(STATUS "Checking for models/MobileSAM-F16.gguf")
file(DOWNLOAD
Expand All @@ -22,4 +21,10 @@ file(DOWNLOAD
EXPECTED_HASH "SHA256=c9f241e96fb5a791f9494fc7d4c2dd793297ae95f05b8423f547d19bea465b81"
SHOW_PROGRESS
)
# TODO: ESRGAN
message(STATUS "Checking for models/RealESRGAN-x4plus_anime-6B-F16.gguf")
file(DOWNLOAD
"https://huggingface.co/Acly/Real-ESRGAN-GGUF/resolve/main/RealESRGAN-x4plus_anime-6B-F16.gguf"
${CMAKE_CURRENT_LIST_DIR}/RealESRGAN-x4plus_anime-6B-F16.gguf
EXPECTED_HASH "SHA256=b741e68720d7ad6251dee2120bf7579ef816ea16da18299b39f6cbcb0e13ecf0"
SHOW_PROGRESS
)
3 changes: 1 addition & 2 deletions scripts/cmake/visioncpp-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set_and_check(VISP_INCLUDE_DIR "@PACKAGE_VISP_INCLUDE_INSTALL_DIR@")
set_and_check(VISP_LIB_DIR "@PACKAGE_VISP_LIB_INSTALL_DIR@")

find_package(ggml REQUIRED)
find_dependency(ggml)

find_library(VISP_LIBRARY visioncpp REQUIRED HINTS ${VISP_LIB_DIR} NO_CMAKE_FIND_ROOT_PATH)

Expand All @@ -14,7 +14,6 @@ set_target_properties(visioncpp PROPERTIES
INTERFACE_COMPILE_FEATURES cxx_std_20
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
IMPORTED_LOCATION "${VISP_LIBRARY}"
POSITION_INDEPENDENT_CODE ON
)

check_required_components(visioncpp)
Loading