// File: binding.cpp
#include "conv2d_depthwise_contract.h"
#include "mat.h"
#include "option.h"

namespace {
constexpr int kernel_h   = 5;
constexpr int kernel_w   = 5;
constexpr int stride_h   = 1;
constexpr int stride_w   = 1;
constexpr int dilation_h = 1;
constexpr int dilation_w = 1;
constexpr int pad        = 2;
} // namespace

extern "C" {
int armbench_entry_conv2d_depthwise(
    void* bottom_v, void* top_v,
    void* weight_v, void* bias_v,
    void* opt_v)
{
    const auto& bottom = *reinterpret_cast<const ncnn::Mat*>(bottom_v);
    auto&       top    = *reinterpret_cast<ncnn::Mat*>(top_v);
    const auto& weight = *reinterpret_cast<const ncnn::Mat*>(weight_v);
    const auto& bias   = *reinterpret_cast<const ncnn::Mat*>(bias_v);
    const auto& opt    = *reinterpret_cast<const ncnn::Option*>(opt_v);

    // Depthwise: num_output == input channels.
    const int C      = bottom.c;
    const int ext_kh = dilation_h * (kernel_h - 1) + 1;
    const int ext_kw = dilation_w * (kernel_w - 1) + 1;
    const int H_out  = (bottom.h + 2 * pad - ext_kh) / stride_h + 1;
    const int W_out  = (bottom.w + 2 * pad - ext_kw) / stride_w + 1;

    top.create(W_out, H_out, C, (size_t)4u, opt.blob_allocator);
    if (top.empty()) return -1;

    return ncnn::conv2d_depthwise_kernel(
        bottom, top, weight, bias,
        kernel_h, kernel_w,
        stride_h, stride_w,
        dilation_h, dilation_w,
        pad, opt);
}
} // extern "C"