test: Enable profiler for inference test 75/233375/1 accepted/tizen/unified/20200603.150125 submit/tizen/20200602.011936 submit/tizen/20200602.084841
authorInki Dae <inki.dae@samsung.com>
Thu, 14 May 2020 05:40:14 +0000 (14:40 +0900)
committerInki Dae <inki.dae@samsung.com>
Thu, 14 May 2020 07:36:01 +0000 (16:36 +0900)
This patch enables and disbles the inference engine profiler
according to a given inference test request with a given mode,
storing profile data on file or just printing out it on
console screen.

Change-Id: I1528ecfb593d11a4686e4c388c01bb8dff9b6b97
Signed-off-by: Inki Dae <inki.dae@samsung.com>
test/src/inference_engine_tc.cpp

index 71dabe4..2738c5c 100644 (file)
 #include "inference_engine_common_impl.h"
 #include "inference_engine_test_common.h"
 
+enum {
+       INFERENCE_ENGINE_PROFILER_OFF = 0, /**< Do not profile inference engine. */
+       INFERENCE_ENGINE_PROFILER_FILE, /**< Profile inference engine, and store the collected data to file. */
+       INFERENCE_ENGINE_PROFILER_CONSOLE, /**< Profile inference engine, and print out the collected data on console screen. */
+       INFERENCE_ENGINE_PROFILER_MAX
+};
+
 typedef std::tuple<std::string> ParamType_One;
 typedef std::tuple<std::string, int> ParamType_Two;
 typedef std::tuple<std::string, int, std::vector<std::string>> ParamType_Three;
 typedef std::tuple<std::string, int, int, int, int, std::vector<std::string>> ParamType_Six;
-typedef std::tuple<std::string, int, int, int, int, std::vector<std::string>, int, int, int, std::vector<std::string>, std::vector<std::string>, std::vector<std::string>, std::vector<int>> ParamType_Many;
+typedef std::tuple<std::string, int, int, int, int, int, std::vector<std::string>, int, int, int, std::vector<std::string>, std::vector<std::string>, std::vector<std::string>, std::vector<int>> ParamType_Many;
 typedef std::tuple<int> ParamType_One_Int;
 
 class InferenceEngineTestCase_G1 : public testing::TestWithParam<ParamType_One> { };
@@ -461,6 +468,7 @@ TEST_P(InferenceEngineTestCase_G1, SetOutputLayer_N2)
 TEST_P(InferenceEngineTestCase_G6, Inference_P)
 {
        std::string backend_name;
+       int profiler;
        int target_devices;
        int test_type;
        int iteration;
@@ -474,7 +482,7 @@ TEST_P(InferenceEngineTestCase_G6, Inference_P)
        std::vector<std::string> model_paths;
        std::vector<int> answers;
 
-       std::tie(backend_name, target_devices, test_type, iteration, tensor_type, image_paths, height, width, ch, input_layers, output_layers, model_paths, answers) = GetParam();
+       std::tie(backend_name, profiler, target_devices, test_type, iteration, tensor_type, image_paths, height, width, ch, input_layers, output_layers, model_paths, answers) = GetParam();
 
        if (iteration < 1) {
                iteration = 1;
@@ -497,6 +505,19 @@ TEST_P(InferenceEngineTestCase_G6, Inference_P)
                return;
        }
 
+       if (profiler > INFERENCE_ENGINE_PROFILER_OFF && profiler < INFERENCE_ENGINE_PROFILER_MAX) {
+               int ret = engine->EnableProfiler(true);
+               ASSERT_EQ(ret, INFERENCE_ENGINE_ERROR_NONE);
+
+               if (profiler == INFERENCE_ENGINE_PROFILER_FILE) {
+                       ret = engine->DumpProfileToFile("profile_data_" + backend_name + "_tflite_model.txt");
+                       ASSERT_EQ(ret, INFERENCE_ENGINE_ERROR_NONE);
+               } else {
+                       ret = engine->DumpProfileToConsole();
+                       ASSERT_EQ(ret, INFERENCE_ENGINE_ERROR_NONE);
+               }
+       }
+
        int ret = InferenceEngineInit_Two_Params(engine.get(), backend_name, target_devices);
        ASSERT_EQ(ret, INFERENCE_ENGINE_ERROR_NONE);
 
@@ -688,11 +709,23 @@ INSTANTIATE_TEST_CASE_P(Prefix, InferenceEngineTestCase_G6,
                        // parameter order : backend name, target device, input image path/s, height, width, channel count, input layer names, output layer names, model path/s, inference result
                        // mobilenet based image classification test
                        // ARMNN.
-                       ParamType_Many("armnn", INFERENCE_TARGET_CPU, TEST_IMAGE_CLASSIFICATION, 10, INFERENCE_TENSOR_DATA_TYPE_FLOAT32, { "/opt/usr/images/image_classification.bin" }, 224, 224, 3, { "input_2" }, { "dense_3/Softmax" }, { "/usr/share/capi-media-vision/models/IC/tflite/ic_tflite_model.tflite" }, { 3 }),
+                       ParamType_Many("armnn", INFERENCE_ENGINE_PROFILER_OFF, INFERENCE_TARGET_CPU, TEST_IMAGE_CLASSIFICATION, 10, INFERENCE_TENSOR_DATA_TYPE_FLOAT32, { "/opt/usr/images/image_classification.bin" }, 224, 224, 3, { "input_2" }, { "dense_3/Softmax" }, { "/usr/share/capi-media-vision/models/IC/tflite/ic_tflite_model.tflite" }, { 3 }),
+                       // TFLITE.
+                       ParamType_Many("tflite", INFERENCE_ENGINE_PROFILER_OFF, INFERENCE_TARGET_CPU, TEST_IMAGE_CLASSIFICATION, 10, INFERENCE_TENSOR_DATA_TYPE_FLOAT32, { "/opt/usr/images/image_classification.bin" }, 224, 224, 3, { "input_2" }, { "dense_3/Softmax" }, { "/usr/share/capi-media-vision/models/IC/tflite/ic_tflite_model.tflite" }, { 3 }),
+                       // OPENCV.
+                       ParamType_Many("opencv", INFERENCE_ENGINE_PROFILER_OFF, INFERENCE_TARGET_CPU, TEST_IMAGE_CLASSIFICATION, 10, INFERENCE_TENSOR_DATA_TYPE_FLOAT32, { "/opt/usr/images/image_classification_caffe.bin" }, 227, 227, 3, { "data" }, { "prob" }, { "/usr/share/capi-media-vision/models/IC/caffe/ic_caffe_model_squeezenet.caffemodel", "/usr/share/capi-media-vision/models/IC/caffe/ic_caffe_model_squeezenet.prototxt" }, { 281 }),
+                       // ARMNN.
+                       ParamType_Many("armnn", INFERENCE_ENGINE_PROFILER_FILE, INFERENCE_TARGET_CPU, TEST_IMAGE_CLASSIFICATION, 10, INFERENCE_TENSOR_DATA_TYPE_FLOAT32, { "/opt/usr/images/image_classification.bin" }, 224, 224, 3, { "input_2" }, { "dense_3/Softmax" }, { "/usr/share/capi-media-vision/models/IC/tflite/ic_tflite_model.tflite" }, { 3 }),
+                       // TFLITE.
+                       ParamType_Many("tflite", INFERENCE_ENGINE_PROFILER_FILE, INFERENCE_TARGET_CPU, TEST_IMAGE_CLASSIFICATION, 10, INFERENCE_TENSOR_DATA_TYPE_FLOAT32, { "/opt/usr/images/image_classification.bin" }, 224, 224, 3, { "input_2" }, { "dense_3/Softmax" }, { "/usr/share/capi-media-vision/models/IC/tflite/ic_tflite_model.tflite" }, { 3 }),
+                       // OPENCV.
+                       ParamType_Many("opencv", INFERENCE_ENGINE_PROFILER_FILE, INFERENCE_TARGET_CPU, TEST_IMAGE_CLASSIFICATION, 10, INFERENCE_TENSOR_DATA_TYPE_FLOAT32, { "/opt/usr/images/image_classification_caffe.bin" }, 227, 227, 3, { "data" }, { "prob" }, { "/usr/share/capi-media-vision/models/IC/caffe/ic_caffe_model_squeezenet.caffemodel", "/usr/share/capi-media-vision/models/IC/caffe/ic_caffe_model_squeezenet.prototxt" }, { 281 }),
+                       // ARMNN.
+                       ParamType_Many("armnn", INFERENCE_ENGINE_PROFILER_CONSOLE, INFERENCE_TARGET_CPU, TEST_IMAGE_CLASSIFICATION, 10, INFERENCE_TENSOR_DATA_TYPE_FLOAT32, { "/opt/usr/images/image_classification.bin" }, 224, 224, 3, { "input_2" }, { "dense_3/Softmax" }, { "/usr/share/capi-media-vision/models/IC/tflite/ic_tflite_model.tflite" }, { 3 }),
                        // TFLITE.
-                       ParamType_Many("tflite", INFERENCE_TARGET_CPU, TEST_IMAGE_CLASSIFICATION, 10, INFERENCE_TENSOR_DATA_TYPE_FLOAT32, { "/opt/usr/images/image_classification.bin" }, 224, 224, 3, { "input_2" }, { "dense_3/Softmax" }, { "/usr/share/capi-media-vision/models/IC/tflite/ic_tflite_model.tflite" }, { 3 }),
+                       ParamType_Many("tflite", INFERENCE_ENGINE_PROFILER_CONSOLE, INFERENCE_TARGET_CPU, TEST_IMAGE_CLASSIFICATION, 10, INFERENCE_TENSOR_DATA_TYPE_FLOAT32, { "/opt/usr/images/image_classification.bin" }, 224, 224, 3, { "input_2" }, { "dense_3/Softmax" }, { "/usr/share/capi-media-vision/models/IC/tflite/ic_tflite_model.tflite" }, { 3 }),
                        // OPENCV.
-                       ParamType_Many("opencv", INFERENCE_TARGET_CPU, TEST_IMAGE_CLASSIFICATION, 10, INFERENCE_TENSOR_DATA_TYPE_FLOAT32, { "/opt/usr/images/image_classification_caffe.bin" }, 227, 227, 3, { "data" }, { "prob" }, { "/usr/share/capi-media-vision/models/IC/caffe/ic_caffe_model_squeezenet.caffemodel", "/usr/share/capi-media-vision/models/IC/caffe/ic_caffe_model_squeezenet.prototxt" }, { 281 })
+                       ParamType_Many("opencv", INFERENCE_ENGINE_PROFILER_CONSOLE, INFERENCE_TARGET_CPU, TEST_IMAGE_CLASSIFICATION, 10, INFERENCE_TENSOR_DATA_TYPE_FLOAT32, { "/opt/usr/images/image_classification_caffe.bin" }, 227, 227, 3, { "data" }, { "prob" }, { "/usr/share/capi-media-vision/models/IC/caffe/ic_caffe_model_squeezenet.caffemodel", "/usr/share/capi-media-vision/models/IC/caffe/ic_caffe_model_squeezenet.prototxt" }, { 281 })
                        /* TODO */
                )
 );