├── .clang-format ├── metal └── README.md ├── doc └── images │ ├── devices.png │ ├── flow_chart.png │ ├── model_desc.png │ └── model_desc_combined.png ├── tools ├── toolchains │ ├── arm-android-neon.cmake │ └── arm-linux-gnueabi.cmake ├── arm-platform.cmake ├── pre-commit.hooks │ ├── cpplint.hook │ ├── clang-tidy.hook │ └── clang-format.hook └── android-debug-script │ ├── push2android.sh │ └── run_on_android.sh ├── .gitmodules ├── demo ├── ReadMe.md └── getDemo.sh ├── .travis └── pre-commit-job.sh ├── src ├── common │ ├── macros.h │ ├── common.h │ └── type_define.h ├── operators │ ├── kernel │ │ ├── arm │ │ │ ├── slice_kernel.cpp │ │ │ ├── pool_kernel.cpp │ │ │ ├── lrn_kernel.cpp │ │ │ ├── mul_kernel.cpp │ │ │ ├── relu_kernel.cpp │ │ │ ├── concat_kernel.cpp │ │ │ ├── reshape_kernel.cpp │ │ │ ├── box_coder_kernel.cpp │ │ │ ├── fusion_fc_kernel.cpp │ │ │ ├── prior_box_kernel.cpp │ │ │ ├── transpose_kernel.cpp │ │ │ ├── batchnorm_kernel.cpp │ │ │ ├── conv_kernel.cpp │ │ │ ├── conv_add_kernel.cpp │ │ │ ├── softmax_kernel.cpp │ │ │ ├── multiclass_nms_kernel.cpp │ │ │ ├── elementwise_add_kernel.cpp │ │ │ ├── depthwise_conv_kernel.cpp │ │ │ ├── conv_add_relu_kernel.cpp │ │ │ ├── sigmoid_kernel.cpp │ │ │ └── dropout_kernel.cpp │ │ ├── prelu_kernel.h │ │ ├── scale_kernel.h │ │ ├── slice_kernel.h │ │ ├── fpga │ │ │ └── conv_kernel.cpp │ │ ├── central-arm-func │ │ │ ├── softmax_arm_func.h │ │ │ ├── elementwise_add_arm_func.h │ │ │ ├── lrn_arm_func.h │ │ │ ├── reshape_arm_func.h │ │ │ └── mul_arm_func.h │ │ ├── relu_kernel.h │ │ ├── dropout_kernel.h │ │ ├── pool_kernel.h │ │ ├── concat_kernel.h │ │ ├── softmax_kernel.h │ │ ├── transpose_kernel.h │ │ ├── multiclass_nms_kernel.h │ │ ├── mul_kernel.h │ │ ├── batchnorm_kernel.h │ │ ├── fusion_fc_kernel.h │ │ ├── sigmoid_kernel.h │ │ ├── box_coder_kernel.h │ │ ├── elementwise_add_kernel.h │ │ ├── conv_kernel.h │ │ ├── depthwise_conv_kernel.h │ │ ├── im2sequence_kernel.h │ │ ├── conv_add_relu_kernel.h │ │ ├── conv_add_bn_relu_kernel.h │ │ ├── conv_add_kernel.h │ │ └── mali │ │ │ ├── elementwise_add_kernel.cpp │ │ │ ├── reshape_kernel.cpp │ │ │ └── mul_kernel.cpp │ ├── math │ │ ├── softmax.h │ │ ├── pool_2x2.h │ │ ├── pool_3x3.h │ │ └── math_function.h │ ├── feed_op.cpp │ ├── fetch_op.cpp │ ├── sigmoid_op.cpp │ ├── dropout_op.cpp │ ├── lrn_op.cpp │ ├── softmax_op.cpp │ ├── slice_op.cpp │ ├── elementwise_add_op.cpp │ ├── scale_op.cpp │ ├── resize_op.cpp │ ├── batchnorm_op.cpp │ ├── relu_op.cpp │ ├── prelu_op.cpp │ ├── reshape_op.cpp │ ├── multiclass_nms_op.cpp │ ├── prelu_op.h │ ├── scale_op.h │ ├── slice_op.h │ ├── resize_op.h │ ├── fetch_op.h │ ├── feed_op.h │ ├── batchnorm_op.h │ ├── mul_op.h │ ├── lrn_op.h │ ├── conv_op.h │ ├── sigmoid_op.h │ ├── concat_op.h │ ├── softmax_op.h │ ├── pool_op.h │ ├── depthwise_conv_op.h │ ├── box_coder_op.h │ ├── prior_box_op.h │ ├── dropout_op.h │ ├── relu_op.h │ └── transpose_op.h ├── framework │ ├── op_proto_maker.h │ ├── tensor_util.h │ ├── tensor_util.cpp │ ├── program │ │ ├── program.h │ │ ├── program_desc.h │ │ ├── block_desc.cpp │ │ └── program-optimize │ │ │ ├── program_optimize.h │ │ │ └── fusion_op_register.h │ ├── attribute.cpp │ └── data_layout.h ├── ios_io │ ├── PaddleMobile.h │ └── op_symbols.h ├── memory │ ├── t_malloc.cpp │ └── t_malloc.h └── io │ └── loader.h ├── test ├── operators │ ├── test_scale_op.cpp │ ├── test_slice_op.cpp │ ├── test_sigmoid_op.cpp │ ├── test_softmax_op.cpp │ ├── test_pool_op.cpp │ ├── test_resize_op.cpp │ ├── test_reshape_op.cpp │ ├── test_cov_op.cpp │ ├── test_conv_add_relu_op.cpp │ ├── test_depthwise_conv_op.cpp │ ├── test_relu_op.cpp │ ├── test_transpose_op.cpp │ └── test_prelu_op.cpp ├── common │ ├── test_lib_size.cpp │ ├── test_enforce.cpp │ ├── test_openmp.cpp │ └── test_log.cpp ├── framework │ ├── test_load.cpp │ └── test_optimize.cpp ├── test_include.h └── net │ ├── test_googlenet.cpp │ ├── test_resnet.cpp │ ├── test_mobilenet+ssd.cpp │ ├── test_mobilenet.cpp │ ├── test_yolo.cpp │ └── test_squeezenet.cpp ├── .travis.yml ├── .gitignore └── Dockerfile /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | BasedOnStyle: Google 4 | Standard: Cpp11 5 | ... 6 | -------------------------------------------------------------------------------- /metal/README.md: -------------------------------------------------------------------------------- 1 | ## Paddle-Mobile 2 | 3 | This folder is used to develop metal version for ios gpu 4 | -------------------------------------------------------------------------------- /doc/images/devices.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binhetech/paddle-mobile/develop/doc/images/devices.png -------------------------------------------------------------------------------- /doc/images/flow_chart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binhetech/paddle-mobile/develop/doc/images/flow_chart.png -------------------------------------------------------------------------------- /doc/images/model_desc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binhetech/paddle-mobile/develop/doc/images/model_desc.png -------------------------------------------------------------------------------- /doc/images/model_desc_combined.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/binhetech/paddle-mobile/develop/doc/images/model_desc_combined.png -------------------------------------------------------------------------------- /tools/toolchains/arm-android-neon.cmake: -------------------------------------------------------------------------------- 1 | set(ANDROID_ARM_NEON ON) 2 | include("${CMAKE_CURRENT_LIST_DIR}/../android-cmake/android.toolchain.cmake") -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/operators/kernel/mali/ACL_Android"] 2 | path = src/operators/kernel/mali/ACL_Android 3 | url = https://github.com/halsay/ACL_Android.git 4 | -------------------------------------------------------------------------------- /demo/ReadMe.md: -------------------------------------------------------------------------------- 1 | ## 如何运行demo 2 | - Android demo下载路径 3 | http://mms-graph.bj.bcebos.com/paddle-mobile%2FPaddleMobile_Android.zip 4 | - iOS demo下载路径: 5 | http://mms-graph.bj.bcebos.com/paddle-mobile%2FPaddleMobileDemo_iOS.zip 6 | 7 | 在demo目录下执行下载demo的脚本 8 | ``` 9 | sh getDemo.sh 10 | ``` 11 | demo工程就下载解压到当前目录中了。 -------------------------------------------------------------------------------- /tools/arm-platform.cmake: -------------------------------------------------------------------------------- 1 | 2 | set(ARCH "armv7-a") 3 | 4 | set(FLOAT_ABI "softfp" CACHE STRING "-mfloat-api chosen") 5 | set_property(CACHE FLOAT_ABI PROPERTY STRINGS "softfp" "soft" "hard") 6 | 7 | set(FPU "neon") 8 | 9 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=${ARCH} -mfloat-abi=${FLOAT_ABI} -mfpu=${FPU}") 10 | -------------------------------------------------------------------------------- /tools/pre-commit.hooks/cpplint.hook: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | TOTAL_ERRORS=0 4 | 5 | # The trick to remove deleted files: https://stackoverflow.com/a/2413151 6 | for file in $(git diff --cached --name-status | awk '$1 != "D" {print $2}' | grep -v ".pb.cpp" | grep -v ".pb.h"); do 7 | cpplint $file; 8 | TOTAL_ERRORS=$(expr $TOTAL_ERRORS + $?); 9 | done 10 | 11 | exit $TOTAL_ERRORS 12 | -------------------------------------------------------------------------------- /demo/getDemo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | wget http://mms-graph.bj.bcebos.com/paddle-mobile%2FPaddleMobile_Android.zip 3 | wget http://mms-graph.bj.bcebos.com/paddle-mobile%2FPaddleMobileDemo_iOS.zip 4 | unzip paddle-mobile%2FPaddleMobile_Android.zip 5 | unzip paddle-mobile%2FPaddleMobileDemo_iOS.zip 6 | rm -rf paddle-mobile%2FPaddleMobile_Android.zip 7 | rm -rf paddle-mobile%2FPaddleMobileDemo_iOS.zip 8 | rm -rf __MACOSX -------------------------------------------------------------------------------- /.travis/pre-commit-job.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | function abort(){ 3 | echo "Your change doesn't follow Paddle-Moible's code style" 1>&2 4 | echo "Please use pre-commit to auto-format your code." 1>&2 5 | exit 1 6 | } 7 | 8 | trap 'abort' 0 9 | set -e 10 | cd `dirname $0` 11 | cd .. 12 | export PATH=/usr/bin:$PATH 13 | pre-commit install 14 | 15 | if ! pre-commit run -a ; then 16 | ls -lh 17 | git diff --exit-code 18 | exit 1 19 | fi 20 | 21 | trap : 0 22 | -------------------------------------------------------------------------------- /tools/toolchains/arm-linux-gnueabi.cmake: -------------------------------------------------------------------------------- 1 | # CMake toolchain file for building ARM software on Linux environment 2 | 3 | set(CMAKE_SYSTEM_NAME Linux) 4 | set(CMAKE_SYSTEM_VERSION 1) 5 | 6 | set(CMAKE_C_COMPILER /usr/bin/arm-linux-gnueabi-gcc) 7 | set(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabi-g++) 8 | set(CMAKE_STRIP /usr/bin/arm-linux-gnueabi-strip) 9 | 10 | set(CMAKE_FIND_ROOT_PATH /usr/arm-linux-gnueabi) 11 | 12 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 13 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | 16 | set(ARM_LINUX 1) 17 | -------------------------------------------------------------------------------- /tools/pre-commit.hooks/clang-tidy.hook: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | bash -c "cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON" 4 | 5 | TOTAL_ERRORS=0 6 | 7 | # The trick to remove deleted files: https://stackoverflow.com/a/2413151 8 | for file in $(git diff --cached --name-status | awk '$1 != "D" {print $2}' | grep "src/" | grep -v ".pb." | grep -v ".h"); do 9 | echo "clang-tidy check $file"; 10 | clang-tidy $file --fix --fix-errors --header-filter=.* 11 | TOTAL_ERRORS=$(expr $TOTAL_ERRORS + $?); 12 | echo "clang-tidy error TOTAL_ERRORS = $TOTAL_ERRORS . " 13 | done 14 | 15 | rm -f compile_commands.json 16 | 17 | exit $TOTAL_ERRORS 18 | 19 | -------------------------------------------------------------------------------- /src/common/macros.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #pragma once 16 | 17 | #define EXPORT __attribute__((visibility("default"))) 18 | -------------------------------------------------------------------------------- /test/operators/test_scale_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "../test_include.h" 16 | #include "operators/scale_op.h" 17 | 18 | int main() {} 19 | -------------------------------------------------------------------------------- /test/operators/test_slice_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "../test_include.h" 16 | #include "operators/slice_op.h" 17 | 18 | int main() {} 19 | -------------------------------------------------------------------------------- /test/common/test_lib_size.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | // 16 | // Created by liuRuiLong on 2018/6/6. 17 | // 18 | 19 | #include "test_lib_size.h" 20 | 21 | static test_lib_size t; 22 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | cache: ccache 3 | sudo: required 4 | dist: trusty 5 | 6 | os: 7 | - linux 8 | 9 | addons: 10 | apt: 11 | packages: 12 | - git 13 | - python 14 | - python-pip 15 | - python2.7-dev 16 | - libc6-i386 17 | - curl 18 | 19 | compiler: 20 | - clang 21 | 22 | before_install: 23 | - sudo pip install -U virtualenv pre-commit pip 24 | # Download and install recent cmake 25 | 26 | script: 27 | - | 28 | function timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; } 29 | - | 30 | timeout 600 .travis/pre-commit-job.sh # 10min timeout 31 | RESULT=$?; if [ $RESULT -eq 0 ] || [ $RESULT -eq 142 ]; then true; else exit 1; fi; 32 | 33 | notifications: 34 | email: 35 | on_success: change 36 | on_failure: always 37 | -------------------------------------------------------------------------------- /tools/pre-commit.hooks/clang-format.hook: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | readonly VERSION="5.0" 5 | 6 | version=$(clang-format -version) 7 | 8 | if ! [[ $version == *"$VERSION"* ]]; then 9 | echo "clang-format version check failed." 10 | echo "a version contains '$VERSION' is needed, but get '$version'" 11 | echo "you can install the right version, and make an soft-link to '\$PATH' env" 12 | exit -1 13 | fi 14 | 15 | # https://medicineyeh.wordpress.com/2017/07/13/clang-format-with-pragma/ 16 | shift 17 | perl -i -pe 's|^\s+#pragma\s+omp|// #pragma omp|' "$@" 18 | ( 19 | # remove clang format ios_io folder 20 | flist=$(echo "$@" | perl -pe 's|src/ios_io/[^ ]*||') 21 | clang-format -i $flist 22 | ) 23 | perl -i -pe 's|// ||' "$@" 24 | -------------------------------------------------------------------------------- /test/common/test_enforce.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "common/enforce.h" 16 | 17 | int main() { 18 | PADDLE_MOBILE_ENFORCE(false, "enforce"); 19 | PADDLE_MOBILE_THROW_EXCEPTION("throw a exception"); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/slice_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef SLICE_OP 16 | 17 | #include "operators/kernel/slice_kernel.h" 18 | 19 | namespace paddle_mobile { 20 | namespace operators {} 21 | } // namespace paddle_mobile 22 | #endif 23 | -------------------------------------------------------------------------------- /src/framework/op_proto_maker.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #pragma once 16 | 17 | namespace paddle_mobile { 18 | namespace framework { 19 | // this class not only make proto but also init attribute checkers. 20 | class OpProtoAndCheckerMaker {}; 21 | } // namespace framework 22 | } // namespace paddle_mobile 23 | -------------------------------------------------------------------------------- /src/framework/tensor_util.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #pragma once 16 | #include 17 | #include "memory/t_malloc.h" 18 | #include "tensor.h" 19 | 20 | namespace paddle_mobile { 21 | namespace framework { 22 | 23 | void TensorCopy(const Tensor &src, Tensor *dst); 24 | 25 | } // namespace framework 26 | } // namespace paddle_mobile 27 | -------------------------------------------------------------------------------- /tools/android-debug-script/push2android.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | push_fn () { 4 | MODELS_PATH="../../test/models/*" 5 | MODELS_SRC="../../test/models" 6 | IMAGE_PATH="../../test/images/*" 7 | EXE_FILE="../../test/build/*" 8 | EXE_DIR="data/local/tmp/bin" 9 | adb shell mkdir ${EXE_DIR} 10 | MODELS_DIR="data/local/tmp/models" 11 | adb shell mkdir ${MODELS_DIR} 12 | for file in `ls ${MODELS_SRC}` 13 | do 14 | adb shell mkdir ${MODELS_DIR}"/"${file} 15 | done 16 | 17 | if [[ -d "../../src/operators/kernel/mali/ACL_Android/build" ]]; then 18 | ACL_BUILD_PATH="../../src/operators/kernel/mali/ACL_Android/build/*" 19 | adb push ${ACL_BUILD_PATH} ${EXE_DIR} 20 | fi 21 | 22 | IMAGES_DIR="data/local/tmp/images" 23 | adb shell mkdir ${IMAGES_DIR} 24 | LIB_PATH="../../build/release/arm-v7a/build/*" 25 | adb push ${EXE_FILE} ${EXE_DIR} 26 | adb push ${LIB_PATH} ${EXE_DIR} 27 | if [[ $1 != "npm" ]]; then 28 | adb push ${IMAGE_PATH} ${IMAGES_DIR} 29 | adb push ${MODELS_PATH} ${MODELS_DIR} 30 | fi 31 | } 32 | 33 | if [[ $1 == "npm" ]]; then 34 | push_fn $1 35 | else 36 | push_fn 37 | fi 38 | -------------------------------------------------------------------------------- /src/common/common.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #pragma once 16 | #include 17 | 18 | using Time = decltype(std::chrono::high_resolution_clock::now()); 19 | 20 | inline Time time() { return std::chrono::high_resolution_clock::now(); } 21 | 22 | inline double time_diff(Time t1, Time t2) { 23 | typedef std::chrono::microseconds ms; 24 | auto diff = t2 - t1; 25 | ms counter = std::chrono::duration_cast(diff); 26 | return counter.count() / 1000.0; 27 | } 28 | -------------------------------------------------------------------------------- /test/common/test_openmp.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | //#include 16 | #include 17 | 18 | int main(void) { 19 | #ifdef PADDLE_MOBILE_USE_OPENMP 20 | #pragma omp parallel num_threads(2) 21 | { 22 | // int thread_id = omp_get_thread_num(); 23 | // int nthreads = omp_get_num_threads(); 24 | // std::cout << "Hello, OMP " << thread_id << "/" << nthreads << 25 | // "\n"; 26 | } 27 | #endif 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /src/operators/math/softmax.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef SOFTMAX_OP 16 | #pragma once 17 | #include "framework/tensor.h" 18 | namespace paddle_mobile { 19 | namespace operators { 20 | namespace math { 21 | 22 | template 23 | class SoftmaxFuntor { 24 | public: 25 | void operator()(const framework::Tensor *X, framework::Tensor *Y); 26 | }; 27 | } // namespace math 28 | } // namespace operators 29 | } // namespace paddle_mobile 30 | #endif 31 | -------------------------------------------------------------------------------- /src/operators/kernel/prelu_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "framework/operator.h" 16 | #include "operators/op_param.h" 17 | 18 | #pragma once; 19 | 20 | namespace paddle_mobile { 21 | namespace operators { 22 | 23 | template 24 | class PReluKernel : public framework::OpKernelBase { 25 | public: 26 | void Compute(const PReluParam& param) const; 27 | }; 28 | } // namespace operators 29 | } // namespace paddle_mobile 30 | -------------------------------------------------------------------------------- /src/operators/kernel/scale_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "framework/operator.h" 16 | #include "operators/op_param.h" 17 | 18 | #pragma once; 19 | 20 | namespace paddle_mobile { 21 | namespace operators { 22 | 23 | template 24 | class ScaleKernel : public framework::OpKernelBase { 25 | public: 26 | void Compute(const ScaleParam& param) const; 27 | }; 28 | } // namespace operators 29 | } // namespace paddle_mobile 30 | -------------------------------------------------------------------------------- /src/operators/kernel/slice_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "framework/operator.h" 16 | #include "operators/op_param.h" 17 | 18 | #pragma once; 19 | 20 | namespace paddle_mobile { 21 | namespace operators { 22 | 23 | template 24 | class SliceKernel : public framework::OpKernelBase { 25 | public: 26 | void Compute(const SliceParam& param) const {} 27 | }; 28 | } // namespace operators 29 | } // namespace paddle_mobile 30 | -------------------------------------------------------------------------------- /tools/android-debug-script/run_on_android.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | push_fn () { 4 | MODELS_PATH="../../test/models/*" 5 | MODELS_SRC="../../test/models" 6 | IMAGE_PATH="../../test/images/*" 7 | EXE_FILE="../../test/build/*" 8 | EXE_DIR="data/local/tmp/bin" 9 | adb shell mkdir ${EXE_DIR} 10 | MODELS_DIR="data/local/tmp/models" 11 | adb shell mkdir ${MODELS_DIR} 12 | for file in `ls ${MODELS_SRC}` 13 | do 14 | adb shell mkdir ${MODELS_DIR}"/"${file} 15 | done 16 | 17 | IMAGES_DIR="data/local/tmp/images" 18 | adb shell mkdir ${IMAGES_DIR} 19 | LIB_PATH="../../build/release/arm-v7a/build/*" 20 | adb push ${EXE_FILE} ${EXE_DIR} 21 | adb push ${LIB_PATH} ${EXE_DIR} 22 | if [[ $1 != "npm" ]]; then 23 | adb push ${IMAGE_PATH} ${IMAGES_DIR} 24 | adb push ${MODELS_PATH} ${MODELS_DIR} 25 | fi 26 | echo "test-op or test-net below : " 27 | adb shell ls /data/local/tmp/bin 28 | echo "**** choose OP or NET to test ****" 29 | read -p "which to test : " test_name 30 | adb shell "cd /data/local/tmp/bin; LD_LIBRARY_PATH=. ./${test_name}" 31 | } 32 | 33 | if [[ $1 == "npm" ]]; then 34 | push_fn $1 35 | else 36 | push_fn 37 | fi -------------------------------------------------------------------------------- /src/operators/feed_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "feed_op.h" 16 | namespace paddle_mobile { 17 | namespace operators { 18 | 19 | template class FeedOp; 20 | } 21 | } // namespace paddle_mobile 22 | 23 | namespace ops = paddle_mobile::operators; 24 | #ifdef PADDLE_MOBILE_CPU 25 | REGISTER_OPERATOR_CPU(feed, ops::FeedOp); 26 | #endif 27 | #ifdef PADDLE_MOBILE_MALI_GPU 28 | REGISTER_OPERATOR_MALI_GPU(feed, ops::FeedOp); 29 | #endif 30 | #ifdef PADDLE_MOBILE_FPGA 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/operators/fetch_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "fetch_op.h" 16 | namespace paddle_mobile { 17 | namespace operators { 18 | 19 | template class FetchOp; 20 | } 21 | } // namespace paddle_mobile 22 | 23 | namespace ops = paddle_mobile::operators; 24 | #ifdef PADDLE_MOBILE_CPU 25 | REGISTER_OPERATOR_CPU(fetch, ops::FetchOp); 26 | #endif 27 | #ifdef PADDLE_MOBILE_MALI_GPU 28 | REGISTER_OPERATOR_MALI_GPU(fetch, ops::FetchOp); 29 | #endif 30 | #ifdef PADDLE_MOBILE_FPGA 31 | #endif 32 | -------------------------------------------------------------------------------- /src/framework/tensor_util.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "tensor_util.h" 16 | 17 | namespace paddle_mobile { 18 | namespace framework { 19 | 20 | void TensorCopy(const Tensor &src, Tensor *dst) { 21 | src.check_memory_size(); 22 | dst->Resize(src.dims()); 23 | auto src_ptr = src.data(); 24 | auto dst_ptr = dst->mutable_data(src.type()); 25 | auto size = src.numel() * SizeOfType(src.type()); 26 | memory::Copy(dst_ptr, src_ptr, size); 27 | } 28 | 29 | } // namespace framework 30 | } // namespace paddle_mobile 31 | -------------------------------------------------------------------------------- /src/operators/kernel/fpga/conv_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef CONV_OP 16 | 17 | #include "operators/kernel/conv_kernel.h" 18 | 19 | namespace paddle_mobile { 20 | namespace operators { 21 | 22 | template <> 23 | bool ConvKernel::Init(ConvParam *param) { 24 | return true; 25 | } 26 | 27 | template <> 28 | void ConvKernel::Compute(const ConvParam ¶m) const {} 29 | template class ConvKernel; 30 | 31 | } // namespace operators 32 | } // namespace paddle_mobile 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /test/framework/test_load.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "../test_helper.h" 16 | #include "io/loader.h" 17 | 18 | int main() { 19 | paddle_mobile::Loader loader; 20 | // ../../../test/models/googlenet 21 | // ../../../test/models/mobilenet 22 | auto program = loader.Load(g_googlenet, true); 23 | // auto program = loader.Load(g_googlenet_combine + "/model", 24 | // g_googlenet_combine + 25 | // "/params", true); 26 | 27 | // program.originProgram->Description("program desc: "); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.lib 27 | 28 | # Executables 29 | *.exe 30 | *.out 31 | *.app 32 | 33 | .DS_Store 34 | 35 | build/ 36 | 37 | .idea/ 38 | 39 | CMakeCache.txt 40 | 41 | CMakeFiles/ 42 | 43 | Makefile 44 | 45 | cmake_install.cmake 46 | 47 | 48 | *.cbp 49 | 50 | paddle-mobile.cbp 51 | 52 | .idea 53 | 54 | compile_commands.json 55 | 56 | cmake-build-debug/ 57 | cmake-build-release/ 58 | 59 | test/models/ 60 | 61 | test/images/ 62 | 63 | # Emacs intermediate files 64 | *~ 65 | 66 | # CMake building directory 67 | build 68 | 69 | # clion building directories 70 | cmake-build-debug 71 | cmake-build-release 72 | 73 | 74 | #ios demo 75 | demo/ios/PaddleMobileDemo/PaddleMobileDemo/googlenet_combine/ 76 | demo/ios/PaddleMobileDemo/PaddleMobileDemo/*.jpg 77 | demo/ios/PaddleMobileDemo/PaddleMobileDemo/PaddleMobile/*.a 78 | *.xcuserstate -------------------------------------------------------------------------------- /src/operators/kernel/central-arm-func/softmax_arm_func.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef SOFTMAX_OP 16 | #pragma once 17 | #include "../../math/softmax.h" 18 | namespace paddle_mobile { 19 | namespace operators { 20 | template 21 | void SoftmaxCompute(const SoftmaxParam ¶m) { 22 | const Tensor *in_x = param.InputX(); 23 | Tensor *out = param.Out(); 24 | auto x_dims = in_x->dims(); 25 | out->Resize(x_dims); 26 | math::SoftmaxFuntor()(in_x, out); 27 | } 28 | } // namespace operators 29 | } // namespace paddle_mobile 30 | #endif 31 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/pool_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef POOL_OP 16 | 17 | #include "operators/kernel/pool_kernel.h" 18 | #include "../central-arm-func/pool_arm_func.h" 19 | namespace paddle_mobile { 20 | namespace operators { 21 | 22 | template <> 23 | bool PoolKernel::Init(PoolParam *param) { 24 | return true; 25 | } 26 | 27 | template <> 28 | void PoolKernel::Compute(const PoolParam ¶m) const { 29 | PoolCompute(param); 30 | } 31 | } // namespace operators 32 | } // namespace paddle_mobile 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/operators/kernel/relu_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef RELU_OP 16 | 17 | #pragma once 18 | 19 | #include "framework/operator.h" 20 | 21 | #include "operators/op_param.h" 22 | 23 | namespace paddle_mobile { 24 | namespace operators { 25 | 26 | template 27 | class ReluKernel : public framework::OpKernelBase { 28 | public: 29 | void Compute(const ReluParam& param) const; 30 | bool Init(ReluParam* param); 31 | }; 32 | } // namespace operators 33 | } // namespace paddle_mobile 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/operators/kernel/dropout_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef DROPOUT_OP 16 | 17 | #include "framework/operator.h" 18 | #include "operators/op_param.h" 19 | 20 | #pragma once; 21 | 22 | namespace paddle_mobile { 23 | namespace operators { 24 | 25 | template 26 | class DropoutKernel : public framework::OpKernelBase { 27 | public: 28 | void Compute(const DropoutParam& param) const; 29 | bool Init(DropoutParam* para); 30 | }; 31 | } // namespace operators 32 | } // namespace paddle_mobile 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/lrn_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef LRN_OP 16 | 17 | #include "operators/kernel/lrn_kernel.h" 18 | #include "operators/kernel/central-arm-func/lrn_arm_func.h" 19 | 20 | namespace paddle_mobile { 21 | namespace operators { 22 | 23 | template <> 24 | bool LrnKernel::Init(LrnParam *param) { 25 | return true; 26 | } 27 | 28 | template <> 29 | void LrnKernel::Compute(const LrnParam ¶m) const { 30 | LrnCompute(param); 31 | } 32 | 33 | } // namespace operators 34 | } // namespace paddle_mobile 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/mul_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef MUL_OP 16 | 17 | #include "operators/kernel/mul_kernel.h" 18 | #include "operators/kernel/central-arm-func/mul_arm_func.h" 19 | 20 | namespace paddle_mobile { 21 | namespace operators { 22 | 23 | template <> 24 | bool MulKernel::Init(MulParam *param) { 25 | return true; 26 | } 27 | 28 | template <> 29 | void MulKernel::Compute(const MulParam ¶m) const { 30 | MulCompute(param); 31 | } 32 | 33 | } // namespace operators 34 | } // namespace paddle_mobile 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/relu_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef RELU_OP 16 | 17 | #include "operators/kernel/relu_kernel.h" 18 | #include "operators/kernel/central-arm-func/relu_arm_func.h" 19 | 20 | namespace paddle_mobile { 21 | namespace operators { 22 | 23 | template <> 24 | bool ReluKernel::Init(ReluParam *param) { 25 | return true; 26 | } 27 | 28 | template <> 29 | void ReluKernel::Compute(const ReluParam ¶m) const { 30 | ReluCompute(param); 31 | } 32 | 33 | } // namespace operators 34 | } // namespace paddle_mobile 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/operators/kernel/pool_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef POOL_OP 16 | 17 | #pragma once 18 | 19 | #include "framework/operator.h" 20 | #include "operators/op_param.h" 21 | 22 | namespace paddle_mobile { 23 | namespace operators { 24 | using framework::OpKernelBase; 25 | 26 | template 27 | class PoolKernel : public OpKernelBase { 28 | public: 29 | void Compute(const PoolParam ¶m) const override; 30 | bool Init(PoolParam *param); 31 | }; 32 | } // namespace operators 33 | } // namespace paddle_mobile 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/concat_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef CONCAT_OP 16 | 17 | #include "operators/kernel/concat_kernel.h" 18 | #include "operators/kernel/central-arm-func/concat_arm_func.h" 19 | 20 | namespace paddle_mobile { 21 | namespace operators { 22 | 23 | template <> 24 | bool ConcatKernel::Init(ConcatParam *param) { 25 | return true; 26 | } 27 | 28 | template <> 29 | void ConcatKernel::Compute(const ConcatParam ¶m) const { 30 | ConcatCompute(param); 31 | } 32 | 33 | } // namespace operators 34 | } // namespace paddle_mobile 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/operators/kernel/concat_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef CONCAT_OP 16 | 17 | #pragma once 18 | #include "framework/operator.h" 19 | #include "operators/op_param.h" 20 | 21 | namespace paddle_mobile { 22 | namespace operators { 23 | 24 | using namespace framework; 25 | 26 | template 27 | class ConcatKernel : public framework::OpKernelBase { 28 | public: 29 | void Compute(const ConcatParam ¶m) const; 30 | bool Init(ConcatParam *param); 31 | }; 32 | 33 | } // namespace operators 34 | } // namespace paddle_mobile 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/operators/kernel/softmax_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef SOFTMAX_OP 16 | 17 | #pragma once 18 | 19 | #include "framework/operator.h" 20 | #include "operators/op_param.h" 21 | 22 | namespace paddle_mobile { 23 | namespace operators { 24 | using framework::OpKernelBase; 25 | 26 | template 27 | class SoftmaxKernel : public OpKernelBase { 28 | public: 29 | void Compute(const SoftmaxParam ¶m) const override; 30 | bool Init(SoftmaxParam *param); 31 | }; 32 | } // namespace operators 33 | } // namespace paddle_mobile 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /test/test_include.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #pragma once 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #include "./test_helper.h" 22 | #include "common/enforce.h" 23 | #include "common/log.h" 24 | #include "executor_for_test.h" 25 | #include "framework/lod_tensor.h" 26 | #include "framework/operator.h" 27 | #include "framework/program/block_desc.h" 28 | #include "framework/program/program.h" 29 | #include "framework/program/program_desc.h" 30 | #include "framework/scope.h" 31 | #include "framework/tensor.h" 32 | #include "framework/variable.h" 33 | #include "io/paddle_mobile.h" 34 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/reshape_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef RESHAPE_OP 16 | 17 | #include "operators/kernel/reshape_kernel.h" 18 | #include "operators/kernel/central-arm-func/reshape_arm_func.h" 19 | 20 | namespace paddle_mobile { 21 | namespace operators { 22 | 23 | template <> 24 | bool ReshapeKernel::Init(ReshapeParam *param) { 25 | return true; 26 | } 27 | 28 | template <> 29 | void ReshapeKernel::Compute(const ReshapeParam ¶m) const { 30 | ReshapeCompute(param); 31 | } 32 | 33 | } // namespace operators 34 | } // namespace paddle_mobile 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/operators/kernel/transpose_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef TRANSPOSE_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #include "framework/operator.h" 22 | #include "operators/op_param.h" 23 | 24 | namespace paddle_mobile { 25 | namespace operators { 26 | 27 | template 28 | class TransposeKernel 29 | : public framework::OpKernelBase { 30 | public: 31 | void Compute(const TransposeParam& param) const; 32 | bool Init(TransposeParam* param); 33 | }; 34 | } // namespace operators 35 | } // namespace paddle_mobile 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/box_coder_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef BOXCODER_OP 16 | 17 | #include "operators/kernel/box_coder_kernel.h" 18 | #include "operators/kernel/central-arm-func/box_coder_arm_func.h" 19 | 20 | namespace paddle_mobile { 21 | namespace operators { 22 | 23 | template <> 24 | bool BoxCoderKernel::Init(BoxCoderParam *param) { 25 | return true; 26 | } 27 | 28 | template <> 29 | void BoxCoderKernel::Compute(const BoxCoderParam ¶m) const { 30 | BoxCoderCompute(param); 31 | } 32 | 33 | } // namespace operators 34 | } // namespace paddle_mobile 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/fusion_fc_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef FUSION_FC_OP 16 | 17 | #include "operators/kernel/fusion_fc_kernel.h" 18 | #include "operators/kernel/central-arm-func/fusion_fc_arm_func.h" 19 | 20 | namespace paddle_mobile { 21 | namespace operators { 22 | 23 | template <> 24 | bool FusionFcKernel::Init(FusionFcParam *param) { 25 | return true; 26 | } 27 | 28 | template <> 29 | void FusionFcKernel::Compute(const FusionFcParam ¶m) const { 30 | FusionFcCompute(param); 31 | } 32 | 33 | } // namespace operators 34 | } // namespace paddle_mobile 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/prior_box_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef PRIORBOX_OP 16 | 17 | #include "operators/kernel/prior_box_kernel.h" 18 | #include "operators/kernel/central-arm-func/prior_box_arm_func.h" 19 | 20 | namespace paddle_mobile { 21 | namespace operators { 22 | 23 | template <> 24 | bool PriorBoxKernel::Init(PriorBoxParam *param) { 25 | return true; 26 | } 27 | 28 | template <> 29 | void PriorBoxKernel::Compute(const PriorBoxParam ¶m) const { 30 | PriorBoxCompute(param); 31 | } 32 | 33 | } // namespace operators 34 | } // namespace paddle_mobile 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/transpose_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | #ifdef TRANSPOSE_OP 15 | 16 | #include "operators/kernel/transpose_kernel.h" 17 | #include "operators/kernel/central-arm-func/transpose_arm_func.h" 18 | 19 | namespace paddle_mobile { 20 | namespace operators { 21 | 22 | template <> 23 | bool TransposeKernel::Init(TransposeParam *param) { 24 | return true; 25 | } 26 | 27 | template <> 28 | void TransposeKernel::Compute(const TransposeParam ¶m) const { 29 | TransposeCompute(param); 30 | } 31 | 32 | } // namespace operators 33 | } // namespace paddle_mobile 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/operators/kernel/multiclass_nms_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef MULTICLASSNMS_OP 16 | 17 | #pragma once 18 | 19 | #include "framework/operator.h" 20 | 21 | #include "operators/op_param.h" 22 | 23 | namespace paddle_mobile { 24 | namespace operators { 25 | 26 | template 27 | class MultiClassNMSKernel 28 | : public framework::OpKernelBase { 29 | public: 30 | void Compute(const MultiClassNMSParam& param) const; 31 | bool Init(MultiClassNMSParam* param); 32 | }; 33 | } // namespace operators 34 | } // namespace paddle_mobile 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/batchnorm_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef BATCHNORM_OP 16 | 17 | #include "operators/kernel/batchnorm_kernel.h" 18 | #include "operators/kernel/central-arm-func/batchnorm_arm_func.h" 19 | 20 | namespace paddle_mobile { 21 | namespace operators { 22 | 23 | template <> 24 | bool BatchNormKernel::Init(BatchNormParam *param) { 25 | return true; 26 | } 27 | 28 | template <> 29 | void BatchNormKernel::Compute(const BatchNormParam ¶m) const { 30 | BatchnormCompute(param); 31 | } 32 | 33 | } // namespace operators 34 | } // namespace paddle_mobile 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/operators/kernel/mul_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef MUL_OP 16 | 17 | #pragma once 18 | 19 | #include "framework/operator.h" 20 | #include "operators/math/math_function.h" 21 | #include "operators/op_param.h" 22 | 23 | namespace paddle_mobile { 24 | namespace operators { 25 | 26 | using namespace framework; 27 | 28 | template 29 | class MulKernel : public framework::OpKernelBase { 30 | public: 31 | void Compute(const MulParam ¶m) const; 32 | bool Init(MulParam *param); 33 | }; 34 | } // namespace operators 35 | } // namespace paddle_mobile 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/conv_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef CONV_OP 16 | 17 | #include "operators/kernel/conv_kernel.h" 18 | #include "operators/kernel/central-arm-func/conv_arm_func.h" 19 | 20 | namespace paddle_mobile { 21 | namespace operators { 22 | 23 | template <> 24 | bool ConvKernel::Init(ConvParam *param) { 25 | return true; 26 | } 27 | 28 | template <> 29 | void ConvKernel::Compute(const ConvParam ¶m) const { 30 | ConvCompute(param); 31 | } 32 | 33 | template class ConvKernel; 34 | 35 | } // namespace operators 36 | } // namespace paddle_mobile 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/operators/kernel/batchnorm_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef BATCHNORM_OP 16 | 17 | #pragma once 18 | 19 | #include "framework/operator.h" 20 | #include "operators/op_param.h" 21 | 22 | namespace paddle_mobile { 23 | namespace operators { 24 | 25 | using namespace framework; 26 | 27 | template 28 | class BatchNormKernel 29 | : public framework::OpKernelBase { 30 | public: 31 | void Compute(const BatchNormParam ¶m) const; 32 | bool Init(BatchNormParam *param); 33 | }; 34 | 35 | } // namespace operators 36 | } // namespace paddle_mobile 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/operators/kernel/fusion_fc_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef FUSION_FC_OP 16 | 17 | #pragma once 18 | 19 | #include "framework/operator.h" 20 | #include "operators/math/math_function.h" 21 | #include "operators/op_param.h" 22 | 23 | namespace paddle_mobile { 24 | namespace operators { 25 | 26 | template 27 | class FusionFcKernel 28 | : public framework::OpKernelBase { 29 | public: 30 | void Compute(const FusionFcParam& param) const; 31 | bool Init(FusionFcParam* param); 32 | }; 33 | } // namespace operators 34 | } // namespace paddle_mobile 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/operators/kernel/sigmoid_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef SIGMOID_OP 16 | 17 | #pragma once 18 | 19 | #include "framework/operator.h" 20 | #include "operators/op_param.h" 21 | namespace paddle_mobile { 22 | namespace operators { 23 | using framework::OpKernelBase; 24 | void sigmoid(const Tensor* X, Tensor* Y); 25 | template 26 | class SigmoidKernel : public OpKernelBase { 27 | public: 28 | void Compute(const SigmoidParam& param) const override; 29 | bool Init(SigmoidParam* param); 30 | }; 31 | } // namespace operators 32 | } // namespace paddle_mobile 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/operators/kernel/box_coder_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef BOXCODER_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #include "framework/operator.h" 22 | #include "operators/math/transform.h" 23 | #include "operators/op_param.h" 24 | 25 | namespace paddle_mobile { 26 | namespace operators { 27 | 28 | template 29 | class BoxCoderKernel 30 | : public framework::OpKernelBase { 31 | public: 32 | void Compute(const BoxCoderParam& param) const; 33 | bool Init(BoxCoderParam* param); 34 | }; 35 | } // namespace operators 36 | } // namespace paddle_mobile 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/conv_add_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | #ifdef FUSION_CONVADD_OP 15 | 16 | #include "operators/kernel/conv_add_kernel.h" 17 | #include "../central-arm-func/conv_add_arm_func.h" 18 | 19 | namespace paddle_mobile { 20 | namespace operators { 21 | 22 | template <> 23 | bool ConvAddKernel::Init(FusionConvAddParam *param) { 24 | return true; 25 | } 26 | 27 | template <> 28 | void ConvAddKernel::Compute(const FusionConvAddParam ¶m) const { 29 | ConvAddCompute(param); 30 | } 31 | 32 | template class ConvAddKernel; 33 | 34 | } // namespace operators 35 | } // namespace paddle_mobile 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/softmax_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef SOFTMAX_OP 16 | 17 | #include "../softmax_kernel.h" 18 | #include "../central-arm-func/softmax_arm_func.h" 19 | #include "operators/math/softmax.h" 20 | namespace paddle_mobile { 21 | namespace operators { 22 | 23 | template <> 24 | bool SoftmaxKernel::Init(SoftmaxParam *param) { 25 | return true; 26 | } 27 | 28 | template <> 29 | void SoftmaxKernel::Compute(const SoftmaxParam ¶m) const { 30 | SoftmaxCompute(param); 31 | } 32 | 33 | template class SoftmaxKernel; 34 | } // namespace operators 35 | } // namespace paddle_mobile 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/framework/program/program.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #pragma once 16 | 17 | #include "common/types.h" 18 | #include "framework/program/program_desc.h" 19 | #include "framework/scope.h" 20 | 21 | namespace paddle_mobile { 22 | namespace framework { 23 | 24 | template 25 | class Program { 26 | public: 27 | std::shared_ptr originProgram; 28 | std::shared_ptr optimizeProgram; 29 | std::shared_ptr scope; 30 | std::string model_path; 31 | std::string para_path; 32 | bool combined = false; 33 | 34 | private: 35 | }; 36 | 37 | } // namespace framework 38 | } // namespace paddle_mobile 39 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/multiclass_nms_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef MULTICLASSNMS_OP 16 | 17 | #include "operators/kernel/multiclass_nms_kernel.h" 18 | #include "operators/kernel/central-arm-func/multiclass_nms_arm_func.h" 19 | 20 | namespace paddle_mobile { 21 | namespace operators { 22 | 23 | template <> 24 | bool MultiClassNMSKernel::Init(MultiClassNMSParam *param) { 25 | return true; 26 | } 27 | 28 | template <> 29 | void MultiClassNMSKernel::Compute( 30 | const MultiClassNMSParam ¶m) const { 31 | MultiClassNMSCompute(param); 32 | } 33 | 34 | } // namespace operators 35 | } // namespace paddle_mobile 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /test/common/test_log.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "common/log.h" 16 | 17 | int main() { 18 | DLOGF("DASJFDAFJ%d -- %f", 12345, 344.234); 19 | 20 | LOGF(paddle_mobile::kLOG_DEBUG, "DASJFDAFJ%d -- %f", 12345, 344.234); 21 | 22 | LOG(paddle_mobile::kLOG_DEBUG) << "test debug" 23 | << " next log"; 24 | 25 | LOG(paddle_mobile::kLOG_DEBUG1) << "test debug1" 26 | << " next log"; 27 | LOG(paddle_mobile::kLOG_DEBUG2) << "test debug2" 28 | << " next log"; 29 | DLOG << "test DLOG"; 30 | 31 | LOG(paddle_mobile::kLOG_ERROR) << " error occur !"; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/elementwise_add_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef ELEMENTWISEADD_OP 16 | 17 | #include "operators/kernel/elementwise_add_kernel.h" 18 | #include "operators/kernel/central-arm-func/elementwise_add_arm_func.h" 19 | 20 | namespace paddle_mobile { 21 | namespace operators { 22 | 23 | template <> 24 | bool ElementwiseAddKernel::Init(ElementwiseAddParam *param) { 25 | return true; 26 | } 27 | 28 | template <> 29 | void ElementwiseAddKernel::Compute( 30 | const ElementwiseAddParam ¶m) const { 31 | ElementwiseAddCompute(param); 32 | } 33 | 34 | } // namespace operators 35 | } // namespace paddle_mobile 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /src/operators/math/pool_2x2.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef POOL_OP 16 | 17 | #pragma once 18 | 19 | #include "framework/tensor.h" 20 | #ifdef __ARM_NEON 21 | #include 22 | #endif // __ARM_NEON 23 | namespace paddle_mobile { 24 | namespace operators { 25 | namespace math { 26 | using framework::Tensor; 27 | using std::vector; 28 | 29 | void Pool2x2Max(vector strides, vector paddings, const Tensor *input, 30 | Tensor *output); 31 | 32 | void Pool2x2Avg(vector strides, vector paddings, const Tensor *in_x, 33 | Tensor *out); 34 | } // namespace math 35 | } // namespace operators 36 | } // namespace paddle_mobile 37 | #endif 38 | -------------------------------------------------------------------------------- /src/operators/sigmoid_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef SIGMOID_OP 16 | 17 | #include "operators/sigmoid_op.h" 18 | 19 | namespace paddle_mobile { 20 | namespace operators { 21 | template 22 | void SigmoidOp::InferShape() const { 23 | this->param_.Out()->Resize(this->param_.InputX()->dims()); 24 | } 25 | template class SigmoidOp; 26 | } // namespace operators 27 | } // namespace paddle_mobile 28 | 29 | namespace ops = paddle_mobile::operators; 30 | #ifdef PADDLE_MOBILE_CPU 31 | REGISTER_OPERATOR_CPU(sigmoid, ops::SigmoidOp); 32 | #endif 33 | #ifdef PADDLE_MOBILE_MALI_GPU 34 | #endif 35 | #ifdef PADDLE_MOBILE_FPGA 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/depthwise_conv_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef DEPTHWISECONV_OP 16 | 17 | #include "operators/kernel/depthwise_conv_kernel.h" 18 | #include "operators/kernel/central-arm-func/depthwise_conv_arm_func.h" 19 | 20 | namespace paddle_mobile { 21 | namespace operators { 22 | 23 | template <> 24 | bool DepthwiseConvKernel::Init(ConvParam *param) { 25 | return true; 26 | } 27 | 28 | template <> 29 | void DepthwiseConvKernel::Compute(const ConvParam ¶m) const { 30 | DepthwiseConvCompute(param); 31 | } 32 | 33 | template class DepthwiseConvKernel; 34 | 35 | } // namespace operators 36 | } // namespace paddle_mobile 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/operators/kernel/elementwise_add_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef ELEMENTWISEADD_OP 16 | 17 | #pragma once 18 | 19 | #include "framework/operator.h" 20 | #include "operators/math/elementwise_op_function.h" 21 | #include "operators/op_param.h" 22 | 23 | namespace paddle_mobile { 24 | namespace operators { 25 | 26 | using namespace framework; 27 | 28 | template 29 | class ElementwiseAddKernel 30 | : public framework::OpKernelBase { 31 | public: 32 | void Compute(const ElementwiseAddParam ¶m) const; 33 | bool Init(ElementwiseAddParam *param); 34 | }; 35 | } // namespace operators 36 | } // namespace paddle_mobile 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/operators/dropout_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef DROPOUT_OP 16 | #include "operators/dropout_op.h" 17 | namespace paddle_mobile { 18 | namespace operators { 19 | 20 | template 21 | void DropoutOp::InferShape() const { 22 | auto input_dims = this->param_.InputX()->dims(); 23 | this->param_.Out()->Resize(input_dims); 24 | } 25 | template class DropoutOp; 26 | } // namespace operators 27 | } // namespace paddle_mobile 28 | 29 | namespace ops = paddle_mobile::operators; 30 | #ifdef PADDLE_MOBILE_CPU 31 | REGISTER_OPERATOR_CPU(dropout, ops::DropoutOp); 32 | #endif 33 | #ifdef PADDLE_MOBILE_MALI_GPU 34 | #endif 35 | #ifdef PADDLE_MOBILE_FPGA 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/conv_add_relu_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef FUSION_CONVADD_RELU_OP 16 | 17 | #include "operators/kernel/conv_add_relu_kernel.h" 18 | #include "operators/kernel/central-arm-func/conv_add_relu_arm_func.h" 19 | 20 | namespace paddle_mobile { 21 | namespace operators { 22 | 23 | template <> 24 | bool ConvAddReluKernel::Init(FusionConvAddReluParam *param) { 25 | return true; 26 | } 27 | 28 | template <> 29 | void ConvAddReluKernel::Compute( 30 | const FusionConvAddReluParam ¶m) const { 31 | ConvAddReluCompute(param); 32 | } 33 | template class ConvAddReluKernel; 34 | 35 | } // namespace operators 36 | } // namespace paddle_mobile 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/framework/attribute.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "attribute.h" 16 | 17 | namespace paddle_mobile { 18 | namespace framework { 19 | 20 | struct PrintVistor : Vistor { 21 | explicit PrintVistor(Print &printer) : printer_(printer) {} 22 | template 23 | Print &operator()(const T &value) { 24 | printer_ << value; 25 | return printer_; 26 | } 27 | 28 | private: 29 | Print &printer_; 30 | }; 31 | 32 | Print &operator<<(Print &printer, const Attribute &attr) { 33 | Attribute::ApplyVistor(PrintVistor(printer), attr); 34 | // std::vector v = {"1", "2"}; 35 | // printer << (v); 36 | return printer; 37 | } 38 | 39 | } // namespace framework 40 | } // namespace paddle_mobile 41 | -------------------------------------------------------------------------------- /src/operators/kernel/conv_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef CONV_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | #include "framework/operator.h" 21 | #include "operators/math/im2col.h" 22 | #include "operators/math/math_function.h" 23 | #include "operators/math/vol2col.h" 24 | #include "operators/op_param.h" 25 | 26 | namespace paddle_mobile { 27 | namespace operators { 28 | 29 | using framework::OpKernelBase; 30 | 31 | template 32 | class ConvKernel : public OpKernelBase { 33 | public: 34 | void Compute(const ConvParam ¶m) const; 35 | bool Init(ConvParam *param); 36 | }; 37 | 38 | } // namespace operators 39 | } // namespace paddle_mobile 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/operators/kernel/depthwise_conv_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef DEPTHWISECONV_OP 16 | 17 | #pragma once 18 | 19 | #include "framework/operator.h" 20 | #include "operators/math/im2col.h" 21 | #include "operators/math/math_function.h" 22 | #include "operators/math/vol2col.h" 23 | #include "operators/op_param.h" 24 | 25 | namespace paddle_mobile { 26 | namespace operators { 27 | 28 | using framework::OpKernelBase; 29 | 30 | template 31 | class DepthwiseConvKernel : public OpKernelBase { 32 | public: 33 | void Compute(const ConvParam ¶m) const; 34 | bool Init(ConvParam *param); 35 | }; 36 | } // namespace operators 37 | } // namespace paddle_mobile 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/operators/lrn_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef LRN_OP 16 | 17 | #include "lrn_op.h" 18 | 19 | namespace paddle_mobile { 20 | namespace operators { 21 | 22 | template 23 | void LrnOp::InferShape() const { 24 | auto x_dims = this->param_.InputX()->dims(); 25 | this->param_.Out()->Resize(x_dims); 26 | } 27 | template class LrnOp; 28 | } // namespace operators 29 | } // namespace paddle_mobile 30 | 31 | namespace ops = paddle_mobile::operators; 32 | #ifdef PADDLE_MOBILE_CPU 33 | REGISTER_OPERATOR_CPU(lrn, ops::LrnOp); 34 | #endif 35 | #ifdef PADDLE_MOBILE_MALI_GPU 36 | REGISTER_OPERATOR_MALI_GPU(lrn, ops::LrnOp); 37 | #endif 38 | #ifdef PADDLE_MOBILE_FPGA 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/operators/softmax_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef SOFTMAX_OP 16 | 17 | #include "operators/softmax_op.h" 18 | 19 | namespace paddle_mobile { 20 | namespace operators { 21 | template 22 | void SoftmaxOp::InferShape() const { 23 | this->param_.Out()->Resize(this->param_.InputX()->dims()); 24 | } 25 | template class SoftmaxOp; 26 | } // namespace operators 27 | } // namespace paddle_mobile 28 | 29 | namespace ops = paddle_mobile::operators; 30 | #ifdef PADDLE_MOBILE_CPU 31 | REGISTER_OPERATOR_CPU(softmax, ops::SoftmaxOp); 32 | #endif 33 | #ifdef PADDLE_MOBILE_MALI_GPU 34 | REGISTER_OPERATOR_MALI_GPU(softmax, ops::SoftmaxOp); 35 | #endif 36 | #ifdef PADDLE_MOBILE_FPGA 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/operators/kernel/im2sequence_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef IM2SEQUENCE_OP 16 | 17 | #include "framework/operator.h" 18 | #include "operators/math/im2col.h" 19 | #include "operators/math/math_function.h" 20 | #include "operators/math/vol2col.h" 21 | #include "operators/op_param.h" 22 | 23 | #pragma once; 24 | 25 | namespace paddle_mobile { 26 | namespace operators { 27 | 28 | using namespace framework; 29 | 30 | template 31 | class Im2SequenceKernel 32 | : public framework::OpKernelBase { 33 | public: 34 | void Compute(const Im2SequenceParam& param) const; 35 | bool Init(Im2SequenceParam* para); 36 | }; 37 | } // namespace operators 38 | } // namespace paddle_mobile 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /test/operators/test_sigmoid_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "../../src/operators/kernel/sigmoid_kernel.h" 16 | #include "../test_helper.h" 17 | #include "io/executor.h" 18 | 19 | int main() { 20 | paddle_mobile::framework::Tensor input; 21 | paddle_mobile::framework::Tensor output; 22 | SetupTensor(&input, {1, 4, 60, 60}, static_cast(0), 23 | static_cast(1)); 24 | 25 | auto out_ddim = paddle_mobile::framework::make_ddim({1, 4, 60, 60}); 26 | output.Resize(out_ddim); 27 | paddle_mobile::operators::sigmoid(&input, &output); 28 | auto *output_ptr = output.data(); 29 | for (int j = 0; j < output.numel(); ++j) { 30 | DLOG << " value of output: " << output_ptr[j]; 31 | } 32 | DLOG << 5; 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/sigmoid_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef SIGMOID_OP 16 | 17 | #include "../sigmoid_kernel.h" 18 | #include "../central-arm-func/sigmoid_arm_func.h" 19 | #ifdef __ARM_NEON 20 | #include "../../math/math_func_neon.h" 21 | #endif 22 | #include 23 | namespace paddle_mobile { 24 | namespace operators { 25 | 26 | using framework::DDim; 27 | using framework::Tensor; 28 | 29 | template <> 30 | bool SigmoidKernel::Init(SigmoidParam *param) { 31 | return true; 32 | } 33 | 34 | template <> 35 | void SigmoidKernel::Compute(const SigmoidParam ¶m) const { 36 | SigmoidCompute(param); 37 | } 38 | 39 | template class SigmoidKernel; 40 | } // namespace operators 41 | } // namespace paddle_mobile 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/operators/slice_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef SLICE_OP 16 | 17 | #include "operators/slice_op.h" 18 | #include 19 | namespace paddle_mobile { 20 | namespace operators { 21 | 22 | template 23 | void SliceOp::InferShape() const { 24 | /// todo: add InputShape() detection. 25 | } 26 | template class SliceOp; 27 | } // namespace operators 28 | } // namespace paddle_mobile 29 | 30 | namespace ops = paddle_mobile::operators; 31 | #ifdef PADDLE_MOBILE_CPU 32 | USE_OP_CPU(slice); 33 | REGISTER_OPERATOR_CPU(slice, ops::SliceOp); 34 | #endif 35 | #ifdef PADDLE_MOBILE_MALI_GPU 36 | USE_OP_MALI_GPU(slice); 37 | REGISTER_OPERATOR_MALI_GPU(slice, ops::SliceOp); 38 | #endif 39 | #ifdef PADDLE_MOBILE_FPGA 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /test/framework/test_optimize.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "../test_helper.h" 16 | #include "framework/program/program-optimize/node.h" 17 | #include "framework/program/program-optimize/program_optimize.h" 18 | #include "io/loader.h" 19 | 20 | int main() { 21 | paddle_mobile::Loader loader; 22 | // "../../../test/models/googlenet" 23 | auto program = loader.Load(g_mobilenet_ssd, true); 24 | paddle_mobile::framework::ProgramOptimize optimize; 25 | // program.originProgram->Description("origin"); 26 | auto optimize_program = optimize.FusionOptimize(program.originProgram); 27 | if (optimize_program != nullptr) { 28 | // optimize_program->Description("optimize"); 29 | } else { 30 | LOG(paddle_mobile::kLOG_ERROR) << "optimize_program is null"; 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /src/operators/elementwise_add_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef ELEMENTWISEADD_OP 16 | 17 | #include "elementwise_add_op.h" 18 | 19 | namespace paddle_mobile { 20 | namespace operators { 21 | 22 | template 23 | void ElementwiseAddOp::InferShape() const { 24 | auto x_dim = this->param_.InputX()->dims(); 25 | this->param_.Out()->Resize(x_dim); 26 | } 27 | template class ElementwiseAddOp; 28 | } // namespace operators 29 | } // namespace paddle_mobile 30 | 31 | namespace ops = paddle_mobile::operators; 32 | #ifdef PADDLE_MOBILE_CPU 33 | REGISTER_OPERATOR_CPU(elementwise_add, ops::ElementwiseAddOp); 34 | #endif 35 | #ifdef PADDLE_MOBILE_MALI_GPU 36 | REGISTER_OPERATOR_MALI_GPU(elementwise_add, ops::ElementwiseAddOp); 37 | #endif 38 | #ifdef PADDLE_MOBILE_FPGA 39 | #endif 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/operators/scale_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef SCALE_OP 16 | 17 | #include "operators/scale_op.h" 18 | #include 19 | namespace paddle_mobile { 20 | namespace operators { 21 | 22 | template 23 | void ScaleOp::InferShape() const { 24 | auto input_dims = this->param_.InputX()->dims(); 25 | this->param_.Out()->Resize(input_dims); 26 | } 27 | template class ScaleOp; 28 | } // namespace operators 29 | } // namespace paddle_mobile 30 | 31 | namespace ops = paddle_mobile::operators; 32 | #ifdef PADDLE_MOBILE_CPU 33 | USE_OP_CPU(scale); 34 | REGISTER_OPERATOR_CPU(scale, ops::ScaleOp); 35 | #endif 36 | #ifdef PADDLE_MOBILE_MALI_GPU 37 | USE_OP_MALI_GPU(scale); 38 | REGISTER_OPERATOR_MALI_GPU(scale, ops::ScaleOp); 39 | #endif 40 | #ifdef PADDLE_MOBILE_FPGA 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /test/net/test_googlenet.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include 16 | #include "../test_helper.h" 17 | #include "../test_include.h" 18 | 19 | int main() { 20 | paddle_mobile::PaddleMobile paddle_mobile; 21 | paddle_mobile.SetThreadNum(4); 22 | bool optimize = true; 23 | auto time1 = time(); 24 | if (paddle_mobile.Load(g_googlenet, optimize)) { 25 | auto time2 = time(); 26 | DLOG << "load cost :" << time_diff(time1, time1) << "ms"; 27 | std::vector input; 28 | std::vector dims{1, 3, 224, 224}; 29 | GetInput(g_test_image_1x3x224x224, &input, dims); 30 | auto time3 = time(); 31 | auto vec_result = paddle_mobile.Predict(input, dims); 32 | auto time4 = time(); 33 | 34 | DLOG << "predict cost :" << time_diff(time3, time4) << "ms"; 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /src/operators/resize_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef RESIZE_OP 16 | 17 | #include "operators/resize_op.h" 18 | #include 19 | namespace paddle_mobile { 20 | namespace operators { 21 | 22 | template 23 | void ResizeOp::InferShape() const { 24 | auto out_dims = CalOutputShape(this->param_); 25 | this->param_.Out()->Resize(out_dims); 26 | } 27 | template class ResizeOp; 28 | } // namespace operators 29 | } // namespace paddle_mobile 30 | 31 | namespace ops = paddle_mobile::operators; 32 | #ifdef PADDLE_MOBILE_CPU 33 | USE_OP_CPU(resize); 34 | REGISTER_OPERATOR_CPU(resize, ops::ResizeOp); 35 | #endif 36 | #ifdef PADDLE_MOBILE_MALI_GPU 37 | USE_OP_MALI_GPU(resize); 38 | REGISTER_OPERATOR_MALI_GPU(resize, ops::ResizeOp); 39 | #endif 40 | #ifdef PADDLE_MOBILE_FPGA 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/ios_io/PaddleMobile.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #pragma once 16 | 17 | #import 18 | #import 19 | 20 | @interface PaddleMobile : NSObject 21 | 22 | /* 23 | 创建对象 24 | */ 25 | - (instancetype)init; 26 | 27 | /* 28 | load 模型, 开辟内存 29 | */ 30 | - (BOOL)load:(NSString *)modelPath andWeightsPath:(NSString *)weighsPath; 31 | 32 | /* 33 | 加载散开形式的模型, 需传入模型的目录 34 | */ 35 | - (BOOL)load:(NSString *)modelAndWeightPath; 36 | 37 | /* 38 | 进行预测, means 和 scale 为训练模型时的预处理参数, 如训练时没有做这些预处理则直接使用 predict 39 | */ 40 | - (NSArray *)predict:(CGImageRef)image dim:(NSArray *)dim means:(NSArray *)means scale:(float)scale; 41 | 42 | /* 43 | 进行预测 44 | */ 45 | - (NSArray *)predict:(CGImageRef)image dim:(NSArray *)dim; 46 | 47 | /* 48 | 清理内存 49 | */ 50 | - (void)clear; 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /src/operators/batchnorm_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef BATCHNORM_OP 16 | 17 | #include "batchnorm_op.h" 18 | #include "framework/op_proto_maker.h" 19 | #include "framework/op_registry.h" 20 | 21 | namespace paddle_mobile { 22 | namespace operators { 23 | 24 | template 25 | void BatchNormOp::InferShape() const { 26 | auto x_dims = this->param_.InputX()->dims(); 27 | this->param_.OutputY()->Resize(x_dims); 28 | } 29 | template class BatchNormOp; 30 | } // namespace operators 31 | } // namespace paddle_mobile 32 | 33 | namespace ops = paddle_mobile::operators; 34 | #ifdef PADDLE_MOBILE_CPU 35 | REGISTER_OPERATOR_CPU(batch_norm, ops::BatchNormOp); 36 | #endif 37 | #ifdef PADDLE_MOBILE_MALI_GPU 38 | REGISTER_OPERATOR_MALI_GPU(batch_norm, ops::BatchNormOp); 39 | #endif 40 | #ifdef PADDLE_MOBILE_FPGA 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/operators/relu_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef RELU_OP 16 | 17 | #include "operators/relu_op.h" 18 | namespace paddle_mobile { 19 | namespace operators { 20 | 21 | template 22 | void ReluOp::InferShape() const { 23 | auto input_dims = this->param_.InputX()->dims(); 24 | this->param_.Out()->Resize(input_dims); 25 | } 26 | template class ReluOp; 27 | } // namespace operators 28 | } // namespace paddle_mobile 29 | 30 | /* 31 | * @b 每一个 op 都需要注册一下的, 32 | * USE_OP的参数 和 REGISTER_OPERATOR的第一个参数 33 | * 都是需要和model中类型对应起来的 34 | * */ 35 | namespace ops = paddle_mobile::operators; 36 | #ifdef PADDLE_MOBILE_CPU 37 | REGISTER_OPERATOR_CPU(relu, ops::ReluOp); 38 | #endif 39 | #ifdef PADDLE_MOBILE_MALI_GPU 40 | REGISTER_OPERATOR_MALI_GPU(relu, ops::ReluOp); 41 | #endif 42 | #ifdef PADDLE_MOBILE_FPGA 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/memory/t_malloc.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "memory/t_malloc.h" 16 | #include 17 | #include 18 | 19 | namespace paddle_mobile { 20 | namespace memory { 21 | const int MALLOC_ALIGN = 64; 22 | 23 | void Copy(void *dst, const void *src, size_t num) { 24 | std::memcpy(dst, src, num); 25 | } 26 | 27 | void *Alloc(size_t size) { 28 | size_t offset = sizeof(void *) + MALLOC_ALIGN - 1; 29 | char *p = static_cast(malloc(offset + size)); 30 | if (!p) { 31 | return nullptr; 32 | } 33 | void *r = reinterpret_cast(reinterpret_cast(p + offset) & 34 | (~(MALLOC_ALIGN - 1))); 35 | static_cast(r)[-1] = p; 36 | return r; 37 | } 38 | 39 | void Free(void *ptr) { 40 | if (ptr) { 41 | free(static_cast(ptr)[-1]); 42 | } 43 | } 44 | 45 | } // namespace memory 46 | } // namespace paddle_mobile 47 | -------------------------------------------------------------------------------- /src/operators/math/pool_3x3.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef POOL_OP 16 | 17 | #pragma once 18 | #ifdef _OPENMP 19 | #include 20 | #endif 21 | #include 22 | #include 23 | #include "framework/tensor.h" 24 | #if __ARM_NEON 25 | #include 26 | #endif // __ARM_NEON 27 | 28 | namespace paddle_mobile { 29 | namespace operators { 30 | namespace math { 31 | using framework::Tensor; 32 | using std::vector; 33 | void Pool3x3Avgs1p1(const Tensor *input, Tensor *output); 34 | void Pool3x3Maxs1p1(const Tensor *input, Tensor *output); 35 | void Pool3x3Max(vector strides, vector paddings, const Tensor *input, 36 | Tensor *output); 37 | 38 | void Pool3x3Avg(vector strides, vector paddings, const Tensor *in_x, 39 | Tensor *out); 40 | } // namespace math 41 | } // namespace operators 42 | } // namespace paddle_mobile 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/operators/kernel/central-arm-func/elementwise_add_arm_func.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef ELEMENTWISEADD_OP 16 | 17 | #pragma once 18 | 19 | namespace paddle_mobile { 20 | namespace operators { 21 | 22 | template 23 | struct AddFunctor { 24 | inline T operator()(T a, T b) const { return a + b; } 25 | }; 26 | 27 | template 28 | void ElementwiseAddCompute(const ElementwiseAddParam ¶m) { 29 | const Tensor *input_x = param.InputX(); 30 | const Tensor *input_y = param.InputY(); 31 | Tensor *Out = param.Out(); 32 | Out->mutable_data(); 33 | int axis = param.Axis(); 34 | ElementwiseComputeEx, float>(input_x, input_y, axis, 35 | AddFunctor(), Out); 36 | } 37 | 38 | template class ElementwiseAddKernel; 39 | 40 | } // namespace operators 41 | } // namespace paddle_mobile 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /src/operators/kernel/conv_add_relu_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #pragma once 16 | 17 | #ifdef FUSION_CONVADD_RELU_OP 18 | 19 | #include 20 | #include "framework/ddim.h" 21 | #include "framework/operator.h" 22 | #include "operators/math/conv_func.h" 23 | #include "operators/math/im2col.h" 24 | #include "operators/math/math_function.h" 25 | #include "operators/math/vol2col.h" 26 | #include "operators/op_param.h" 27 | 28 | namespace paddle_mobile { 29 | namespace operators { 30 | 31 | using framework::DDim; 32 | using framework::OpKernelBase; 33 | 34 | template 35 | class ConvAddReluKernel 36 | : public OpKernelBase { 37 | public: 38 | void Compute(const FusionConvAddReluParam ¶m) const; 39 | bool Init(FusionConvAddReluParam *param); 40 | }; 41 | 42 | } // namespace operators 43 | } // namespace paddle_mobile 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/operators/kernel/conv_add_bn_relu_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #pragma once 16 | 17 | #ifdef FUSION_CONVADDBNRELU_OP 18 | 19 | #include 20 | #include "framework/ddim.h" 21 | #include "framework/operator.h" 22 | #include "operators/math/conv_func.h" 23 | #include "operators/math/im2col.h" 24 | #include "operators/math/math_function.h" 25 | #include "operators/math/vol2col.h" 26 | #include "operators/op_param.h" 27 | 28 | namespace paddle_mobile { 29 | namespace operators { 30 | 31 | using framework::DDim; 32 | using framework::OpKernelBase; 33 | 34 | template 35 | class ConvAddBNReluKernel 36 | : public OpKernelBase { 37 | public: 38 | void Compute(const FusionConvAddBNReluParam ¶m) const; 39 | bool Init(FusionConvAddBNReluParam *param); 40 | }; 41 | 42 | } // namespace operators 43 | } // namespace paddle_mobile 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/operators/math/math_function.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #pragma once 16 | 17 | #include 18 | #include "framework/tensor.h" 19 | 20 | namespace paddle_mobile { 21 | namespace operators { 22 | namespace math { 23 | 24 | // matrix multiply with continuous memory 25 | template 26 | void matmul(const framework::Tensor &matrix_a, bool trans_a, 27 | const framework::Tensor &matrix_b, bool trans_b, T alpha, 28 | framework::Tensor *matrix_out, T beta, bool relu = false); 29 | 30 | template 31 | void matmulWithBn(const framework::Tensor &matrix_a, bool trans_a, 32 | const framework::Tensor &matrix_b, bool trans_b, T alpha, 33 | framework::Tensor *matrix_out, T beta, bool relu, 34 | framework::Tensor *new_scale, framework::Tensor *new_bias); 35 | } // namespace math 36 | } // namespace operators 37 | } // namespace paddle_mobile 38 | -------------------------------------------------------------------------------- /src/operators/prelu_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef PRELU_OP 16 | 17 | #include "operators/prelu_op.h" 18 | namespace paddle_mobile { 19 | namespace operators { 20 | 21 | template 22 | void PReluOp::InferShape() const { 23 | auto input_dims = this->param_.InputX()->dims(); 24 | this->param_.Out()->Resize(input_dims); 25 | } 26 | template class PReluOp; 27 | } // namespace operators 28 | } // namespace paddle_mobile 29 | 30 | /* 31 | * @b 每一个 op 都需要注册一下的, 32 | * USE_OP的参数 和 REGISTER_OPERATOR的第一个参数 33 | * 都是需要和model中类型对应起来的 34 | * */ 35 | namespace ops = paddle_mobile::operators; 36 | #ifdef PADDLE_MOBILE_CPU 37 | USE_OP_CPU(prelu); 38 | REGISTER_OPERATOR_CPU(prelu, ops::PReluOp); 39 | #endif 40 | #ifdef PADDLE_MOBILE_MALI_GPU 41 | USE_OP_MALI_GPU(prelu); 42 | REGISTER_OPERATOR_MALI_GPU(prelu, ops::PReluOp); 43 | #endif 44 | #ifdef PADDLE_MOBILE_FPGA 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/operators/kernel/central-arm-func/lrn_arm_func.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef LRN_OP 16 | 17 | #pragma once 18 | 19 | namespace paddle_mobile { 20 | namespace operators { 21 | 22 | template 23 | void LrnCompute(const LrnParam ¶m) { 24 | const Tensor *input_x = param.InputX(); 25 | auto x_dims = input_x->dims(); 26 | Tensor *out = param.Out(); 27 | out->mutable_data(); 28 | /// data_format = NCHW 29 | const int N = x_dims[0]; 30 | const int C = x_dims[1]; 31 | const int H = x_dims[2]; 32 | const int W = x_dims[3]; 33 | 34 | const int n = param.N(); 35 | const float alpha = param.Alpha(); 36 | const float beta = param.Beta(); 37 | const float k = param.K(); 38 | LRNFunctor lrnFunctor; 39 | lrnFunctor(*input_x, out, N, C, H, W, n, k, alpha, beta); 40 | } 41 | 42 | template class LrnKernel; 43 | 44 | } // namespace operators 45 | } // namespace paddle_mobile 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/operators/reshape_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef RESHAPE_OP 16 | 17 | #include "operators/reshape_op.h" 18 | #include 19 | namespace paddle_mobile { 20 | namespace operators { 21 | 22 | template 23 | void ReshapeOp::InferShape() const { 24 | /// todo: add InputShape() detection. 25 | auto &shape = this->param_.Shape(); 26 | auto input_x_dims = this->param_.InputX()->dims(); 27 | auto out_dims = ValidateShape(shape, input_x_dims); 28 | this->param_.Out()->Resize(out_dims); 29 | } 30 | template class ReshapeOp; 31 | } // namespace operators 32 | } // namespace paddle_mobile 33 | 34 | namespace ops = paddle_mobile::operators; 35 | #ifdef PADDLE_MOBILE_CPU 36 | REGISTER_OPERATOR_CPU(reshape, ops::ReshapeOp); 37 | #endif 38 | #ifdef PADDLE_MOBILE_MALI_GPU 39 | REGISTER_OPERATOR_MALI_GPU(reshape, ops::ReshapeOp); 40 | #endif 41 | #ifdef PADDLE_MOBILE_FPGA 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /test/net/test_resnet.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include 16 | #include "../test_helper.h" 17 | #include "../test_include.h" 18 | 19 | int main() { 20 | paddle_mobile::PaddleMobile paddle_mobile; 21 | auto time1 = time(); 22 | if (paddle_mobile.Load(g_resnet, false)) { 23 | auto time2 = time(); 24 | DLOG << "load cost :" << time_diff(time1, time1) << "ms"; 25 | std::vector dims{1, 3, 32, 32}; 26 | Tensor input_tensor; 27 | SetupTensor(&input_tensor, {1, 3, 32, 32}, static_cast(0), 28 | static_cast(1)); 29 | 30 | std::vector input(input_tensor.data(), 31 | input_tensor.data() + input_tensor.numel()); 32 | auto time3 = time(); 33 | paddle_mobile.Predict(input, dims); 34 | auto time4 = time(); 35 | DLOG << "predict cost :" << time_diff(time3, time4) << "ms"; 36 | } 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /src/ios_io/op_symbols.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #pragma once 16 | 17 | #include "operators/batchnorm_op.h" 18 | #include "operators/box_coder_op.h" 19 | #include "operators/concat_op.h" 20 | #include "operators/conv_op.h" 21 | #include "operators/depthwise_conv_op.h" 22 | #include "operators/dropout_op.h" 23 | #include "operators/elementwise_add_op.h" 24 | #include "operators/feed_op.h" 25 | #include "operators/fetch_op.h" 26 | #include "operators/fusion_conv_add.h" 27 | #include "operators/fusion_conv_add_bn_relu_op.h" 28 | #include "operators/fusion_fc_op.h" 29 | #include "operators/im2sequence_op.h" 30 | #include "operators/lrn_op.h" 31 | #include "operators/mul_op.h" 32 | #include "operators/multiclass_nms_op.h" 33 | #include "operators/pool_op.h" 34 | #include "operators/prior_box_op.h" 35 | #include "operators/relu_op.h" 36 | #include "operators/reshape_op.h" 37 | #include "operators/sigmoid_op.h" 38 | #include "operators/softmax_op.h" 39 | #include "operators/transpose_op.h" 40 | -------------------------------------------------------------------------------- /test/net/test_mobilenet+ssd.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include 16 | #include "../test_helper.h" 17 | #include "../test_include.h" 18 | 19 | int main() { 20 | paddle_mobile::PaddleMobile paddle_mobile; 21 | auto time1 = time(); 22 | if (paddle_mobile.Load(g_mobilenet_ssd, true)) { 23 | auto time2 = time(); 24 | DLOG << "load cost :" << time_diff(time1, time1) << "ms"; 25 | 26 | std::vector dims{1, 3, 300, 300}; 27 | Tensor input_tensor; 28 | SetupTensor(&input_tensor, {1, 3, 300, 300}, static_cast(0), 29 | static_cast(1)); 30 | 31 | std::vector input(input_tensor.data(), 32 | input_tensor.data() + input_tensor.numel()); 33 | auto time3 = time(); 34 | paddle_mobile.Predict(input, dims); 35 | auto time4 = time(); 36 | DLOG << "predict cost :" << time_diff(time3, time4) << "ms"; 37 | } 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /src/operators/kernel/arm/dropout_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef DROPOUT_OP 16 | 17 | #pragma once 18 | 19 | #include "operators/kernel/dropout_kernel.h" 20 | #include 21 | 22 | namespace paddle_mobile { 23 | namespace operators { 24 | 25 | template <> 26 | bool DropoutKernel::Init(DropoutParam *para) { 27 | return true; 28 | } 29 | 30 | template 31 | struct DropoutFunctor { 32 | inline T operator()(T in) const { return in; } 33 | }; 34 | 35 | template <> 36 | void DropoutKernel::Compute(const DropoutParam ¶m) const { 37 | const auto *input_x = param.InputX(); 38 | auto *input_x_ptr = input_x->data(); 39 | auto *out = param.Out(); 40 | auto *out_ptr = out->mutable_data(); 41 | 42 | DropoutFunctor func_; 43 | math::Transform trans; 44 | trans(input_x_ptr, input_x_ptr + input_x->numel(), out_ptr, func_); 45 | } 46 | } // namespace operators 47 | } // namespace paddle_mobile 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/operators/kernel/conv_add_kernel.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef FUSION_CONVADD_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | #ifdef __ARM_NEON 21 | #include 22 | #endif 23 | #include "common/common.h" 24 | #include "framework/ddim.h" 25 | #include "framework/operator.h" 26 | #include "operators/math/conv_func.h" 27 | #include "operators/math/depthwise_conv_3x3.h" 28 | #include "operators/math/im2col.h" 29 | #include "operators/math/math_function.h" 30 | #include "operators/math/vol2col.h" 31 | #include "operators/op_param.h" 32 | 33 | namespace paddle_mobile { 34 | namespace operators { 35 | 36 | using framework::DDim; 37 | using framework::OpKernelBase; 38 | 39 | template 40 | class ConvAddKernel : public OpKernelBase { 41 | public: 42 | void Compute(const FusionConvAddParam ¶m) const; 43 | bool Init(FusionConvAddParam *param); 44 | }; 45 | 46 | } // namespace operators 47 | } // namespace paddle_mobile 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /test/net/test_mobilenet.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include 16 | #include "../test_helper.h" 17 | #include "../test_include.h" 18 | 19 | int main() { 20 | paddle_mobile::PaddleMobile paddle_mobile; 21 | paddle_mobile.SetThreadNum(4); 22 | auto time1 = time(); 23 | if (paddle_mobile.Load(g_mobilenet, true)) { 24 | auto time2 = time(); 25 | DLOG << "load cost :" << time_diff(time1, time1) << "ms"; 26 | 27 | std::vector dims{1, 3, 224, 224}; 28 | Tensor input_tensor; 29 | SetupTensor(&input_tensor, {1, 3, 224, 224}, static_cast(0), 30 | static_cast(1)); 31 | 32 | std::vector input(input_tensor.data(), 33 | input_tensor.data() + input_tensor.numel()); 34 | auto time3 = time(); 35 | auto vec_result = paddle_mobile.Predict(input, dims); 36 | auto time4 = time(); 37 | 38 | DLOG << "predict cost :" << time_diff(time3, time4) << "ms"; 39 | } 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /test/net/test_yolo.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include 16 | #include "../test_helper.h" 17 | #include "../test_include.h" 18 | 19 | int main() { 20 | paddle_mobile::PaddleMobile paddle_mobile; 21 | // ../../../test/models/googlenet 22 | // ../../../test/models/mobilenet 23 | auto time1 = time(); 24 | if (paddle_mobile.Load(g_yolo, false)) { 25 | auto time2 = time(); 26 | DLOG << "load cost :" << time_diff(time1, time1) << "ms"; 27 | 28 | std::vector dims{1, 3, 227, 227}; 29 | Tensor input_tensor; 30 | SetupTensor(&input_tensor, {1, 3, 227, 227}, static_cast(0), 31 | static_cast(1)); 32 | 33 | std::vector input(input_tensor.data(), 34 | input_tensor.data() + input_tensor.numel()); 35 | auto time3 = time(); 36 | paddle_mobile.Predict(input, dims); 37 | auto time4 = time(); 38 | DLOG << "predict cost :" << time_diff(time3, time4) << "ms"; 39 | } 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /test/operators/test_softmax_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "../test_include.h" 16 | 17 | #include "operators/softmax_op.h" 18 | 19 | int main() { 20 | paddle_mobile::Loader loader; 21 | auto program = loader.Load(std::string(g_mobilenet)); 22 | if (program.originProgram == nullptr) { 23 | DLOG << "program read file"; 24 | } 25 | Executor4Test> 27 | executor(program, "softmax"); 28 | paddle_mobile::framework::Tensor input; 29 | SetupTensor(&input, {1, 1000}, static_cast(0), 30 | static_cast(1)); 31 | auto out_ddim = paddle_mobile::framework::make_ddim({1, 1000}); 32 | auto output = 33 | executor.Predict(input, "reshape_0.tmp_0", "softmax_0.tmp_0", out_ddim); 34 | auto *output_ptr = output->data(); 35 | for (int j = 0; j < output->numel(); ++j) { 36 | DLOG << " value of output: " << output_ptr[j]; 37 | } 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /test/net/test_squeezenet.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include 16 | #include "../test_helper.h" 17 | #include "../test_include.h" 18 | 19 | int main() { 20 | paddle_mobile::PaddleMobile paddle_mobile; 21 | // ../../../test/models/googlenet 22 | // ../../../test/models/mobilenet 23 | auto time1 = time(); 24 | if (paddle_mobile.Load(g_squeezenet, false)) { 25 | auto time2 = time(); 26 | DLOG << "load cost :" << time_diff(time1, time1) << "ms"; 27 | std::vector dims{1, 3, 227, 227}; 28 | Tensor input_tensor; 29 | SetupTensor(&input_tensor, {1, 3, 227, 227}, static_cast(0), 30 | static_cast(1)); 31 | 32 | std::vector input(input_tensor.data(), 33 | input_tensor.data() + input_tensor.numel()); 34 | auto time3 = time(); 35 | paddle_mobile.Predict(input, dims); 36 | auto time4 = time(); 37 | DLOG << "predict cost :" << time_diff(time3, time4) << "ms"; 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /test/operators/test_pool_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "../test_include.h" 16 | #include "operators/pool_op.h" 17 | 18 | int main() { 19 | paddle_mobile::Loader loader; 20 | auto program = loader.Load(std::string(g_googlenet)); 21 | if (program.originProgram == nullptr) { 22 | DLOG << "program read file"; 23 | } 24 | 25 | Executor4Test> 27 | executor(program, "pool2d"); 28 | 29 | paddle_mobile::framework::Tensor input; 30 | SetupTensor(&input, {1, 64, 112, 112}, static_cast(0), 31 | static_cast(1)); 32 | auto out_ddim = paddle_mobile::framework::make_ddim({1, 64, 56, 56}); 33 | auto output = 34 | executor.Predict(input, "conv2d_0.tmp_1", "pool2d_0.tmp_0", out_ddim); 35 | 36 | float *output_ptr = output->data(); 37 | for (int j = 0; j < output->numel(); ++j) { 38 | DLOG << " value of output: " << output_ptr[j]; 39 | } 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /src/framework/program/program_desc.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #pragma once 16 | 17 | #include 18 | 19 | #include "common/types.h" 20 | #include "framework/framework.pb-c.h" 21 | #include "framework/program/block_desc.h" 22 | 23 | namespace paddle_mobile { 24 | namespace framework { 25 | 26 | class ProgramDesc { 27 | public: 28 | friend class Node; 29 | friend class ProgramOptimize; 30 | explicit ProgramDesc(PaddleMobile__Framework__Proto__ProgramDesc *desc); 31 | 32 | std::shared_ptr Block(size_t idx); 33 | 34 | const std::vector> &Blocks() { return blocks_; } 35 | ProgramDesc(const ProgramDesc &program_desc) { 36 | for (auto &block : program_desc.blocks_) { 37 | std::shared_ptr copy_block = 38 | std::make_shared(*block); 39 | blocks_.push_back(copy_block); 40 | } 41 | } 42 | 43 | void Description(std::string header = ""); 44 | 45 | private: 46 | std::vector> blocks_; 47 | }; 48 | 49 | } // namespace framework 50 | } // namespace paddle_mobile 51 | -------------------------------------------------------------------------------- /src/operators/kernel/mali/elementwise_add_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef ELEMENTWISEADD_OP 16 | 17 | #pragma once 18 | 19 | #include "operators/kernel/elementwise_add_kernel.h" 20 | 21 | namespace paddle_mobile { 22 | namespace operators { 23 | 24 | template 25 | struct AddFunctor { 26 | inline T operator()(T a, T b) const { return a + b; } 27 | }; 28 | 29 | template <> 30 | bool ElementwiseAddKernel::Init(ElementwiseAddParam *param) { 31 | return true; 32 | } 33 | 34 | template <> 35 | void ElementwiseAddKernel::Compute( 36 | const ElementwiseAddParam ¶m) const { 37 | const Tensor *input_x = param.InputX(); 38 | const Tensor *input_y = param.InputY(); 39 | Tensor *Out = param.Out(); 40 | Out->mutable_data(); 41 | int axis = param.Axis(); 42 | ElementwiseComputeEx, float>(input_x, input_y, axis, 43 | AddFunctor(), Out); 44 | } 45 | 46 | template class ElementwiseAddKernel; 47 | 48 | } // namespace operators 49 | } // namespace paddle_mobile 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:16.04 2 | 3 | RUN echo '\ 4 | deb main restricted universe multiverse\n\ 5 | deb -updates main restricted universe multiverse\n\ 6 | deb -backports main restricted universe multiverse\n\ 7 | deb -security main restricted universe multiverse\n'\ 8 | > /etc/apt/sources.list 9 | RUN sed -ie 's||http://mirrors.tuna.tsinghua.edu.cn/ubuntu/|' /etc/apt/sources.list 10 | RUN sed -ie 's||xenial|' /etc/apt/sources.list 11 | 12 | RUN apt-get update && apt-get upgrade -y 13 | RUN apt-get install -y --no-install-recommends \ 14 | curl \ 15 | unzip \ 16 | git \ 17 | make \ 18 | cmake-curses-gui \ 19 | python \ 20 | python-pip \ 21 | python-setuptools \ 22 | clang-format-5.0 \ 23 | graphviz \ 24 | g++-arm-linux-gnueabi \ 25 | gcc-arm-linux-gnueabi 26 | RUN apt-get autoremove -y && apt-get clean 27 | RUN ln -s clang-format-5.0 /usr/bin/clang-format 28 | RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip 29 | RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple wheel 30 | RUN pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pre-commit 31 | RUN cd /tmp && curl -O http://mirrors.neusoft.edu.cn/android/repository/android-ndk-r17b-linux-x86_64.zip 32 | RUN curl -O https://mms-res.cdn.bcebos.com/cmake-3.10.3-Linux-x86_64.tar.gz && \ 33 | tar xzf cmake-3.10.3-Linux-x86_64.tar.gz && \ 34 | mv cmake-3.10.3-Linux-x86_64 /opt/cmake-3.10 && \ 35 | mv /usr/bin/cmake /usr/bin/cmake.bak && ln -s /opt/cmake-3.10/bin/cmake /usr/bin/cmake 36 | RUN cd /opt && unzip /tmp/android-ndk-r17b-linux-x86_64.zip 37 | ENV NDK_ROOT /opt/android-ndk-r17b 38 | -------------------------------------------------------------------------------- /src/common/type_define.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #pragma once 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "framework/attribute.h" 22 | #include "framework/scope.h" 23 | 24 | namespace paddle_mobile { 25 | 26 | namespace framework { 27 | template 28 | class OperatorBase; 29 | class OpDesc; 30 | class BlockDesc; 31 | class InferShapeContext; 32 | } // namespace framework 33 | 34 | using VariableNameMap = std::map>; 35 | 36 | template 37 | using OpCreator = std::function *( 38 | const std::string & /*type*/, const VariableNameMap & /*inputs*/, 39 | const VariableNameMap & /*outputs*/, 40 | const framework::AttributeMap & /*attrs*/, 41 | std::shared_ptr /*scope*/)>; 42 | 43 | using InferVarTypeFN = std::function; 45 | 46 | using InferShapeFN = std::function; 47 | }; // namespace paddle_mobile 48 | -------------------------------------------------------------------------------- /src/framework/program/block_desc.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "block_desc.h" 16 | #include 17 | 18 | namespace paddle_mobile { 19 | namespace framework { 20 | 21 | std::vector> BlockDesc::Vars() const { return vars_; } 22 | 23 | std::vector> BlockDesc::Ops() const { return ops_; } 24 | 25 | BlockDesc::BlockDesc(PaddleMobile__Framework__Proto__BlockDesc *desc) 26 | : index_(desc->idx), parent_index_(desc->idx) { 27 | for (int i = 0; i < desc->n_vars; ++i) { 28 | PaddleMobile__Framework__Proto__VarDesc *var_desc = desc->vars[i]; 29 | vars_.emplace_back(std::shared_ptr(new VarDesc(var_desc))); 30 | } 31 | 32 | std::sort(vars_.begin(), vars_.end(), 33 | [](std::shared_ptr left, std::shared_ptr right) { 34 | return left->Name() < right->Name(); 35 | }); 36 | 37 | for (int j = 0; j < desc->n_ops; ++j) { 38 | PaddleMobile__Framework__Proto__OpDesc *op_desc = desc->ops[j]; 39 | ops_.emplace_back(new framework::OpDesc(op_desc)); 40 | } 41 | } 42 | 43 | } // namespace framework 44 | } // namespace paddle_mobile 45 | -------------------------------------------------------------------------------- /src/operators/kernel/central-arm-func/reshape_arm_func.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef RESHAPE_OP 16 | #pragma once 17 | 18 | #include 19 | 20 | namespace paddle_mobile { 21 | namespace operators { 22 | 23 | template 24 | void ReshapeCompute(const ReshapeParam ¶m) { 25 | const auto *input_x = param.InputX(); 26 | const auto &input_x_dims = input_x->dims(); 27 | auto *out = param.Out(); 28 | framework::DDim out_dims = out->dims(); 29 | const auto *input_shape = param.InputShape(); 30 | 31 | if (input_shape) { 32 | auto *shape_data = input_shape->data(); 33 | framework::Tensor cpu_shape_tensor; 34 | auto shape = 35 | std::vector(shape_data, shape_data + input_shape->numel()); 36 | out_dims = ValidateShape(shape, input_x->dims()); 37 | } 38 | 39 | bool inplace = param.Inplace(); 40 | out->Resize(out_dims); 41 | if (!inplace) { 42 | out->mutable_data(); 43 | framework::TensorCopy(*input_x, out); 44 | out->Resize(out_dims); 45 | } else { 46 | out->ShareDataWith(*input_x); 47 | out->Resize(out_dims); 48 | } 49 | } 50 | 51 | } // namespace operators 52 | } // namespace paddle_mobile 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /src/io/loader.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #pragma once 16 | 17 | #include 18 | 19 | #include "common/types.h" 20 | #include "framework/program/program.h" 21 | 22 | namespace paddle_mobile { 23 | 24 | template 25 | class Loader { 26 | public: 27 | /* 28 | * @b load separate format fluid model 29 | * @b 加载分开形式的 fluid 模型 30 | * */ 31 | const framework::Program Load(const std::string &dirname, 32 | bool optimize = false, 33 | bool can_add_split = false); 34 | 35 | /* 36 | * @b load combine format fluid mode 37 | * @b 加载结合在一起格式的模型 38 | * */ 39 | const framework::Program Load(const std::string &model_path, 40 | const std::string ¶_path, 41 | bool optimize = false); 42 | 43 | private: 44 | const framework::Program LoadProgram(const std::string &model_path, 45 | bool optimize = false, 46 | bool can_add_split = false); 47 | }; 48 | 49 | } // namespace paddle_mobile 50 | -------------------------------------------------------------------------------- /src/operators/kernel/central-arm-func/mul_arm_func.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef MUL_OP 16 | 17 | #pragma once 18 | 19 | namespace paddle_mobile { 20 | namespace operators { 21 | 22 | template 23 | void MulCompute(const MulParam ¶m) { 24 | const Tensor *input_x = param.InputX(); 25 | const Tensor *input_y = param.InputY(); 26 | Tensor *out = param.Out(); 27 | out->mutable_data(); 28 | const Tensor x_matrix = 29 | input_x->dims().size() > 2 30 | ? framework::ReshapeToMatrix(*input_x, param.XNumColDims()) 31 | : *input_x; 32 | const Tensor y_matrix = 33 | input_y->dims().size() > 2 34 | ? framework::ReshapeToMatrix(*input_y, param.YNumColDims()) 35 | : *input_y; 36 | auto out_dim = out->dims(); 37 | if (out_dim.size() != 2) { 38 | out->Resize({x_matrix.dims()[0], y_matrix.dims()[1]}); 39 | } 40 | math::matmul(x_matrix, false, y_matrix, false, static_cast(1), 41 | out, static_cast(0)); 42 | if (out_dim.size() != 2) { 43 | out->Resize(out_dim); 44 | } 45 | } 46 | 47 | template class MulKernel; 48 | 49 | } // namespace operators 50 | } // namespace paddle_mobile 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/framework/program/program-optimize/program_optimize.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #pragma once 16 | 17 | #include 18 | #include 19 | 20 | #include "framework/operator.h" 21 | #include "framework/program/program-optimize/node.h" 22 | #include "framework/program/program_desc.h" 23 | 24 | namespace paddle_mobile { 25 | 26 | namespace framework { 27 | class ProgramOptimize { 28 | public: 29 | ProgramOptimize() {} 30 | std::shared_ptr FusionOptimize( 31 | std::shared_ptr ori_des, bool add_split = false); 32 | 33 | private: 34 | int current_block_; 35 | std::vector> new_blocks_; 36 | void GenerateOps(std::vector> *op_descs, 37 | Node *begin_node, bool can_add_split); 38 | void GenerateOps(std::vector> *op_desc, 39 | Node *input_node, Node *current_node); 40 | void GenerateOps(std::vector> *op_desc, 41 | Node *input_node, Node *current_node, bool adding_thread, 42 | int thread_num, std::shared_ptr new_block); 43 | }; 44 | } // namespace framework 45 | } // namespace paddle_mobile 46 | -------------------------------------------------------------------------------- /test/operators/test_resize_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "../test_include.h" 16 | #include "operators/resize_op.h" 17 | 18 | int main() { 19 | paddle_mobile::Loader loader; 20 | auto program = loader.Load(std::string(g_mobilenet_ssd)); 21 | if (program.originProgram == nullptr) { 22 | DLOG << "program read file"; 23 | } 24 | Executor4Test> 26 | executor(program, "resize"); 27 | paddle_mobile::framework::Tensor input; 28 | SetupTensor(&input, {2, 3, 3, 2}, static_cast(0), 29 | static_cast(1)); 30 | auto input_ptr = input.data(); 31 | auto out_ddim = paddle_mobile::framework::make_ddim({2, 9, 2}); 32 | auto output = 33 | executor.Predict(input, "transpose_0.tmp_0", "reshape_0.tmp_0", out_ddim); 34 | auto *output_ptr = output->data(); 35 | 36 | DLOG << "input : "; 37 | for (int j = 0; j < input.numel(); ++j) { 38 | DLOG << " index " << j << " : " << input_ptr[j]; 39 | } 40 | 41 | DLOG << "output : "; 42 | for (int j = 0; j < output->numel(); ++j) { 43 | DLOG << " index " << j << " : " << output_ptr[j]; 44 | } 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /test/operators/test_reshape_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "../test_include.h" 16 | #include "operators/reshape_op.h" 17 | 18 | int main() { 19 | paddle_mobile::Loader loader; 20 | auto program = loader.Load(std::string(g_mobilenet_ssd)); 21 | if (program.originProgram == nullptr) { 22 | DLOG << "program read file"; 23 | } 24 | Executor4Test> 26 | executor(program, "reshape"); 27 | paddle_mobile::framework::Tensor input; 28 | SetupTensor(&input, {2, 3, 3, 2}, static_cast(0), 29 | static_cast(1)); 30 | auto input_ptr = input.data(); 31 | auto out_ddim = paddle_mobile::framework::make_ddim({2, 9, 2}); 32 | auto output = 33 | executor.Predict(input, "transpose_0.tmp_0", "reshape_0.tmp_0", out_ddim); 34 | auto *output_ptr = output->data(); 35 | 36 | DLOG << "input : "; 37 | for (int j = 0; j < input.numel(); ++j) { 38 | DLOG << " index " << j << " : " << input_ptr[j]; 39 | } 40 | 41 | DLOG << "output : "; 42 | for (int j = 0; j < output->numel(); ++j) { 43 | DLOG << " index " << j << " : " << output_ptr[j]; 44 | } 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /src/operators/multiclass_nms_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef MULTICLASSNMS_OP 16 | 17 | #include "operators/multiclass_nms_op.h" 18 | namespace paddle_mobile { 19 | namespace operators { 20 | 21 | template 22 | void MultiClassNMSOp::InferShape() const { 23 | auto input_bboxes_dims = this->param_.InputBBoxes()->dims(); 24 | auto input_scores_dims = this->param_.InputScores()->dims(); 25 | if (input_scores_dims.size() != 3) { 26 | LOG(kLOG_ERROR) << "Input Scores size must be 3"; 27 | } 28 | if (input_bboxes_dims[2] != 4) { 29 | LOG(kLOG_ERROR) << "Input BBoxes 2nd dimension must be 4"; 30 | } 31 | if (input_bboxes_dims[1] != input_scores_dims[2]) { 32 | LOG(kLOG_ERROR) << "Predict bboxes must be equal"; 33 | } 34 | // pre size, will change in Compute. 35 | this->param_.Out()->Resize(framework::make_ddim({input_bboxes_dims[1], 6})); 36 | } 37 | template class MultiClassNMSOp; 38 | } // namespace operators 39 | } // namespace paddle_mobile 40 | 41 | namespace ops = paddle_mobile::operators; 42 | #ifdef PADDLE_MOBILE_CPU 43 | REGISTER_OPERATOR_CPU(multiclass_nms, ops::MultiClassNMSOp); 44 | #endif 45 | #ifdef PADDLE_MOBILE_MALI_GPU 46 | #endif 47 | #ifdef PADDLE_MOBILE_FPGA 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/operators/prelu_op.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef PRELU_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #include "framework/operator.h" 22 | #include "operators/kernel/prelu_kernel.h" 23 | #include "operators/op_param.h" 24 | 25 | namespace paddle_mobile { 26 | namespace operators { 27 | 28 | using paddle_mobile::framework::Tensor; 29 | 30 | template 31 | class PReluOp 32 | : public framework::OperatorWithKernel< 33 | DeviceType, PReluParam, operators::PReluKernel> { 34 | public: 35 | PReluOp(const std::string &type, const VariableNameMap &inputs, 36 | const VariableNameMap &outputs, const framework::AttributeMap &attrs, 37 | std::shared_ptr scope) 38 | : framework::OperatorWithKernel>( 40 | type, inputs, outputs, attrs, scope) {} 41 | 42 | using framework::OperatorWithKernel< 43 | DeviceType, PReluParam, 44 | operators::PReluKernel>::OperatorWithKernel; 45 | void InferShape() const override; 46 | 47 | protected: 48 | }; 49 | 50 | } // namespace operators 51 | } // namespace paddle_mobile 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/operators/scale_op.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef SCALE_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #include "framework/operator.h" 22 | #include "operators/kernel/scale_kernel.h" 23 | #include "operators/op_param.h" 24 | 25 | namespace paddle_mobile { 26 | namespace operators { 27 | 28 | using paddle_mobile::framework::Tensor; 29 | 30 | template 31 | class ScaleOp 32 | : public framework::OperatorWithKernel< 33 | DeviceType, ScaleParam, operators::ScaleKernel> { 34 | public: 35 | ScaleOp(const std::string &type, const VariableNameMap &inputs, 36 | const VariableNameMap &outputs, const framework::AttributeMap &attrs, 37 | std::shared_ptr scope) 38 | : framework::OperatorWithKernel>( 40 | type, inputs, outputs, attrs, scope) {} 41 | 42 | using framework::OperatorWithKernel< 43 | DeviceType, ScaleParam, 44 | operators::ScaleKernel>::OperatorWithKernel; 45 | void InferShape() const override; 46 | 47 | protected: 48 | }; 49 | 50 | } // namespace operators 51 | } // namespace paddle_mobile 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/operators/slice_op.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef SLICE_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #include "framework/operator.h" 22 | #include "operators/kernel/slice_kernel.h" 23 | #include "operators/op_param.h" 24 | 25 | namespace paddle_mobile { 26 | namespace operators { 27 | 28 | using paddle_mobile::framework::Tensor; 29 | 30 | template 31 | class SliceOp 32 | : public framework::OperatorWithKernel< 33 | DeviceType, SliceParam, operators::SliceKernel> { 34 | public: 35 | SliceOp(const std::string &type, const VariableNameMap &inputs, 36 | const VariableNameMap &outputs, const framework::AttributeMap &attrs, 37 | std::shared_ptr scope) 38 | : framework::OperatorWithKernel>( 40 | type, inputs, outputs, attrs, scope) {} 41 | 42 | using framework::OperatorWithKernel< 43 | DeviceType, SliceParam, 44 | operators::SliceKernel>::OperatorWithKernel; 45 | void InferShape() const override; 46 | 47 | protected: 48 | }; 49 | 50 | } // namespace operators 51 | } // namespace paddle_mobile 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/operators/resize_op.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef RESIZE_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #include "framework/operator.h" 22 | #include "operators/kernel/resize_kernel.h" 23 | #include "operators/op_param.h" 24 | 25 | namespace paddle_mobile { 26 | namespace operators { 27 | 28 | using paddle_mobile::framework::Tensor; 29 | 30 | template 31 | class ResizeOp 32 | : public framework::OperatorWithKernel< 33 | DeviceType, ResizeParam, operators::ResizeKernel> { 34 | public: 35 | ResizeOp(const std::string &type, const VariableNameMap &inputs, 36 | const VariableNameMap &outputs, const framework::AttributeMap attrs, 37 | std::shared_ptr scope) 38 | : framework::OperatorWithKernel>( 40 | type, inputs, outputs, attrs, scope) {} 41 | 42 | using framework::OperatorWithKernel< 43 | DeviceType, ResizeParam, 44 | operators::ResizeKernel>::OperatorWithKernel; 45 | void InferShape() const override; 46 | 47 | protected: 48 | }; 49 | } // namespace operators 50 | } // namespace paddle_mobile 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /test/operators/test_cov_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "../test_include.h" 16 | #include "operators/conv_op.h" 17 | 18 | int main() { 19 | paddle_mobile::Loader loader; 20 | // ../models/image_classification_resnet.inference.model 21 | auto program = loader.Load(g_googlenet); 22 | 23 | PADDLE_MOBILE_ENFORCE(program.originProgram != nullptr, 24 | "program file read fail"); 25 | 26 | Executor4Test> 28 | executor(program, "conv2d"); 29 | 30 | paddle_mobile::framework::Tensor input; 31 | GetInput(g_test_image_1x3x224x224, &input, {1, 3, 224, 224}); 32 | // // use SetupTensor if not has local input image . 33 | // SetupTensor(&input, {1, 3, 224, 224}, static_cast(0), 34 | // static_cast(1)); 35 | 36 | auto out_ddim = paddle_mobile::framework::make_ddim({1, 64, 112, 112}); 37 | auto output = executor.Predict(input, "data", "conv2d_0.tmp_0", out_ddim); 38 | 39 | auto output_ptr = output->data(); 40 | for (int j = 0; j < 20; ++j) { 41 | DLOG << " value of output: " << output_ptr[j]; 42 | } 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /src/framework/program/program-optimize/fusion_op_register.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #pragma once 16 | 17 | #include 18 | #include 19 | 20 | #include "framework/operator.h" 21 | #include "node.h" 22 | 23 | namespace paddle_mobile { 24 | namespace framework { 25 | 26 | class FusionOpRegister { 27 | public: 28 | static FusionOpRegister* Instance() { 29 | static FusionOpRegister* regist = nullptr; 30 | if (regist == nullptr) { 31 | regist = new FusionOpRegister(); 32 | } 33 | return regist; 34 | } 35 | 36 | void regist(FusionOpMatcher* matcher) { 37 | if (matchers_.find(matcher->Type()) != matchers_.end()) { 38 | return; 39 | } 40 | 41 | std::shared_ptr shared_matcher(matcher); 42 | matchers_[matcher->Type()] = shared_matcher; 43 | } 44 | 45 | const std::map> Matchers() { 46 | return matchers_; 47 | } 48 | 49 | private: 50 | std::map> matchers_; 51 | FusionOpRegister() {} 52 | }; 53 | 54 | class FusionOpRegistrar { 55 | public: 56 | explicit FusionOpRegistrar(FusionOpMatcher* matcher) { 57 | FusionOpRegister::Instance()->regist(matcher); 58 | } 59 | }; 60 | 61 | } // namespace framework 62 | } // namespace paddle_mobile 63 | -------------------------------------------------------------------------------- /src/operators/fetch_op.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #pragma once 16 | 17 | #include 18 | #include "framework/operator.h" 19 | #include "operators/op_param.h" 20 | 21 | namespace paddle_mobile { 22 | namespace operators { 23 | using std::string; 24 | 25 | template 26 | class FetchOp : public framework::OperatorBase { 27 | public: 28 | FetchOp(const string &type, const VariableNameMap &inputs, 29 | const VariableNameMap &outputs, const framework::AttributeMap attrs, 30 | std::shared_ptr scope) 31 | : framework::OperatorBase(type, inputs, outputs, attrs, 32 | scope), 33 | param_(inputs, outputs, attrs, *scope) {} 34 | void RunImpl() const { param_.Out()->ShareDataWith(*param_.InputX()); } 35 | 36 | void Init() {} 37 | 38 | void InferShape() const { 39 | auto x_dims = param_.InputX()->dims(); 40 | param_.Out()->Resize(x_dims); 41 | } 42 | 43 | protected: 44 | FetchParam param_; 45 | }; 46 | 47 | } // namespace operators 48 | } // namespace paddle_mobile 49 | 50 | #ifdef PADDLE_MOBILE_CPU 51 | USE_OP_CPU(fetch); 52 | #endif 53 | #ifdef PADDLE_MOBILE_MALI_GPU 54 | USE_OP_MALI_GPU(fetch); 55 | #endif 56 | #ifdef PADDLE_MOBILE_FPGA 57 | #endif 58 | -------------------------------------------------------------------------------- /test/operators/test_conv_add_relu_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "../test_include.h" 16 | #include "operators/fusion_conv_add_relu_op.h" 17 | 18 | int main() { 19 | paddle_mobile::Loader loader; 20 | // ../models/image_classification_resnet.inference.model 21 | auto program = loader.Load(g_googlenet, true); 22 | 23 | PADDLE_MOBILE_ENFORCE(program.originProgram != nullptr, 24 | "program file read fail"); 25 | 26 | Executor4Test< 27 | paddle_mobile::CPU, 28 | paddle_mobile::operators::FusionConvAddReluOp> 29 | executor(program, "fusion_conv_add_relu", true); 30 | 31 | paddle_mobile::framework::Tensor input; 32 | GetInput(g_test_image_1x3x224x224, &input, {1, 3, 224, 224}); 33 | // // use SetupTensor if not has local input image . 34 | // SetupTensor(&input, {1, 3, 224, 224}, static_cast(0), 35 | // static_cast(1)); 36 | 37 | auto out_ddim = paddle_mobile::framework::make_ddim({1, 64, 112, 112}); 38 | auto output = executor.Predict(input, "data", "conv2d_0.tmp_2", out_ddim); 39 | 40 | auto output_ptr = output->data(); 41 | for (int j = 0; j < 25; ++j) { 42 | DLOG << " value of output: " << output_ptr[j]; 43 | } 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /src/framework/data_layout.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #pragma once 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | namespace paddle_mobile { 22 | namespace framework { 23 | 24 | enum class DataLayout { 25 | kNHWC = 0, 26 | kNCHW = 1, 27 | kAnyLayout = 2, 28 | }; 29 | 30 | inline DataLayout StringToDataLayout(const std::string &str) { 31 | std::string s(str); 32 | for (size_t i = 0; i < s.size(); ++i) { 33 | s[i] = toupper(s[i]); 34 | } 35 | 36 | if (s == "NHWC") { 37 | return DataLayout::kNHWC; 38 | } else if (s == "NCHW") { 39 | return DataLayout::kNCHW; 40 | } else if (s == "ANYLAYOUT") { 41 | return DataLayout::kAnyLayout; 42 | } else { 43 | PADDLE_MOBILE_THROW_EXCEPTION("Unknown storage order string: %s", s.c_str()) 44 | exit(0); 45 | } 46 | } 47 | 48 | inline std::string DataLayoutToString(const DataLayout &data_layout) { 49 | switch (data_layout) { 50 | case DataLayout::kNHWC: 51 | return "NHWC"; 52 | case DataLayout::kNCHW: 53 | return "NCHW"; 54 | case DataLayout::kAnyLayout: 55 | return "ANY_LAYOUT"; 56 | default: 57 | PADDLE_MOBILE_THROW_EXCEPTION("Unknown storage order string ") 58 | exit(0); 59 | break; 60 | } 61 | } 62 | 63 | } // namespace framework 64 | } // namespace paddle_mobile 65 | -------------------------------------------------------------------------------- /src/memory/t_malloc.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #pragma once 16 | 17 | #include 18 | #include 19 | 20 | namespace paddle_mobile { 21 | namespace memory { 22 | 23 | void Copy(void *dst, const void *src, size_t num); 24 | 25 | void *Alloc(size_t size); 26 | 27 | void Free(void *ptr); 28 | 29 | /** 30 | * \brief Free memory block in one place. 31 | * 32 | * \note In some cases, custom deleter is used to 33 | * deallocate the memory automatically for 34 | * std::unique_ptr in tensor.h. 35 | * static_cast 36 | */ 37 | template 38 | class PODDeleter { 39 | static_assert(std::is_pod::value, "T must be POD"); 40 | 41 | public: 42 | explicit PODDeleter(){}; 43 | 44 | void operator()(T *ptr) { Free(static_cast(ptr)); } 45 | }; 46 | 47 | /** 48 | * \brief Free memory block in one place does not meet POD 49 | * 50 | * \note In some cases, custom deleter is used to 51 | * deallocate the memory automatically for 52 | * std::unique_ptr in tensor.h. 53 | * reinterpret_cast 54 | */ 55 | template 56 | class PlainDeleter { 57 | public: 58 | explicit PlainDeleter(){}; 59 | 60 | void operator()(T *ptr) { Free(reinterpret_cast(ptr)); } 61 | }; 62 | } // namespace memory 63 | } // namespace paddle_mobile 64 | -------------------------------------------------------------------------------- /src/operators/feed_op.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #pragma once 16 | 17 | #include 18 | #include "framework/operator.h" 19 | #include "operators/op_param.h" 20 | 21 | namespace paddle_mobile { 22 | namespace operators { 23 | using std::string; 24 | template 25 | class FeedOp : public framework::OperatorBase { 26 | public: 27 | FeedOp(const string &type, const VariableNameMap &inputs, 28 | const VariableNameMap &outputs, const framework::AttributeMap attrs, 29 | std::shared_ptr scope) 30 | : framework::OperatorBase(type, inputs, outputs, attrs, 31 | scope), 32 | param_(inputs, outputs, attrs, *scope) {} 33 | void RunImpl() const { param_.Out()->ShareDataWith(*param_.InputX()); } 34 | 35 | void Init() {} 36 | 37 | void InferShape() const { 38 | auto out_dims = param_.Out()->dims(); 39 | out_dims[0] = param_.BatchSize(); 40 | param_.Out()->Resize(out_dims); 41 | } 42 | 43 | protected: 44 | FeedParam param_; 45 | }; 46 | 47 | } // namespace operators 48 | } // namespace paddle_mobile 49 | 50 | #ifdef PADDLE_MOBILE_CPU 51 | USE_OP_CPU(feed); 52 | #endif 53 | #ifdef PADDLE_MOBILE_MALI_GPU 54 | USE_OP_MALI_GPU(feed); 55 | #endif 56 | #ifdef PADDLE_MOBILE_FPGA 57 | #endif 58 | -------------------------------------------------------------------------------- /src/operators/kernel/mali/reshape_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef RESHAPE_OP 16 | 17 | #pragma once 18 | 19 | #include "operators/kernel/reshape_kernel.h" 20 | 21 | namespace paddle_mobile { 22 | namespace operators { 23 | 24 | template <> 25 | bool ReshapeKernel::Init(ReshapeParam *param) { 26 | return true; 27 | } 28 | 29 | template <> 30 | void ReshapeKernel::Compute(const ReshapeParam ¶m) const { 31 | const auto *input_x = param.InputX(); 32 | const auto &input_x_dims = input_x->dims(); 33 | auto *out = param.Out(); 34 | framework::DDim out_dims = out->dims(); 35 | const auto *input_shape = param.InputShape(); 36 | 37 | if (input_shape) { 38 | auto *shape_data = input_shape->data(); 39 | framework::Tensor cpu_shape_tensor; 40 | auto shape = 41 | std::vector(shape_data, shape_data + input_shape->numel()); 42 | out_dims = ValidateShape(shape, input_x->dims()); 43 | } 44 | 45 | bool inplace = param.Inplace(); 46 | out->Resize(out_dims); 47 | if (!inplace) { 48 | out->mutable_data(); 49 | framework::TensorCopy(*input_x, out); 50 | out->Resize(out_dims); 51 | } else { 52 | out->ShareDataWith(*input_x); 53 | out->Resize(out_dims); 54 | } 55 | } 56 | 57 | } // namespace operators 58 | } // namespace paddle_mobile 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/operators/batchnorm_op.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef BATCHNORM_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | #include "framework/operator.h" 21 | #include "operators/kernel/batchnorm_kernel.h" 22 | #include "operators/op_param.h" 23 | 24 | namespace paddle_mobile { 25 | namespace operators { 26 | using std::string; 27 | template 28 | class BatchNormOp 29 | : public framework::OperatorWithKernel> { 31 | public: 32 | BatchNormOp(const string &type, const VariableNameMap &inputs, 33 | const VariableNameMap &outputs, 34 | const framework::AttributeMap &attrs, 35 | std::shared_ptr scope) 36 | : framework::OperatorWithKernel>( 38 | type, inputs, outputs, attrs, scope) {} 39 | 40 | void InferShape() const override; 41 | 42 | protected: 43 | }; 44 | 45 | } // namespace operators 46 | } // namespace paddle_mobile 47 | 48 | #ifdef PADDLE_MOBILE_CPU 49 | USE_OP_CPU(batch_norm); 50 | #endif 51 | #ifdef PADDLE_MOBILE_MALI_GPU 52 | USE_OP_MALI_GPU(batch_norm); 53 | #endif 54 | #ifdef PADDLE_MOBILE_FPGA 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /src/operators/mul_op.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef MUL_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | #include "framework/operator.h" 21 | #include "operators/kernel/mul_kernel.h" 22 | #include "operators/op_param.h" 23 | 24 | namespace paddle_mobile { 25 | namespace operators { 26 | 27 | template 28 | class MulOp : public framework::OperatorWithKernel< 29 | DeviceType, MulParam, operators::MulKernel> { 30 | public: 31 | MulOp(const std::string &type, const VariableNameMap &inputs, 32 | const VariableNameMap &outputs, const framework::AttributeMap &attrs, 33 | std::shared_ptr scope) 34 | : framework::OperatorWithKernel>( 36 | type, inputs, outputs, attrs, scope) {} 37 | 38 | using framework::OperatorWithKernel< 39 | DeviceType, MulParam, 40 | operators::MulKernel>::OperatorWithKernel; 41 | void InferShape() const override; 42 | 43 | protected: 44 | }; 45 | 46 | } // namespace operators 47 | } // namespace paddle_mobile 48 | 49 | #ifdef PADDLE_MOBILE_CPU 50 | USE_OP_CPU(mul); 51 | #endif 52 | #ifdef PADDLE_MOBILE_MALI_GPU 53 | USE_OP_MALI_GPU(mul); 54 | #endif 55 | #ifdef PADDLE_MOBILE_FPGA 56 | #endif 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/operators/lrn_op.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef LRN_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | #include "framework/operator.h" 21 | #include "operators/kernel/lrn_kernel.h" 22 | #include "operators/op_param.h" 23 | 24 | namespace paddle_mobile { 25 | namespace operators { 26 | using std::string; 27 | template 28 | class LrnOp : public framework::OperatorWithKernel< 29 | DeviceType, LrnParam, operators::LrnKernel> { 30 | public: 31 | LrnOp(const string &type, const VariableNameMap &inputs, 32 | const VariableNameMap &outputs, const framework::AttributeMap &attrs, 33 | std::shared_ptr scope) 34 | : framework::OperatorWithKernel>( 36 | type, inputs, outputs, attrs, scope) {} 37 | 38 | using framework::OperatorWithKernel< 39 | DeviceType, LrnParam, 40 | operators::LrnKernel>::OperatorWithKernel; 41 | void InferShape() const override; 42 | 43 | protected: 44 | }; 45 | 46 | } // namespace operators 47 | } // namespace paddle_mobile 48 | 49 | #ifdef PADDLE_MOBILE_CPU 50 | USE_OP_CPU(lrn); 51 | #endif 52 | #ifdef PADDLE_MOBILE_MALI_GPU 53 | USE_OP_MALI_GPU(lrn); 54 | #endif 55 | #ifdef PADDLE_MOBILE_FPGA 56 | #endif 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/operators/conv_op.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef CONV_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | #include "framework/operator.h" 21 | #include "operators/kernel/conv_kernel.h" 22 | 23 | namespace paddle_mobile { 24 | namespace operators { 25 | using std::string; 26 | template 27 | class ConvOp 28 | : public framework::OperatorWithKernel< 29 | DeviceType, ConvParam, operators::ConvKernel> { 30 | public: 31 | ConvOp(const std::string &type, const VariableNameMap &inputs, 32 | const VariableNameMap &outputs, const framework::AttributeMap &attrs, 33 | std::shared_ptr scope) 34 | : framework::OperatorWithKernel>( 36 | type, inputs, outputs, attrs, scope) {} 37 | 38 | using framework::OperatorWithKernel< 39 | DeviceType, ConvParam, 40 | operators::ConvKernel>::OperatorWithKernel; 41 | void InferShape() const override; 42 | 43 | private: 44 | }; 45 | 46 | } // namespace operators 47 | } // namespace paddle_mobile 48 | 49 | #ifdef PADDLE_MOBILE_CPU 50 | USE_OP_CPU(conv2d); 51 | #endif 52 | #ifdef PADDLE_MOBILE_MALI_GPU 53 | USE_OP_MALI_GPU(conv2d); 54 | #endif 55 | #ifdef PADDLE_MOBILE_FPGA 56 | USE_OP_FPGA(conv2d); 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/operators/kernel/mali/mul_kernel.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef MUL_OP 16 | 17 | #pragma once 18 | 19 | #include "operators/kernel/mul_kernel.h" 20 | 21 | namespace paddle_mobile { 22 | namespace operators { 23 | 24 | template <> 25 | bool MulKernel::Init(MulParam *param) { 26 | return true; 27 | } 28 | 29 | template <> 30 | void MulKernel::Compute(const MulParam ¶m) const { 31 | const Tensor *input_x = param.InputX(); 32 | const Tensor *input_y = param.InputY(); 33 | Tensor *out = param.Out(); 34 | out->mutable_data(); 35 | const Tensor x_matrix = 36 | input_x->dims().size() > 2 37 | ? framework::ReshapeToMatrix(*input_x, param.XNumColDims()) 38 | : *input_x; 39 | const Tensor y_matrix = 40 | input_y->dims().size() > 2 41 | ? framework::ReshapeToMatrix(*input_y, param.YNumColDims()) 42 | : *input_y; 43 | auto out_dim = out->dims(); 44 | if (out_dim.size() != 2) { 45 | out->Resize({x_matrix.dims()[0], y_matrix.dims()[1]}); 46 | } 47 | math::matmul(x_matrix, false, y_matrix, false, static_cast(1), 48 | out, static_cast(0)); 49 | if (out_dim.size() != 2) { 50 | out->Resize(out_dim); 51 | } 52 | } 53 | 54 | template class MulKernel; 55 | 56 | } // namespace operators 57 | } // namespace paddle_mobile 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/operators/sigmoid_op.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef SIGMOID_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #include "framework/operator.h" 22 | #include "operators/kernel/sigmoid_kernel.h" 23 | #include "operators/op_param.h" 24 | 25 | namespace paddle_mobile { 26 | namespace operators { 27 | template 28 | class SigmoidOp 29 | : public framework::OperatorWithKernel< 30 | DeviceType, SigmoidParam, operators::SigmoidKernel> { 31 | public: 32 | SigmoidOp(const std::string &type, const VariableNameMap &inputs, 33 | const VariableNameMap &outputs, 34 | const framework::AttributeMap &attrs, 35 | std::shared_ptr scope) 36 | : framework::OperatorWithKernel>( 38 | type, inputs, outputs, attrs, scope) {} 39 | 40 | using framework::OperatorWithKernel< 41 | DeviceType, SigmoidParam, 42 | operators::SigmoidKernel>::OperatorWithKernel; 43 | 44 | void InferShape() const override; 45 | }; 46 | } // namespace operators 47 | } // namespace paddle_mobile 48 | 49 | #ifdef PADDLE_MOBILE_CPU 50 | USE_OP_CPU(sigmoid); 51 | #endif 52 | #ifdef PADDLE_MOBILE_MALI_GPU 53 | #endif 54 | #ifdef PADDLE_MOBILE_FPGA 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /test/operators/test_depthwise_conv_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "../test_include.h" 16 | #include "operators/depthwise_conv_op.h" 17 | 18 | int main() { 19 | paddle_mobile::Loader loader; 20 | // ../models/image_classification_resnet.inference.model 21 | auto program = loader.Load(g_mobilenet_ssd); 22 | 23 | PADDLE_MOBILE_ENFORCE(program.originProgram != nullptr, 24 | "program file read fail"); 25 | 26 | Executor4Test> 28 | executor(program, "depthwise_conv2d"); 29 | 30 | paddle_mobile::framework::LoDTensor input; 31 | // GetInput(g_test_image_1x3x224x224, &input, {1, 3, 224, 224}); 32 | // use SetupTensor if not has local input image . 33 | SetupTensor(&input, {1, 32, 150, 150}, static_cast(0), 34 | static_cast(1)); 35 | auto input_ptr = input.data(); 36 | auto out_ddim = paddle_mobile::framework::make_ddim({1, 32, 150, 150}); 37 | auto output = executor.Predict(input, "batch_norm_0.tmp_3", 38 | "depthwise_conv2d_0.tmp_0", out_ddim); 39 | 40 | auto output_ptr = output->data(); 41 | for (int j = 0; j < output->numel(); ++j) { 42 | DLOG << " value of output: " << output_ptr[j]; 43 | } 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /src/operators/concat_op.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef CONCAT_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | #include "framework/operator.h" 21 | #include "operators/kernel/concat_kernel.h" 22 | #include "operators/op_param.h" 23 | namespace paddle_mobile { 24 | namespace operators { 25 | using std::string; 26 | template 27 | class ConcatOp 28 | : public framework::OperatorWithKernel< 29 | DeviceType, ConcatParam, operators::ConcatKernel> { 30 | public: 31 | ConcatOp(const string &type, const VariableNameMap &inputs, 32 | const VariableNameMap &outputs, const framework::AttributeMap &attrs, 33 | std::shared_ptr scope) 34 | : framework::OperatorWithKernel>( 36 | type, inputs, outputs, attrs, scope) {} 37 | 38 | using framework::OperatorWithKernel< 39 | DeviceType, ConcatParam, 40 | operators::ConcatKernel>::OperatorWithKernel; 41 | void InferShape() const override; 42 | 43 | protected: 44 | }; 45 | 46 | } // namespace operators 47 | } // namespace paddle_mobile 48 | 49 | #ifdef PADDLE_MOBILE_CPU 50 | USE_OP_CPU(concat); 51 | #endif 52 | #ifdef PADDLE_MOBILE_MALI_GPU 53 | USE_OP_MALI_GPU(concat); 54 | #endif 55 | #ifdef PADDLE_MOBILE_FPGA 56 | #endif 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/operators/softmax_op.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef SOFTMAX_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #include "framework/operator.h" 22 | #include "operators/kernel/softmax_kernel.h" 23 | #include "operators/op_param.h" 24 | 25 | namespace paddle_mobile { 26 | namespace operators { 27 | template 28 | class SoftmaxOp 29 | : public framework::OperatorWithKernel< 30 | DeviceType, SoftmaxParam, operators::SoftmaxKernel> { 31 | public: 32 | SoftmaxOp(const std::string &type, const VariableNameMap &inputs, 33 | const VariableNameMap &outputs, 34 | const framework::AttributeMap &attrs, 35 | std::shared_ptr scope) 36 | : framework::OperatorWithKernel>( 38 | type, inputs, outputs, attrs, scope) {} 39 | 40 | using framework::OperatorWithKernel< 41 | DeviceType, SoftmaxParam, 42 | operators::SoftmaxKernel>::OperatorWithKernel; 43 | 44 | void InferShape() const override; 45 | 46 | private: 47 | }; 48 | } // namespace operators 49 | } // namespace paddle_mobile 50 | 51 | #ifdef PADDLE_MOBILE_CPU 52 | USE_OP_CPU(softmax); 53 | #endif 54 | #ifdef PADDLE_MOBILE_MALI_GPU 55 | USE_OP_MALI_GPU(softmax); 56 | #endif 57 | #ifdef PADDLE_MOBILE_FPGA 58 | #endif 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /test/operators/test_relu_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "../test_include.h" 16 | #include "operators/relu_op.h" 17 | 18 | int main() { 19 | paddle_mobile::Loader loader; 20 | auto program = loader.Load(g_resnet); 21 | PADDLE_MOBILE_ENFORCE(program.originProgram != nullptr, 22 | "program file read fail"); 23 | 24 | Executor4Test> 26 | executor(program, "relu"); 27 | 28 | // 1. input_tensors; 29 | vector input_tensors; 30 | 31 | Tensor input1; 32 | auto input1_data = CreateInput(&input1, {1, 2, 3, 4}, -1, 1); 33 | input_tensors.push_back(input1); 34 | 35 | // 2. input_names 36 | vector input_names({ 37 | "batch_norm_0.tmp_2", 38 | }); 39 | 40 | // 3. output_names 41 | vector output_names({"batch_norm_0.tmp_3"}); 42 | 43 | // 4. out_dims; 44 | vector out_ddims; 45 | auto out_ddim = paddle_mobile::framework::make_ddim({1, 2, 3, 4}); 46 | out_ddims.push_back(out_ddim); 47 | 48 | auto output = executor.Predict(input_tensors, input_names, 49 | output_names, out_ddims); 50 | 51 | auto output0_data = output[0]->data(); 52 | 53 | for (int j = 0; j < output[0]->numel(); ++j) { 54 | DLOG << " value of output: " << output0_data[j]; 55 | } 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /src/operators/pool_op.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef POOL_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #include "framework/operator.h" 22 | #include "operators/kernel/pool_kernel.h" 23 | #include "operators/op_param.h" 24 | 25 | namespace paddle_mobile { 26 | namespace operators { 27 | using framework::AttributeMap; 28 | using framework::OperatorWithKernel; 29 | using framework::Scope; 30 | using std::string; 31 | template 32 | class PoolOp : public OperatorWithKernel> { 34 | public: 35 | PoolOp(const string &type, const VariableNameMap &inputs, 36 | const VariableNameMap &outputs, const AttributeMap &attrs, 37 | std::shared_ptr scope) 38 | : OperatorWithKernel>( 40 | type, inputs, outputs, attrs, scope) {} 41 | using OperatorWithKernel< 42 | DeviceType, PoolParam, 43 | operators::PoolKernel>::OperatorWithKernel; 44 | void InferShape() const override; 45 | 46 | private: 47 | }; 48 | } // namespace operators 49 | } // namespace paddle_mobile 50 | 51 | #ifdef PADDLE_MOBILE_CPU 52 | USE_OP_CPU(pool2d); 53 | #endif 54 | #ifdef PADDLE_MOBILE_MALI_GPU 55 | USE_OP_MALI_GPU(pool2d); 56 | #endif 57 | #ifdef PADDLE_MOBILE_FPGA 58 | #endif 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /test/operators/test_transpose_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "../test_helper.h" 16 | #include "../test_include.h" 17 | #include "operators/transpose_op.h" 18 | int main() { 19 | paddle_mobile::Loader loader; 20 | auto program = loader.Load(std::string(g_mobilenet_ssd)); 21 | if (program.originProgram == nullptr) { 22 | DLOG << "program read file"; 23 | } 24 | Executor4Test> 26 | executor(program, "transpose"); 27 | paddle_mobile::framework::Tensor input; 28 | SetupTensor(&input, {1, 2, 3, 4}, static_cast(0), 29 | static_cast(1)); 30 | auto input_ptr = input.data(); 31 | auto out_ddim = paddle_mobile::framework::make_ddim({1, 3, 4, 2}); 32 | auto output = 33 | executor.Predict(input, "conv2d_22.tmp_1", "transpose_0.tmp_0", out_ddim); 34 | auto *output_ptr = output->data(); 35 | 36 | DLOG << "input : "; 37 | for (int j = 0; j < input.numel(); ++j) { 38 | DLOG << " index " << j << " : " << input_ptr[j]; 39 | } 40 | 41 | DLOG << "output : "; 42 | for (int j = 0; j < output->numel(); ++j) { 43 | DLOG << " index " << j << " : " << output_ptr[j]; 44 | } 45 | DLOG << " for example : "; 46 | DLOG << " you can check if input[16] == output[9] "; 47 | DLOG << " you can check if input[12] == output[1] "; 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /src/operators/depthwise_conv_op.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef DEPTHWISECONV_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | #include "framework/operator.h" 21 | #include "operators/kernel/depthwise_conv_kernel.h" 22 | 23 | namespace paddle_mobile { 24 | namespace operators { 25 | 26 | template 27 | class DepthwiseConvOp : public framework::OperatorWithKernel< 28 | DeviceType, ConvParam, 29 | operators::DepthwiseConvKernel> { 30 | public: 31 | DepthwiseConvOp(const std::string &type, const VariableNameMap &inputs, 32 | const VariableNameMap &outputs, 33 | const framework::AttributeMap &attrs, 34 | std::shared_ptr scope) 35 | : framework::OperatorWithKernel< 36 | DeviceType, ConvParam, 37 | operators::DepthwiseConvKernel>( 38 | type, inputs, outputs, attrs, scope) {} 39 | 40 | using framework::OperatorWithKernel< 41 | DeviceType, ConvParam, 42 | operators::DepthwiseConvKernel>::OperatorWithKernel; 43 | void InferShape() const override; 44 | 45 | private: 46 | }; 47 | 48 | } // namespace operators 49 | } // namespace paddle_mobile 50 | 51 | #ifdef PADDLE_MOBILE_CPU 52 | USE_OP_CPU(depthwise_conv2d); 53 | #endif 54 | #ifdef PADDLE_MOBILE_MALI_GPU 55 | #endif 56 | #ifdef PADDLE_MOBILE_FPGA 57 | #endif 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /test/operators/test_prelu_op.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #include "../executor_for_test.h" 16 | #include "../test_include.h" 17 | #include "operators/prelu_op.h" 18 | 19 | int main() { 20 | paddle_mobile::Loader loader; 21 | auto program = loader.Load(g_resnet); 22 | PADDLE_MOBILE_ENFORCE(program.originProgram != nullptr, 23 | "program file read fail"); 24 | 25 | Executor4Test> 27 | executor(program, "prelu"); 28 | 29 | // 1. input_tensors; 30 | vector input_tensors; 31 | 32 | Tensor input1; 33 | auto input1_data = CreateInput(&input1, {1, 2, 3, 4}, -1, 1); 34 | input_tensors.push_back(input1); 35 | 36 | // 2. input_names 37 | vector input_names({ 38 | "batch_norm_0.tmp_2", 39 | }); 40 | 41 | // 3. output_names 42 | vector output_names({"batch_norm_0.tmp_3"}); 43 | 44 | // 4. out_dims; 45 | vector out_ddims; 46 | auto out_ddim = paddle_mobile::framework::make_ddim({1, 2, 3, 4}); 47 | out_ddims.push_back(out_ddim); 48 | 49 | auto output = executor.Predict(input_tensors, input_names, 50 | output_names, out_ddims); 51 | 52 | auto output0_data = output[0]->data(); 53 | 54 | for (int j = 0; j < output[0]->numel(); ++j) { 55 | DLOG << " value of output: " << output0_data[j]; 56 | } 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /src/operators/box_coder_op.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef BOXCODER_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #include "framework/operator.h" 22 | #include "operators/kernel/box_coder_kernel.h" 23 | #include "operators/op_param.h" 24 | 25 | namespace paddle_mobile { 26 | namespace operators { 27 | 28 | using paddle_mobile::framework::Tensor; 29 | 30 | template 31 | class BoxCoderOp 32 | : public framework::OperatorWithKernel< 33 | DeviceType, BoxCoderParam, operators::BoxCoderKernel> { 34 | public: 35 | BoxCoderOp(const std::string &type, const VariableNameMap &inputs, 36 | const VariableNameMap &outputs, 37 | const framework::AttributeMap &attrs, 38 | std::shared_ptr scope) 39 | : framework::OperatorWithKernel>( 41 | type, inputs, outputs, attrs, scope) {} 42 | 43 | using framework::OperatorWithKernel< 44 | DeviceType, BoxCoderParam, 45 | operators::BoxCoderKernel>::OperatorWithKernel; 46 | void InferShape() const override; 47 | 48 | protected: 49 | }; 50 | 51 | } // namespace operators 52 | } // namespace paddle_mobile 53 | 54 | #ifdef PADDLE_MOBILE_CPU 55 | USE_OP_CPU(box_coder); 56 | #endif 57 | #ifdef PADDLE_MOBILE_MALI_GPU 58 | #endif 59 | #ifdef PADDLE_MOBILE_FPGA 60 | #endif 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/operators/prior_box_op.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef PRIORBOX_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #include "framework/operator.h" 22 | #include "operators/kernel/prior_box_kernel.h" 23 | #include "operators/op_param.h" 24 | 25 | namespace paddle_mobile { 26 | namespace operators { 27 | 28 | using paddle_mobile::framework::Tensor; 29 | 30 | template 31 | class PriorBoxOp 32 | : public framework::OperatorWithKernel< 33 | DeviceType, PriorBoxParam, operators::PriorBoxKernel> { 34 | public: 35 | PriorBoxOp(const std::string &type, const VariableNameMap &inputs, 36 | const VariableNameMap &outputs, 37 | const framework::AttributeMap &attrs, 38 | std::shared_ptr scope) 39 | : framework::OperatorWithKernel>( 41 | type, inputs, outputs, attrs, scope) {} 42 | 43 | using framework::OperatorWithKernel< 44 | DeviceType, PriorBoxParam, 45 | operators::PriorBoxKernel>::OperatorWithKernel; 46 | void InferShape() const override; 47 | 48 | protected: 49 | }; 50 | 51 | } // namespace operators 52 | } // namespace paddle_mobile 53 | 54 | #ifdef PADDLE_MOBILE_CPU 55 | USE_OP_CPU(prior_box); 56 | #endif 57 | #ifdef PADDLE_MOBILE_MALI_GPU 58 | #endif 59 | #ifdef PADDLE_MOBILE_FPGA 60 | #endif 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/operators/dropout_op.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef DROPOUT_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #include "framework/operator.h" 22 | #include "operators/kernel/dropout_kernel.h" 23 | #include "operators/op_param.h" 24 | 25 | namespace paddle_mobile { 26 | namespace operators { 27 | 28 | using paddle_mobile::framework::Tensor; 29 | 30 | template 31 | class DropoutOp 32 | : public framework::OperatorWithKernel< 33 | DeviceType, DropoutParam, operators::DropoutKernel> { 34 | public: 35 | DropoutOp(const std::string &type, const VariableNameMap &inputs, 36 | const VariableNameMap &outputs, const framework::AttributeMap attrs, 37 | std::shared_ptr scope) 38 | : framework::OperatorWithKernel>( 40 | type, inputs, outputs, attrs, scope) {} 41 | 42 | // using framework::OperatorWithKernel>; 45 | void InferShape() const override; 46 | 47 | protected: 48 | }; 49 | 50 | } // namespace operators 51 | } // namespace paddle_mobile 52 | 53 | #ifdef PADDLE_MOBILE_CPU 54 | USE_OP_CPU(dropout); 55 | #endif 56 | #ifdef PADDLE_MOBILE_MALI_GPU 57 | #endif 58 | #ifdef PADDLE_MOBILE_FPGA 59 | #endif 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /src/operators/relu_op.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef RELU_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #include "framework/operator.h" 22 | #include "operators/kernel/relu_kernel.h" 23 | #include "operators/op_param.h" 24 | 25 | namespace paddle_mobile { 26 | namespace operators { 27 | 28 | using paddle_mobile::framework::Tensor; 29 | 30 | template 31 | class ReluOp 32 | : public framework::OperatorWithKernel< 33 | DeviceType, ReluParam, operators::ReluKernel> { 34 | public: 35 | /* 36 | * @b op 的实例化方法, 需要调用父类的实例化方法, 以及实例化自己的参数结构体 37 | * */ 38 | ReluOp(const std::string &type, const VariableNameMap &inputs, 39 | const VariableNameMap &outputs, const framework::AttributeMap &attrs, 40 | std::shared_ptr scope) 41 | : framework::OperatorWithKernel>( 43 | type, inputs, outputs, attrs, scope) {} 44 | 45 | using framework::OperatorWithKernel< 46 | DeviceType, ReluParam, 47 | operators::ReluKernel>::OperatorWithKernel; 48 | void InferShape() const override; 49 | 50 | protected: 51 | }; 52 | 53 | } // namespace operators 54 | } // namespace paddle_mobile 55 | 56 | #ifdef PADDLE_MOBILE_CPU 57 | USE_OP_CPU(relu); 58 | #endif 59 | #ifdef PADDLE_MOBILE_MALI_GPU 60 | USE_OP_MALI_GPU(relu); 61 | #endif 62 | #ifdef PADDLE_MOBILE_FPGA 63 | #endif 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /src/operators/transpose_op.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. */ 14 | 15 | #ifdef TRANSPOSE_OP 16 | 17 | #pragma once 18 | 19 | #include 20 | 21 | #include "framework/operator.h" 22 | #include "operators/kernel/transpose_kernel.h" 23 | #include "operators/op_param.h" 24 | 25 | namespace paddle_mobile { 26 | namespace operators { 27 | 28 | using paddle_mobile::framework::Tensor; 29 | 30 | template 31 | class TransposeOp : public framework::OperatorWithKernel< 32 | DeviceType, TransposeParam, 33 | operators::TransposeKernel> { 34 | public: 35 | TransposeOp(const std::string &type, const VariableNameMap &inputs, 36 | const VariableNameMap &outputs, 37 | const framework::AttributeMap &attrs, 38 | std::shared_ptr scope) 39 | : framework::OperatorWithKernel< 40 | DeviceType, TransposeParam, 41 | operators::TransposeKernel>(type, inputs, outputs, 42 | attrs, scope) {} 43 | 44 | using framework::OperatorWithKernel< 45 | DeviceType, TransposeParam, 46 | operators::TransposeKernel>::OperatorWithKernel; 47 | void InferShape() const override; 48 | }; 49 | 50 | } // namespace operators 51 | } // namespace paddle_mobile 52 | 53 | #ifdef PADDLE_MOBILE_CPU 54 | USE_OP_CPU(transpose); 55 | #endif 56 | #ifdef PADDLE_MOBILE_MALI_GPU 57 | #endif 58 | #ifdef PADDLE_MOBILE_FPGA 59 | #endif 60 | 61 | #endif 62 | --------------------------------------------------------------------------------