[pkg] Enable debug mode for CI
authorParichay Kapoor <pk.kapoor@samsung.com>
Thu, 7 Oct 2021 03:32:33 +0000 (12:32 +0900)
committerJijoong Moon <jijoong.moon@samsung.com>
Thu, 7 Oct 2021 04:17:11 +0000 (13:17 +0900)
This patch enables debug mode for the CI build for both ubuntu and
tizen. This enables all the debug tests to be done in the CI which were
disabled till now.
Fixes required to enable the DEBUG mode is also added.

Signed-off-by: Parichay Kapoor <pk.kapoor@samsung.com>
Applications/Custom/pow.cpp
debian/rules
meson.build
meson_options.txt
nntrainer/dataset/iteration_queue.cpp
nntrainer/layers/layer_context.cpp
nntrainer/layers/layer_context.h
nntrainer/layers/layer_node.cpp
nntrainer/layers/tflite_layer.cpp
nntrainer/tensor/basic_planner.cpp
packaging/nntrainer.spec

index 123d16e..9e82775 100644 (file)
@@ -98,7 +98,7 @@ void PowLayer::forwarding(nntrainer::RunLayerContext &context, bool training) {
 #ifdef DEBUG
   std::cout << "input: " << context.getInput(SINGLE_INOUT_IDX);
   std::cout << "output: " << context.getOutput(SINGLE_INOUT_IDX);
-  PowUtil::pause();
+  /// PowUtil::pause();
 #endif
 }
 
@@ -117,7 +117,7 @@ void PowLayer::calcDerivative(nntrainer::RunLayerContext &context) {
 #ifdef DEBUG
   std::cout << "input: " << context.getOutput(SINGLE_INOUT_IDX);
   std::cout << "output: " << context.getInput(SINGLE_INOUT_IDX);
-  PowUtil::pause();
+  /// PowUtil::pause();
 #endif
 }
 
index f18fd57..e64a340 100755 (executable)
@@ -18,8 +18,10 @@ export DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
 export DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
 ifdef unit_test
        export ENABLE_REDUCE_TOLERANCE ?= false
+       export ENABLE_DEBUG?= false
 else
        export ENABLE_REDUCE_TOLERANCE ?= true
+       export ENABLE_DEBUG?= true
 endif
 
 %:
@@ -33,7 +35,8 @@ override_dh_auto_configure:
        meson --buildtype=plain --prefix=/usr --sysconfdir=/etc \
                --libdir=lib/$(DEB_HOST_MULTIARCH) --bindir=lib/nntrainer/bin \
                --includedir=include -Dinstall-app=true \
-               -Dreduce-tolerance=$(ENABLE_REDUCE_TOLERANCE) build
+               -Dreduce-tolerance=$(ENABLE_REDUCE_TOLERANCE) \
+               -Denable-debug=$(ENABLE_DEBUG) build
 
 override_dh_auto_build:
        ninja -C build
index 3e5d312..d84d4cf 100644 (file)
@@ -120,6 +120,10 @@ if get_option('enable-profile')
   add_project_arguments('-DPROFILE=1', language:['c', 'cpp'])
 endif
 
+if get_option('enable-debug')
+  add_project_arguments('-DDEBUG=1', language:['c', 'cpp'])
+endif
+
 if get_option('use_gym')
    add_project_arguments('-DUSE_GYM=1', language:['c','cpp'])
 endif
index 01674bd..877158a 100644 (file)
@@ -14,6 +14,7 @@ option('enable-nnstreamer-backbone', type: 'boolean', value: true)
 option('enable-tflite-backbone', type: 'boolean', value: true)
 option('enable-android', type: 'boolean', value: false)
 option('enable-profile', type: 'boolean', value: false)
+option('enable-debug', type: 'boolean', value: true)
 option('enable-tflite-interpreter', type: 'boolean', value: true)
 
 # dependency conflict resolution
index a2758f5..b7ff262 100644 (file)
@@ -217,7 +217,7 @@ void IterationQueue::MarkableIteration::setEndSample(
   if (old_batch != new_batch && num_observed == new_batch) {
 #if DEBUG
     NNTR_THROW_IF_CLEANUP(iq->empty_mutex.try_lock(), std::runtime_error,
-                          [iq] { iq->empty_mutex.unlock(); })
+                          [this] { iq->empty_mutex.unlock(); })
       << "iteration queue must be locked already but empty_mutex is not "
          "locked.";
 #endif
index 3526d8c..3b73bd7 100644 (file)
@@ -344,7 +344,7 @@ bool RunLayerContext::validate(bool skip_input, bool skip_label) {
    * references which leads to nasty bugs. This validation ensures that the
    * tensors are not set mistakenly by verifying their unique names
    */
-#ifdef ENABLE_TEST
+#ifdef DEBUG
   if (tensor_map.empty() || !tensor_map[inputs[0]->getName()]) {
     auto filler = [this](const auto &vec) {
       for (auto const &val : vec) {
@@ -379,14 +379,13 @@ bool RunLayerContext::validate(bool skip_input, bool skip_label) {
     };
 
     auto matcher_w = [this, matcher](const std::vector<Weight *> &vec) {
-      auto ret = true;
-      for (auto const &val : vec)
-        ret &= matcher(val);
-      return ret;
+      return std::all_of(vec.begin(), vec.end(), matcher);
     };
 
     auto matcher_vw = [this, matcher](const std::vector<Var_Grad *> &vec,
                                       bool skip_grad = false) {
+      return std::all_of(vec.begin(), vec.end(),
+                         std::bind(matcher, std::placeholders::_1, skip_grad));
       auto ret = true;
       for (auto const &val : vec)
         ret &= matcher(val, skip_grad);
index aeada49..e445464 100644 (file)
@@ -624,7 +624,7 @@ private:
   std::vector<Var_Grad *> outputs; /**< outputs of the layer */
   std::vector<Var_Grad *> tensors; /**< tensors of the layer */
 
-#ifdef ENABLE_TEST
+#ifdef DEBUG
   std::map<std::string, const void *>
     tensor_map; /**< map of tensor name to tensor address */
 #endif
index 1a10b70..55b71e1 100644 (file)
@@ -470,7 +470,7 @@ void LayerNode::forwarding(bool training) {
   layer->forwarding(*run_context, training);
   END_PROFILE(forward_event_key);
 
-#ifdef ENABLE_TEST
+#ifdef DEBUG
   if (!run_context->validate(getNumInputConnections() == 0, !requireLabel()))
     throw std::runtime_error("Running forwarding() layer " + getName() +
                              " invalidated the context.");
@@ -489,7 +489,7 @@ void LayerNode::calcDerivative() {
   layer->calcDerivative(*run_context);
   END_PROFILE(calc_deriv_event_key);
 
-#ifdef ENABLE_TEST
+#ifdef DEBUG
   if (!run_context->validate(getNumInputConnections() == 0, !requireLabel()))
     throw std::runtime_error("Running calcDerivative() layer " + getName() +
                              " invalidated the context.");
@@ -505,7 +505,7 @@ void LayerNode::calcGradient() {
     layer->calcGradient(*run_context);
   END_PROFILE(calc_grad_event_key);
 
-#ifdef ENABLE_TEST
+#ifdef DEBUG
   if (!run_context->validate(getNumInputConnections() == 0, !requireLabel()))
     throw std::runtime_error("Running calcGradient() layer " + getName() +
                              " invalidated the context.");
index 28b19a4..83f7af4 100644 (file)
@@ -143,14 +143,14 @@ void TfLiteLayer::forwarding(RunLayerContext &context, bool training) {
 #ifdef DEBUG
   std::vector<TensorDim> out_tf_dim;
   setDimensions(interpreter->outputs(), out_tf_dim, true);
-  if (out_tf_dim.size() != output_dim.size()) {
+  if (out_tf_dim.size() != context.getNumOutputs()) {
     throw std::invalid_argument(
       "[TfliteLayer::forward] number of output dimension does not match");
   }
 
   for (unsigned int i = 0; i < out_tf_dim.size(); ++i) {
-    if (output_dim[i] != out_tf_dim[i]) {
-      throw std::invalid_argumetns(
+    if (context.getOutput(i).getDim() != out_tf_dim[i]) {
+      throw std::invalid_argument(
         "[TfliteLayer::forward] output dimension does not match");
     }
   }
index 3122549..5657f9f 100644 (file)
@@ -12,6 +12,7 @@
  */
 
 #include <basic_planner.h>
+#include <nntrainer_error.h>
 
 namespace nntrainer {
 
index a1473b4..08bf707 100644 (file)
@@ -277,12 +277,18 @@ NNSteamer tensor filter static package for nntrainer to support inference.
 %define enable_profile -Denable-profile=false
 %define capi_ml_pkg_dep_resolution -Dcapi-ml-inference-actual=%{?capi_ml_inference_pkg_name} -Dcapi-ml-common-actual=%{?capi_ml_common_pkg_name}
 %define enable_reduce_tolerance -Dreduce-tolerance=true
+%define enable_debug -Denable-debug=false
 
 # enable full tolerance on the CI
 %if 0%{?unit_test}
 %define enable_reduce_tolerance -Dreduce-tolerance=false
 %endif
 
+# enable debug on the CI for build
+%if 0%{?unit_test}
+%define enable_debug -Denable-debug=true
+%endif
+
 %if %{with tizen}
 %define platform -Dplatform=tizen
 
@@ -347,7 +353,7 @@ meson --buildtype=plain --prefix=%{_prefix} --sysconfdir=%{_sysconfdir} \
       %{enable_gym} %{enable_nnstreamer_tensor_filter} %{enable_profile} \
       %{enable_nnstreamer_backbone} %{enable_tflite_backbone} \
       %{enable_tflite_interpreter} %{capi_ml_pkg_dep_resolution} \
-      %{enable_reduce_tolerance} build
+      %{enable_reduce_tolerance} %{enable_debug} build
 
 ninja -C build %{?_smp_mflags}