From 8585b0a195525a92fc72e3e41fb68067fd769b83 Mon Sep 17 00:00:00 2001 From: Nik Bamert Date: Fri, 14 Nov 2025 14:01:55 +0100 Subject: [PATCH 1/2] ci build, cmakelists --- .github/workflows/build.yml | 18 +++++++++++++++++ lib/gpc/Feature.hpp | 1 + samples/CMakeLists.txt | 39 ++++++++++++++++++++++++------------- 3 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..b0401a8 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,18 @@ +name: Build + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Configure + run: cd samples && mkdir build && cd build && cmake .. + + - name: Build + run: cd samples/build && make -j + diff --git a/lib/gpc/Feature.hpp b/lib/gpc/Feature.hpp index fac61c5..c461f1a 100644 --- a/lib/gpc/Feature.hpp +++ b/lib/gpc/Feature.hpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 62b5724..f10bbc0 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -1,7 +1,7 @@ -cmake_minimum_required(VERSION 3.6) - +cmake_minimum_required(VERSION 3.10) +include(CheckCXXCompilerFlag) +include(CheckCXXSourceRuns) project(openGPC CXX) -# Use C++11 features. set (REQ_CPP11_FEATURES cxx_strong_enums cxx_auto_type) set(CMAKE_CXX_STANDARD 11) @@ -12,31 +12,42 @@ find_package(Eigen3 REQUIRED) include_directories(${EIGEN3_INCLUDE_DIR}) #By default, use SSE intrinsics -option(SSE "SSE" ON) +option(SSE "Enable SSE/AVX optimizations if available" ON) + +add_compile_options(-O3 -funroll-loops) if(SSE) - add_definitions(-D_INTRINSICS_SSE) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -mavx2 -march=core-avx2 -lpthread -funroll-loops") -else() - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -lpthread -funroll-loops") + message(STATUS "Checking if target CPU supports AVX2 instructions...") + check_cxx_source_runs(" + #include + int main() { + __m256i x = _mm256_set1_epi32(1); + return _mm256_extract_epi32(x, 0); + } + " CPU_HAS_AVX2) + + if(CPU_HAS_AVX2) + message(STATUS "AVX2: supported and enabled") + add_compile_definitions(_INTRINSICS_SSE) + add_compile_options(-mavx2 -march=core-avx2) + endif() endif() #find pnglib (used to load and store images for training and during evaluation) find_package(PNG REQUIRED) include_directories(${PNG_INCLUDE_DIRS}) +set(THREADS_PREFER_PTHREAD_FLAG ON) +find_package(Threads REQUIRED) -#Add gpc header directy include_directories("../lib") -#Three examples for GPC library add_executable(extract extract.cpp) -target_link_libraries(extract ${PNG_LIBRARIES}) +target_link_libraries(extract ${PNG_LIBRARIES} Threads::Threads) add_executable(train train.cpp) -target_link_libraries(train ${PNG_LIBRARIES}) - +target_link_libraries(train ${PNG_LIBRARIES} Threads::Threads) add_executable(sparsematch sparsematch.cpp) -target_link_libraries(sparsematch ${PNG_LIBRARIES}) +target_link_libraries(sparsematch ${PNG_LIBRARIES} Threads::Threads) From 3a665b998b57b6c55a86214ea1b4eb3313f8d23c Mon Sep 17 00:00:00 2001 From: Nik Bamert Date: Fri, 14 Nov 2025 14:05:09 +0100 Subject: [PATCH 2/2] deps --- .github/workflows/build.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b0401a8..6e6d04c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,6 +10,11 @@ jobs: - name: Checkout uses: actions/checkout@v3 + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y libeigen3-dev libpng-dev + - name: Configure run: cd samples && mkdir build && cd build && cmake ..