From bb6fa857035b23206da74a00ab4971e8403decb1 Mon Sep 17 00:00:00 2001 From: Alan Kelly Date: Sun, 13 Nov 2022 07:08:28 -0800 Subject: [PATCH] Enable unsigned quantized infererence using XNNPACK. PiperOrigin-RevId: 488179656 --- mediapipe/calculators/tensor/inference_calculator_cpu.cc | 2 ++ mediapipe/calculators/tensor/inference_calculator_xnnpack.cc | 2 ++ mediapipe/calculators/tflite/tflite_inference_calculator.cc | 2 ++ 3 files changed, 6 insertions(+) diff --git a/mediapipe/calculators/tensor/inference_calculator_cpu.cc b/mediapipe/calculators/tensor/inference_calculator_cpu.cc index 79df97638..46804b6fd 100644 --- a/mediapipe/calculators/tensor/inference_calculator_cpu.cc +++ b/mediapipe/calculators/tensor/inference_calculator_cpu.cc @@ -151,6 +151,8 @@ InferenceCalculatorCpuImpl::MaybeCreateDelegate(CalculatorContext* cc) { auto xnnpack_opts = TfLiteXNNPackDelegateOptionsDefault(); xnnpack_opts.num_threads = GetXnnpackNumThreads(opts_has_delegate, opts_delegate); + // TODO Remove once XNNPACK is enabled by default. + xnnpack_opts.flags |= TFLITE_XNNPACK_DELEGATE_FLAG_QU8; return TfLiteDelegatePtr(TfLiteXNNPackDelegateCreate(&xnnpack_opts), &TfLiteXNNPackDelegateDelete); } diff --git a/mediapipe/calculators/tensor/inference_calculator_xnnpack.cc b/mediapipe/calculators/tensor/inference_calculator_xnnpack.cc index a9417d508..4212534a1 100644 --- a/mediapipe/calculators/tensor/inference_calculator_xnnpack.cc +++ b/mediapipe/calculators/tensor/inference_calculator_xnnpack.cc @@ -114,6 +114,8 @@ InferenceCalculatorXnnpackImpl::CreateDelegate(CalculatorContext* cc) { auto xnnpack_opts = TfLiteXNNPackDelegateOptionsDefault(); xnnpack_opts.num_threads = GetXnnpackNumThreads(opts_has_delegate, opts_delegate); + // TODO Remove once XNNPACK is enabled by default. + xnnpack_opts.flags |= TFLITE_XNNPACK_DELEGATE_FLAG_QU8; return TfLiteDelegatePtr(TfLiteXNNPackDelegateCreate(&xnnpack_opts), &TfLiteXNNPackDelegateDelete); } diff --git a/mediapipe/calculators/tflite/tflite_inference_calculator.cc b/mediapipe/calculators/tflite/tflite_inference_calculator.cc index 027e4446d..afdc9ed6f 100644 --- a/mediapipe/calculators/tflite/tflite_inference_calculator.cc +++ b/mediapipe/calculators/tflite/tflite_inference_calculator.cc @@ -941,6 +941,8 @@ absl::Status TfLiteInferenceCalculator::LoadDelegate(CalculatorContext* cc) { if (use_xnnpack) { auto xnnpack_opts = TfLiteXNNPackDelegateOptionsDefault(); xnnpack_opts.num_threads = GetXnnpackNumThreads(calculator_opts); + // TODO Remove once XNNPACK is enabled by default. + xnnpack_opts.flags |= TFLITE_XNNPACK_DELEGATE_FLAG_QU8; delegate_ = TfLiteDelegatePtr(TfLiteXNNPackDelegateCreate(&xnnpack_opts), &TfLiteXNNPackDelegateDelete); RET_CHECK_EQ(interpreter_->ModifyGraphWithDelegate(delegate_.get()),