From 833873dfa9666d6ed49fe33c1e654a1e275c37b4 Mon Sep 17 00:00:00 2001 From: Parichay Kapoor Date: Thu, 7 Oct 2021 12:32:33 +0900 Subject: [PATCH] [pkg] Enable debug mode for CI 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 --- Applications/Custom/pow.cpp | 4 ++-- debian/rules | 5 ++++- meson.build | 4 ++++ meson_options.txt | 1 + nntrainer/dataset/iteration_queue.cpp | 2 +- nntrainer/layers/layer_context.cpp | 9 ++++----- nntrainer/layers/layer_context.h | 2 +- nntrainer/layers/layer_node.cpp | 6 +++--- nntrainer/layers/tflite_layer.cpp | 6 +++--- nntrainer/tensor/basic_planner.cpp | 1 + packaging/nntrainer.spec | 8 +++++++- 11 files changed, 31 insertions(+), 17 deletions(-) diff --git a/Applications/Custom/pow.cpp b/Applications/Custom/pow.cpp index 123d16e..9e82775 100644 --- a/Applications/Custom/pow.cpp +++ b/Applications/Custom/pow.cpp @@ -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 } diff --git a/debian/rules b/debian/rules index f18fd57..e64a340 100755 --- a/debian/rules +++ b/debian/rules @@ -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 diff --git a/meson.build b/meson.build index 3e5d312..d84d4cf 100644 --- a/meson.build +++ b/meson.build @@ -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 diff --git a/meson_options.txt b/meson_options.txt index 01674bd..877158a 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -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 diff --git a/nntrainer/dataset/iteration_queue.cpp b/nntrainer/dataset/iteration_queue.cpp index a2758f5..b7ff262 100644 --- a/nntrainer/dataset/iteration_queue.cpp +++ b/nntrainer/dataset/iteration_queue.cpp @@ -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 diff --git a/nntrainer/layers/layer_context.cpp b/nntrainer/layers/layer_context.cpp index 3526d8c..3b73bd7 100644 --- a/nntrainer/layers/layer_context.cpp +++ b/nntrainer/layers/layer_context.cpp @@ -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 &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 &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); diff --git a/nntrainer/layers/layer_context.h b/nntrainer/layers/layer_context.h index aeada49..e445464 100644 --- a/nntrainer/layers/layer_context.h +++ b/nntrainer/layers/layer_context.h @@ -624,7 +624,7 @@ private: std::vector outputs; /**< outputs of the layer */ std::vector tensors; /**< tensors of the layer */ -#ifdef ENABLE_TEST +#ifdef DEBUG std::map tensor_map; /**< map of tensor name to tensor address */ #endif diff --git a/nntrainer/layers/layer_node.cpp b/nntrainer/layers/layer_node.cpp index 1a10b70..55b71e1 100644 --- a/nntrainer/layers/layer_node.cpp +++ b/nntrainer/layers/layer_node.cpp @@ -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."); diff --git a/nntrainer/layers/tflite_layer.cpp b/nntrainer/layers/tflite_layer.cpp index 28b19a4..83f7af4 100644 --- a/nntrainer/layers/tflite_layer.cpp +++ b/nntrainer/layers/tflite_layer.cpp @@ -143,14 +143,14 @@ void TfLiteLayer::forwarding(RunLayerContext &context, bool training) { #ifdef DEBUG std::vector 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"); } } diff --git a/nntrainer/tensor/basic_planner.cpp b/nntrainer/tensor/basic_planner.cpp index 3122549..5657f9f 100644 --- a/nntrainer/tensor/basic_planner.cpp +++ b/nntrainer/tensor/basic_planner.cpp @@ -12,6 +12,7 @@ */ #include +#include namespace nntrainer { diff --git a/packaging/nntrainer.spec b/packaging/nntrainer.spec index a1473b4..08bf707 100644 --- a/packaging/nntrainer.spec +++ b/packaging/nntrainer.spec @@ -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} -- 2.7.4