name: Bench

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

  workflow_dispatch:

jobs:
  build_and_test:
    if: contains(toJson(github.event.commits), '***NO_CI***') == false && contains(toJson(github.event.commits), '[ci skip]') == false && contains(toJson(github.event.commits), '[skip ci]') == false
    name: Benchmark library with backend ${{ matrix.name }}
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false # show all errors for each platform (vs. cancel jobs on error)
      matrix:
        include:
        - name: "Eigen"
          backend: "-DRTNEURAL_EIGEN=ON"
        - name: "xsimd"
          backend: "-DRTNEURAL_XSIMD=ON"
        - name: "STL"
          backend: "-DRTNEURAL_STL=ON"

    
    steps:
    - name: Get latest CMake
      uses: lukka/get-cmake@latest

    - name: Checkout code
      uses: actions/checkout@v2
      with:
        submodules: true

    - name: Configure
      env:
        BACKEND_ARG: ${{ matrix.backend }}
      shell: bash
      run: cmake -Bbuild -DBUILD_BENCH=ON -DCMAKE_BUILD_TYPE=Release $BACKEND_ARG

    - name: Build
      shell: bash
      run: cmake --build build --config Release --parallel

    - name: Benchmark Dense
      run: |
       ./build/rtneural_layer_bench dense 5 4 4
       ./build/rtneural_layer_bench dense 5 16 16
       ./build/rtneural_layer_bench dense 5 24 1

    - name: Benchmark Conv1D
      run: |
       ./build/rtneural_layer_bench conv1d 5 4 4
       ./build/rtneural_layer_bench conv1d 5 16 16

    - name: Benchmark GRU
      run: |
        ./build/rtneural_layer_bench gru 5 4 4
        ./build/rtneural_layer_bench gru 5 16 16

    - name: Benchmark LSTM
      run: |
        ./build/rtneural_layer_bench lstm 5 4 4
        ./build/rtneural_layer_bench lstm 5 16 16
        ./build/rtneural_layer_bench lstm 5 1 24

    - name: Benchmark Tanh
      run: |
        ./build/rtneural_layer_bench tanh 5 4 4
        ./build/rtneural_layer_bench tanh 5 16 16

    - name: Benchmark ReLu
      run: |
        ./build/rtneural_layer_bench relu 5 4 4
        ./build/rtneural_layer_bench relu 5 16 16

    - name: Benchmark Sigmoid
      run: |
        ./build/rtneural_layer_bench sigmoid 5 4 4
        ./build/rtneural_layer_bench sigmoid 5 16 16

    - name: Benchmark Softmax
      run: |
        ./build/rtneural_layer_bench softmax 5 4 4
        ./build/rtneural_layer_bench softmax 5 16 16

    - name: Benchmark Model
      run: |
        ./build/rtneural_model_bench
