From d8734b55d89f05901ba9a75349761a9c955d9243 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Fri, 22 Dec 2017 15:27:52 +0000 Subject: COMPMID-793 : Add graph intermediate representation Change-Id: Ic1685de4e19e0ac79669ef2da64e1dc96c7ea0bf Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/115248 Tested-by: Jenkins Reviewed-by: Anthony Barbier --- examples/graph_squeezenet.cpp | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'examples/graph_squeezenet.cpp') diff --git a/examples/graph_squeezenet.cpp b/examples/graph_squeezenet.cpp index d0c823a11c..b4e00a451b 100644 --- a/examples/graph_squeezenet.cpp +++ b/examples/graph_squeezenet.cpp @@ -21,9 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include "arm_compute/graph/Graph.h" -#include "arm_compute/graph/Nodes.h" -#include "arm_compute/graph/SubGraph.h" +#include "arm_compute/graph2.h" #include "support/ToolchainSupport.h" #include "utils/GraphUtils.h" #include "utils/Utils.h" @@ -32,14 +30,10 @@ #include using namespace arm_compute::utils; -using namespace arm_compute::graph; +using namespace arm_compute::graph2::frontend; using namespace arm_compute::graph_utils; using namespace arm_compute::logging; -namespace -{ -} // namespace - /** Example demonstrating how to implement Squeezenet's network using the Compute Library's graph API * * @param[in] argc Number of arguments @@ -59,8 +53,10 @@ public: std::unique_ptr preprocessor = arm_compute::support::cpp14::make_unique(mean_rgb); // Set target. 0 (NEON), 1 (OpenCL), 2 (OpenCL with Tuner). By default it is NEON - const int int_target_hint = argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0; - TargetHint target_hint = set_target_hint(int_target_hint); + const int target = argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0; + Target target_hint = set_target_hint2(target); + bool enable_tuning = (target == 2); + bool enable_memory_management = true; // Parse arguments if(argc < 2) @@ -95,8 +91,8 @@ public: } graph << target_hint - << Tensor(TensorInfo(TensorShape(224U, 224U, 3U, 1U), 1, DataType::F32), - get_input_accessor(image, std::move(preprocessor))) + << InputLayer(TensorDescriptor(TensorShape(224U, 224U, 3U, 1U), DataType::F32), + get_input_accessor(image, std::move(preprocessor))) << ConvolutionLayer( 7U, 7U, 96U, get_weights_accessor(data_path, "/cnn_data/squeezenet_v1.0_model/conv1_w.npy"), @@ -171,10 +167,10 @@ public: << PoolingLayer(PoolingLayerInfo(PoolingType::AVG)) << FlattenLayer() << SoftmaxLayer() - << Tensor(get_output_accessor(label, 5)); + << OutputLayer(get_output_accessor(label, 5)); - // In order to enable the OpenCL tuner, graph_init() has to be called only when all nodes have been instantiated - graph.graph_init(int_target_hint == 2); + // Finalize graph + graph.finalize(target_hint, enable_tuning, enable_memory_management); } void do_run() override { @@ -183,12 +179,12 @@ public: } private: - Graph graph{}; + Stream graph{ 0, "SqueezeNetV1" }; BranchLayer get_expand_fire_node(const std::string &data_path, std::string &¶m_path, unsigned int expand1_filt, unsigned int expand3_filt) { std::string total_path = "/cnn_data/squeezenet_v1.0_model/" + param_path + "_"; - SubGraph i_a; + SubStream i_a(graph); i_a << ConvolutionLayer( 1U, 1U, expand1_filt, get_weights_accessor(data_path, total_path + "expand1x1_w.npy"), @@ -196,7 +192,7 @@ private: PadStrideInfo(1, 1, 0, 0)) << ActivationLayer(ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU)); - SubGraph i_b; + SubStream i_b(graph); i_b << ConvolutionLayer( 3U, 3U, expand3_filt, get_weights_accessor(data_path, total_path + "expand3x3_w.npy"), -- cgit v1.2.1