From 80f1188eb1a20f2dc43ade9ce3ec47fe4326290a Mon Sep 17 00:00:00 2001 From: Max Ren Date: Wed, 23 Aug 2023 15:12:43 -0700 Subject: [PATCH] add preprocessor flag for enabling dq linear in runtime (#66) Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/66 DQ Linear runtime logic for XNNPACK is FB internal only, so we are adding a flag in the dq linear logic to remove dq linear logic from xnnpack delegate in OSS Reviewed By: digantdesai Differential Revision: D48335277 fbshipit-source-id: b137a667ab204bf94c8332cb31eeedf26ed7672f --- backends/xnnpack/runtime/XNNCompiler.cpp | 5 +++++ backends/xnnpack/runtime/XNNExecutor.cpp | 7 +++++++ backends/xnnpack/targets.bzl | 1 + 3 files changed, 13 insertions(+) diff --git a/backends/xnnpack/runtime/XNNCompiler.cpp b/backends/xnnpack/runtime/XNNCompiler.cpp index 0c1c9e6d42c..8498bd84c5f 100644 --- a/backends/xnnpack/runtime/XNNCompiler.cpp +++ b/backends/xnnpack/runtime/XNNCompiler.cpp @@ -1517,6 +1517,7 @@ __ET_NODISCARD Error XNNCompiler::compileModel( if (!executor->qinputs_.empty() && flatbuffer_graph->xnodes()->size() > 0 && flatbuffer_graph->xnodes()->Get(0)->xnode_union_type() == fb_xnnpack::XNodeUnion::XNNFullyConnected) { +#ifdef ENABLE_DYNAMIC_QUANTIZATION // This delegate is for DQLinear which supports dynamic input shapes if (executor->getNumInputs() < 1 || executor->getNumOutputs() != 1) { ET_LOG( @@ -1525,6 +1526,10 @@ __ET_NODISCARD Error XNNCompiler::compileModel( return Error::NotSupported; } executor->setNeedsResizeOutput(); +#else + ET_LOG(Error, "DQ Linear is not supported"); + return Error::NotSupported; +#endif } return err; diff --git a/backends/xnnpack/runtime/XNNExecutor.cpp b/backends/xnnpack/runtime/XNNExecutor.cpp index 5e39c86c1ba..30b60ee329d 100644 --- a/backends/xnnpack/runtime/XNNExecutor.cpp +++ b/backends/xnnpack/runtime/XNNExecutor.cpp @@ -7,7 +7,9 @@ */ #include +#ifdef ENABLE_DYNAMIC_QUANTIZATION #include +#endif namespace torch { namespace executor { @@ -17,6 +19,7 @@ namespace delegate { Error XNNExecutor::set_external_input(uint32_t id, Tensor* input) { auto qinput_pair = qinputs_.find(id); if (qinput_pair != qinputs_.end()) { +#ifdef ENABLE_DYNAMIC_QUANTIZATION auto qinput = qinput_pair->second; // dq the input and copy it in to qinput float input_min, input_max; @@ -60,6 +63,10 @@ Error XNNExecutor::set_external_input(uint32_t id, Tensor* input) { {static_cast(input_qparam.scale), static_cast(input_qparam.zero_point)}, batch_size}); +#else + ET_LOG(Error, "Dynamic Quantization is not supported"); + return Error::NotSupported; +#endif } else { externals_.emplace_back(xnn_external_value{id, input->mutable_data_ptr()}); } diff --git a/backends/xnnpack/targets.bzl b/backends/xnnpack/targets.bzl index 6df70f654aa..0f80af77cd0 100644 --- a/backends/xnnpack/targets.bzl +++ b/backends/xnnpack/targets.bzl @@ -65,6 +65,7 @@ def define_common_targets(): "//executorch/extension/pybindings/...", "@EXECUTORCH_CLIENTS", ], + preprocessor_flags = [] if runtime.is_oss else ["-DENABLE_DYNAMIC_QUANTIZATION"], deps = [ third_party_dep("XNNPACK"), ":xnnpack_schema",