From 140567aa4be5ed224de3932c23752ed8087f0259 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Tue, 27 Nov 2018 11:35:44 +0900 Subject: [PATCH] [enco] Do NOT reduce identical objects with side effect (#2419) * [enco] Do NOT reduce identical objects with side effect Update on one object may have a side effect through its backing bag. So, reduction in identical objects with side effect results in incorrect compilation artifact. Signed-off-by: Jonghyun Park * Update the examples in the comment --- .../src/Transforms/IdenticalObjectReduction.cpp | 44 +++++++++++++++++++ contrib/enco/test/tflite/Regression_0001/INFERENCE | 0 .../enco/test/tflite/Regression_0001/test.recipe | 50 ++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 contrib/enco/test/tflite/Regression_0001/INFERENCE create mode 100644 contrib/enco/test/tflite/Regression_0001/test.recipe diff --git a/contrib/enco/core/src/Transforms/IdenticalObjectReduction.cpp b/contrib/enco/core/src/Transforms/IdenticalObjectReduction.cpp index 12cbb6c..03df6ec 100644 --- a/contrib/enco/core/src/Transforms/IdenticalObjectReduction.cpp +++ b/contrib/enco/core/src/Transforms/IdenticalObjectReduction.cpp @@ -77,6 +77,50 @@ void reduce_identical_object(enco::Code *code) continue; } + if (ofm->bag()->reads()->size() > 0) + { + // Let us consider the following code: + // + // Bag: + // %bag_0 = Bag(...) + // %bag_1 = Bag(...) + // %bag_2 = Bag(...) + // + // Object: + // %obj_0 = FeatureObject(bag: %bag_0) + // %obj_1 = FeatureObject(bag: %bag_1) + // + // Instr: + // copy an object from %obj_0 into %obj_1 + // shuffle values from %bag_1 into %bag_2 + // eval Conv2D with %obj_1 + // + // Identical Object Reduction (IOR) tries to eliminate the first copy via + // substitution (substitute all the occurrence of %obj_1 as use with %obj_0). + // + // Here is the code transformed by IOR: + // + // Bag: + // %bag_0 = Bag(...) + // %bag_1 = Bag(...) + // %bag_2 = Bag(...) + // + // Object: + // %obj_0 = FeatureObject(bag: %bag_0) + // %obj_1 = FeatureObject(bag: %bag_1) + // + // Instr: + // shuffle values from %bag_1 into %bag_2 + // eval Conv2D with %obj_0 + // + // Note that there is no updater of %bag_1 after IOR, and thus the behavior + // of the first shuffle instruction has changed. + // + // This examples shows that it is impossible to simply substitute %obj_1 + // with %obj_0 in the presence of readers over its backing bag. + continue; + } + subst(copy->into(), copy->from()); copy->detach(); diff --git a/contrib/enco/test/tflite/Regression_0001/INFERENCE b/contrib/enco/test/tflite/Regression_0001/INFERENCE new file mode 100644 index 0000000..e69de29 diff --git a/contrib/enco/test/tflite/Regression_0001/test.recipe b/contrib/enco/test/tflite/Regression_0001/test.recipe new file mode 100644 index 0000000..e6f4eca --- /dev/null +++ b/contrib/enco/test/tflite/Regression_0001/test.recipe @@ -0,0 +1,50 @@ +operand { + name: "ifm" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } +} +operand { + name: "ker" + type: FLOAT32 + shape { dim: 1 dim: 1 dim: 1 dim: 2 } + filler { tag: "gaussian" arg: "0.0" arg: "1.0" } +} +operand { + name: "bias" + type: FLOAT32 + shape { dim: 1 } + filler { tag: "gaussian" arg: "0.0" arg: "1.0" } +} +operand { + name: "ofm" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 1 } +} +operand { + name: "arr" + type: FLOAT32 + shape { dim: 1 dim: 9 } +} +operand { + name: "shape" + type: INT32 + shape { dim: 2 } + filler { tag: "explicit" arg: "-1" arg: "9" } +} +operation { + type: "Conv2D" + conv2d_options { padding: VALID stride_w: 1 stride_h: 1 activation: RELU6 } + input: "ifm" + input: "ker" + input: "bias" + output: "ofm" +} +operation { + type: "Reshape" + input: "ofm" + input: "shape" + output: "arr" + reshape_options { new_shape: [-1, 9] } +} +input: "ifm" +output: "arr" -- 2.7.4