diff --git a/debian/nntrainer-dev.install b/debian/nntrainer-dev.install index 5902803746..d5b31e9361 100644 --- a/debian/nntrainer-dev.install +++ b/debian/nntrainer-dev.install @@ -26,6 +26,7 @@ /usr/include/nntrainer/layer_devel.h /usr/include/nntrainer/layer_impl.h /usr/include/nntrainer/acti_func.h +/usr/include/nntrainer/loss_layer.h # custom layer kits /usr/include/nntrainer/app_context.h # logger diff --git a/nntrainer/graph/network_graph.h b/nntrainer/graph/network_graph.h index 727401d46d..8756e97775 100644 --- a/nntrainer/graph/network_graph.h +++ b/nntrainer/graph/network_graph.h @@ -327,9 +327,9 @@ class NetworkGraph { * @param lnode layer node to finalize and set run context * @param prev_inputs previous input information */ - std::vector finalizeContext( - const std::shared_ptr &lnode, - const std::vector &prev_inputs); + std::vector + finalizeContext(const std::shared_ptr &lnode, + const std::vector &prev_inputs); /** * @brief Recreate run layer context from the given init layer context @@ -337,9 +337,9 @@ class NetworkGraph { * @param lnode layer node to finalize and set run context * @param prev_inputs previous input information */ - std::vector refinalizeContext( - const std::shared_ptr &lnode, - const std::vector &prev_inputs); + std::vector + refinalizeContext(const std::shared_ptr &lnode, + const std::vector &prev_inputs); /** Interface for manager */ diff --git a/nntrainer/layers/layer_node.cpp b/nntrainer/layers/layer_node.cpp index 8ea270ac13..89728d3262 100644 --- a/nntrainer/layers/layer_node.cpp +++ b/nntrainer/layers/layer_node.cpp @@ -817,8 +817,8 @@ void LayerNode::forwarding(bool training) { if (executeInPlace() == InPlace::NONE) { for (unsigned int i = 0; i < run_context->getNumOutputs(); ++i) { run_context->getOutput(i).setValue(0); - if(!run_context->getOutputGradUnsafe(i).isValid()) - run_context->getOutputGradUnsafe(i).setValue(0); + if (!run_context->getOutputGradUnsafe(i).isValid()) + run_context->getOutputGradUnsafe(i).setValue(0); } for (unsigned int i = 0; i < run_context->getNumWeights(); ++i) { if (run_context->weightHasGradient(i)) { diff --git a/nntrainer/layers/loss/loss_layer.h b/nntrainer/layers/loss/loss_layer.h index 418777606c..17fee0c333 100644 --- a/nntrainer/layers/loss/loss_layer.h +++ b/nntrainer/layers/loss/loss_layer.h @@ -47,7 +47,7 @@ class LossLayer : public Layer { */ virtual bool supportBackwarding() const override { return true; } - bool supportInPlace() const override {return is_inplace;} + bool supportInPlace() const override { return is_inplace; } /** * @copydoc Layer::requireLabel() @@ -72,7 +72,7 @@ class LossLayer : public Layer { Tensor l; /**< loss tensor to store intermediate value to calculate loss value */ - bool is_inplace; + bool is_inplace; }; } // namespace nntrainer diff --git a/nntrainer/layers/loss/mse_loss_layer.h b/nntrainer/layers/loss/mse_loss_layer.h index 829b921668..387e92b3b5 100644 --- a/nntrainer/layers/loss/mse_loss_layer.h +++ b/nntrainer/layers/loss/mse_loss_layer.h @@ -51,7 +51,6 @@ class MSELossLayer : public LossLayer { const std::string getType() const override { return MSELossLayer::type; }; inline static const std::string type = "mse"; - }; } // namespace nntrainer diff --git a/nntrainer/layers/lstm.cpp b/nntrainer/layers/lstm.cpp index 5cbf5f5863..2788188e4a 100644 --- a/nntrainer/layers/lstm.cpp +++ b/nntrainer/layers/lstm.cpp @@ -58,7 +58,7 @@ void LSTMLayer::forwardingBatchFirstLSTM( TensorDim input_tensor_dim({feature_size}, tensor_type); TensorDim unit_tensor_dim({unit}, tensor_type); TensorDim num_gate_unit_tensor_dim({NUM_GATE * unit}, tensor_type); - + for (unsigned int batch = 0; batch < batch_size; ++batch) { const Tensor input_sample = input_.getBatchSlice(batch, 1); Tensor hidden_state_sample = hidden_state_.getBatchSlice(batch, 1); diff --git a/nntrainer/tensor/weight.h b/nntrainer/tensor/weight.h index aaacfcf6d8..f12f9597ec 100644 --- a/nntrainer/tensor/weight.h +++ b/nntrainer/tensor/weight.h @@ -288,9 +288,11 @@ class Weight : public Var_Grad { /** * @brief Apply the gradient to the weight */ - void applyGradient(double lr) { var->add_i(*grad.get(), -lr); - std::cout << var->getName() << " --------------------------" <print(std::cout);} + void applyGradient(double lr) { + var->add_i(*grad.get(), -lr); + std::cout << var->getName() << " --------------------------" << std::endl; + var->print(std::cout); + } /** * @brief Apply the gradient to the weight with updated gradient diff --git a/nntrainer/utils/base_properties.h b/nntrainer/utils/base_properties.h index 1f83fb63aa..d8c3bc4a50 100644 --- a/nntrainer/utils/base_properties.h +++ b/nntrainer/utils/base_properties.h @@ -720,7 +720,8 @@ class TensorFormat final : public EnumProperty { }; // /** -// * @brief trainable property, use this to set and check how if certain layer is +// * @brief trainable property, use this to set and check how if certain layer +// is // * trainable // * // */ @@ -734,7 +735,7 @@ class TensorFormat final : public EnumProperty { // static constexpr const char *key = "trainable"; // using prop_tag = bool_prop_tag; // }; - + } // namespace props } // namespace nntrainer diff --git a/packaging/nntrainer.spec b/packaging/nntrainer.spec index 84456aa191..4793759cfc 100644 --- a/packaging/nntrainer.spec +++ b/packaging/nntrainer.spec @@ -573,9 +573,7 @@ cp -r result %{buildroot}%{_datadir}/nntrainer/unittest/ %{_includedir}/nntrainer/util_func.h %{_includedir}/nntrainer/fp16.h %{_includedir}/nntrainer/util_simd.h -# In the current version, Neon SIMD is enabled only when FP16 is enabled with AArch64. -# This may be subject to change in future versions. -%ifarch aarch64 +%{_includedir}/nntrainer/loss_layer.h %if 0%{?enable_fp16} %{_includedir}/nntrainer/util_simd_neon.h %{_includedir}/nntrainer/blas_neon.h diff --git a/test/jni/README.md b/test/jni/README.md index 591568336d..fb573e6802 100644 --- a/test/jni/README.md +++ b/test/jni/README.md @@ -13,3 +13,11 @@ please do #cp ${ANDROIND_SDK_HOME}/Sdk/ndk/${NDK_VERSION}/sources/third_party/googletest . ``` +and to use android builddir/android_build_result, do +``` bash +#ln -s ../../builddir/android_build_result ../nntrainer + +``` + + + diff --git a/test/unittest/jni/Android.mk b/test/unittest/jni/Android.mk index 40fe50d28e..afcfe749bb 100644 --- a/test/unittest/jni/Android.mk +++ b/test/unittest/jni/Android.mk @@ -7,33 +7,19 @@ ifndef ANDROID_NDK $(error ANDROID_NDK is not defined!) endif -ifndef NNTRAINER_ROOT -NNTRAINER_ROOT := $(LOCAL_PATH)/../../.. -endif +NNTRAINER_ROOT := ../nntrainer -ML_API_COMMON_INCLUDES := ${NNTRAINER_ROOT}/ml_api_common/include -NNTRAINER_INCLUDES := $(NNTRAINER_ROOT)/nntrainer \ - $(NNTRAINER_ROOT)/nntrainer/dataset \ - $(NNTRAINER_ROOT)/nntrainer/models \ - $(NNTRAINER_ROOT)/nntrainer/layers \ - $(NNTRAINER_ROOT)/nntrainer/compiler \ - $(NNTRAINER_ROOT)/nntrainer/graph \ - $(NNTRAINER_ROOT)/nntrainer/optimizers \ - $(NNTRAINER_ROOT)/nntrainer/tensor \ - $(NNTRAINER_ROOT)/nntrainer/utils \ - $(NNTRAINER_ROOT)/api \ - $(NNTRAINER_ROOT)/api/ccapi/include \ - ${ML_API_COMMON_INCLUDES} +NNTRAINER_INCLUDES := $(NNTRAINER_ROOT)/include/ LOCAL_MODULE := nntrainer -LOCAL_SRC_FILES := $(NNTRAINER_ROOT)/libs/$(TARGET_ARCH_ABI)/libnntrainer.so +LOCAL_SRC_FILES := $(NNTRAINER_ROOT)/lib/$(TARGET_ARCH_ABI)/libnntrainer.so +LOCAL_EXPORT_C_INCLUDES := $(NNTRAINER_INCLUDES) include $(PREBUILT_SHARED_LIBRARY) -include $(CLEAR_VARS) - LOCAL_MODULE := ccapi-nntrainer -LOCAL_SRC_FILES := $(NNTRAINER_ROOT)/libs/$(TARGET_ARCH_ABI)/libccapi-nntrainer.so +LOCAL_SRC_FILES := $(NNTRAINER_ROOT)/lib/$(TARGET_ARCH_ABI)/libccapi-nntrainer.so +LOCAL_EXPORT_C_INCLUDES := $(NNTRAINER_INCLUDES) $(NNTRAINER_INCLUDES)/nntrainer include $(PREBUILT_SHARED_LIBRARY) @@ -67,3 +53,22 @@ LOCAL_C_INCLUDES += $(NNTRAINER_INCLUDES) LOCAL_SHARED_LIBRARIES := nntrainer ccapi-nntrainer LOCAL_STATIC_LIBRARIES := googletest_main include $(BUILD_EXECUTABLE) + +include $(CLEAR_VARS) + +LOCAL_MODULE := tensor_unittest +LOCAL_CFLAGS := -Itests/googletest/include -Itests -pthread -fexceptions -fopenmp -static-openmp -DMIN_CPP_VERSION=201703L -DNNTR_NUM_THREADS=1 -D__LOGGING__=1 -DENABLE_TEST=1 -DREDUCE_TOLERANCE=1 -march=armv8.2-a+fp16 -mfpu=neon-fp16 -mfloat-abi=softfp -O3 -frtti -DENABLE_FP16=1 +LOCAL_CXXFLAGS += -std=c++17 -frtti -fexceptions +LOCAL_LDLIBS := -llog -landroid -fopenmp -static-openmp + +LOCAL_SRC_FILES := \ + tests/unittest_nntrainer_tensor_neon_fp16.cpp \ + # tests/unittest_nntrainer_tensor_fp16.cpp \ + tests/nntrainer_test_util.cpp + +LOCAL_C_INCLUDES += $(NNTRAINER_INCLUDES) + +LOCAL_SHARED_LIBRARIES := nntrainer ccapi-nntrainer +LOCAL_STATIC_LIBRARIES := googletest_main +include $(BUILD_EXECUTABLE) +