From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Tue, 27 Nov 2018 02:35:44 +0000 (+0900) Subject: [enco] Do NOT reduce identical objects with side effect (#2419) X-Git-Tag: nncc_backup~1253 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=140567aa4be5ed224de3932c23752ed8087f0259;p=platform%2Fcore%2Fml%2Fnnfw.git [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 --- 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"