diff --git a/src/common/types.h b/src/common/types.h index 7745f80a9ca2ef6f0258f6f2eacf45761d29a00e..6066879305d5ea7d1b6dcb0bb618c234338cc171 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -20,7 +20,9 @@ limitations under the License. */ #include namespace paddle_mobile { -enum class Precision : int { FP32 = 0 }; +enum class Precision : int { FP32 = 0, FP16 = 1 }; + +typedef int16_t half; template struct PrecisionTrait { @@ -31,6 +33,10 @@ template <> struct PrecisionTrait { typedef float ptype; }; +template <> +struct PrecisionTrait { + typedef half ptype; +}; //! device type enum DeviceTypeEnum { kINVALID = -1, kCPU = 0, kFPGA = 1, kGPU_MALI = 2 }; diff --git a/src/framework/program/program-optimize/fusion_op_register.h b/src/framework/program/program-optimize/fusion_op_register.h index f16a65c28fb47e1cf4139588742ebe1073c3f3e6..a5890d34c600f6c4f4838ec94c202801b3044d3f 100644 --- a/src/framework/program/program-optimize/fusion_op_register.h +++ b/src/framework/program/program-optimize/fusion_op_register.h @@ -14,11 +14,13 @@ limitations under the License. */ #pragma once +#include #include #include +#include #include "framework/operator.h" -#include "node.h" +#include "framework/program/program-optimize/node.h" namespace paddle_mobile { namespace framework { diff --git a/src/framework/tensor.h b/src/framework/tensor.h index 56e6d6bf18740489c195a66db70331cbab42aeea..954a65a3605c4d0204890d9414aeb074371b0d69 100644 --- a/src/framework/tensor.h +++ b/src/framework/tensor.h @@ -16,14 +16,15 @@ limitations under the License. */ #include #include +#include #include +#include #include #include #include -#include "common/enforce.h" -#include #include "common/enforce.h" +#include "common/types.h" #include "framework/data_layout.h" #include "framework/ddim.h" #include "memory/t_malloc.h" @@ -63,7 +64,8 @@ struct SizeOfTypeFunctor { }; static inline size_t SizeOfType(std::type_index type) { - SizeOfTypeFunctor functor; + SizeOfTypeFunctor + functor; size_t size = functor(type); PADDLE_MOBILE_ENFORCE(size != 0UL, "Cannot get size of type %s", type.name()); diff --git a/src/io/executor.cpp b/src/io/executor.cpp index 65f019d1e3c3f6f6bdb8a18a9ff99bb7ecb2012c..53351a84e063ffd194a28513e11cee3ffea5cdb6 100644 --- a/src/io/executor.cpp +++ b/src/io/executor.cpp @@ -187,7 +187,7 @@ void Executor::LoadMemory(const framework::VarDesc var_desc, memcpy(&max_value, *data + sizeof(float), sizeof(float)); *data += 2 * sizeof(float); const float factor = (max_value - min_value) / 255.0; - uint8_t *uint8_data = (uint8_t *)(*data); + uint8_t *uint8_data = reinterpret_cast(*data); for (int k = 0; k < memory_size; ++k) { static_cast(memory)[k] = uint8_data[k] * factor + min_value; } @@ -420,6 +420,6 @@ std::vector::Ptype> Executor::Predict( template class Executor; template class Executor; -template class Executor; +template class Executor; } // namespace paddle_mobile diff --git a/src/operators/concat_op.cpp b/src/operators/concat_op.cpp index 19d771ddd5884412624a0720368ecc80f92678ea..f767f3481c999a16da46e75e314e8ebcb54193fa 100644 --- a/src/operators/concat_op.cpp +++ b/src/operators/concat_op.cpp @@ -14,7 +14,9 @@ limitations under the License. */ #ifdef CONCAT_OP -#include "concat_op.h" +#include + +#include "operators/concat_op.h" namespace paddle_mobile { namespace operators { @@ -68,6 +70,7 @@ REGISTER_OPERATOR_CPU(concat, ops::ConcatOp); REGISTER_OPERATOR_MALI_GPU(concat, ops::ConcatOp); #endif #ifdef PADDLE_MOBILE_FPGA +REGISTER_OPERATOR_FPGA(concat, ops::ConcatOp); #endif #endif diff --git a/src/operators/concat_op.h b/src/operators/concat_op.h index 7aedaab4b1fa00707661ada428c7c1dc27f124cd..bad0015917c2a9d4016def26c8a332d076b39c99 100644 --- a/src/operators/concat_op.h +++ b/src/operators/concat_op.h @@ -53,6 +53,7 @@ USE_OP_CPU(concat); USE_OP_MALI_GPU(concat); #endif #ifdef PADDLE_MOBILE_FPGA +USE_OP_FPGA(concat); #endif #endif diff --git a/src/operators/kernel/fpga/concat_kernel.cpp b/src/operators/kernel/fpga/concat_kernel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c691988f4a388c7835a7016602d7a1ac9cb5f9b6 --- /dev/null +++ b/src/operators/kernel/fpga/concat_kernel.cpp @@ -0,0 +1,55 @@ +/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. */ + +#ifdef CONCAT_OP + +#include "operators/kernel/concat_kernel.h" + +namespace paddle_mobile { +namespace operators { + +template <> +bool ConcatKernel::Init(ConcatParam *param) { + return true; +} + +template <> +void ConcatKernel::Compute(const ConcatParam ¶m) const { + auto inputs = param.Inputs(); + auto *out = param.Out(); + int64_t axis = param.Axis(); + out->mutable_data(); + + DDim out_dim = out->dims(); + int pixels = out_dim[1] * out_dim[2]; + auto out_channel = out_dim[3]; + + auto out_offset = 0; + + for (int i = 0; i < inputs.size(); ++i) { + auto input = inputs[i]; + auto channels = input[3]; + out_offset += channels; + auto src = input->data(); + for (int j = 0; j < pixels; ++j) { + auto dst = out->data() + out_offset; + memory::Copy(dst, src, sizeof(half)); + } + } +} + +} // namespace operators +} // namespace paddle_mobile + +#endif diff --git a/tools/android-cmake/android.toolchain.cmake b/tools/android-cmake/android.toolchain.cmake index 0d0e8393625273061a66f8642808e357874b9308..55b90ba65260b99d9af4a29832ed6f8ff5b235c8 100644 --- a/tools/android-cmake/android.toolchain.cmake +++ b/tools/android-cmake/android.toolchain.cmake @@ -65,6 +65,8 @@ endif() file(TO_CMAKE_PATH "${ANDROID_NDK}" ANDROID_NDK) # Android NDK revision +message("${ANDROID_NDK}") + file(READ "${ANDROID_NDK}/source.properties" ANDROID_NDK_SOURCE_PROPERTIES) set(ANDROID_NDK_SOURCE_PROPERTIES_REGEX "^Pkg\\.Desc = Android NDK\nPkg\\.Revision = ([0-9]+)\\.") diff --git a/tools/build.sh b/tools/build.sh index db809f71076e6b6d4aacc53bd8e144db3935cb91..ced18a180762826ffa2c45949e5aab9bfe5c8f88 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -40,8 +40,8 @@ build_for_android() { fi if [ -z "$PLATFORM" ]; then - PLATFORM="arm-v7a" # Users could choose "arm-v8a" platform. -# PLATFORM="arm-v8a" +# PLATFORM="arm-v7a" # Users could choose "arm-v8a" platform. + PLATFORM="arm-v8a" fi if [ "${PLATFORM}" = "arm-v7a" ]; then @@ -63,7 +63,7 @@ build_for_android() { TOOLCHAIN_FILE="./tools/android-cmake/android.toolchain.cmake" ANDROID_ARM_MODE="arm" - if [ "${#NETS}" > 1 ]; then + if [ "${#NETS}" -gt 1 ]; then cmake .. \ -B"../build/release/${PLATFORM}" \ -DANDROID_ABI="${ABI}" \ @@ -99,7 +99,7 @@ build_for_ios() { BUILD_DIR=../build/release/"${PLATFORM}"/ TOOLCHAIN_FILE="./tools/ios-cmake/ios.toolchain.cmake" mkdir -p "${BUILD_DIR}" - if [ "${#NETS}" > 1 ]; then + if [ "${#NETS}" -gt 1 ]; then cmake .. \ -B"${BUILD_DIR}" \ -DCMAKE_BUILD_TYPE="${MODE}" \