name: linux-x64-cpu-gcc
on:
  push:
    branches: [master]
    paths:
    - '.ci/linux-x64-cpu-gcc.yml'
    - 'CMakeLists.txt'
    - 'cmake/**'
    - 'src/*'
    - 'src/layer/*'
    - 'src/layer/x86/**'
    - 'tests/**'
    - 'tools/**'
    - '!tools/pnnx/**'
    - 'examples/**'
  mr:
    target-branches: [master]
    paths:
    - '.ci/linux-x64-cpu-gcc.yml'
    - 'CMakeLists.txt'
    - 'cmake/**'
    - 'src/*'
    - 'src/layer/*'
    - 'src/layer/x86/**'
    - 'tests/**'
    - 'tools/**'
    - '!tools/pnnx/**'
    - 'examples/**'
concurrency:
  group: linux-x64-cpu-gcc-${{ ci.head_ref }}

jobs:
  linux-gcc:
    name: linux-gcc
    strategy:
      matrix:
        include:
          - { SSE2: 'OFF', AVX: 'OFF', AVX2: 'OFF', AVX512: 'OFF' }
          - { SSE2: 'ON',  AVX: 'OFF', AVX2: 'OFF', AVX512: 'OFF' }
          - { SSE2: 'ON',  AVX: 'ON',  AVX2: 'OFF', AVX512: 'OFF' }
          - { SSE2: 'ON',  AVX: 'ON',  AVX2: 'ON',  AVX512: 'OFF' }
          - { SSE2: 'ON',  AVX: 'ON',  AVX2: 'ON',  AVX512: 'ON'  }

    runs-on:
      pool-name: docker
      container:
        image: bkci/ci:ubuntu
    steps:
    - name: checkout
      checkout: self
      with:
        strategy: FRESH_CHECKOUT
        enableSubmodule: false
        enableGitLfs: false

    - name: install-deps
      run: |
        apt-get update
        apt-get install -y libprotobuf-dev protobuf-compiler libopencv-dev

    - name: build
      run: |
        mkdir build && cd build
        cmake -DNCNN_SSE2=${{matrix.SSE2}} -DNCNN_AVX=${{matrix.AVX}} -DNCNN_AVX2=${{matrix.AVX2}} -DNCNN_AVX512=${{matrix.AVX512}} -DNCNN_BUILD_TESTS=ON ..
        cmake --build . -j 4
    - name: test
      run: cd build && ctest --output-on-failure -j 4
    - name: build-shared
      run: |
        mkdir build-shared && cd build-shared
        cmake -DNCNN_SSE2=${{matrix.SSE2}} -DNCNN_AVX=${{matrix.AVX}} -DNCNN_AVX2=${{matrix.AVX2}} -DNCNN_AVX512=${{matrix.AVX512}} -DNCNN_SHARED_LIB=ON ..
        cmake --build . -j 4
    - name: build-noint8
      run: |
        mkdir build-noint8 && cd build-noint8
        cmake -DNCNN_SSE2=${{matrix.SSE2}} -DNCNN_AVX=${{matrix.AVX}} -DNCNN_AVX2=${{matrix.AVX2}} -DNCNN_AVX512=${{matrix.AVX512}} -DNCNN_INT8=OFF -DNCNN_BUILD_TESTS=ON ..
        cmake --build . -j 4
    - name: test-noint8
      run: cd build-noint8 && ctest --output-on-failure -j 4

  linux-gcc-cpp03-nostdio-nostring-simplestl:
    runs-on:
      pool-name: docker
      container:
        image: bkci/ci:ubuntu
    steps:
    - name: checkout
      checkout: self
      with:
        strategy: FRESH_CHECKOUT
        enableSubmodule: false
        enableGitLfs: false

    - name: build-nostdio
      run: |
        mkdir build-nostdio && cd build-nostdio
        cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/host.gcc-c++03.toolchain.cmake -DNCNN_BUILD_TESTS=ON -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF ..
        cmake --build . -j 4
    - name: test-nostdio
      run: cd build-nostdio && ctest --output-on-failure -j 4
    - name: build-nostdio-nostring
      run: |
        mkdir build-nostdio-nostring && cd build-nostdio-nostring
        cmake -DNCNN_STDIO=OFF -DNCNN_STRING=OFF -DNCNN_BUILD_TESTS=OFF -DNCNN_BUILD_BENCHMARK=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF ..
        cmake --build . -j 4
    - name: build-simplestl
      run: |
        mkdir build-simplestl && cd build-simplestl
        cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/host-c.gcc.toolchain.cmake -DNCNN_STDIO=ON -DNCNN_STRING=ON -DNCNN_SIMPLESTL=ON -DNCNN_BUILD_TESTS=ON -DNCNN_BUILD_BENCHMARK=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF ..
        cmake --build . -j 4
    - name: test-simplestl
      run: cd build-simplestl && ctest --output-on-failure -j 4
    - name: build-simplestl-simpleomp
      run: |
        mkdir build-simplestl-simpleomp && cd build-simplestl-simpleomp
        cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/host-c.gcc.toolchain.cmake -DNCNN_STDIO=ON -DNCNN_STRING=ON -DNCNN_SIMPLESTL=ON -DNCNN_SIMPLEOMP=ON -DNCNN_BUILD_TESTS=ON -DNCNN_BUILD_BENCHMARK=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF ..
        cmake --build . -j 4
    - name: test-simplestl-simpleomp
      run: cd build-simplestl-simpleomp && ctest --output-on-failure -j 4
    - name: build-simplestl-simplemath
      run: |
        mkdir build-simplestl-simplemath && cd build-simplestl-simplemath
        cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/host-c.gcc.toolchain.cmake -DNCNN_STDIO=ON -DNCNN_STRING=ON -DNCNN_SIMPLESTL=ON -DNCNN_SIMPLEMATH=ON -DNCNN_BUILD_TESTS=ON -DNCNN_BUILD_BENCHMARK=OFF -DNCNN_BUILD_TOOLS=OFF -DNCNN_BUILD_EXAMPLES=OFF ..
        cmake --build . -j 4
    - name: test-simplestl-simplemath
      run: cd build-simplestl-simplemath && ctest --output-on-failure -j 4

