diff --git a/CMakeLists.txt b/CMakeLists.txt index b0f8790b3cff653ea2351a029df21128ab81e940..0b9d2a6e6a1bc4108e13a9361abf496f70d51801 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -140,8 +140,8 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY build) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build) # NET default -set(NET "defult" CACHE STRING "select net type") -set_property(CACHE NET PROPERTY STRINGS "defult" "googlenet" "mobilenet" "yolo" "squeezenet" "FPGAnets") +set(NET "default" CACHE STRING "select net type") +set_property(CACHE NET PROPERTY STRINGS "default" "googlenet" "mobilenet" "yolo" "squeezenet" "FPGAnets") include("${CMAKE_CURRENT_LIST_DIR}/tools/op.cmake") diff --git a/tools/build.sh b/tools/build.sh index e0eb05fc8c13973c0ec22dfec7f4573c459f936b..db809f71076e6b6d4aacc53bd8e144db3935cb91 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -1,4 +1,6 @@ #!/usr/bin/env bash +NETS="" +declare -a supportedNets=("googlenet" "mobilenet" "yolo" "squeezenet" "resnet") build_for_mac() { if [ ! `which brew` ]; then @@ -60,7 +62,8 @@ build_for_android() { ANDROID_PLATFORM_VERSION="android-22" TOOLCHAIN_FILE="./tools/android-cmake/android.toolchain.cmake" ANDROID_ARM_MODE="arm" - if [ $# -eq 1 ]; then + + if [ "${#NETS}" > 1 ]; then cmake .. \ -B"../build/release/${PLATFORM}" \ -DANDROID_ABI="${ABI}" \ @@ -70,7 +73,7 @@ build_for_android() { -DCMAKE_CXX_FLAGS="${CXX_FLAGS}" \ -DANDROID_STL=c++_static \ -DANDROID=true \ - -DNET=$1 \ + -DNET="${NETS}" \ -D"${ARM_PLATFORM}"=true else @@ -96,14 +99,14 @@ build_for_ios() { BUILD_DIR=../build/release/"${PLATFORM}"/ TOOLCHAIN_FILE="./tools/ios-cmake/ios.toolchain.cmake" mkdir -p "${BUILD_DIR}" - if [ $# -eq 1 ]; then + if [ "${#NETS}" > 1 ]; then cmake .. \ -B"${BUILD_DIR}" \ -DCMAKE_BUILD_TYPE="${MODE}" \ -DIOS_PLATFORM=OS \ -DIOS_ARCH="${IOS_ARCH}" \ -DCMAKE_TOOLCHAIN_FILE="${TOOLCHAIN_FILE}" \ - -DNET=$1 \ + -DNET="${NETS}" \ -DIS_IOS="true" else cmake .. \ @@ -123,7 +126,7 @@ build_for_ios() { } build_error() { - echo "unknown argument" + echo "unknown target : $1" } if [ $# -lt 1 ]; then @@ -131,31 +134,37 @@ if [ $# -lt 1 ]; then echo "available targets: ios|android" echo "sample usage: ./build.sh android" else - if [ $# -eq 2 ]; then - if [ $2 != "googlenet" -a $2 != "mobilenet" -a $2 != "yolo" -a $2 != "squeezenet" -a $2 != "resnet" ]; then - if [ $1 = "android" ]; then - build_for_android - elif [ $1 = "ios" ]; then - build_for_ios - else - build_error - fi - else - if [ $1 = "android" ]; then - build_for_android $2 - elif [ $1 = "ios" ]; then - build_for_ios $2 - else - build_error - fi + params=($@) + for(( i=1; i<$#; i++ )); do + if [ ${i} != 1 ]; then + NETS=$NETS$";" + fi + NETS=$NETS$"${params[i]}" + done + params=${@:2} + + supported=false + for name in ${params[@]}; do + for net in ${supportedNets[@]}; do + match=false + if [ "$name"x = "$net"x ];then + supported=true + match=true + break 1 + fi + done + if [ "$match" = false ];then + echo "${name} not supported!" + echo "supported nets are: ${supportedNets[@]}" + exit -1 fi + done + + if [ $1 = "android" ]; then + build_for_android + elif [ $1 = "ios" ]; then + build_for_ios else - if [ $1 = "android" ]; then - build_for_android - elif [ $1 = "ios" ]; then - build_for_ios - else - build_error - fi - fi + build_error "$1" + fi fi \ No newline at end of file diff --git a/tools/op.cmake b/tools/op.cmake index 50fca67092d964baeafecf10146e22efce24c98a..d90a3db9883bd189e3187e11164994646c16fc33 100644 --- a/tools/op.cmake +++ b/tools/op.cmake @@ -1,4 +1,6 @@ -if (NET STREQUAL "googlenet") +set(FOUND_MATCH OFF) +if ("googlenet" IN_LIST NET) + message("googlenet enabled") set(CONCAT_OP ON) set(CONV_OP ON) set(LRN_OP ON) @@ -9,7 +11,12 @@ if (NET STREQUAL "googlenet") set(RELU_OP ON) set(FUSION_CONVADD_OP ON) set(FUSION_CONVADD_RELU_OP ON) -elseif (NET STREQUAL "mobilenet") + + set(FOUND_MATCH ON) +endif() + +if ("mobilenet" IN_LIST NET) + message("mobilenet enabled") set(CONV_OP ON) set(ELEMENTWISEADD_OP ON) set(RELU_OP ON) @@ -21,12 +28,23 @@ elseif (NET STREQUAL "mobilenet") set(RESHAPE_OP ON) set(FUSION_CONVADDBNRELU_OP ON) set(FUSION_CONVADD_OP ON) -elseif (NET STREQUAL "yolo") + + set(FOUND_MATCH ON) +endif() + + +if ("yolo" IN_LIST NET) + message("yolo enabled") set(BATCHNORM_OP ON) set(CONV_OP ON) set(RELU_OP ON) set(ELEMENTWISEADD_OP ON) -elseif (NET STREQUAL "squeezenet") + + set(FOUND_MATCH ON) +endif() + +if ("squeezenet" IN_LIST NET) + message("squeezenet enabled") set(CONCAT_OP ON) set(CONV_OP ON) set(RELU_OP ON) @@ -34,15 +52,26 @@ elseif (NET STREQUAL "squeezenet") set(POOL_OP ON) set(RESHAPE_OP ON) set(SOFTMAX_OP ON) -elseif (NET STREQUAL "resnet") + + set(FOUND_MATCH ON) +endif() + + +if ("resnet" IN_LIST NET) + message("resnet enabled") + set(CONCAT_OP ON) set(CONV_OP ON) - set(BATCHNORM_OP ON) + set(RELU_OP ON) set(ELEMENTWISEADD_OP ON) - set(SOFTMAX_OP ON) - set(MUL_OP ON) set(POOL_OP ON) - set(RELU_OP ON) -elseif (NET STREQUAL "FPGAnets") + set(RESHAPE_OP ON) + set(SOFTMAX_OP ON) + + set(FOUND_MATCH ON) +endif() + +if ("FPGAnets" IN_LIST NET) + message("FPGAnets enabled") set(FUSION_CONVRELU_OP ON) set(FUSION_CONVBNSCALE_OP ON) set(FUSION_CONVBNSCALERELU_OP ON) @@ -51,8 +80,14 @@ elseif (NET STREQUAL "FPGAnets") set(REGION_OP ON) set(POOL_OP ON) set(CONCAT_OP ON) - set(SOFTMAX_OP ON) -else () + set(SOFTMAX_OP ON) + + set(FOUND_MATCH ON) +endif() + + +if(NOT FOUND_MATCH) + message("--default--") set(BATCHNORM_OP ON) set(BOXCODER_OP ON) set(CONCAT_OP ON) @@ -82,6 +117,8 @@ else () set(SLICE_OP ON) set(DROPOUT_OP ON) set(IM2SEQUENCE_OP ON) +endif() + # option(BATCHNORM_OP "" ON) # option(BOXCODER_OP "" ON) # option(CONCAT_OP "" ON) @@ -102,7 +139,7 @@ else () # option(SOFTMAX_OP "" ON) # option(TRANSPOSE_OP "" ON) # option(FUSION_CONVADD_RELU_OP "" ON) -endif () +# endif () if (BATCHNORM_OP) add_definitions(-DBATCHNORM_OP)