// Copyright 2020 ETH Zurich and University of Bologna.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Author: Matteo Perotti

#ifndef ICONV3D_H
#define ICONV3D_H

#define MIN(a, b) ((a) <= (b) ? (a) : (b))

#include <stdint.h>
#include <stdio.h>

// Threshold for FP numbers comparison during the final check
#define THRESHOLD 0

// Help calculate performance
// How many parallel elements in an ELEN-wide FPU data bus?
#define DTYPE_FACTOR 4
#define DTYPE_PREFIX "HP"
#define DATA_WIDTH "int16"

void convolve2D(
    int16_t *ooutput,   // output buffer
    int16_t *image,     // input image with padding applied
    int16_t *filter,    // filter kernel
    int32_t ImageHeight,
    int32_t ImageWidth,
    int32_t Channels,
    int32_t FilterSize
);

void hp_iconv3d_CHx7x7(int16_t *o, int16_t *i, int16_t *f, int32_t M, int32_t N,
                       int32_t C, int32_t F);

void hp_iconv3d_CHx7x7_block(int16_t *o, int16_t *i, int16_t *f, int32_t M,
                             int32_t N, int32_t n_, int32_t C, int32_t F);

// Verify the matrices
int hp_iconv3d_verify(int16_t *matrix, int16_t *golden_matrix, int32_t R,
                      int32_t C, int32_t threshold);

#endif