diff options
-rw-r--r-- | arm_compute/graph/Graph.h | 5 | ||||
-rw-r--r-- | examples/graph_alexnet.cpp | 10 | ||||
-rw-r--r-- | examples/graph_googlenet.cpp | 8 | ||||
-rw-r--r-- | examples/graph_inception_v3.cpp | 8 | ||||
-rw-r--r-- | examples/graph_lenet.cpp | 8 | ||||
-rw-r--r-- | examples/graph_mobilenet.cpp | 10 | ||||
-rw-r--r-- | examples/graph_mobilenet_qasymm8.cpp (renamed from examples/graph_cl_mobilenet_qasymm8.cpp) | 30 | ||||
-rw-r--r-- | examples/graph_squeezenet.cpp | 8 | ||||
-rw-r--r-- | examples/graph_squeezenet_v1_1.cpp | 8 | ||||
-rw-r--r-- | examples/graph_vgg16.cpp | 8 | ||||
-rw-r--r-- | examples/graph_vgg19.cpp | 10 | ||||
-rw-r--r-- | src/graph/Graph.cpp | 14 | ||||
-rw-r--r-- | utils/GraphUtils.h | 6 |
13 files changed, 96 insertions, 37 deletions
diff --git a/arm_compute/graph/Graph.h b/arm_compute/graph/Graph.h index 853b90df82..72130878f8 100644 --- a/arm_compute/graph/Graph.h +++ b/arm_compute/graph/Graph.h @@ -56,6 +56,11 @@ public: Graph(Graph &&) = delete; /** Prevent instances from being move assigned */ Graph &operator=(Graph &&) = delete; + /** Initialize the graph + * + * @param[in] use_cl_tuner Use the CLTuner if this value is true + */ + void graph_init(const bool use_cl_tuner = false); /** Executes the graph */ void run(); /** Adds a node to the graph diff --git a/examples/graph_alexnet.cpp b/examples/graph_alexnet.cpp index 2f2c8bd182..bd620574b8 100644 --- a/examples/graph_alexnet.cpp +++ b/examples/graph_alexnet.cpp @@ -38,7 +38,7 @@ using namespace arm_compute::graph_utils; /** Example demonstrating how to implement AlexNet's network using the Compute Library's graph API * * @param[in] argc Number of arguments - * @param[in] argv Arguments ( [optional] Target (0 = NEON, 1 = OpenCL), [optional] Path to the weights folder, [optional] image, [optional] labels ) + * @param[in] argv Arguments ( [optional] Target (0 = NEON, 1 = OpenCL, 2 = OpenCL with Tuner), [optional] Path to the weights folder, [optional] image, [optional] labels ) */ class GraphAlexnetExample : public Example { @@ -53,8 +53,9 @@ public: constexpr float mean_g = 116.67f; /* Mean value to subtract from green channel */ constexpr float mean_b = 104.01f; /* Mean value to subtract from blue channel */ - // Set target. 0 (NEON), 1 (OpenCL). By default it is NEON - TargetHint target_hint = set_target_hint(argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0); + // 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 bool is_gemm_convolution5x5 = Graph::gpu_target() == arm_compute::GPUTarget::MIDGARD || target_hint == TargetHint::NEON; ConvolutionMethodHint convolution_5x5_hint = is_gemm_convolution5x5 ? ConvolutionMethodHint::GEMM : ConvolutionMethodHint::DIRECT; @@ -91,6 +92,9 @@ public: label = argv[4]; } + // Initialize the graph + graph.graph_init(int_target_hint == 2); + graph << target_hint << Tensor(TensorInfo(TensorShape(227U, 227U, 3U, 1U), 1, DataType::F32), get_input_accessor(image, mean_r, mean_g, mean_b)) diff --git a/examples/graph_googlenet.cpp b/examples/graph_googlenet.cpp index b2e2f1bf8f..13f6543ef6 100644 --- a/examples/graph_googlenet.cpp +++ b/examples/graph_googlenet.cpp @@ -53,8 +53,9 @@ public: constexpr float mean_g = 116.67f; /* Mean value to subtract from green channel */ constexpr float mean_b = 104.01f; /* Mean value to subtract from blue channel */ - // Set target. 0 (NEON), 1 (OpenCL). By default it is NEON - TargetHint target_hint = set_target_hint(argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0); + // 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); ConvolutionMethodHint convolution_hint = ConvolutionMethodHint::GEMM; // Parse arguments @@ -89,6 +90,9 @@ public: label = argv[4]; } + // Initialize graph + graph.graph_init(int_target_hint == 2); + graph << target_hint << Tensor(TensorInfo(TensorShape(224U, 224U, 3U, 1U), 1, DataType::F32), get_input_accessor(image, mean_r, mean_g, mean_b)) diff --git a/examples/graph_inception_v3.cpp b/examples/graph_inception_v3.cpp index 88a0325b63..f2423eb4bd 100644 --- a/examples/graph_inception_v3.cpp +++ b/examples/graph_inception_v3.cpp @@ -52,8 +52,9 @@ public: constexpr float mean = 0.f; /* Mean value to subtract from the channels */ constexpr float std = 255.f; /* Standard deviation value to divide from the channels */ - // Set target. 0 (NEON), 1 (OpenCL). By default it is NEON - TargetHint target_hint = set_target_hint(argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0); + // 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); // Parse arguments if(argc < 2) @@ -87,6 +88,9 @@ public: label = argv[4]; } + // Initialize graph + graph.graph_init(int_target_hint == 2); + graph << target_hint << Tensor(TensorInfo(TensorShape(299U, 299U, 3U, 1U), 1, DataType::F32), get_input_accessor(image, mean, mean, mean, diff --git a/examples/graph_lenet.cpp b/examples/graph_lenet.cpp index 1d4fc33357..863efeafbf 100644 --- a/examples/graph_lenet.cpp +++ b/examples/graph_lenet.cpp @@ -46,8 +46,9 @@ public: std::string data_path; /** Path to the trainable data */ unsigned int batches = 4; /** Number of batches */ - // Set target. 0 (NEON), 1 (OpenCL). By default it is NEON - TargetHint target_hint = set_target_hint(argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0); + // 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); // Parse arguments if(argc < 2) @@ -75,6 +76,9 @@ public: batches = std::strtol(argv[3], nullptr, 0); } + // Initialize graph + graph.graph_init(int_target_hint == 2); + //conv1 << pool1 << conv2 << pool2 << fc1 << act1 << fc2 << smx graph << target_hint << Tensor(TensorInfo(TensorShape(28U, 28U, 1U, batches), 1, DataType::F32), DummyAccessor()) diff --git a/examples/graph_mobilenet.cpp b/examples/graph_mobilenet.cpp index d3d4774eaa..0cc636a07d 100644 --- a/examples/graph_mobilenet.cpp +++ b/examples/graph_mobilenet.cpp @@ -36,7 +36,7 @@ using namespace arm_compute::graph_utils; /** Example demonstrating how to implement MobileNet's network using the Compute Library's graph API * * @param[in] argc Number of arguments - * @param[in] argv Arguments ( [optional] Target (0 = NEON, 1 = OpenCL), [optional] Path to the weights folder, [optional] image, [optional] labels ) + * @param[in] argv Arguments ( [optional] Target (0 = NEON, 1 = OpenCL, 2 = OpenCL with Tuner), [optional] Path to the weights folder, [optional] image, [optional] labels ) */ class GraphMobilenetExample : public Example { @@ -50,8 +50,9 @@ public: constexpr float mean = 0.f; /* Mean value to subtract from the channels */ constexpr float std = 255.f; /* Standard deviation value to divide from the channels */ - // Set target. 0 (NEON), 1 (OpenCL). By default it is NEON - TargetHint target_hint = set_target_hint(argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0); + // 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); ConvolutionMethodHint convolution_hint = ConvolutionMethodHint::GEMM; // Set model to execute. 0 (MobileNetV1_1.0_224), 1 (MobileNetV1_0.75_160) @@ -106,6 +107,9 @@ public: data_path += model_path; } + // Initialize graph + graph.graph_init(int_target_hint == 2); + graph << target_hint << convolution_hint << Tensor(TensorInfo(TensorShape(spatial_size, spatial_size, 3U, 1U), 1, DataType::F32), diff --git a/examples/graph_cl_mobilenet_qasymm8.cpp b/examples/graph_mobilenet_qasymm8.cpp index 046c7779b1..29daeffeac 100644 --- a/examples/graph_cl_mobilenet_qasymm8.cpp +++ b/examples/graph_mobilenet_qasymm8.cpp @@ -34,7 +34,7 @@ using namespace arm_compute::graph_utils; /** Example demonstrating how to implement QASYMM8 MobileNet's network using the Compute Library's graph API * * @param[in] argc Number of arguments - * @param[in] argv Arguments ( [optional] Path to the weights folder, [optional] npy_input, [optional] labels ) + * @param[in] argv Arguments ( [optional] Target (0 = NEON, 1 = OpenCL, 2 = OpenCL with Tuner), [optional] Path to the weights folder, [optional] npy_input, [optional] labels ) */ class GraphMobileNetQASYMM8Example : public utils::Example { @@ -89,34 +89,40 @@ public: QuantizationInfo(0.0338749065995f, 140) // dwsc13 }; + // 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); + // Parse arguments if(argc < 2) { // Print help - std::cout << "Usage: " << argv[0] << " [path_to_data] [npy_input] [labels]\n\n"; + std::cout << "Usage: " << argv[0] << " [target] [path_to_data] [npy_input] [labels]\n\n"; std::cout << "No data folder provided: using random values\n\n"; } else if(argc == 2) { - data_path = argv[1]; - std::cout << "Usage: " << argv[0] << " " << argv[1] << " [npy_input] [labels]\n\n"; + std::cout << "Usage: " << argv[0] << " " << argv[1] << " [path_to_data] [npy_input] [labels]\n\n"; std::cout << "No input provided: using random values\n\n"; } - else if(argc == 3) + else if(argc == 4) { - data_path = argv[1]; - input = argv[2]; - std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " [labels]\n\n"; + data_path = argv[2]; + input = argv[3]; + std::cout << "Usage: " << argv[0] << " " << argv[1] << " " << argv[2] << " " << argv[3] << " [labels]\n\n"; std::cout << "No text file with labels provided: skipping output accessor\n\n"; } else { - data_path = argv[1]; - input = argv[2]; - label = argv[3]; + data_path = argv[2]; + input = argv[3]; + label = argv[4]; } - graph << TargetHint::OPENCL + // Initialize graph + graph.graph_init(int_target_hint == 2); + + graph << target_hint << arm_compute::graph::Tensor(TensorInfo(TensorShape(224U, 224U, 3U, 1U), 1, DataType::QASYMM8, in_quant_info), get_weights_accessor(data_path, "/cnn_data/mobilenet_qasymm8_model/" + input)) << ConvolutionLayer( diff --git a/examples/graph_squeezenet.cpp b/examples/graph_squeezenet.cpp index e85108702d..517d0cc127 100644 --- a/examples/graph_squeezenet.cpp +++ b/examples/graph_squeezenet.cpp @@ -58,8 +58,9 @@ public: constexpr float mean_g = 116.67f; /* Mean value to subtract from green channel */ constexpr float mean_b = 104.01f; /* Mean value to subtract from blue channel */ - // Set target. 0 (NEON), 1 (OpenCL). By default it is NEON - TargetHint target_hint = set_target_hint(argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0); + // 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); // Parse arguments if(argc < 2) @@ -93,6 +94,9 @@ public: label = argv[4]; } + // Initialize graph + graph.graph_init(int_target_hint == 2); + graph << target_hint << Tensor(TensorInfo(TensorShape(224U, 224U, 3U, 1U), 1, DataType::F32), get_input_accessor(image, mean_r, mean_g, mean_b)) diff --git a/examples/graph_squeezenet_v1_1.cpp b/examples/graph_squeezenet_v1_1.cpp index fad07e5043..3c6be742fa 100644 --- a/examples/graph_squeezenet_v1_1.cpp +++ b/examples/graph_squeezenet_v1_1.cpp @@ -58,8 +58,9 @@ public: constexpr float mean_g = 116.67f; /* Mean value to subtract from green channel */ constexpr float mean_b = 104.01f; /* Mean value to subtract from blue channel */ - // Set target. 0 (NEON), 1 (OpenCL). By default it is NEON - TargetHint target_hint = set_target_hint(argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0); + // 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); // Parse arguments if(argc < 2) @@ -93,6 +94,9 @@ public: label = argv[4]; } + // Initialize graph + graph.graph_init(int_target_hint == 2); + graph << target_hint << Tensor(TensorInfo(TensorShape(227U, 227U, 3U, 1U), 1, DataType::F32), get_input_accessor(image, mean_r, mean_g, mean_b)) diff --git a/examples/graph_vgg16.cpp b/examples/graph_vgg16.cpp index c3eb922f0e..ccb9dbb19d 100644 --- a/examples/graph_vgg16.cpp +++ b/examples/graph_vgg16.cpp @@ -65,8 +65,9 @@ public: constexpr float mean_g = 116.779f; /* Mean value to subtract from green channel */ constexpr float mean_b = 103.939f; /* Mean value to subtract from blue channel */ - // Set target. 0 (NEON), 1 (OpenCL). By default it is NEON - TargetHint target_hint = set_target_hint(argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0); + // 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); // Check if we can use GEMM-based convolutions evaluating if the platform has at least 1.8 GB of available memory const size_t memory_required = 1932735283L; @@ -104,6 +105,9 @@ public: label = argv[4]; } + // Initialize graph + graph.graph_init(int_target_hint == 2); + graph << target_hint << convolution_hint << Tensor(TensorInfo(TensorShape(224U, 224U, 3U, 1U), 1, DataType::F32), diff --git a/examples/graph_vgg19.cpp b/examples/graph_vgg19.cpp index 5214438d7f..c940c4ef73 100644 --- a/examples/graph_vgg19.cpp +++ b/examples/graph_vgg19.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2018 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -51,8 +51,9 @@ public: constexpr float mean_g = 116.779f; /* Mean value to subtract from green channel */ constexpr float mean_b = 103.939f; /* Mean value to subtract from blue channel */ - // Set target. 0 (NEON), 1 (OpenCL). By default it is NEON - TargetHint target_hint = set_target_hint(argc > 1 ? std::strtol(argv[1], nullptr, 10) : 0); + // 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); ConvolutionMethodHint convolution_hint = ConvolutionMethodHint::DIRECT; // Parse arguments @@ -87,6 +88,9 @@ public: label = argv[4]; } + // Initialize graph + graph.graph_init(int_target_hint == 2); + graph << target_hint << convolution_hint << Tensor(TensorInfo(TensorShape(224U, 224U, 3U, 1U), 1, DataType::F32), diff --git a/src/graph/Graph.cpp b/src/graph/Graph.cpp index e14bea0846..7af313acbb 100644 --- a/src/graph/Graph.cpp +++ b/src/graph/Graph.cpp @@ -62,6 +62,7 @@ public: std::unique_ptr<INode> _current_node{ nullptr }; ITensorObject *_current_output{ nullptr }; bool _info_enabled{ false }; + CLTuner _tuner{}; private: ITensorObject *_current_input{ nullptr }; @@ -76,10 +77,21 @@ Graph::~Graph() //NOLINT Graph::Graph() : _pimpl{ new Private() } { +} + +void Graph::graph_init(const bool use_cl_tuner) +{ // Check if OpenCL is available and initialize the scheduler if(opencl_is_available()) { - arm_compute::CLScheduler::get().default_init(); + if(use_cl_tuner) + { + arm_compute::CLScheduler::get().default_init(&_pimpl->_tuner); + } + else + { + arm_compute::CLScheduler::get().default_init(); + } } } diff --git a/utils/GraphUtils.h b/utils/GraphUtils.h index da52c26520..b48e5b563d 100644 --- a/utils/GraphUtils.h +++ b/utils/GraphUtils.h @@ -256,14 +256,14 @@ inline std::unique_ptr<graph::ITensorAccessor> get_input_accessor(const std::str /** Utility function to return the TargetHint * - * @param[in] target Integer value which expresses the selected target. Must be 0 for NEON or 1 for OpenCL + * @param[in] target Integer value which expresses the selected target. Must be 0 for NEON, 1 for OpenCL or 2 for OpenCL with Tuner * * @return the TargetHint */ inline graph::TargetHint set_target_hint(int target) { - ARM_COMPUTE_ERROR_ON_MSG(target > 1, "Invalid target. Target must be 0 (NEON) or 1 (OpenCL)"); - if(target == 1 && graph::Graph::opencl_is_available()) + ARM_COMPUTE_ERROR_ON_MSG(target > 2, "Invalid target. Target must be 0 (NEON), 1 (OpenCL) or 2 (OpenCL with Tuner)"); + if((target == 1 || target == 2) && graph::Graph::opencl_is_available()) { // If type of target is OpenCL, check if OpenCL is available and initialize the scheduler return graph::TargetHint::OPENCL; |