未验证 提交 988e2869 编写于 作者: C cad-audio 提交者: GitHub

Cadence HiFi 5 Neural Network Library v1.6.0 (#276)

* Cadence HiFi 5 Neural Network Library v1.6.0
updated the download script to use hifi5 v1.6.0 archive.
depthwise_conv kernel is updated and patch is not required now.
quantize optimized kernel is renamed in the v1.6.0, updated with new
kernel name.

* Fix formatting.
Co-authored-by: Nbhanu prakash bandaru venkata <bhanup@cadence.com>
Co-authored-by: NAdvait Jain <advaitjain@users.noreply.github.com>
Co-authored-by: NAdvait Jain <advaitjain@google.com>
上级 e9591074
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
/* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
......@@ -117,7 +117,7 @@ TfLiteStatus EvalXtensa(TfLiteContext* context, TfLiteNode* node) {
auto* op_data = static_cast<OpData*>(node->user_data);
#elif defined(FUSION_F1) || defined(HIFI5)
auto* op_data = static_cast<OpDataQuantizeReference*>(node->user_data);
#endif
#endif // defined(HIFIMINI) || defined(FUSION_F1) || defined(HIFI5)
const TfLiteEvalTensor* input = tflite::micro::GetEvalInput(context, node, 0);
TfLiteEvalTensor* output = tflite::micro::GetEvalOutput(context, node, 0);
......@@ -129,7 +129,7 @@ TfLiteStatus EvalXtensa(TfLiteContext* context, TfLiteNode* node) {
tflite::micro::GetTensorData<int16_t>(input),
tflite::micro::GetTensorShape(output),
tflite::micro::GetTensorData<int8_t>(output));
#elif defined(FUSION_F1) || defined(HIFI5)
#elif defined(FUSION_F1)
int size = ElementCount(*input->dims);
TF_LITE_ENSURE_EQ(
context,
......@@ -140,9 +140,20 @@ TfLiteStatus EvalXtensa(TfLiteContext* context, TfLiteNode* node) {
op_data->requantize_output_shift,
op_data->requantize_output_multiplier, size),
0);
#elif defined(HIFI5)
int size = ElementCount(*input->dims);
TF_LITE_ENSURE_EQ(
context,
xa_nn_elm_requantize_asym16s_asym8s(
tflite::micro::GetTensorData<int8_t>(output),
tflite::micro::GetTensorData<int16_t>(input),
op_data->input_zero_point, op_data->quantization_params.zero_point,
op_data->requantize_output_shift,
op_data->requantize_output_multiplier, size),
0);
#else
static_assert(false, "Unsupported xtensa architecture.");
#endif
#endif // defined(HIFIMINI) || defined(FUSION_F1) || defined(HIFI5)
} else if (output->type == kTfLiteInt32 &&
(input->type == kTfLiteInt16 || input->type == kTfLiteInt8)) {
int size = ElementCount(*input->dims);
......@@ -154,19 +165,47 @@ TfLiteStatus EvalXtensa(TfLiteContext* context, TfLiteNode* node) {
int32_t zero_point = op_data->zero_point;
#elif defined(FUSION_F1) || defined(HIFI5)
int32_t zero_point = op_data->quantization_params.zero_point;
#endif
#endif // defined(HIFIMINI) || defined(FUSION_F1) || defined(HIFI5)
if (input->type == kTfLiteInt16) {
#if defined(HIFI5)
int size = ElementCount(*input->dims);
TF_LITE_ENSURE_EQ(context,
xa_nn_elm_requantize_asym16s_asym32s(
tflite::micro::GetTensorData<int32_t>(output),
tflite::micro::GetTensorData<int16_t>(input),
op_data->input_zero_point,
op_data->quantization_params.zero_point,
op_data->requantize_output_shift,
op_data->requantize_output_multiplier, size),
0);
#else
reference_ops::Requantize(tflite::micro::GetTensorData<int16_t>(input),
size, op_data->requantize_output_multiplier,
op_data->requantize_output_shift,
op_data->input_zero_point, zero_point,
tflite::micro::GetTensorData<int32_t>(output));
#endif // defined(HIFI5)
} else {
#if defined(HIFI5)
const int8_t* input_data_ptr;
int32_t* output_data_ptr;
input_data_ptr = tflite::micro::GetTensorData<int8_t>(input);
output_data_ptr = tflite::micro::GetTensorData<int32_t>(output);
TF_LITE_ENSURE_EQ(
context,
xa_nn_elm_requantize_asym8s_asym32s(
output_data_ptr, input_data_ptr, op_data->input_zero_point,
zero_point, op_data->requantize_output_shift,
op_data->requantize_output_multiplier, size),
0);
#else
reference_ops::Requantize(tflite::micro::GetTensorData<int8_t>(input),
size, op_data->requantize_output_multiplier,
op_data->requantize_output_shift,
op_data->input_zero_point, zero_point,
tflite::micro::GetTensorData<int32_t>(output));
#endif // defined(HIFI5)
}
} else {
TF_LITE_KERNEL_LOG(context, "Input %s, output %s not supported.",
......@@ -185,7 +224,7 @@ void* Init(TfLiteContext* context, const char* buffer, size_t length) {
#else
return context->AllocatePersistentBuffer(context,
sizeof(OpDataQuantizeReference));
#endif
#endif // defined(HIFIMINI)
}
TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
......@@ -205,7 +244,7 @@ TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
op_data->quantization_params.zero_point = output->params.zero_point;
op_data->quantization_params.scale =
static_cast<double>(output->params.scale);
#endif
#endif // defined(HIFIMINI)
op_data->input_zero_point = input->params.zero_point;
......@@ -222,7 +261,7 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
return EvalXtensa(context, node);
#else
return EvalQuantizeReference(context, node);
#endif
#endif // defined(HIFIMINI) || defined(FUSION_F1) || defined(HIFI5)
}
} // namespace
......
diff --git a/algo/kernels/cnn/hifi5/xa_nn_conv2d_depthwise.c b/algo/kernels/cnn/hifi5/xa_nn_conv2d_depthwise.c
index 48fccdc..3c10040 100644
--- a/algo/kernels/cnn/hifi5/xa_nn_conv2d_depthwise.c
+++ b/algo/kernels/cnn/hifi5/xa_nn_conv2d_depthwise.c
@@ -348,8 +348,6 @@ WORD32 xa_nn_conv2d_depthwise_getsize
XA_NNLIB_CHK_COND((kernel_height <= 0), -1);
XA_NNLIB_CHK_COND((kernel_width <= 0), -1);
XA_NNLIB_CHK_COND((channels_multiplier <= 0), -1);
- XA_NNLIB_CHK_COND((x_stride <= 0 || x_stride > kernel_width), -1); //TODO: x_stride > kernel_width is supported ?
- XA_NNLIB_CHK_COND((y_stride <= 0 || y_stride > kernel_height), -1);
XA_NNLIB_CHK_COND((x_padding < 0), -1);
XA_NNLIB_CHK_COND((y_padding < 0), -1);
XA_NNLIB_CHK_COND((output_height <= 0), -1);
diff --git a/algo/kernels/cnn/hifi5/xa_nn_conv2d_depthwise_sym8sxasym8s.c b/algo/kernels/cnn/hifi5/xa_nn_conv2d_depthwise_sym8sxasym8s.c
index 71611f4..0fd19ae 100644
--- a/algo/kernels/cnn/hifi5/xa_nn_conv2d_depthwise_sym8sxasym8s.c
+++ b/algo/kernels/cnn/hifi5/xa_nn_conv2d_depthwise_sym8sxasym8s.c
@@ -2122,10 +2122,7 @@ WORD32 xa_nn_conv2d_depthwise_nhwc_per_chan_sym8sxasym8s_k3x3
/* Implementation dependent checks */
//TOOD: support y_stride 2
XA_NNLIB_ARG_CHK_COND((y_stride != 1) && (y_stride != 2), -1);
- XA_NNLIB_ARG_CHK_COND((y_stride > kernel_height), -1);
- XA_NNLIB_ARG_CHK_COND((x_stride > kernel_width), -1);
XA_NNLIB_ARG_CHK_COND((kernel_height > input_height), -1);
- XA_NNLIB_ARG_CHK_COND((kernel_width > input_width), -1);
#ifndef DISABLE_DEPTHWISE_CONV2D_K3X3_SPECIAL_CASE
WORD32 input_zero_bias_neg = -input_zero_bias;
@@ -2271,7 +2268,6 @@ WORD32 xa_nn_conv2d_depthwise_per_chan_sym8sxasym8s_generic
XA_NNLIB_ARG_CHK_COND((input_channels <= 0), -1);
XA_NNLIB_ARG_CHK_COND((kernel_height <= 0 || kernel_width <= 0), -1);
XA_NNLIB_ARG_CHK_COND((kernel_height > input_height), -1);
- XA_NNLIB_ARG_CHK_COND((kernel_width > input_width), -1);
XA_NNLIB_ARG_CHK_COND((channels_multiplier <= 0), -1);
XA_NNLIB_ARG_CHK_COND((y_stride <= 0 || x_stride <= 0), -1);
XA_NNLIB_ARG_CHK_COND((y_padding < 0 || x_padding < 0), -1);
@@ -2282,8 +2278,6 @@ WORD32 xa_nn_conv2d_depthwise_per_chan_sym8sxasym8s_generic
XA_NNLIB_ARG_CHK_COND((inp_data_format != 0 && inp_data_format != 1), -1);
XA_NNLIB_ARG_CHK_COND((out_data_format != 0), -1);
/* Implementation dependent checks */
- XA_NNLIB_ARG_CHK_COND((y_stride > kernel_height), -1);
- XA_NNLIB_ARG_CHK_COND((x_stride > kernel_width), -1);
if(inp_data_format == 0)
{
......@@ -51,9 +51,9 @@ if [[ ${2} == "hifi4" ]]; then
LIBRARY_DIRNAME="xa_nnlib_hifi4"
LIBRARY_MD5="8b934f61ffe0a966644849602810fb1b"
elif [[ ${2} == "hifi5" ]]; then
LIBRARY_URL="http://github.com/foss-xtensa/nnlib-hifi5/raw/master/archive/xa_nnlib_hifi5_02_22.zip"
LIBRARY_URL="http://github.com/foss-xtensa/nnlib-hifi5/raw/master/archive/xa_nnlib_hifi5_06_30.zip"
LIBRARY_DIRNAME="xa_nnlib_hifi5"
LIBRARY_MD5="08cd4d446b3e0b7d180f9ef0dec9ad0a"
LIBRARY_MD5="0c832b15d27ac557fa5453c902c5662a"
else
echo "Attempting to download an unsupported xtensa variant: ${2}"
exit 1
......@@ -80,10 +80,6 @@ else
apply_patch_to_folder ${DOWNLOADS_DIR}/xa_nnlib_hifi4/ ../../ext_libs/xtensa_patch.patch
fi
if [[ ${2} == "hifi5" ]]; then
apply_patch_to_folder ${DOWNLOADS_DIR}/xa_nnlib_hifi5/ ../../ext_libs/xtensa_depthwise_patch_hifi5.patch
fi
fi
echo "SUCCESS"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册