Skip to content

Commit 6bca62e

Browse files
mcr229facebook-github-bot
authored andcommitted
add preprocessor flag for enabling dq linear in runtime (#66)
Summary: Pull Request resolved: #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 Differential Revision: D48335277 fbshipit-source-id: 0f2c8c56a75772cf1105b6c37523d0b84b6c6b33
1 parent 4885608 commit 6bca62e

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

backends/xnnpack/runtime/XNNCompiler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,7 @@ __ET_NODISCARD Error XNNCompiler::compileModel(
15171517
if (!executor->qinputs_.empty() && flatbuffer_graph->xnodes()->size() > 0 &&
15181518
flatbuffer_graph->xnodes()->Get(0)->xnode_union_type() ==
15191519
fb_xnnpack::XNodeUnion::XNNFullyConnected) {
1520+
#ifdef ENABLE_DYNAMIC_QUANTIZATION
15201521
// This delegate is for DQLinear which supports dynamic input shapes
15211522
if (executor->getNumInputs() < 1 || executor->getNumOutputs() != 1) {
15221523
ET_LOG(
@@ -1525,6 +1526,10 @@ __ET_NODISCARD Error XNNCompiler::compileModel(
15251526
return Error::NotSupported;
15261527
}
15271528
executor->setNeedsResizeOutput();
1529+
#else
1530+
ET_LOG(Error, "DQ Linear is not supported");
1531+
return Error::NotSupported;
1532+
#endif
15281533
}
15291534

15301535
return err;

backends/xnnpack/runtime/XNNExecutor.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
*/
88

99
#include <executorch/backends/xnnpack/runtime/XNNExecutor.h>
10+
#ifdef ENABLE_DYNAMIC_QUANTIZATION
1011
#include <executorch/backends/xnnpack/runtime/utils/utils.h>
12+
#endif
1113

1214
namespace torch {
1315
namespace executor {
@@ -17,6 +19,7 @@ namespace delegate {
1719
Error XNNExecutor::set_external_input(uint32_t id, Tensor* input) {
1820
auto qinput_pair = qinputs_.find(id);
1921
if (qinput_pair != qinputs_.end()) {
22+
#ifdef ENABLE_DYNAMIC_QUANTIZATION
2023
auto qinput = qinput_pair->second;
2124
// dq the input and copy it in to qinput
2225
float input_min, input_max;
@@ -60,6 +63,10 @@ Error XNNExecutor::set_external_input(uint32_t id, Tensor* input) {
6063
{static_cast<float>(input_qparam.scale),
6164
static_cast<int8_t>(input_qparam.zero_point)},
6265
batch_size});
66+
#else
67+
ET_LOG(Error, "Dynamic Quantization is not supported");
68+
return Error::NotSupported;
69+
#endif
6370
} else {
6471
externals_.emplace_back(xnn_external_value{id, input->mutable_data_ptr()});
6572
}

backends/xnnpack/targets.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def define_common_targets():
6565
"//executorch/extension/pybindings/...",
6666
"@EXECUTORCH_CLIENTS",
6767
],
68+
preprocessor_flags = [] if runtime.is_oss else ["-DENABLE_DYNAMIC_QUANTIZATION"],
6869
deps = [
6970
third_party_dep("XNNPACK"),
7071
":xnnpack_schema",

0 commit comments

Comments
 (0)