From: 박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 Date: Fri, 6 Sep 2019 06:45:21 +0000 (+0900) Subject: [locop] Introduce ExampleGraph (#7229) X-Git-Tag: accepted/tizen/unified/20190911.111615~66 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bdcd9b81acdd90c58b475d55a26e88ab880085ef;p=platform%2Fcore%2Fml%2Fnnfw.git [locop] Introduce ExampleGraph (#7229) Let's reuse common test code. Signed-off-by: Jonghyun Park --- diff --git a/compiler/locop/src/ExampleGraph.h b/compiler/locop/src/ExampleGraph.h new file mode 100644 index 0000000..76813bc --- /dev/null +++ b/compiler/locop/src/ExampleGraph.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __EXAMPLE_GRAPH_H__ +#define __EXAMPLE_GRAPH_H__ + +#include + +#include + +namespace +{ + +enum GraphCode +{ + PullPush, /* Pull - Push network */ +}; + +template struct Bundle; +template std::unique_ptr> make_bundle(void); + +template <> struct Bundle +{ + std::unique_ptr g; + loco::Pull *pull; + loco::Push *push; + + loco::Graph *graph(void) { return g.get(); } +}; + +template <> std::unique_ptr> make_bundle(void) +{ + auto g = loco::make_graph(); + + auto pull = g->nodes()->create(); + + pull->rank(2); + pull->dim(0) = loco::make_dimension(); // Mark dim 0 as unknown + pull->dim(1) = 4; + + auto push = g->nodes()->create(); + + push->from(pull); + + auto res = stdex::make_unique>(); + + res->g = std::move(g); + res->pull = pull; + res->push = push; + + return std::move(res); +} + +} // namespace + +#endif // __EXAMPLE_GRAPH_H__ diff --git a/compiler/locop/src/FormattedGraph.test.cpp b/compiler/locop/src/FormattedGraph.test.cpp index 13ca3a3..c9808d3 100644 --- a/compiler/locop/src/FormattedGraph.test.cpp +++ b/compiler/locop/src/FormattedGraph.test.cpp @@ -15,6 +15,7 @@ */ #include "locop/FormattedGraph.h" +#include "ExampleGraph.h" #include @@ -22,18 +23,8 @@ TEST(LinearV1FormatterTest, simple) { - auto g = loco::make_graph(); - { - auto pull = g->nodes()->create(); - - pull->rank(2); - pull->dim(0) = loco::make_dimension(); // Mark dim 0 as unknown - pull->dim(1) = 4; - - auto push = g->nodes()->create(); - - push->from(pull); - } + auto bundle = make_bundle(); + auto g = bundle->graph(); // TODO Validate the output (when the implementation becomes stable) std::cout << locop::fmt(g) << std::endl; @@ -46,18 +37,10 @@ TEST(LinearV1FormatterTest, user_defined_node_summary_builder) // DO NOTHING }; - auto g = loco::make_graph(); + auto bundle = make_bundle(); + auto g = bundle->graph(); { - auto pull = g->nodes()->create(); - - pull->rank(2); - pull->dim(0) = loco::make_dimension(); // Mark dim 0 as unknown - pull->dim(1) = 4; - - auto push = g->nodes()->create(); - - push->annot(stdex::make_unique()); - push->from(pull); + bundle->push->annot(stdex::make_unique()); } struct MyBuilder final : public locop::NodeSummaryBuilder