Skip to content

Commit

Permalink
Synchronize internal github for version 1.2.0 (#1518)
Browse files Browse the repository at this point in the history
  • Loading branch information
hush-alibaba authored Jun 11, 2021
1 parent 75eed04 commit 58545d6
Show file tree
Hide file tree
Showing 621 changed files with 96,935 additions and 34,577 deletions.
8 changes: 4 additions & 4 deletions 3rd_party/flatbuffers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ if(EXISTS "${CMAKE_TOOLCHAIN_FILE}")
# is being configured externally
elseif(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Wno-unused-parameter")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -Wno-unused-parameter")
set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
elseif(CMAKE_COMPILER_IS_GNUCXX)
if(CYGWIN)
Expand All @@ -165,15 +165,15 @@ elseif(CMAKE_COMPILER_IS_GNUCXX)
"${CMAKE_CXX_FLAGS} -std=c++0x")
endif(CYGWIN)
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wall -pedantic -Werror -Wextra -Werror=shadow")
"${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra")
set(FLATBUFFERS_PRIVATE_CXX_FLAGS "-Wold-style-cast")
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.4)
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -faligned-new -Werror=implicit-fallthrough=2")
"${CMAKE_CXX_FLAGS} -faligned-new")
endif()
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wunused-result -Werror=unused-result -Wunused-parameter -Werror=unused-parameter")
"${CMAKE_CXX_FLAGS} -Wunused-result -Wunused-parameter")
endif()

# Certain platforms such as ARM do not use signed chars by default
Expand Down
35 changes: 5 additions & 30 deletions 3rd_party/flatbuffers/src/idl_gen_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1422,9 +1422,8 @@ class CppGenerator : public BaseGenerator {
}

std::string GenFieldOffsetName(const FieldDef &field) {
std::string uname = Name(field);
std::transform(uname.begin(), uname.end(), uname.begin(), ToUpper);
return "VT_" + uname;
std::string uname = NumToString(field.value.offset);
return uname;
}

void GenFullyQualifiedNameGetter(const StructDef &struct_def,
Expand Down Expand Up @@ -1750,32 +1749,8 @@ class CppGenerator : public BaseGenerator {
code_ += " }";
}


GenFullyQualifiedNameGetter(struct_def, Name(struct_def));

// Generate field id constants.
if (struct_def.fields.vec.size() > 0) {
// We need to add a trailing comma to all elements except the last one as
// older versions of gcc complain about this.
code_.SetValue("SEP", "");
code_ += " enum FlatBuffersVTableOffset FLATBUFFERS_VTABLE_UNDERLYING_TYPE {";
for (auto it = struct_def.fields.vec.begin();
it != struct_def.fields.vec.end(); ++it) {
const auto &field = **it;
if (field.deprecated) {
// Deprecated fields won't be accessible.
continue;
}

code_.SetValue("OFFSET_NAME", GenFieldOffsetName(field));
code_.SetValue("OFFSET_VALUE", NumToString(field.value.offset));
code_ += "{{SEP}} {{OFFSET_NAME}} = {{OFFSET_VALUE}}\\";
code_.SetValue("SEP", ",\n");
}
code_ += "";
code_ += " };";
}

// Generate the accessors.
for (auto it = struct_def.fields.vec.begin();
it != struct_def.fields.vec.end(); ++it) {
Expand All @@ -1798,7 +1773,7 @@ class CppGenerator : public BaseGenerator {
} else {
accessor = "GetPointer<";
}
auto offset_str = GenFieldOffsetName(field);
auto offset_str = NumToString(field.value.offset);
auto offset_type =
GenTypeGet(field.value.type, "", "const ", " *", false);

Expand Down Expand Up @@ -2021,7 +1996,7 @@ class CppGenerator : public BaseGenerator {
// }
code_.SetValue("FIELD_NAME", Name(field));
code_.SetValue("FIELD_TYPE", GenTypeWire(field.value.type, " ", true));
code_.SetValue("ADD_OFFSET", Name(struct_def) + "::" + offset);
code_.SetValue("ADD_OFFSET", offset);
code_.SetValue("ADD_NAME", name);
code_.SetValue("ADD_VALUE", value);
if (is_scalar) {
Expand Down Expand Up @@ -2068,7 +2043,7 @@ class CppGenerator : public BaseGenerator {
if (!field.deprecated && field.required) {
code_.SetValue("FIELD_NAME", Name(field));
code_.SetValue("OFFSET_NAME", GenFieldOffsetName(field));
code_ += " fbb_.Required(o, {{STRUCT_NAME}}::{{OFFSET_NAME}});";
code_ += " fbb_.Required(o, {{OFFSET_NAME}});";
}
}
code_ += " return o;";
Expand Down
34 changes: 31 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ option(MNN_USE_SSE "Use SSE optimization for x86 if possiable" ON)
option(MNN_BUILD_CODEGEN "Build with codegen" OFF)
option(MNN_ENABLE_COVERAGE "Build with coverage enable" OFF)

IF (NOT DEFINED MNN_USE_SPARSE_COMPUTE)
IF (TARGET_OS_IPHONE OR TARGET_OS_SIMULATOR)
set(MNN_USE_SPARSE_COMPUTE OFF)
ELSE()
set(MNN_USE_SPARSE_COMPUTE ON)
ENDIF()
ENDIF()

IF(NOT MNN_BUILD_SHARED_LIBS AND MNN_SEP_BUILD)
message(WARNING "Close MNN_SEP_BUILD for static library")
SET(MNN_SEP_BUILD OFF CACHE BOOL "<docstring>" FORCE)
Expand Down Expand Up @@ -117,7 +125,6 @@ IF(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT MNN_BUILD_SHARED_LIBS AND NOT (M
ENDIF()
ENDIF()


if(MNN_FORBID_MULTI_THREAD)
add_definitions(-DMNN_FORBIT_MULTI_THREADS)
endif()
Expand Down Expand Up @@ -146,6 +153,7 @@ option(MNN_ONEDNN "Enable oneDNN" OFF)
option(MNN_AVX512 "Enable AVX512" OFF)
option(MNN_CUDA "Enable CUDA" OFF)
option(MNN_TENSORRT "Enable TensorRT" OFF)
option(MNN_COREML "Enable CoreML" OFF)

if (MNN_USE_THREAD_POOL)
message(STATUS "Use Threadpool, forbid openmp")
Expand Down Expand Up @@ -182,6 +190,7 @@ message(STATUS "\tVulkan: ${MNN_VULKAN}")
message(STATUS "\tARM82: ${MNN_ARM82}")
message(STATUS "\toneDNN: ${MNN_ONEDNN}")
message(STATUS "\tTensorRT: ${MNN_TENSORRT}")
message(STATUS "\tCoreML: ${MNN_COREML}")
message(STATUS "\tCUDA: ${MNN_CUDA}")
message(STATUS "\tOpenMP: ${MNN_OPENMP}")
message(STATUS "\tBF16: ${MNN_SUPPORT_BF16}")
Expand Down Expand Up @@ -319,8 +328,14 @@ FILE(GLOB MNN_CV_SRC ${CMAKE_CURRENT_LIST_DIR}/source/cv/*)
add_library(MNNCV OBJECT ${MNN_CV_SRC})
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNNCV>)
list(APPEND MNN_TARGETS MNNCV)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(X86_64)|(x64)|(X64)|(amd64)|(AMD64)|(i686)")
if (APPLE)
add_definitions(-fno-stack-check) # Workaround a Xcode 11.X bug
endif()
endif()
if (MNN_USE_SSE)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(X86_64)|(x64)|(X64)|(amd64)|(AMD64)|(i686)")
target_compile_options(MNNCV PRIVATE -DMNN_USE_SSE)
if (NOT MSVC)
target_compile_options(MNNCV PRIVATE -msse4.1)
endif()
Expand Down Expand Up @@ -401,8 +416,6 @@ if (NOT APPLE)
endif()
endif()

set(CMAKE_CXX_FLAGS_ORIGIN ${CMAKE_CXX_FLAGS})
set(CMAKE_C_FLAGS_ORIGIN ${CMAKE_C_FLAGS})
if ((NOT MSVC) AND MNN_HIDDEN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden -fvisibility=hidden")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
Expand Down Expand Up @@ -435,6 +448,21 @@ if(MNN_METAL AND APPLE)
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNNMetal>)
endif()

# CoreML
IF(MNN_COREML)
add_definitions(-DMNN_COREML_ENABLED=1)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/source/backend/coreml/)
list(APPEND MNN_DEPS MNNCoreML)
list(APPEND MNN_OBJECTS_TO_LINK $<TARGET_OBJECTS:MNNCoreML>)

find_library(COREML CoreML)
find_library(FOUNDATION Foundation)
find_library(METAL Metal)
list(APPEND MNN_EXTRA_DEPENDS ${COREML})
list(APPEND MNN_EXTRA_DEPENDS ${FOUNDATION})
list(APPEND MNN_EXTRA_DEPENDS ${METAL})
ENDIF()

# Vulkan
IF(MNN_VULKAN)
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/source/backend/vulkan/)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
47 changes: 38 additions & 9 deletions benchmark/benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ std::vector<Model> findModelFiles(const char* dir) {

void setInputData(MNN::Tensor* tensor) {
float* data = tensor->host<float>();
for (int i = 0; i < tensor->elementSize(); i++) {
data[i] = Revert::getRandValue();
}
Revert::fillRandValue(data, tensor->elementSize());
}

static inline uint64_t getTimeInUs() {
Expand All @@ -117,9 +115,9 @@ static inline uint64_t getTimeInUs() {
}

std::vector<float> doBench(Model& model, int loop, int warmup = 10, int forward = MNN_FORWARD_CPU, bool only_inference = true,
int numberThread = 4, int precision = 2) {
int numberThread = 4, int precision = 2, float sparsity = 0.0f, int sparseBlockOC = 1) {
auto revertor = std::unique_ptr<Revert>(new Revert(model.model_file.c_str()));
revertor->initialize();
revertor->initialize(sparsity, sparseBlockOC);
auto modelBuffer = revertor->getBuffer();
const auto bufferSize = revertor->getBufferSize();
auto net = std::shared_ptr<MNN::Interpreter>(MNN::Interpreter::createFromBuffer(modelBuffer, bufferSize));
Expand Down Expand Up @@ -348,15 +346,36 @@ void set_cpu_affinity()
#endif
}

#if TARGET_OS_IPHONE
void iosBenchAll(const char* modelPath) {
std::cout << "MNN benchmark" << std::endl;
int loop = 20;
int warmup = 10;
MNNForwardType forward = MNN_FORWARD_CPU;
forward = MNN_FORWARD_NN;
int numberThread = 4;
int precision = 2;
std::cout << "Forward type: **" << forwardType(forward) << "** thread=" << numberThread << "** precision=" <<precision << std::endl;
std::vector<Model> models = findModelFiles(modelPath);
std::cout << "--------> Benchmarking... loop = " << loop << ", warmup = " << warmup << std::endl;

for (auto& m : models) {
std::vector<float> costs = doBench(m, loop, warmup, forward, false, numberThread, precision);
displayStats(m.name, costs);
}
}
#else
int main(int argc, const char* argv[]) {
std::cout << "MNN benchmark" << std::endl;
int loop = 10;
int warmup = 10;
MNNForwardType forward = MNN_FORWARD_CPU;
int numberThread = 4;
int precision = 2;
float sparsity = 0.0f;
int sparseBlockOC = 1;
if (argc <= 2) {
std::cout << "Usage: " << argv[0] << " models_folder [loop_count] [warmup] [forwardtype] [numberThread] [precision]" << std::endl;
std::cout << "Usage: " << argv[0] << " models_folder [loop_count] [warmup] [forwardtype] [numberThread] [precision] [weightSparsity]" << std::endl;
return 1;
}
if (argc >= 3) {
Expand All @@ -371,11 +390,20 @@ int main(int argc, const char* argv[]) {
if (argc >= 6) {
numberThread = atoi(argv[5]);
}
int precision = 2;

if (argc >= 7) {
precision = atoi(argv[6]);
}
std::cout << "Forward type: **" << forwardType(forward) << "** thread=" << numberThread << "** precision=" <<precision << std::endl;

if(argc >= 8) {
sparsity = atof(argv[7]);
}

if(argc >= 9) {
sparseBlockOC = atoi(argv[8]);
}

std::cout << "Forward type: **" << forwardType(forward) << "** thread=" << numberThread << "** precision=" <<precision << "** sparsity=" <<sparsity << "** sparseBlockOC=" << sparseBlockOC << std::endl;
std::vector<Model> models = findModelFiles(argv[1]);

std::cout << "--------> Benchmarking... loop = " << argv[2] << ", warmup = " << warmup << std::endl;
Expand All @@ -384,7 +412,8 @@ int main(int argc, const char* argv[]) {
// set_cpu_affinity();

for (auto& m : models) {
std::vector<float> costs = doBench(m, loop, warmup, forward, false, numberThread, precision);
std::vector<float> costs = doBench(m, loop, warmup, forward, false, numberThread, precision, sparsity, sparseBlockOC);
displayStats(m.name, costs);
}
}
#endif
9 changes: 9 additions & 0 deletions benchmark/benchmark.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// benchmark.h
// MNN
//
// Created by MNN on 2021/04/13.
// Copyright © 2018, Alibaba Group Holding Limited
//

void iosBenchAll(const char* modelPath);
34 changes: 27 additions & 7 deletions demo/exec/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
message(STATUS "MNN Depends:" ${MNN_DEPS})
set(MNN_EXEC_DEMOS "")

add_executable(pictureRecognition.out ${CMAKE_CURRENT_LIST_DIR}/pictureRecognition.cpp)
target_link_libraries(pictureRecognition.out ${MNN_DEPS})
list(APPEND MNN_EXEC_DEMOS pictureRecognition.out)
add_executable(pictureRecognition_module.out ${CMAKE_CURRENT_LIST_DIR}/pictureRecognition_module.cpp)
list(APPEND MNN_EXEC_DEMOS pictureRecognition_module.out)

add_executable(pictureRotate.out ${CMAKE_CURRENT_LIST_DIR}/pictureRotate.cpp)
target_link_libraries(pictureRotate.out ${MNN_DEPS})
list(APPEND MNN_EXEC_DEMOS pictureRotate.out)

add_executable(multiPose.out ${CMAKE_CURRENT_LIST_DIR}/multiPose.cpp)
target_link_libraries(multiPose.out ${MNN_DEPS})
list(APPEND MNN_EXEC_DEMOS multiPose.out)

add_executable(segment.out ${CMAKE_CURRENT_LIST_DIR}/segment.cpp)
target_link_libraries(segment.out ${MNN_DEPS})
list(APPEND MNN_EXEC_DEMOS segment.out)

add_executable(expressDemo.out ${CMAKE_CURRENT_LIST_DIR}/expressDemo.cpp)
target_link_libraries(expressDemo.out ${MNN_DEPS})
list(APPEND MNN_EXEC_DEMOS expressDemo.out)

add_executable(transformerDemo.out ${CMAKE_CURRENT_LIST_DIR}/transformerDemo.cpp)
target_link_libraries(transformerDemo.out ${MNN_DEPS})
list(APPEND MNN_EXEC_DEMOS transformerDemo.out)

add_executable(rasterDemo.out ${CMAKE_CURRENT_LIST_DIR}/rasterDemo.cpp)
target_link_libraries(rasterDemo.out ${MNN_DEPS})
list(APPEND MNN_EXEC_DEMOS rasterDemo.out)

add_executable(nluDemo.out ${CMAKE_CURRENT_LIST_DIR}/nluDemo.cpp)
list(APPEND MNN_EXEC_DEMOS nluDemo.out)

foreach(TARGET ${MNN_EXEC_DEMOS})
target_link_libraries(${TARGET} ${MNN_DEPS})
if (MSVC)
target_compile_definitions(${TARGET} PRIVATE "_CRT_SECURE_NO_WARNINGS")
if (NOT MNN_BUILD_SHARED_LIBS)
foreach (DEPEND ${MNN_DEPS})
target_link_options(${TARGET} PRIVATE /WHOLEARCHIVE:$<TARGET_FILE:${DEPEND}>)
endforeach ()
endif()
endif()
endforeach()
8 changes: 8 additions & 0 deletions demo/exec/expressDemo.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
//
// expressDemo.cpp
// MNN
//
// Created by MNN on b'2019/08/19'.
// Copyright © 2018, Alibaba Group Holding Limited
//

#include <MNN/expr/Expr.hpp>
#include <MNN/expr/ExprCreator.hpp>
#include <MNN/expr/Executor.hpp>
Expand Down
Loading

0 comments on commit 58545d6

Please sign in to comment.