Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
9 changes: 7 additions & 2 deletions lite/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,15 @@ else()
# 1. enable -flto compiling flag if toochain==gcc
# TODO (hong19860320): Disable lto temporarily since it causes fail to catch the exceptions in android when toolchain is gcc.
if (NOT (ARM_TARGET_LANG STREQUAL "clang"))
if (ARM_TARGET_OS STREQUAL "android" AND LITE_WITH_EXCEPTION)
if ((ARM_TARGET_OS STREQUAL "android" OR ARM_TARGET_OS STREQUAL "armmacos") AND LITE_WITH_EXCEPTION)
set(TARGET_COMIPILE_FLAGS "")
else()
set(TARGET_COMIPILE_FLAGS "-fdata-sections -flto")
endif()
else()
set(TARGET_COMIPILE_FLAGS "-fdata-sections")
if (NOT LITE_WITH_METAL)
set(TARGET_COMIPILE_FLAGS "-fdata-sections")
endif()
endif()
# 1.1 enable -flto on PADDLELITE_OBJS
set_target_properties(PADDLELITE_OBJS PROPERTIES COMPILE_FLAGS "${TARGET_COMIPILE_FLAGS}")
Expand All @@ -159,6 +161,9 @@ else()
add_library(paddle_light_api_shared SHARED $<TARGET_OBJECTS:PADDLELITE_OBJS>)
set_target_properties(paddle_light_api_shared PROPERTIES COMPILE_FLAGS "${TARGET_COMIPILE_FLAGS}")
# 2.1 link `paddle_light_api_shared` to third-party libs
if (LITE_WITH_METAL)
target_link_libraries(paddle_light_api_shared ${METAL_LIBRARY} ${MPS_LIBRARY} ${FOUNDATION_LIBRARY})
endif()
if (LITE_WITH_NPU)
# Need to add HIAI runtime libs (libhiai.so) dependency
target_link_libraries(paddle_light_api_shared ${npu_builder_libs} ${npu_runtime_libs})
Expand Down
6 changes: 4 additions & 2 deletions lite/backends/metal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ FILE(GLOB LITE_METAL_KERNELS_SRC ${CMAKE_SOURCE_DIR}/lite/backends/metal/metal_k
${CMAKE_SOURCE_DIR}/lite/backends/metal/metal_kernel/texture/*.metal
)

IF (DEFINED SDK_VERSION)
IF (SDK_NAME STREQUAL "iphoneos")
#Defined by iOS toolchain
SET(SDK_NAME "iphoneos")
SET(METAL_STD_OPTION "-std=ios-metal1.1")
SET(TARGET_OPTION "-mios-version-min=${DEPLOYMENT_TARGET}")
ELSE ()
SET(SDK_NAME "macosx")
SET(METAL_STD_OPTION "-std=macos-metal1.1")
SET(TARGET_OPTION "")
ENDIF ()

Expand All @@ -41,6 +42,7 @@ lite_cc_library(metal_target_wrapper SRCS
target_wrapper.mm
)

target_link_libraries(metal_target_wrapper ${METAL_LIBRARY} ${GRAPHIC} ${MPS_LIBRARY} ${FOUNDATION_LIBRARY})

target_link_libraries(metal_target_wrapper ${METAL_LIBRARY} ${MPS_LIBRARY} ${FOUNDATION_LIBRARY})

add_dependencies(metal_target_wrapper LiteMetalLIB)
3 changes: 2 additions & 1 deletion lite/backends/metal/metal_context_imp.mm
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ - (void)dealloc {

- (void)setMetalPath:(std::string)path {
NSString* pathStr = cString2NSString(path);
NSError* libraryErr = nil;
if (pathStr) {
self.libPath = pathStr;
self.library = [self.device newLibraryWithFile:pathStr error:NULL];
self.library = [self.device newLibraryWithFile:pathStr error:&libraryErr];
}
if (nil == _library) {
LOG(INFO) << "Can't load metallib: " << [pathStr cStringUsingEncoding:NSUTF8StringEncoding];
Expand Down
16 changes: 16 additions & 0 deletions lite/tools/build_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ BUILD_CV=OFF
WITH_LOG=ON
WITH_MKL=ON
WITH_OPENCL=OFF
WITH_METAL=OFF
LITE_ON_TINY_PUBLISH=OFF
WITH_STATIC_MKL=OFF
WITH_AVX=ON
Expand Down Expand Up @@ -129,13 +130,20 @@ function make_armosx {
fi

build_dir=$workspace/build.macos.${os}.${arch}

if [ ${WITH_METAL} == "ON" ]; then
BUILD_EXTRA=ON
build_dir=${build_dir}.metal
fi

if [ ${WITH_OPENCL} == "ON" ]; then
build_dir=${build_dir}.opencl
prepare_opencl_source_code $workspace
fi
if [ "${WITH_BENCHMARK}" == "ON" ]; then
set_benchmark_options
fi

if [ -d $build_dir ]
then
rm -rf $build_dir
Expand All @@ -154,6 +162,7 @@ function make_armosx {
cmake $workspace \
-DWITH_LITE=ON \
-DLITE_WITH_ARM=ON \
-DLITE_WITH_METAL=${WITH_METAL} \
-DLITE_WITH_OPENCL=${WITH_OPENCL} \
-DLITE_ON_TINY_PUBLISH=${LITE_ON_TINY_PUBLISH} \
-DLITE_WITH_OPENMP=OFF \
Expand Down Expand Up @@ -199,6 +208,10 @@ function make_x86 {
prepare_opencl_source_code $root_dir $build_directory
fi

if [ ${WITH_METAL} == "ON" ]; then
BUILD_EXTRA=ON
build_directory=$BUILD_DIR/build.lite.x86.metal
fi
if [ ${BUILD_PYTHON} == "ON" ]; then
BUILD_EXTRA=ON
fi
Expand Down Expand Up @@ -226,6 +239,7 @@ function make_x86 {
-DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=OFF \
-DLITE_WITH_ARM=OFF \
-DLITE_WITH_OPENCL=${WITH_OPENCL} \
-DLITE_WITH_METAL=${WITH_METAL} \
-DWITH_GPU=OFF \
-DLITE_WITH_PYTHON=${BUILD_PYTHON} \
-DLITE_BUILD_EXTRA=${BUILD_EXTRA} \
Expand Down Expand Up @@ -368,6 +382,8 @@ function main {
WITH_OPENCL="${i#*=}"
shift
;;
--with_metal=*)
WITH_METAL="${i#*=}"
--tiny_publish=*)
LITE_ON_TINY_PUBLISH="${i#*=}"
shift
Expand Down