From bff3fce03b5a8a7ce621003b3029ab13dbefb207 Mon Sep 17 00:00:00 2001 From: "jijoong.moon" Date: Wed, 3 Jul 2024 07:56:41 +0900 Subject: [PATCH] [TEST] using builddir/android_build_result to build test This PR includes changes in Android.mk to use builddir/android_build_result. In order to use, soft link of android_build_reuslt dir is necessary in upper dir (../) ln -s ../../buildir/android_build_result ../nntrainer Resolves: **Self evaluation:** 1. Build test: [X]Passed [ ]Failed [ ]Skipped 2. Run test: [X]Passed [ ]Failed [ ]Skipped Signed-off-by: jijoong.moon --- debian/nntrainer-dev.install | 1 + nntrainer/layers/layer_node.cpp | 4 +-- nntrainer/layers/lstm.cpp | 2 +- packaging/nntrainer.spec | 1 + test/jni/README.md | 8 ++++++ test/unittest/jni/Android.mk | 45 ++++++++++++++++++--------------- 6 files changed, 38 insertions(+), 23 deletions(-) diff --git a/debian/nntrainer-dev.install b/debian/nntrainer-dev.install index 11b41f990b..23fa92d5c0 100644 --- a/debian/nntrainer-dev.install +++ b/debian/nntrainer-dev.install @@ -24,6 +24,7 @@ /usr/include/nntrainer/layer_context.h /usr/include/nntrainer/layer_devel.h /usr/include/nntrainer/layer_impl.h +/usr/include/nntrainer/loss_layer.h # custom layer kits /usr/include/nntrainer/app_context.h # logger 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/lstm.cpp b/nntrainer/layers/lstm.cpp index a96db8a5f3..8f7a56ab8b 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/packaging/nntrainer.spec b/packaging/nntrainer.spec index 2f1dc57f68..dc764791a9 100644 --- a/packaging/nntrainer.spec +++ b/packaging/nntrainer.spec @@ -566,6 +566,7 @@ cp -r result %{buildroot}%{_datadir}/nntrainer/unittest/ %{_includedir}/nntrainer/util_func.h %{_includedir}/nntrainer/fp16.h %{_includedir}/nntrainer/util_simd.h +%{_includedir}/nntrainer/loss_layer.h %if 0%{?enable_fp16} %{_includedir}/nntrainer/util_simd_neon.h %endif 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 ed27dde7ee..ae3a4bb94f 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) +