Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mnn,flatbuffers] add a new port and patch #15717

Merged
merged 20 commits into from
Mar 23, 2021
Merged
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
1 change: 1 addition & 0 deletions ports/flatbuffers/CONTROL
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Source: flatbuffers
Version: 1.12.0
Port-Version: 1
Description: Memory Efficient Serialization Library
FlatBuffers is an efficient cross platform serialization library for games and other memory constrained apps. It allows you to directly access serialized data without unpacking/parsing it first, while still having great forwards/backwards compatibility.
Homepage: https://google.github.io/flatbuffers/
23 changes: 23 additions & 0 deletions ports/flatbuffers/fix-issue-6036.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff --git a/include/flatbuffers/flatbuffers.h b/include/flatbuffers/flatbuffers.h
index c4dc5bc..c090455 100644
--- a/include/flatbuffers/flatbuffers.h
+++ b/include/flatbuffers/flatbuffers.h
@@ -1861,14 +1861,14 @@ class FlatBufferBuilder {

/// @cond FLATBUFFERS_INTERNAL
template<typename T> struct TableKeyComparator {
- TableKeyComparator(vector_downward &buf) : buf_(buf) {}
+ TableKeyComparator(vector_downward &buf) : buf_(&buf) {}
TableKeyComparator(const TableKeyComparator &other) : buf_(other.buf_) {}
bool operator()(const Offset<T> &a, const Offset<T> &b) const {
- auto table_a = reinterpret_cast<T *>(buf_.data_at(a.o));
- auto table_b = reinterpret_cast<T *>(buf_.data_at(b.o));
+ auto table_a = reinterpret_cast<T *>(buf_->data_at(a.o));
+ auto table_b = reinterpret_cast<T *>(buf_->data_at(b.o));
return table_a->KeyCompareLessThan(table_b);
}
- vector_downward &buf_;
+ vector_downward *buf_;

private:
TableKeyComparator &operator=(const TableKeyComparator &other) {
4 changes: 3 additions & 1 deletion ports/flatbuffers/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ vcpkg_from_github(
PATCHES
ignore_use_of_cmake_toolchain_file.patch
no-werror.patch
fix-uwp-build.patch
fix-uwp-build.patch
fix-issue-6036.patch # this patch is already applied to the latest master branch.
# remove it in next version update
)

set(OPTIONS)
Expand Down
105 changes: 105 additions & 0 deletions ports/mnn/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
vcpkg_fail_port_install(ON_ARCH "arm" ON_TARGET "uwp" "ios" "android")
if(VCPKG_TARGET_IS_WINDOWS)
vcpkg_check_linkage(ONLY_STATIC_LIBRARY)
endif()

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO alibaba/MNN
REF 1.1.0
SHA512 3e31eec9a876be571cb2d29e0a2bcdb8209a43a43a5eeae19b295fadfb1252dd5bd4ed5b7c584706171e1b531710248193bc04520a796963e2b21546acbedae0
HEAD_REF master
PATCHES
use-package-and-install.patch
)

vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
FEATURES
test MNN_BUILD_TEST
test MNN_BUILD_BENCHMARK
cuda MNN_CUDA
cuda MNN_GPU_TRACE
vulkan MNN_VULKAN
vulkan MNN_GPU_TRACE
vulkan MNN_USE_SYSTEM_LIB
opencl MNN_OPENCL
opencl MNN_USE_SYSTEM_LIB
metal MNN_METAL
metal MNN_GPU_TRACE
tools MNN_BUILD_TOOLS
tools MNN_BUILD_QUANTOOLS
tools MNN_BUILD_TRAIN
tools MNN_EVALUATION
tools MNN_BUILD_CONVERTER
)

# 'cuda' feature in Windows failes with Ninja because of parallel PDB access. Make it optional
set(NINJA_OPTION PREFER_NINJA)
if("cuda" IN_LIST FEATURES)
unset(NINJA_OPTION)
endif()

if(VCPKG_TARGET_IS_WINDOWS)
string(COMPARE EQUAL "${VCPKG_CRT_LINKAGE}" "static" USE_RUNTIME_MT)
list(APPEND PLATFORM_OPTIONS -DMNN_WIN_RUNTIME_MT=${USE_RUNTIME_MT})
endif()

string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" BUILD_SHARED)

vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
${NINJA_OPTION}
OPTIONS
${FEATURE_OPTIONS} ${PLATFORM_OPTIONS}
-DMNN_BUILD_SHARED_LIBS=${BUILD_SHARED}
# 1.1.0.0-${commit}
-DMNN_VERSION_MAJOR=1 -DMNN_VERSION_MINOR=1 -DMNN_VERSION_PATCH=0 -DMNN_VERSION_BUILD=0 -DMNN_VERSION_SUFFIX=-d6795ad
OPTIONS_DEBUG
-DMNN_DEBUG_MEMORY=ON -DMNN_DEBUG_TENSOR_SIZE=ON
)
vcpkg_install_cmake()
vcpkg_copy_pdbs()

vcpkg_download_distfile(COPYRIGHT_PATH
URLS "https://apache.org/licenses/LICENSE-2.0.txt"
FILENAME 98f6b79b778f7b0a1541.txt
SHA512 98f6b79b778f7b0a15415bd750c3a8a097d650511cb4ec8115188e115c47053fe700f578895c097051c9bc3dfb6197c2b13a15de203273e1a3218884f86e90e8
)
file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/share/${PORT})
file(RENAME ${COPYRIGHT_PATH} ${CURRENT_PACKAGES_DIR}/share/${PORT}/copyright)

if(VCPKG_TARGET_IS_OSX OR VCPKG_TARGET_IS_IOS)
if("metal" IN_LIST FEATURES)
file(RENAME ${CURRENT_PACKAGES_DIR}/bin/mnn.metallib
${CURRENT_PACKAGES_DIR}/share/${PORT}/mnn.metallib)
endif()
else()
file(MAKE_DIRECTORY ${CURRENT_PACKAGES_DIR}/share/${PORT})
endif()

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
if("test" IN_LIST FEATURES)
# no install(TARGETS) for the following binaries. check the buildtrees...
# vcpkg_copy_tools(
# TOOL_NAMES run_test.out benchmark.out benchmarkExprModels.out # test/
# AUTO_CLEAN
# )
endif()
if("tools" IN_LIST FEATURES)
vcpkg_copy_tools(
TOOL_NAMES MNNV2Basic.out mobilenetTest.out backendTest.out testModel.out testModelWithDescrisbe.out getPerformance.out checkInvalidValue.out timeProfile.out # tools/cpp
quantized.out # tools/quantization
classficationTopkEval.out # tools/evaluation
MNNDump2Json MNNConvert # tools/converter
transformer.out train.out dataTransformer.out runTrainDemo.out # tools/train
AUTO_CLEAN
)
if(BUILD_SHARED)
vcpkg_copy_tools(TOOL_NAMES TestConvertResult AUTO_CLEAN) # tools/converter
endif()
endif()
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
# remove the others. ex) mnn.metallib
file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin
${CURRENT_PACKAGES_DIR}/debug/bin)
endif()
194 changes: 194 additions & 0 deletions ports/mnn/use-package-and-install.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 993f15d..53f24ae 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -270,18 +270,24 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "^Linux")
include_directories(${aarch64_linux_include})
endif()
endif()
+
+if(MNN_OPENCL)
+ find_package(OpenCL REQUIRED)
+endif()
+find_package(RapidJSON CONFIG REQUIRED)
+find_path(STB_INCLUDE_DIRS "stb.h")
+find_package(Flatbuffers CONFIG REQUIRED)
include_directories(${CMAKE_CURRENT_LIST_DIR}/include/
${CMAKE_CURRENT_LIST_DIR}/source/
${CMAKE_CURRENT_LIST_DIR}/express/
${CMAKE_CURRENT_LIST_DIR}/tools/
${CMAKE_CURRENT_LIST_DIR}/schema/current/
- ${CMAKE_CURRENT_LIST_DIR}/3rd_party/
- ${CMAKE_CURRENT_LIST_DIR}/3rd_party/flatbuffers/include
${CMAKE_CURRENT_LIST_DIR}/3rd_party/half
- ${CMAKE_CURRENT_LIST_DIR}/3rd_party/imageHelper
- ${CMAKE_CURRENT_LIST_DIR}/3rd_party/OpenCLHeaders/
+ ${RAPIDJSON_INCLUDE_DIRS}
+ ${STB_INCLUDE_DIRS}
+ ${OpenCL_INCLUDE_DIRS}
)
-
+link_libraries(flatbuffers::flatbuffers ${OpenCL_LIBRARIES})

set(MNN_OBJECTS_TO_LINK "")
set(MNN_TARGETS "")
@@ -631,10 +637,14 @@ ELSEIF(NOT APPLE)
INSTALL(FILES ${MNN_PUB_HDRS} DESTINATION include/MNN/)
INSTALL(FILES ${MNN_EXPR_PUB_HDRS} DESTINATION include/MNN/expr/)
install(TARGETS MNN
+ RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
+
ELSE()
+ INSTALL(FILES ${MNN_PUB_HDRS} DESTINATION include/MNN/)
+ INSTALL(FILES ${MNN_EXPR_PUB_HDRS} DESTINATION include/MNN/expr/)
install(TARGETS MNN
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
@@ -648,5 +658,6 @@ ELSE()
ENDFOREACH()
IF(MNN_METAL)
SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_BINARY_DIR}/mnn.metallib PROPERTIES MACOSX_PACKAGE_LOCATION Resources/)
+ INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/mnn.metallib DESTINATION bin)
ENDIF()
ENDIF()
diff --git a/source/backend/cuda/CMakeLists.txt b/source/backend/cuda/CMakeLists.txt
index f9a24cc..8b1f96f 100644
--- a/source/backend/cuda/CMakeLists.txt
+++ b/source/backend/cuda/CMakeLists.txt
@@ -16,9 +16,26 @@ endif()
file(GLOB_RECURSE MNN_CUDA_SRC ${CMAKE_CURRENT_LIST_DIR}/core/* ${CMAKE_CURRENT_SOURCE_DIR}/execution/*)
message(STATUS "message ${CUDA_NVCC_FLAGS} !!!!!!!!!!!")

+# see https://github.com/microsoft/vcpkg/blob/master/ports/cudnn/FindCUDNN.cmake
+find_package(CUDNN REQUIRED)
+message(STATUS "using cudnn: ${CUDNN_LIBRARIES}")
+
+if(WIN32)
+ find_library(CUBLAS_LIB NAMES cublas PATHS $ENV{CUDA_PATH}/lib/x64)
+else()
+ find_library(CUBLAS_LIB cublas)
+endif()
+if(NOT CUBLAS_LIB)
+ message(FATAL_ERROR "cublas not found")
+else()
+ message(STATUS "using cublas: ${CUBLAS_LIB}")
+endif()
+
# add_library(MNN_Cuda SHARED ${MNN_CUDA_SRC} )
-cuda_add_library(MNN_Cuda_Main SHARED ${MNN_CUDA_SRC} )
-set(MNN_CUDA_LIBS MNN_Cuda_Main cudnn cublas PARENT_SCOPE)
+cuda_add_library(MNN_Cuda_Main STATIC ${MNN_CUDA_SRC} )
+target_link_libraries(MNN_Cuda_Main CuDNN::CuDNN ${CUBLAS_LIB})
+
+set(MNN_CUDA_LIBS MNN_Cuda_Main ${CUDNN_LIB} PARENT_SCOPE)
add_library(MNN_CUDA OBJECT Register.cpp)

include_directories(
diff --git a/source/backend/tensorrt/CMakeLists.txt b/source/backend/tensorrt/CMakeLists.txt
index aadabd6..3a0d81e 100644
--- a/source/backend/tensorrt/CMakeLists.txt
+++ b/source/backend/tensorrt/CMakeLists.txt
@@ -7,7 +7,7 @@ FIND_PACKAGE(CUDA REQUIRED)

add_library( MNN_TRT OBJECT ${MNN_TRT_SRCS})

-include_directories(/usr/local/cuda/include/)
+include_directories(${CUDA_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_LIST_DIR}/backend/)
include_directories(${CMAKE_CURRENT_LIST_DIR}/execution/)
include_directories(${CMAKE_CURRENT_LIST_DIR}/execution/plugin/)
diff --git a/tools/converter/CMakeLists.txt b/tools/converter/CMakeLists.txt
index 2d5133a..d39977a 100644
--- a/tools/converter/CMakeLists.txt
+++ b/tools/converter/CMakeLists.txt
@@ -38,11 +38,12 @@ IF(MNN_BUILD_CONVERTER)
${CMAKE_CURRENT_LIST_DIR}/source/cli.cpp
${CMAKE_CURRENT_LIST_DIR}/source/config.cpp
)
- IF(MNN_BUILD_SHARED_LIBS)
- add_library(MNNConvertDeps SHARED ${COMMON_SRC} ${MNN_CONVERTER_BACKENDS_OBJECTS} ${CMAKE_CURRENT_LIST_DIR}/../../3rd_party/flatbuffers/src/util.cpp $<TARGET_OBJECTS:MNNUtils>)
+ # if Windows, meld MNNConvertDeps(lib) into MNNConvert(exe)
+ IF(MNN_BUILD_SHARED_LIBS AND NOT WIN32)
+ add_library(MNNConvertDeps SHARED ${COMMON_SRC} ${MNN_CONVERTER_BACKENDS_OBJECTS} $<TARGET_OBJECTS:MNNUtils>)
add_dependencies(MNNConvertDeps MNN)
ELSE()
- add_library(MNNConvertDeps STATIC ${COMMON_SRC} ${MNN_CONVERTER_BACKENDS_OBJECTS} ${CMAKE_CURRENT_LIST_DIR}/../../3rd_party/flatbuffers/src/util.cpp)
+ add_library(MNNConvertDeps STATIC ${COMMON_SRC} ${MNN_CONVERTER_BACKENDS_OBJECTS})
ENDIF()


@@ -68,5 +69,7 @@ IF(MNN_BUILD_CONVERTER)
add_executable(TestConvertResult ${CMAKE_CURRENT_LIST_DIR}/source/TestConvertResult.cpp)
target_link_libraries(TestConvertResult MNNConvertDeps)
target_link_libraries(MNNConvert MNNConvertDeps)
+ install(TARGETS TestConvertResult RUNTIME DESTINATION bin)
ENDIF()
+ install(TARGETS MNNDump2Json MNNConvert RUNTIME DESTINATION bin)
ENDIF()
diff --git a/tools/cpp/CMakeLists.txt b/tools/cpp/CMakeLists.txt
index def574c..f4e48c6 100644
--- a/tools/cpp/CMakeLists.txt
+++ b/tools/cpp/CMakeLists.txt
@@ -53,3 +53,5 @@ if (MSVC)
endif()
endforeach()
endif()
+
+install(TARGETS ${MNN_CPP_TOOLS} RUNTIME DESTINATION bin)
diff --git a/tools/evaluation/CMakeLists.txt b/tools/evaluation/CMakeLists.txt
index 8773372..e40b66d 100644
--- a/tools/evaluation/CMakeLists.txt
+++ b/tools/evaluation/CMakeLists.txt
@@ -7,4 +7,5 @@ IF(MNN_EVALUATION)
target_link_options(classficationTopkEval.out PRIVATE /WHOLEARCHIVE:$<TARGET_FILE:${DEPEND}>)
endforeach ()
endif()
+ install(TARGETS classficationTopkEval.out RUNTIME DESTINATION bin)
ENDIF()
diff --git a/tools/quantization/CMakeLists.txt b/tools/quantization/CMakeLists.txt
index 1e84ee0..86f3cbc 100644
--- a/tools/quantization/CMakeLists.txt
+++ b/tools/quantization/CMakeLists.txt
@@ -1,3 +1,5 @@
file(GLOB QUANFILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp)
add_executable(quantized.out ${QUANFILES})
target_link_libraries(quantized.out ${MNN_DEPS})
+
+install(TARGETS quantized.out RUNTIME DESTINATION bin)
diff --git a/tools/train/CMakeLists.txt b/tools/train/CMakeLists.txt
index 48f355b..026dc24 100644
--- a/tools/train/CMakeLists.txt
+++ b/tools/train/CMakeLists.txt
@@ -27,6 +27,10 @@ if (MNN_BUILD_TRAIN_MINI)
else()
add_library(MNNTrain ${MNN_LIBARY_TYPE} ${GRAD} ${BASIC_INCLUDE} ${OPTIMIZER} ${DATALOADER} ${TRANSFORMER} ${MODELS} ${DATASETS})
endif()
+IF(MNN_BUILD_SHARED_LIBS)
+ target_compile_definitions(MNNTrain PRIVATE BUILDING_MNN_DLL)
+ENDIF()
+
target_link_libraries(MNNTrain ${MNN_DEPS})

add_executable(transformer.out ${CMAKE_CURRENT_LIST_DIR}/source/exec/transformerExecution.cpp)
@@ -38,7 +42,7 @@ target_link_libraries(train.out MNN)

add_executable(rawDataTransform.out ${CMAKE_CURRENT_LIST_DIR}/source/exec/rawDataTransform.cpp ${SCHEMA} ${BASIC_INCLUDE})

-include_directories(../../3rd_party/imageHelper/)
+# include_directories(../../3rd_party/imageHelper/)
add_executable(dataTransformer.out ${CMAKE_CURRENT_LIST_DIR}/source/exec/dataTransformer.cpp ${SCHEMA} ${BASIC_INCLUDE})
target_link_libraries(dataTransformer.out MNN)

@@ -59,3 +63,9 @@ if (MNN_USE_OPENCV)
add_definitions(-D MNN_USE_OPENCV)
target_link_libraries(runTrainDemo.out ${OpenCV_LIBS})
endif()
+
+install(TARGETS MNNTrain transformer.out train.out dataTransformer.out runTrainDemo.out
+ RUNTIME DESTINATION bin
+ LIBRARY DESTINATION lib
+ ARCHIVE DESTINATION lib
+)
46 changes: 46 additions & 0 deletions ports/mnn/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "mnn",
"version-string": "1.1.0",
"description": "MNN is a blazing fast, lightweight deep learning framework, battle-tested by business-critical use cases in Alibaba",
"homepage": "https://www.mnn.zone/",
"license": "Apache-2.0",
"supports": "!(arm | uwp | ios | android)",
"dependencies": [
"flatbuffers",
"rapidjson",
"stb"
],
"features": {
"cuda": {
"description": "Enable CUDA API backend",
"dependencies": [
"cuda",
"cudnn"
]
},
"metal": {
"description": "Enable Metal API backend for Apple platforms"
},
"opencl": {
"description": "Enable OpenCL API backend",
"dependencies": [
"opencl"
]
},
"test": {
"description": "Build MNN test programs"
},
"tools": {
"description": "Build MNN tools",
"dependencies": [
"protobuf"
]
},
"vulkan": {
"description": "Enable Vulkan API backend",
"dependencies": [
"vulkan"
]
}
}
}
Loading