Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmake/external/gflags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
if (NOT EMSCRIPTEN)
INCLUDE(ExternalProject)

if (OHOS)
find_package(gflags)
message("GFLAGS_FOUND: ${gflags_FOUND},${GFLAGS_INCLUDE_DIR}")
INCLUDE_DIRECTORIES(${GFLAGS_INCLUDE_DIR})
SET_PROPERTY(TARGET gflags PROPERTY IMPORTED_LOCATION ${GFLAGS_LIBRARIES})
return()
endif()

SET(GFLAGS_SOURCES_DIR ${PADDLE_SOURCE_DIR}/third-party/gflags)
SET(GFLAGS_INSTALL_DIR ${THIRD_PARTY_PATH}/install/gflags)
SET(GFLAGS_INCLUDE_DIR "${GFLAGS_INSTALL_DIR}/include" CACHE PATH "gflags include directory." FORCE)
Expand Down
30 changes: 24 additions & 6 deletions cmake/external/protobuf.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ IF (WIN32)
SET(PROTOBUF_ROOT ${THIRD_PARTY_PATH}/install/protobuf)
ENDIF(WIN32)

if (NOT "${PROTOBUF_ROOT}" STREQUAL "")
if (NOT ("${PROTOBUF_ROOT}" STREQUAL "" and OHOS))
find_path(PROTOBUF_INCLUDE_DIR google/protobuf/message.h PATHS ${PROTOBUF_ROOT}/include NO_DEFAULT_PATH)
find_library(PROTOBUF_LIBRARY protobuf libprotobuf.lib PATHS ${PROTOBUF_ROOT}/lib NO_DEFAULT_PATH)
find_library(PROTOBUF_LITE_LIBRARY protobuf-lite libprotobuf-lite.lib PATHS ${PROTOBUF_ROOT}/lib NO_DEFAULT_PATH)
Expand Down Expand Up @@ -231,7 +231,9 @@ FUNCTION(build_protobuf TARGET_NAME BUILD_FOR_HOST)
${TARGET_NAME}
${EXTERNAL_PROJECT_LOG_ARGS}
PREFIX ${PROTOBUF_SOURCES_DIR}
SOURCE_SUBDIR cmake
if (NOT OHOS)
SOURCE_SUBDIR cmake
endif()
UPDATE_COMMAND ""
PATCH_COMMAND ${PATCH_COMMAND}
GIT_REPOSITORY ""
Expand Down Expand Up @@ -286,10 +288,26 @@ ENDFUNCTION()
SET(PROTOBUF_VERSION 3.3.0)

IF(LITE_WITH_ARM)
build_protobuf(protobuf_host TRUE)
LIST(APPEND external_project_dependencies protobuf_host)
SET(PROTOBUF_PROTOC_EXECUTABLE ${protobuf_host_PROTOC_EXECUTABLE}
CACHE FILEPATH "protobuf executable." FORCE)
IF(OHOS)
find_path(PROTOBUF_INCLUDE_DIR google/protobuf/message.h PATHS ${PROTOBUF_ROOT}/include NO_DEFAULT_PATH)
find_library(PROTOBUF_LIBRARY protobuf libprotobuf.a PATHS ${PROTOBUF_ROOT}/lib NO_DEFAULT_PATH)
find_library(PROTOBUF_LITE_LIBRARY protobuf-lite libprotobuf-lite.a PATHS ${PROTOBUF_ROOT}/lib NO_DEFAULT_PATH)
find_library(PROTOBUF_PROTOC_LIBRARY protoc libprotoc.a PATHS ${PROTOBUF_ROOT}/lib NO_DEFAULT_PATH)
SET(PROTOBUF_PROTOC_EXECUTABLE ${protobuf_host_PROTOC_EXECUTABLE})
IF (PROTOBUF_INCLUDE_DIR AND PROTOBUF_LIBRARY AND PROTOBUF_LITE_LIBRARY AND PROTOBUF_PROTOC_LIBRARY AND PROTOBUF_PROTOC_EXECUTABLE)
message(STATUS "Using custom protobuf library in ${PROTOBUF_ROOT}.")
SET(PROTOBUF_FOUND true)
SET_PROTOBUF_VERSION()
PROMPT_PROTOBUF_LIB()
ELSE()
message(WARNING "Cannot find protobuf library in ${PROTOBUF_ROOT}")
ENDIF()
ELSE()
build_protobuf(protobuf_host TRUE)
LIST(APPEND external_project_dependencies protobuf_host)
SET(PROTOBUF_PROTOC_EXECUTABLE ${protobuf_host_PROTOC_EXECUTABLE}
CACHE FILEPATH "protobuf executable." FORCE)
ENDIF()
ENDIF()

IF(NOT PROTOBUF_FOUND)
Expand Down
20 changes: 18 additions & 2 deletions cmake/postproject.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ function(check_linker_flag)
set(CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS} PARENT_SCOPE)
endfunction()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
if (NOT OHOS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
endif()
if((LITE_WITH_OPENCL AND (ARM_TARGET_LANG STREQUAL "clang")) OR LITE_WITH_PYTHON OR LITE_WITH_EXCEPTION OR (NOT LITE_ON_TINY_PUBLISH))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -fasynchronous-unwind-tables -funwind-tables")
else ()
Expand Down Expand Up @@ -247,7 +251,19 @@ if(ANDROID)
"-D__ANDROID_API__=${ANDROID_NATIVE_API_LEVEL}"
)
endif()


if(OHOS)
set(CROSS_COMPILE_CMAKE_ARGS ${CROSS_COMPILE_CMAKE_ARGS}
"-DCMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}"
"-DCMAKE_CXX_STANDARD=17"
"-DCMAKE_TOOLCHAIN_FILE=${OHOS_SDK}/native/build/cmake/ohos.toolchain.cmake"
"-DARM_TARGET_ARCH_ABI=${ARM_TARGET_ARCH_ABI}"
"-DOHOS_ARCH=${OHOS_ARCH}"
"-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS}"
"-DCMAKE_SHARED_LINKER_FLAGS=${CMAKE_SHARED_LINKER_FLAGS}"
)
endif()

if(IOS)
if(LITE_WITH_ARM82_FP16)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8.2-a+fp16+nolse")
Expand Down
3 changes: 2 additions & 1 deletion lite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ if (WITH_TESTING)
lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL_FOR_NNADAPTER_UNITTESTS} "ppTSN.tar.gz" MODEL_PATH "PaddleVideo/v2.2.0")
endif()
if(LITE_WITH_ARM)
lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "mobilenet_v1_int8.tar.gz")
lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "mobilenet_v1_int16.tar.gz")
lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "resnet50.tar.gz")
lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "MobileNetV1_quant.tar.gz")
Expand Down Expand Up @@ -428,7 +429,7 @@ if (LITE_WITH_ARM)
if (ARM_TARGET_OS STREQUAL "android")
add_dependencies(publish_inference_cxx_lib test_arm_performance)
endif()
if (ARM_TARGET_OS STREQUAL "android" OR ARM_TARGET_OS STREQUAL "armlinux" OR ARM_TARGET_OS STREQUAL "armmacos" OR ARM_TARGET_OS STREQUAL "qnx")
if (ARM_TARGET_OS STREQUAL "android" OR ARM_TARGET_OS STREQUAL "ohos" OR ARM_TARGET_OS STREQUAL "armlinux" OR ARM_TARGET_OS STREQUAL "armmacos" OR ARM_TARGET_OS STREQUAL "qnx")
add_dependencies(publish_inference_cxx_lib paddle_full_api_shared)
add_dependencies(publish_inference paddle_light_api_shared)
add_custom_command(TARGET publish_inference_cxx_lib
Expand Down
2 changes: 1 addition & 1 deletion lite/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ if (NOT LITE_ON_TINY_PUBLISH)
set_target_properties(paddle_light_api_shared PROPERTIES LINK_FLAGS ${LINK_FLAGS})
add_dependencies(paddle_light_api_shared custom_linker_map)
endif()
if(NOT WIN32 AND NOT ARM_TARGET_OS STREQUAL "android" AND WITH_TESTING)
if(NOT WIN32 AND ((NOT ARM_TARGET_OS STREQUAL "android") OR (NOT ARM_TARGET_OS STREQUAL "ohos")) AND WITH_TESTING)
# check symbol hidden
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/check_symbol.cmake
"execute_process(COMMAND sh -c \"${CMAKE_CURRENT_SOURCE_DIR}/../tools/check_symbol.sh"
Expand Down
19 changes: 17 additions & 2 deletions lite/api/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,17 @@ endif()
if(LITE_WITH_ARM AND WITH_TESTING)
set(lite_model_test_DEPS cxx_api ops kernels)

if(OHOS)
message("test_mobilenetv1_int8 --model_dir=${LITE_MODEL_DIR}/mobilenet_v1_int8")
lite_cc_test(test_mobilenetv1_int8 SRCS mobilenetv1_int8_test.cc
ARGS --model_dir=${LITE_MODEL_DIR}/mobilenet_v1_int8 SERIAL)
add_dependencies(test_mobilenetv1_int8 extern_lite_download_mobilenet_v1_int8_tar_gz)
else()
message("test_mobilenetv1_int8 --model_dir=${LITE_MODEL_DIR}/MobilenetV1_quant")
lite_cc_test(test_mobilenetv1_int8 SRCS mobilenetv1_int8_test.cc
ARGS --model_dir=${LITE_MODEL_DIR}/MobilenetV1_quant SERIAL)
add_dependencies(test_mobilenetv1_int8 extern_lite_download_MobileNetV1_quant_tar_gz)
endif()

lite_cc_test(test_mobilenetv1 SRCS mobilenetv1_test.cc
ARGS --model_dir=${LITE_MODEL_DIR}/mobilenet_v1 SERIAL)
Expand Down Expand Up @@ -72,11 +80,18 @@ if(LITE_WITH_ARM AND WITH_TESTING)
ARGS --model_dir=${LITE_MODEL_DIR}/resnet50 SERIAL)
add_dependencies(test_resnet50 extern_lite_download_resnet50_tar_gz)

if(LITE_WITH_OPENCL)
lite_cc_test(test_inceptionv4 SRCS inceptionv4_test.cc
ARGS --model_dir=${LITE_MODEL_DIR}/inception_v4 SERIAL)
add_dependencies(test_inceptionv4 extern_lite_download_inception_v4_tar_gz)
else()
lite_cc_test(test_inceptionv4 SRCS inceptionv4_test.cc
ARGS --model_dir=${LITE_MODEL_DIR}/inception_v4_simple SERIAL)
add_dependencies(test_inceptionv4 extern_lite_download_inception_v4_simple_tar_gz)

lite_cc_test(test_fast_rcnn SRCS fast_rcnn_test.cc)
endif()

lite_cc_test(test_fast_rcnn SRCS fast_rcnn_test.cc
ARGS --model_dir=${LITE_MODEL_DIR}/fast_rcnn_fluid184 SERIAL)
add_dependencies(test_fast_rcnn extern_lite_download_fast_rcnn_fluid184_tar_gz)

# brief: we comment ocr_test_ut because we do not supply ocr model to test, it is the reference to infer nlp model
Expand Down
12 changes: 10 additions & 2 deletions lite/backends/arm/math/gemm_prepacked_int8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4969,7 +4969,11 @@ void prepackA_m4k2x2_trans_int8(int8_t* out,
int8x16_t vzero = vdupq_n_s8(0);
uint8x16_t vmask = vcltq_u8(vld1q_u8(mask_buffer), vdupq_n_u8(x_rem));

int stride_out = ylen_roundup * MBLOCK_INT8_OTH;
#ifdef __aarch64__
int64_t stride_out = ylen_roundup * MBLOCK_INT8_OTH;
#else
int32_t stride_out = ylen_roundup * MBLOCK_INT8_OTH;
#endif

int8_t* zerobuf = static_cast<int8_t*>(malloc(xlen_roundup));
memset(zerobuf, 0, xlen_roundup);
Expand Down Expand Up @@ -5290,7 +5294,11 @@ void packb_int8(int8_t* out,
int kup = ROUNDUP(y_len, KBLOCK_INT8);
int kcnt = x_len / NBLOCK_INT8_OTH;
int rem = x_len & (NBLOCK_INT8_OTH - 1);
int stride_out = NBLOCK_INT8_OTH * kup;
#ifdef __aarch64__
int64_t stride_out = NBLOCK_INT8_OTH * kup;
#else
int32_t stride_out = NBLOCK_INT8_OTH * kup;
#endif

int8x16_t vzero = vdupq_n_s8(0);
uint8x16_t vmask = vcltq_u8(vld1q_u8(mask_buffer), vdupq_n_u8(rem));
Expand Down