chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:33:03 +08:00
commit 5b57521aa1
8226 changed files with 3425766 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
## scp package_scripts/linux/build.sh mnnteam@30.6.159.68:/mnt/partition4/CI/scripts
# scp ~/.ssh/id_rsa* mnnteam@30.6.159.68:/mnt/partition4/CI
# ssh mnnteam@30.6.159.68
# docker run --name CI_tmp --rm -it -v /mnt/partition4/CI:/mnt reg.docker.alibaba-inc.com/shuhui/manylinux_2014 bash /mnt/scripts/build.sh -r git@gitlab.alibaba-inc.com:AliNN/AliNNPrivate.git
# docker run --name CI_tmp --rm -it -v /mnt/partition4/CI:/mnt reg.docker.alibaba-inc.com/shuhui/manylinux_2014 bash /mnt/scripts/build.sh -r git@gitlab.alibaba-inc.com:AliNN/MNN.git
# docker run --name CI_tmp --rm -it -v /mnt/partition4/CI:/mnt reg.docker.alibaba-inc.com/shuhui/manylinux_2014 bash /mnt/scripts/build.sh -r git@github.com:alibaba/MNN.git
set -e
usage() {
echo "Usage: $0 -r code_repo"
echo -e "\t-r code repository"
exit 1
}
while getopts 'r:' opt; do
case "$opt" in
r ) CODE_REPO=$OPTARG ;;
h|? ) usage ;;
esac
done
yes | cp /mnt/id_rsa* ~/.ssh 2>/dev/null
cd /root
git clone $CODE_REPO MNN && cd MNN
mkdir MNN
cp -r include/* MNN
./package_scripts/linux/build_lib.sh -o MNN-CPU/lib
# ./package_scripts/linux/build_tools.sh -o MNN-CPU/tools
./package_scripts/linux/build_whl.sh -o MNN-CPU/py_whl
# ./package_scripts/linux/build_bridge.sh -o MNN-CPU/py_bridge
+118
View File
@@ -0,0 +1,118 @@
#!/bin/bash
# MNN
# |--- Debug
# | |--- libmnnpybridge.a
# | |--- libmnnpybridge.so
# |
# |--- Release
# |--- libmnnpybridge.a
# |--- libmnnpybridge.so
set -e
usage() {
echo "Usage: $0 -i mnn_path -o path [-t build_type -t lib_type]"
echo -e "\t-i MNN library path"
echo -e "\t-o package files output directory"
echo -e "\t-t build type (debug/release), lib_type (dynamic/static), build all when unspecify"
exit 1
}
build_all=true
while getopts "i:o:ft:h" opt; do
case "$opt" in
i ) mnn_path=$OPTARG ;;
o ) path=$OPTARG ;;
t ) build_all=""
case "$OPTARG" in
"debug"|"release" ) build_type=$OPTARG ;;
"dynamic"|"static" ) lib_type=$OPTARG ;;
esac ;;
h|? ) usage ;;
esac
done
if [ -z $build_all ] && ([ -z $build_type ] || [ -z $lib_type ]); then
echo "build_type(debug/release) and lib_type(dynamic/static) should be set or not-set together"
exit 1
fi
rm -rf $path && mkdir -p $path
pushd $path
mkdir -p include wrapper lib/Debug lib/Release
popd
PACKAGE_PATH=$(realpath $path)
MNN_PACKAGE_PATH=$(realpath $mnn_path)
pushd pymnn/3rd_party
rm -rf MNN && mkdir -p MNN/lib
cp -r $MNN_PACKAGE_PATH/* MNN/lib
cp -r ../../include MNN
popd
cp pymnn/src/MNNPyBridge.h $PACKAGE_PATH/include
rm -rf /tmp/mnn_py && mkdir -p /tmp/mnn_py
cp -r pymnn/pip_package/MNN /tmp/mnn_py
pushd /tmp/mnn_py
find . -name __pycache__ | xargs rm -rf
pushd MNN
rm -rf tools
cat __init__.py | sed '/from . import tools/d' > __init__.py.tmp
mv __init__.py.tmp __init__.py
rm -rf data
cat __init__.py | sed '/from . import data/d' > __init__.py.tmp
mv __init__.py.tmp __init__.py
rm -rf optim
cat __init__.py | sed '/from . import optim/d' > __init__.py.tmp
mv __init__.py.tmp __init__.py
python -c "import compileall; compileall.compile_dir('/tmp/mnn_py/MNN', force=True)"
find . -name "*.py" | xargs rm -rf
popd
cp -r MNN $PACKAGE_PATH/wrapper
popd
CMAKE_ARGS="-DPYMNN_USE_ALINNPYTHON=ON -DPYMNN_RUNTIME_CHECK_VM=ON -DPYMNN_EXPR_API=ON -DPYMNN_NUMPY_USABLE=ON -DPYMNN_TRAIN_API=OFF"
rm -rf mnnpybridge_build && mkdir mnnpybridge_build
pushd mnnpybridge_build
log() {
echo "==================================="
echo "Build mnnpybridge $1"
echo "==================================="
}
# Debug Dynamic
if [ $build_all ] || [ $build_type = "debug" -a $lib_type = "dynamic" ]; then
log "debug + dynamic"
[ -f CMakeCache.txt ] && rm CMakeCache.txt
cmake $CMAKE_ARGS -DCMAKE_BUILD_TYPE=Debug -DMNN_BUILD_SHARED_LIBS=ON ../pymnn && make -j8
cp libmnnpybridge.so $PACKAGE_PATH/lib/Debug
fi
# Debug Static
if [ $build_all ] || [ $build_type = "debug" -a $lib_type = "static" ]; then
log "debug + static"
[ -f CMakeCache.txt ] && rm CMakeCache.txt
cmake $CMAKE_ARGS -DCMAKE_BUILD_TYPE=Debug -DMNN_BUILD_SHARED_LIBS=OFF ../pymnn && make -j8
cp libmnnpybridge.a $PACKAGE_PATH/lib/Debug
fi
# Release Dynamic
if [ $build_all ] || [ $build_type = "release" -a $lib_type = "dynamic" ]; then
log "release + dynamic"
[ -f CMakeCache.txt ] && rm CMakeCache.txt
cmake $CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DMNN_BUILD_SHARED_LIBS=ON ../pymnn && make -j8
cp libmnnpybridge.so $PACKAGE_PATH/lib/Release
fi
# Release Static
if [ $build_all ] || [ $build_type = "release" -a $lib_type = "static" ]; then
log "release + static"
[ -f CMakeCache.txt ] && rm CMakeCache.txt
cmake $CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DMNN_BUILD_SHARED_LIBS=OFF ../pymnn && make -j8
cp libmnnpybridge.a $PACKAGE_PATH/lib/Release
fi
popd
+112
View File
@@ -0,0 +1,112 @@
#!/bin/bash
# MNN
# |--- Debug
# | |--- libMNN.a
# | |--- libMNN.so
# |
# |--- Release
# |--- libMNN.a
# |--- libMNN.so
set -e
usage() {
echo "Usage: $0 -o path [-b backends] [-s] [-c] [-t build_type -t lib_type [-c]]"
echo -e "\t-o package files output directory"
echo -e "\t-b extra backends to support (opencl, opengl, vulkan, onednn, avx512, coreml)"
echo -e "\t-s re-generate schema"
echo -e "\t-c clean build folder"
echo -e "\t-t build type (debug/release), lib_type (dynamic/static), build all when unspecify"
exit 1
}
build_all=true
while getopts "o:b:sct:h" opt; do
case "$opt" in
o ) path=$OPTARG ;;
b ) IFS="," read -a backends <<< $OPTARG ;;
s ) clean_schema=true ;;
c ) clean_build=true ;;
t ) build_all=""
case "$OPTARG" in
"debug"|"release" ) build_type=$OPTARG ;;
"dynamic"|"static" ) lib_type=$OPTARG ;;
esac ;;
h|? ) usage ;;
esac
done
if [ -z $build_all ] && ([ -z $build_type ] || [ -z $lib_type ]); then
echo "build_type(debug/release) and lib_type(dynamic/static) should be set or not-set together"
exit 1
fi
# clear and create package directory
if [ $clean_schema ]; then
./schema/generate.sh
fi
rm -rf $path && mkdir -p $path
mkdir -p $path/Debug
mkdir -p $path/Release
PACKAGE_PATH=$(realpath $path)
CMAKE_ARGS="-DMNN_SEP_BUILD=OFF -DMNN_BUILD_TOOLS=OFF -DLLM_SUPPORT_VISION=true -DMNN_BUILD_OPENCV=true -DMNN_IMGCODECS=true -DMNN_LOW_MEMORY=true -DMNN_BUILD_LLM=true -DMNN_SUPPORT_TRANSFORMER_FUSE=true -DLLM_SUPPORT_AUDIO=true -DMNN_BUILD_AUDIO=true -DMNN_OPENCL=ON -DMNN_VULKAN=ON"
if [ "$backends" ]; then
for backend in $backends; do
case $backend in
"opencl" ) CMAKE_ARGS="$CMAKE_ARGS -DMNN_OPENCL=ON" ;;
"opengl" ) CMAKE_ARGS="$CMAKE_ARGS -DMNN_OPENGL=ON" ;;
"vulkan" ) CMAKE_ARGS="$CMAKE_ARGS -DMNN_VULKAN=ON" ;;
"onednn" ) CMAKE_ARGS="$CMAKE_ARGS -DMNN_ONEDNN=ON" ;;
"avx512" ) CMAKE_ARGS="$CMAKE_ARGS -DMNN_AVX512=ON" ;;
"coreml" ) CMAKE_ARGS="$CMAKE_ARGS -DMNN_COREML=ON" ;;
esac
done
fi
if [ $clean_build ]; then
rm -rf build && mkdir build
fi
pushd build
log() {
echo "==================================="
echo "Build MNN (CPU $backends) $1"
echo "==================================="
}
# Debug Dynamic
if [ $build_all ] || [ $build_type = "debug" -a $lib_type = "dynamic" ]; then
log "debug + dynamic"
[ -f CMakeCache.txt ] && rm CMakeCache.txt
cmake $CMAKE_ARGS -DCMAKE_BUILD_TYPE=Debug -DMNN_BUILD_SHARED_LIBS=ON .. && make -j24
cp libMNN.so $PACKAGE_PATH/Debug
fi
# Debug Static
if [ $build_all ] || [ $build_type = "debug" -a $lib_type = "static" ]; then
log "debug + static"
[ -f CMakeCache.txt ] && rm CMakeCache.txt
cmake $CMAKE_ARGS -DCMAKE_BUILD_TYPE=Debug -DMNN_BUILD_SHARED_LIBS=OFF .. && make -j24
cp libMNN.a $PACKAGE_PATH/Debug
fi
# Release Dynamic
if [ $build_all ] || [ $build_type = "release" -a $lib_type = "dynamic" ]; then
log "release + dynamic"
[ -f CMakeCache.txt ] && rm CMakeCache.txt
cmake $CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DMNN_BUILD_SHARED_LIBS=ON .. && make -j24
cp libMNN.so $PACKAGE_PATH/Release
fi
# Release Static
if [ $build_all ] || [ $build_type = "release" -a $lib_type = "static" ]; then
log "release + static"
[ -f CMakeCache.txt ] && rm CMakeCache.txt
cmake $CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DMNN_BUILD_SHARED_LIBS=OFF .. && make -j24
cp libMNN.a $PACKAGE_PATH/Release
fi
popd
+35
View File
@@ -0,0 +1,35 @@
set -e
usage() {
echo "Usage: $0 -o path [-b]"
echo -e "\t-o package files output directory"
echo -e "\t-b opencl backend"
exit 1
}
while getopts "o:hb" opt; do
case "$opt" in
o ) path=$OPTARG ;;
b ) opencl=true ;;
h|? ) usage ;;
esac
done
# clear and create package directory
./schema/generate.sh
rm -rf $path && mkdir -p $path
TOOLS_PATH=$(realpath $path)
CMAKE_ARGS="-DCMAKE_BUILD_TYPE=Release -DMNN_SEP_BUILD=OFF -DMNN_BUILD_SHARED_LIBS=OFF -DMNN_BUILD_CONVERTER=ON -DMNN_BUILD_TRAIN=ON -DMNN_PORTABLE_BUILD=ON -DMNN_BUILD_TOOLS=ON -DMNN_BUILD_QUANTOOLS=ON -DMNN_BUILD_BENCHMARK=ON -DMNN_BUILD_TEST=ON"
if [ ! -z $opencl ]; then
CMAKE_ARGS="$CMAKE_ARGS -DMNN_OPENCL=ON"
fi
rm -rf build && mkdir build
pushd build
[ -f CMakeCache.txt ] && rm CMakeCache.txt
cmake $CMAKE_ARGS .. && make -j24
cp *.out $TOOLS_PATH
popd
+51
View File
@@ -0,0 +1,51 @@
set -e
usage() {
echo "Usage: $0 -o path [-b]"
echo -e "\t-o package files output directory"
echo -e "\t-v MNN dist version"
echo -e "\t-b opencl backend"
exit 1
}
while getopts "o:v:hb" opt; do
case "$opt" in
o ) path=$OPTARG ;;
v ) mnn_version=$OPTARG ;;
b ) opencl=true ;;
h|? ) usage ;;
esac
done
torch_libs="$(pwd)/pymnn_build/tools/converter/libtorch/lib"
./schema/generate.sh
rm -rf $path && mkdir -p $path
PACKAGE_PATH=$(realpath $path)
CMAKE_ARGS="-DMNN_BUILD_CONVERTER=on -DMNN_BUILD_TRAIN=ON -DCMAKE_BUILD_TYPE=Release -DMNN_BUILD_SHARED_LIBS=OFF -DMNN_SEP_BUILD=OFF -DMNN_USE_THREAD_POOL=OFF -DMNN_OPENMP=ON -DMNN_BUILD_OPENCV=ON -DMNN_IMGCODECS=ON -DMNN_BUILD_TORCH=ON"
if [ ! -z $opencl ]; then
CMAKE_ARGS="$CMAKE_ARGS -DMNN_OPENCL=ON"
fi
rm -rf pymnn_build && mkdir pymnn_build
pushd pymnn_build
cmake $CMAKE_ARGS .. && make MNN MNNTrain MNNConvert MNNOpenCV -j24
popd
pushd pymnn/pip_package
rm -rf build && mkdir build
rm -rf dist && mkdir dist
rm -rf wheelhouse && mkdir wheelhouse
#Compile wheels
for PYBIN in /opt/python/*/bin; do
"${PYBIN}/pip" install -U numpy
"${PYBIN}/python" setup.py bdist_wheel --version $mnn_version
done
# Bundle external shared libraries into the wheels
export LD_LIBRARY_PATH=$torch_libs:$LD_LIBRARY_PATH
for whl in dist/*.whl; do
auditwheel repair "$whl" --plat manylinux2014_x86_64 -w wheelhouse
done
cp wheelhouse/* $PACKAGE_PATH
popd