├── tools ├── pnnx │ ├── python │ │ ├── requirements.txt │ │ └── pnnx │ │ │ └── utils │ │ │ └── __init__.py │ ├── tests │ │ └── run_test.cmake │ └── src │ │ ├── pass_level4 │ │ ├── canonicalize.h │ │ ├── dead_code_elimination.h │ │ └── fuse_custom_op.h │ │ ├── pass_level3 │ │ ├── fuse_rnn_unpack.h │ │ ├── rename_F_convmode.h │ │ ├── assign_unique_name.h │ │ ├── eliminate_noop_math.h │ │ ├── eliminate_tuple_pair.h │ │ ├── fuse_einsum_operands.h │ │ ├── fuse_maxpool_unpack.h │ │ ├── fuse_op1ton_unpack.h │ │ ├── fuse_opnto1_tensors.h │ │ ├── rename_F_dropoutnd.h │ │ ├── fuse_index_expression.h │ │ ├── rename_F_conv_transposend.h │ │ ├── expand_quantization_modules.h │ │ ├── fuse_dynamic_adaptive_pool.h │ │ ├── fuse_multiheadattention_unpack.h │ │ └── fuse_expression.h │ │ ├── pass_level5 │ │ ├── eval_expression.h │ │ ├── fuse_layernorm.h │ │ ├── fuse_pad_conv1d.h │ │ ├── fuse_pad_conv2d.h │ │ ├── fuse_slice_copy.h │ │ ├── attribute_unpooling.h │ │ ├── eliminate_dropout.h │ │ ├── eliminate_type_as.h │ │ ├── fuse_static_conv.h │ │ ├── unroll_rnn_op.h │ │ ├── eliminate_noop_cat.h │ │ ├── eliminate_noop_pad.h │ │ ├── eliminate_noop_slice.h │ │ ├── fuse_channel_shuffle.h │ │ ├── fuse_contiguous_view.h │ │ ├── fuse_pixel_unshuffle.h │ │ ├── fuse_slice_indices.h │ │ ├── fuse_static_linear.h │ │ ├── eliminate_noop_einsum.h │ │ ├── eliminate_noop_expand.h │ │ ├── fuse_adjacent_reshape.h │ │ ├── fuse_select_to_unbind.h │ │ ├── fuse_static_batchnorm.h │ │ ├── fuse_static_embedding.h │ │ ├── fuse_static_groupnorm.h │ │ ├── fuse_static_layernorm.h │ │ ├── eliminate_maxpool_indices.h │ │ ├── eliminate_noop_expression.h │ │ ├── eliminate_noop_upsample.h │ │ ├── fuse_constant_expression.h │ │ ├── fuse_conv1d_batchnorm1d.h │ │ ├── fuse_conv2d_batchnorm2d.h │ │ ├── fuse_conv3d_batchnorm3d.h │ │ ├── fuse_linear_batchnorm1d.h │ │ ├── fuse_multiheadattention.h │ │ ├── fuse_static_convtranspose.h │ │ ├── fuse_static_instancenorm.h │ │ ├── normalize_einsum_equation.h │ │ ├── eliminate_identity_operator.h │ │ ├── eliminate_noop_view_reshape.h │ │ ├── fuse_slice_to_tensor_split.h │ │ ├── fuse_convtranspose1d_batchnorm1d.h │ │ ├── fuse_convtranspose2d_batchnorm2d.h │ │ ├── fuse_convtranspose3d_batchnorm3d.h │ │ ├── eliminate_reshape_shape_expression.h │ │ ├── fuse_scaled_dot_product_attention.h │ │ └── fold_constants.h │ │ ├── pass_ncnn │ │ ├── F_conv3d.cpp │ │ ├── F_linear.cpp │ │ ├── F_conv_transpose3d.cpp │ │ ├── convert_input.h │ │ ├── insert_split.h │ │ ├── eliminate_noop.h │ │ ├── chain_multi_output.h │ │ ├── convert_attribute.h │ │ ├── convert_custom_op.h │ │ ├── convert_torch_cat.h │ │ ├── eliminate_output.h │ │ ├── expand_expression.h │ │ ├── fuse_binaryop_eltwise.h │ │ ├── fuse_transpose_matmul.h │ │ ├── solve_batch_index.h │ │ ├── convert_Tensor_slice.h │ │ ├── convert_torch_chunk.h │ │ ├── convert_torch_einsum.h │ │ ├── convert_torch_split.h │ │ ├── convert_torch_stack.h │ │ ├── convert_torch_unbind.h │ │ ├── convert_Tensor_select.h │ │ ├── convert_half_to_float.h │ │ ├── insert_reshape_linear.h │ │ ├── insert_reshape_pooling.h │ │ ├── convert_Tensor_slice_copy.h │ │ ├── fuse_convolution1d_activation.h │ │ ├── fuse_convolution_activation.h │ │ ├── fuse_deconvolution_activation.h │ │ ├── fuse_innerproduct_activation.h │ │ ├── convert_torch_tensor_split.h │ │ ├── eliminate_tail_reshape_permute.h │ │ ├── fuse_convert_shufflechannel_slice.h │ │ ├── insert_reshape_global_pooling.h │ │ ├── fuse_convolutiondepthwise_activation.h │ │ ├── fuse_convolutiondepthwise1d_activation.h │ │ ├── fuse_deconvolutiondepthwise_activation.h │ │ ├── insert_reshape_numpy_binaryop_broadcast.h │ │ └── convert_module_op.h │ │ ├── pass_level0 │ │ ├── convert_half_to_float.h │ │ ├── flatten_input.h │ │ ├── constant_unpooling.h │ │ ├── reset_device.h │ │ └── inline_block.h │ │ ├── pass_onnx │ │ ├── canonicalize.h │ │ ├── eliminate_noop.h │ │ ├── fold_constants.h │ │ ├── shape_inference.h │ │ ├── inline_containers.h │ │ └── dead_code_elimination.h │ │ ├── pass_level4.h │ │ ├── load_onnx.h │ │ ├── save_onnx.h │ │ ├── save_ncnn.h │ │ ├── pass_level3.h │ │ └── pass_level5.h ├── darknet │ ├── output.jpg │ └── CMakeLists.txt ├── plugin │ ├── ncnn_snapshot.png │ └── nnie_snapshot.png ├── quantize │ └── README.md ├── tensorflow │ └── readme.txt ├── mxnet │ └── CMakeLists.txt ├── pytorch │ └── readme.txt ├── keras │ └── readme.md └── mlir │ └── fix_td.sh ├── .gitattributes ├── images ├── 16-ncnn.png ├── 32-ncnn.png ├── 64-ncnn.png ├── 128-ncnn.png └── 256-ncnn.png ├── python ├── requirements.txt ├── tests │ ├── custom_layer.param │ └── test.param ├── ncnn │ ├── __init__.py │ ├── utils │ │ └── __init__.py │ └── model_zoo │ │ └── __init__.py └── examples │ └── model_zoo.py ├── examples ├── squeezenet_v1.1.bin ├── squeezenet_v1.1.caffemodel ├── squeezenet_v1.1.param.bin └── squeezencnn │ └── README.md ├── src ├── mat_pixel_drawing_font.png ├── layer_type_enum.h.in ├── layer_declaration.h.in ├── layer_shader_registry.h.in ├── layer_shader_spv_data.h.in ├── layer_shader_type_enum.h.in ├── ncnn.pc.in ├── blob.cpp ├── layer_type.h ├── layer │ ├── arm │ │ ├── lrn_arm.h │ │ ├── bias_arm.h │ │ └── selu_arm.h │ ├── mips │ │ ├── bias_mips.h │ │ ├── softmax_mips.h │ │ ├── clip_mips.h │ │ └── tanh_mips.h │ ├── x86 │ │ ├── lrn_x86.h │ │ ├── bias_x86.h │ │ ├── elu_x86.h │ │ ├── clip_x86.h │ │ ├── mish_x86.h │ │ ├── selu_x86.h │ │ └── tanh_x86.h │ ├── erf.h │ ├── mish.h │ ├── tanh.h │ ├── swish.h │ ├── absval.h │ ├── noop.h │ ├── riscv │ │ └── selu_riscv.h │ ├── bnll.h │ ├── sigmoid.h │ ├── flatten.h │ └── softplus.h └── layer_shader_type.h ├── .github ├── ISSUE_TEMPLATE │ ├── others.md │ ├── bug.md │ ├── model-convert.md │ └── quantization.md ├── dependabot.yml └── workflows │ ├── labeler.yml │ └── sync-wiki.yml ├── .gitmodules ├── pyproject.toml ├── benchmark ├── RankCards │ └── CMakeLists.txt └── CMakeLists.txt ├── cmake ├── run_test.cmake ├── ncnn_generate_avx_source.cmake ├── ncnn_generate_fma_source.cmake ├── ncnn_generate_msa_source.cmake ├── ncnn_generate_avx512_source.cmake ├── ncnn_generate_rvv_source.cmake ├── ncnn_generate_lsx_source.cmake └── ncnn_generate_lasx_source.cmake ├── CONTRIBUTING.md ├── toolchains ├── host.gcc-m32.toolchain.cmake ├── host.clang-m32.toolchain.cmake ├── host.gcc-c++03.toolchain.cmake ├── host.gcc.toolchain.cmake ├── host-c.gcc.toolchain.cmake ├── host-c.clang.toolchain.cmake ├── mipsel-linux-gnu.toolchain.cmake ├── aarch64-linux-gnu.toolchain.cmake ├── powerpc-linux-gnu.toolchain.cmake ├── riscv64-linux-gnu.toolchain.cmake ├── mips-mti-linux-gnu.toolchain.cmake ├── mips64el-linux-gnuabi64.toolchain.cmake ├── mipsisa32r6el-linux-gnu.toolchain.cmake ├── powerpc64le-linux-gnu.toolchain.cmake ├── pi3.toolchain.cmake ├── mips32r2-linux-gnu.toolchain.cmake ├── arm-linux-gnueabihf.toolchain.cmake ├── arm-linux-gnueabihf-vfpv3-d16.toolchain.cmake ├── loongson2f-linux-gnuabi64.toolchain.cmake ├── arm-linux-gnueabi.toolchain.cmake ├── mipsisa64r6el-linux-gnuabi64.toolchain.cmake ├── aarch64-linux-gnu-c.toolchain.cmake ├── arm-linux-gnueabi-c.toolchain.cmake ├── riscv64-unknown-elf.toolchain.cmake ├── riscv32-unknown-elf.toolchain.cmake ├── jetson.toolchain.cmake ├── power8le-linux-gnu-vsx.toolchain.cmake └── power9le-linux-gnu-vsx.toolchain.cmake ├── Info.plist ├── docs ├── developer-guide │ ├── how-to-write-a-neon-optimized-op-kernel.md │ └── preload-practice.zh.md └── how-to-use-and-FAQ │ └── use-ncnnoptimize-to-optimize-model.md ├── .astylerc ├── CITATION.cff ├── .gitignore └── codeformat.sh /tools/pnnx/python/requirements.txt: -------------------------------------------------------------------------------- 1 | torch -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.comp linguist-language=GLSL 2 | -------------------------------------------------------------------------------- /images/16-ncnn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jameschz/ncnn/master/images/16-ncnn.png -------------------------------------------------------------------------------- /images/32-ncnn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jameschz/ncnn/master/images/32-ncnn.png -------------------------------------------------------------------------------- /images/64-ncnn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jameschz/ncnn/master/images/64-ncnn.png -------------------------------------------------------------------------------- /python/requirements.txt: -------------------------------------------------------------------------------- 1 | numpy 2 | tqdm 3 | requests 4 | portalocker 5 | opencv-python -------------------------------------------------------------------------------- /images/128-ncnn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jameschz/ncnn/master/images/128-ncnn.png -------------------------------------------------------------------------------- /images/256-ncnn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jameschz/ncnn/master/images/256-ncnn.png -------------------------------------------------------------------------------- /tools/darknet/output.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jameschz/ncnn/master/tools/darknet/output.jpg -------------------------------------------------------------------------------- /examples/squeezenet_v1.1.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jameschz/ncnn/master/examples/squeezenet_v1.1.bin -------------------------------------------------------------------------------- /src/mat_pixel_drawing_font.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jameschz/ncnn/master/src/mat_pixel_drawing_font.png -------------------------------------------------------------------------------- /tools/plugin/ncnn_snapshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jameschz/ncnn/master/tools/plugin/ncnn_snapshot.png -------------------------------------------------------------------------------- /tools/plugin/nnie_snapshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jameschz/ncnn/master/tools/plugin/nnie_snapshot.png -------------------------------------------------------------------------------- /tools/quantize/README.md: -------------------------------------------------------------------------------- 1 | see [quantized-int8-inference](../../docs/how-to-use-and-FAQ/quantized-int8-inference.md) 2 | -------------------------------------------------------------------------------- /examples/squeezenet_v1.1.caffemodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jameschz/ncnn/master/examples/squeezenet_v1.1.caffemodel -------------------------------------------------------------------------------- /examples/squeezenet_v1.1.param.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jameschz/ncnn/master/examples/squeezenet_v1.1.param.bin -------------------------------------------------------------------------------- /examples/squeezencnn/README.md: -------------------------------------------------------------------------------- 1 | The squeezenet android example project has been moved to https://github.com/nihui/ncnn-android-squeezenet 2 | -------------------------------------------------------------------------------- /src/layer_type_enum.h.in: -------------------------------------------------------------------------------- 1 | // Layer Type Enum header 2 | // 3 | // This file is auto-generated by cmake, don't edit it. 4 | 5 | @layer_type_enum@ 6 | -------------------------------------------------------------------------------- /src/layer_declaration.h.in: -------------------------------------------------------------------------------- 1 | // Layer Declaration header 2 | // 3 | // This file is auto-generated by cmake, don't edit it. 4 | 5 | @layer_declaration@ 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/others.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F4DD others" 3 | about: discussion, suggestion and question 4 | --- 5 | 6 | ## detail | 详细描述 | 詳細な説明 7 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | -------------------------------------------------------------------------------- /tools/tensorflow/readme.txt: -------------------------------------------------------------------------------- 1 | You can find tensorflow2ncnn tool here 2 | 3 | https://github.com/hanzy88/ckpt2ncnn 4 | https://github.com/hanzy88/tensorflow2ncnn 5 | -------------------------------------------------------------------------------- /src/layer_shader_registry.h.in: -------------------------------------------------------------------------------- 1 | // Layer Shader Registry header 2 | // 3 | // This file is auto-generated by cmake, don't edit it. 4 | 5 | @layer_shader_registry@ 6 | -------------------------------------------------------------------------------- /src/layer_shader_spv_data.h.in: -------------------------------------------------------------------------------- 1 | // Layer Shader Spv Data header 2 | // 3 | // This file is auto-generated by cmake, don't edit it. 4 | 5 | @layer_shader_spv_data@ 6 | -------------------------------------------------------------------------------- /src/layer_shader_type_enum.h.in: -------------------------------------------------------------------------------- 1 | // Layer Shader Enum header 2 | // 3 | // This file is auto-generated by cmake, don't edit it. 4 | 5 | @layer_shader_type_enum@ 6 | -------------------------------------------------------------------------------- /python/tests/custom_layer.param: -------------------------------------------------------------------------------- 1 | 7767517 2 | 2 2 3 | Input data 0 1 data 4 | CustomLayer cl_fwd 1 1 data output 5 | -------------------------------------------------------------------------------- /tools/darknet/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(darknet2ncnn darknet2ncnn.cpp) 2 | set_property(TARGET darknet2ncnn PROPERTY FOLDER "tools/converter") 3 | ncnn_install_tool(darknet2ncnn) 4 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "glslang"] 2 | path = glslang 3 | url = https://github.com/KhronosGroup/glslang 4 | [submodule "python/pybind11"] 5 | path = python/pybind11 6 | url = https://github.com/pybind/pybind11.git 7 | -------------------------------------------------------------------------------- /tools/mxnet/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_executable(mxnet2ncnn mxnet2ncnn.cpp) 3 | 4 | # add all mxnet2ncnn tool to a virtual project group 5 | set_property(TARGET mxnet2ncnn PROPERTY FOLDER "tools/converter") 6 | ncnn_install_tool(mxnet2ncnn) 7 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ 3 | "setuptools>=42", 4 | "wheel", 5 | "ninja; sys_platform != 'win32'", 6 | "cmake>=3.12", 7 | "importlib-metadata", 8 | ] 9 | build-backend = "setuptools.build_meta" 10 | -------------------------------------------------------------------------------- /.github/workflows/labeler.yml: -------------------------------------------------------------------------------- 1 | name: labeler 2 | on: [pull_request_target] 3 | 4 | permissions: 5 | contents: read 6 | pull-requests: write 7 | 8 | jobs: 9 | label: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/labeler@v5 13 | -------------------------------------------------------------------------------- /benchmark/RankCards/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | project(RankCards CXX) 4 | 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | set(EXECUTABLE_OUTPUT_PATH "../") 8 | 9 | add_executable(RankCards main.cpp) 10 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F41B bug issue" 3 | about: submit a bug report +_+ 4 | --- 5 | 6 | ## error log | 日志或报错信息 | ログ 7 | 8 | ## context | 编译/运行环境 | バックグラウンド 9 | 10 | ## how to reproduce | 复现步骤 | 再現方法 11 | 1. 12 | 2. 13 | 3. 14 | 15 | ## more | 其他 | その他 16 | -------------------------------------------------------------------------------- /cmake/run_test.cmake: -------------------------------------------------------------------------------- 1 | 2 | execute_process(COMMAND $ENV{TESTS_EXECUTABLE_LOADER} $ENV{TESTS_EXECUTABLE_LOADER_ARGUMENTS} ${TEST_EXECUTABLE} $ENV{TESTS_ARGUMENTS} RESULT_VARIABLE result) 3 | if(NOT "${result}" STREQUAL "0") 4 | message(FATAL_ERROR "Test failed with return value '${result}'") 5 | endif() 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/model-convert.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F6B8 model convert issue" 3 | about: "Life is Short, Use pnnx and convertmodel.com" 4 | --- 5 | 6 | ## error log | 日志或报错信息 | ログ 7 | 8 | ## model | 模型 | モデル 9 | 1. original model 10 | 11 | ## how to reproduce | 复现步骤 | 再現方法 12 | 1. 13 | 2. 14 | 3. 15 | -------------------------------------------------------------------------------- /python/tests/test.param: -------------------------------------------------------------------------------- 1 | 7767517 2 | 3 3 3 | Input data 0 1 data 4 | Convolution conv0_fwd 1 1 data conv0_fwd 0=3 1=3 11=3 2=1 12=1 3=1 13=1 4=0 14=0 5=1 6=81 5 | InnerProduct dense0_fwd 1 1 conv0_fwd output 0=1 1=1 2=151875 6 | -------------------------------------------------------------------------------- /tools/pnnx/tests/run_test.cmake: -------------------------------------------------------------------------------- 1 | 2 | set(ENV{PYTHONPATH} "ENV{PYTHONPATH}:${CMAKE_CURRENT_BINARY_DIR}") 3 | execute_process(COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_SCRIPT} RESULT_VARIABLE result) 4 | if(NOT "${result}" STREQUAL "0") 5 | message(FATAL_ERROR "Test failed with return value '${result}'") 6 | endif() 7 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/quantization.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: "\U0001F4C8 quantization" 3 | about: best wishes for your low bit quantization has a low accuracy loss...\(^▽^)/...2333... 4 | --- 5 | 6 | ## expectation | 诉求 | 期待する 7 | 1. speed 8 | 2. precision 9 | 10 | ## model | 模型 | モデル 11 | 1. model.param and model.bin 12 | 13 | ## detail | 详细描述 | 詳細な説明 14 | -------------------------------------------------------------------------------- /tools/pytorch/readme.txt: -------------------------------------------------------------------------------- 1 | You can find pytorch2ncnn tool here 2 | 3 | https://github.com/starimeL/PytorchConverter 4 | https://github.com/inisis/brocolli 5 | 6 | For newer version, pytorch already supports exporting to onnx out of box 7 | You can follow the practical guide here 8 | 9 | https://github.com/Tencent/ncnn/wiki/use-ncnn-with-pytorch-or-onnx 10 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | 2 | # Acknowledgements 3 | 4 | - Thanks to bug1989 [https://github.com/bug1989] for contributing the initial quantized int8 inference code and a large variety of device benchmark 5 | - Thanks to zhiliu6 [https://github.com/zhiliu6] for contributing the darknet conversion tool, operators and YOLO examples 6 | - Thanks to Tijmen Verhulsdonck [https://github.com/Timen] for contributing the massive AVX optimization for x86 platform 7 | -------------------------------------------------------------------------------- /src/ncnn.pc.in: -------------------------------------------------------------------------------- 1 | prefix=${pcfiledir}/../.. 2 | librarydir=${prefix}/@CMAKE_INSTALL_LIBDIR@ 3 | includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ 4 | 5 | Name: @CMAKE_PROJECT_NAME@ 6 | Description: high-performance neural network inference framework optimized for the mobile platform 7 | Version: @NCNN_VERSION_STRING@ 8 | URL: https://github.com/Tencent/ncnn 9 | Libs: -L"${librarydir}" -lncnn 10 | Cflags: -I"${includedir}" 11 | 12 | -------------------------------------------------------------------------------- /toolchains/host.gcc-m32.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR x86) 3 | 4 | set(CMAKE_C_COMPILER "gcc") 5 | set(CMAKE_CXX_COMPILER "g++") 6 | 7 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 9 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 10 | 11 | set(CMAKE_C_FLAGS "-m32") 12 | set(CMAKE_CXX_FLAGS "-m32") 13 | 14 | # cache flags 15 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 16 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 17 | -------------------------------------------------------------------------------- /toolchains/host.clang-m32.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR x86) 3 | 4 | set(CMAKE_C_COMPILER "clang") 5 | set(CMAKE_CXX_COMPILER "clang++") 6 | 7 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 9 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 10 | 11 | set(CMAKE_C_FLAGS "-m32") 12 | set(CMAKE_CXX_FLAGS "-m32") 13 | 14 | # cache flags 15 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 16 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 17 | -------------------------------------------------------------------------------- /toolchains/host.gcc-c++03.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR x86) 3 | 4 | set(CMAKE_C_COMPILER "gcc") 5 | set(CMAKE_CXX_COMPILER "g++") 6 | 7 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 9 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 10 | 11 | set(CMAKE_C_FLAGS "-ansi") 12 | set(CMAKE_CXX_FLAGS "-std=c++03") 13 | 14 | # cache flags 15 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 16 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 17 | -------------------------------------------------------------------------------- /toolchains/host.gcc.toolchain.cmake: -------------------------------------------------------------------------------- 1 | # set cross-compiled system type, it's better not use the type which cmake cannot recognized. 2 | set(CMAKE_SYSTEM_NAME Linux) 3 | set(CMAKE_SYSTEM_PROCESSOR x86) 4 | # if gcc/g++ was installed: 5 | set(CMAKE_C_COMPILER "gcc") 6 | set(CMAKE_CXX_COMPILER "g++") 7 | 8 | # set searching rules 9 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 10 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 12 | 13 | # set ${CMAKE_C_FLAGS} and ${CMAKE_CXX_FLAGS}flag 14 | set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}") 15 | -------------------------------------------------------------------------------- /cmake/ncnn_generate_avx_source.cmake: -------------------------------------------------------------------------------- 1 | 2 | # must define SRC DST CLASS 3 | 4 | file(READ ${SRC} source_data) 5 | 6 | # replace 7 | string(TOUPPER ${CLASS} CLASS_UPPER) 8 | string(TOLOWER ${CLASS} CLASS_LOWER) 9 | 10 | string(REGEX REPLACE "LAYER_${CLASS_UPPER}_X86_H" "LAYER_${CLASS_UPPER}_X86_AVX_H" source_data "${source_data}") 11 | string(REGEX REPLACE "${CLASS}_x86" "${CLASS}_x86_avx" source_data "${source_data}") 12 | string(REGEX REPLACE "#include \"${CLASS_LOWER}_x86.h\"" "#include \"${CLASS_LOWER}_x86_avx.h\"" source_data "${source_data}") 13 | 14 | file(WRITE ${DST} "${source_data}") 15 | -------------------------------------------------------------------------------- /cmake/ncnn_generate_fma_source.cmake: -------------------------------------------------------------------------------- 1 | 2 | # must define SRC DST CLASS 3 | 4 | file(READ ${SRC} source_data) 5 | 6 | # replace 7 | string(TOUPPER ${CLASS} CLASS_UPPER) 8 | string(TOLOWER ${CLASS} CLASS_LOWER) 9 | 10 | string(REGEX REPLACE "LAYER_${CLASS_UPPER}_X86_H" "LAYER_${CLASS_UPPER}_X86_FMA_H" source_data "${source_data}") 11 | string(REGEX REPLACE "${CLASS}_x86" "${CLASS}_x86_fma" source_data "${source_data}") 12 | string(REGEX REPLACE "#include \"${CLASS_LOWER}_x86.h\"" "#include \"${CLASS_LOWER}_x86_fma.h\"" source_data "${source_data}") 13 | 14 | file(WRITE ${DST} "${source_data}") 15 | -------------------------------------------------------------------------------- /cmake/ncnn_generate_msa_source.cmake: -------------------------------------------------------------------------------- 1 | 2 | # must define SRC DST CLASS 3 | 4 | file(READ ${SRC} source_data) 5 | 6 | # replace 7 | string(TOUPPER ${CLASS} CLASS_UPPER) 8 | string(TOLOWER ${CLASS} CLASS_LOWER) 9 | 10 | string(REGEX REPLACE "LAYER_${CLASS_UPPER}_MIPS_H" "LAYER_${CLASS_UPPER}_MIPS_MSA_H" source_data "${source_data}") 11 | string(REGEX REPLACE "${CLASS}_mips" "${CLASS}_mips_msa" source_data "${source_data}") 12 | string(REGEX REPLACE "#include \"${CLASS_LOWER}_mips.h\"" "#include \"${CLASS_LOWER}_mips_msa.h\"" source_data "${source_data}") 13 | 14 | file(WRITE ${DST} "${source_data}") 15 | -------------------------------------------------------------------------------- /cmake/ncnn_generate_avx512_source.cmake: -------------------------------------------------------------------------------- 1 | 2 | # must define SRC DST CLASS 3 | 4 | file(READ ${SRC} source_data) 5 | 6 | # replace 7 | string(TOUPPER ${CLASS} CLASS_UPPER) 8 | string(TOLOWER ${CLASS} CLASS_LOWER) 9 | 10 | string(REGEX REPLACE "LAYER_${CLASS_UPPER}_X86_H" "LAYER_${CLASS_UPPER}_X86_AVX512_H" source_data "${source_data}") 11 | string(REGEX REPLACE "${CLASS}_x86" "${CLASS}_x86_avx512" source_data "${source_data}") 12 | string(REGEX REPLACE "#include \"${CLASS_LOWER}_x86.h\"" "#include \"${CLASS_LOWER}_x86_avx512.h\"" source_data "${source_data}") 13 | 14 | file(WRITE ${DST} "${source_data}") 15 | -------------------------------------------------------------------------------- /cmake/ncnn_generate_rvv_source.cmake: -------------------------------------------------------------------------------- 1 | 2 | # must define SRC DST CLASS 3 | 4 | file(READ ${SRC} source_data) 5 | 6 | # replace 7 | string(TOUPPER ${CLASS} CLASS_UPPER) 8 | string(TOLOWER ${CLASS} CLASS_LOWER) 9 | 10 | string(REGEX REPLACE "LAYER_${CLASS_UPPER}_RISCV_H" "LAYER_${CLASS_UPPER}_RISCV_RVV_H" source_data "${source_data}") 11 | string(REGEX REPLACE "${CLASS}_riscv" "${CLASS}_riscv_rvv" source_data "${source_data}") 12 | string(REGEX REPLACE "#include \"${CLASS_LOWER}_riscv.h\"" "#include \"${CLASS_LOWER}_riscv_rvv.h\"" source_data "${source_data}") 13 | 14 | file(WRITE ${DST} "${source_data}") 15 | -------------------------------------------------------------------------------- /benchmark/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | if(MSVC) 3 | # warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 4 | add_definitions(/wd4996) 5 | endif() 6 | 7 | add_executable(benchncnn benchncnn.cpp) 8 | target_link_libraries(benchncnn PRIVATE ncnn) 9 | 10 | if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten") 11 | target_link_libraries(benchncnn PRIVATE nodefs.js) 12 | endif() 13 | 14 | # add benchncnn to a virtual project group 15 | set_property(TARGET benchncnn PROPERTY FOLDER "benchmark") 16 | -------------------------------------------------------------------------------- /cmake/ncnn_generate_lsx_source.cmake: -------------------------------------------------------------------------------- 1 | 2 | # must define SRC DST CLASS 3 | 4 | file(READ ${SRC} source_data) 5 | 6 | # replace 7 | string(TOUPPER ${CLASS} CLASS_UPPER) 8 | string(TOLOWER ${CLASS} CLASS_LOWER) 9 | 10 | string(REGEX REPLACE "LAYER_${CLASS_UPPER}_LOONGARCH_H" "LAYER_${CLASS_UPPER}_LOONGARCH_LSX_H" source_data "${source_data}") 11 | string(REGEX REPLACE "${CLASS}_loongarch" "${CLASS}_loongarch_lsx" source_data "${source_data}") 12 | string(REGEX REPLACE "#include \"${CLASS_LOWER}_loongarch.h\"" "#include \"${CLASS_LOWER}_loongarch_lsx.h\"" source_data "${source_data}") 13 | 14 | file(WRITE ${DST} "${source_data}") 15 | -------------------------------------------------------------------------------- /cmake/ncnn_generate_lasx_source.cmake: -------------------------------------------------------------------------------- 1 | 2 | # must define SRC DST CLASS 3 | 4 | file(READ ${SRC} source_data) 5 | 6 | # replace 7 | string(TOUPPER ${CLASS} CLASS_UPPER) 8 | string(TOLOWER ${CLASS} CLASS_LOWER) 9 | 10 | string(REGEX REPLACE "LAYER_${CLASS_UPPER}_LOONGARCH_H" "LAYER_${CLASS_UPPER}_LOONGARCH_LASX_H" source_data "${source_data}") 11 | string(REGEX REPLACE "${CLASS}_loongarch" "${CLASS}_loongarch_lasx" source_data "${source_data}") 12 | string(REGEX REPLACE "#include \"${CLASS_LOWER}_loongarch.h\"" "#include \"${CLASS_LOWER}_loongarch_lasx.h\"" source_data "${source_data}") 13 | 14 | file(WRITE ${DST} "${source_data}") 15 | -------------------------------------------------------------------------------- /tools/keras/readme.md: -------------------------------------------------------------------------------- 1 | ## You can find keras2ncnn tools here 2 | 3 | [https://github.com/MarsTechHAN/keras2ncnn](https://github.com/MarsTechHAN/keras2ncnn) 4 | [https://github.com/azeme1/keras2ncnn](https://github.com/azeme1/keras2ncnn) 5 | 6 | ---- 7 | ### From tensorflow 2.x, you can also export mlir and use mlir2ncnn which is maintained by the official. 8 | 9 | The source code is located here: [https://github.com/Tencent/ncnn/tree/master/tools/mlir](https://github.com/Tencent/ncnn/tree/master/tools/mlir) 10 | For Chinese, you can refer the guide here [https://zhuanlan.zhihu.com/p/152535430](https://zhuanlan.zhihu.com/p/152535430) -------------------------------------------------------------------------------- /Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleName 6 | __NAME__ 7 | CFBundleIdentifier 8 | __IDENTIFIER__ 9 | CFBundleVersion 10 | __VERSION__ 11 | CFBundleShortVersionString 12 | __VERSION__ 13 | CFBundleSignature 14 | ???? 15 | CFBundlePackageType 16 | FMWK 17 | 18 | 19 | -------------------------------------------------------------------------------- /docs/developer-guide/how-to-write-a-neon-optimized-op-kernel.md: -------------------------------------------------------------------------------- 1 | # benchmark 2 | op 3 | 4 | # naive C with openmp 5 | for for for 6 | 7 | # unroll, first try 8 | h 9 | 10 | # register allocation 11 | kernels 12 | 13 | # unroll, second try 14 | simd 15 | 16 | # neon intrinsics 17 | optional 18 | 19 | # naive neon assembly with pld 20 | asm 21 | 22 | # pipeline optimize, first try 23 | more register load mla 24 | 25 | # pipeline optimize, second try 26 | interleave load mla 27 | 28 | # pipeline optimize, third try 29 | loop tail 30 | 31 | # usual practice, load/save 32 | 233 33 | 34 | # usual practice, unroll 35 | 233 36 | 37 | # usual practice, save register 38 | 233 39 | -------------------------------------------------------------------------------- /tools/mlir/fix_td.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This dirty script eat td files :P 4 | # https://github.com/tensorflow/tensorflow/tree/master/tensorflow/compiler/mlir/tensorflow/ir 5 | 6 | sed -i 's!tensorflow/compiler/mlir/tensorflow/ir/!!g' *.td tf_traits.h tf_types.h tf_types.cc tf_attributes.cc 7 | 8 | sed -i '/let hasCanonicalizer = 1;/d' *.td 9 | sed -i '/let hasFolder = 1;/d' *.td 10 | sed -i '/StringRef GetOptimalLayout(const RuntimeDevices& devices);/d' *.td 11 | sed -i '/LogicalResult UpdateDataFormat(StringRef data_format);/d' *.td 12 | sed -i '/LogicalResult FoldOperandsPermutation(ArrayRef permutation);/d' *.td 13 | sed -i '/Optional GetContractionFusion();/d' *.td 14 | -------------------------------------------------------------------------------- /docs/how-to-use-and-FAQ/use-ncnnoptimize-to-optimize-model.md: -------------------------------------------------------------------------------- 1 | 2 | the typical usage 3 | ``` 4 | ncnnoptimize mobilenet.param mobilenet.bin mobilenet-opt.param mobilenet-opt.bin 65536 5 | ``` 6 | 7 | operator fusion 8 | * batchnorm - scale 9 | * convolution - batchnorm 10 | * convolutiondepthwise - batchnorm 11 | * deconvolution - batchnorm 12 | * deconvolutiondepthwise - batchnorm 13 | * innerproduct - batchnorm 14 | * convolution - relu 15 | * convolutiondepthwise - relu 16 | * deconvolution - relu 17 | * deconvolutiondepthwise - relu 18 | * innerproduct - relu 19 | 20 | eliminate noop operator 21 | * innerproduct - dropout 22 | * flatten after global pooling 23 | 24 | prefer better operator 25 | * replace convolution with innerproduct after global pooling 26 | -------------------------------------------------------------------------------- /.astylerc: -------------------------------------------------------------------------------- 1 | # astyle -n -r "benchmark/*.h,*.cpp" "src/*.h,*.cpp" "tests/*.h,*.cpp" "tools/*.h,*.cpp" "examples/*.h,*.cpp" 2 | 3 | # brace style 4 | --style=allman 5 | 6 | # tab 7 | --attach-namespaces 8 | --attach-extern-c 9 | --attach-closing-while 10 | 11 | # indentation 12 | --indent-preproc-define 13 | --indent-col1-comments 14 | --min-conditional-indent=0 15 | --max-continuation-indent=120 16 | 17 | # padding 18 | --pad-oper 19 | --pad-comma 20 | --pad-header 21 | --align-pointer=type 22 | --align-reference=type 23 | 24 | # formatting 25 | --break-closing-braces 26 | --attach-return-type 27 | --attach-return-type-decl 28 | --keep-one-line-blocks 29 | --keep-one-line-statements 30 | --convert-tabs 31 | --max-code-length=200 32 | --mode=c 33 | 34 | # other 35 | --lineend=linux 36 | -------------------------------------------------------------------------------- /CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | title: ncnn 3 | message: >- 4 | If you use this software, please cite it using the 5 | metadata from this file. 6 | type: software 7 | authors: 8 | - family-names: "Ni" 9 | given-names: "Hui" 10 | - name: "The ncnn contributors" 11 | abstract: >- 12 | ncnn is a high-performance neural network inference 13 | computing framework optimized for mobile platforms. 14 | date-released: 2017-06-30 15 | keywords: 16 | - "neural network" 17 | - "artificial intelligence" 18 | - "deep learning" 19 | - android 20 | - ios 21 | - windows 22 | - linux 23 | - macos 24 | - pnnx 25 | - simd 26 | - vulkan 27 | - riscv 28 | - x86 29 | - arm 30 | - mips 31 | - loongarch 32 | license: BSD-3-Clause 33 | repository-code: "https://github.com/Tencent/ncnn" 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # CMake build directory 2 | build*/ 3 | 4 | # Backup files. 5 | *~ 6 | 7 | # Prerequisites 8 | *.d 9 | 10 | # Compiled Object files 11 | *.slo 12 | *.lo 13 | *.o 14 | *.obj 15 | 16 | # Precompiled Headers 17 | *.gch 18 | *.pch 19 | 20 | # Compiled Dynamic libraries 21 | *.so 22 | *.dylib 23 | *.dll 24 | 25 | # Fortran module files 26 | *.mod 27 | *.smod 28 | 29 | # Compiled Static libraries 30 | *.lai 31 | *.la 32 | *.a 33 | *.lib 34 | 35 | # Executables 36 | *.exe 37 | *.out 38 | *.app 39 | 40 | # MACOSX 41 | .DS_Store 42 | 43 | # IDE 44 | .vs 45 | .vscode 46 | .idea 47 | cmake-build-debug 48 | cmake-build-release 49 | CMakeSettings.json 50 | 51 | # Compiled python 52 | __pycache__ 53 | *.pyc 54 | *.pyd 55 | *.egg-info/ 56 | python/setup.py 57 | 58 | # Clangd 59 | .cache/ 60 | 61 | # Xmake 62 | .xmake/ 63 | -------------------------------------------------------------------------------- /docs/developer-guide/preload-practice.zh.md: -------------------------------------------------------------------------------- 1 | ## 只是实践经验,没有理论,不一定正确 2 | 3 | ``` 4 | prfm pldl1keep, [x0, #256] 5 | ``` 6 | * 放在 ld1 [x0] 前面 0~8 条指令 7 | * #256 表示把 x0+256 的内容放进 L1 cache 8 | * ldp 也适用 9 | * (经验)不写 offset 不如写个 #128 10 | * (经验)pldl1strm 似乎没啥意思,也没 pldl1keep 快 11 | * (经验)x0 ~ x0+256 的内容也会进来 12 | * (经验)load 128bit 用 #128,256bit或更多用 #256 13 | * (经验)避免 pld a,pld b,load a,load b 顺序,可能相互干扰 14 | * (经验)提前太多会失效 15 | * (经验)适合连续读 16 | 17 | ``` 18 | prfm pldl2strm, [x0, #256] 19 | ``` 20 | * 放在 ld1 [x0] 前面 N 条指令,N 尽量大些 21 | * #256 表示把 x0+256 的内容放进 L2 cache 22 | * ldp 也适用 23 | * (经验)不写 offset 不如写个 #128 24 | * (经验)pldl2strm 效果稍好于 pldl2keep 25 | * (经验)x0 ~ x0+256 的内容也会进来 26 | * (经验)load 128bit 用 #128,256bit 用 #256 27 | * (经验)读很多数据,用不同 offset 连续两次 pldl2strm 28 | * (经验)后面不要对同位置再 pldl1keep,会变慢 29 | * (经验)适合提前准备要跳到很远的地方读,比如换 channel 30 | -------------------------------------------------------------------------------- /codeformat.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # we run clang-format and astyle twice to get stable format output 4 | 5 | format_code() { 6 | find src/ tools/ tests/ examples/ benchmark/ python/ -type f -name '*.c' -o -name '*.cpp' -o -name '*.cc' -o -name '*.h' | grep -v python/pybind11 | grep -v stb_image | grep -v ruapu | xargs -i clang-format -i {} 7 | astyle -n -r "benchmark/*.h,*.cpp,*.cc" "tests/*.h,*.cpp,*.cc" "tools/*.h,*.cpp,*.cc" "examples/*.h,*.cpp,*.cc" 8 | astyle -n -r "src/*.h,*.cpp,*.cc" --exclude=src/stb_image.h --exclude=src/stb_image_write.h --exclude=src/ruapu.h 9 | astyle -n -r "python/*.h,*.cpp,*.cc" --exclude=python/pybind11 10 | } 11 | 12 | format_code || { echo 'Formatting failed' ; exit 1; } #first time execute 13 | format_code || { echo 'Formatting failed' ; exit 1; } #second time execute 14 | -------------------------------------------------------------------------------- /python/ncnn/__init__.py: -------------------------------------------------------------------------------- 1 | # Tencent is pleased to support the open source community by making ncnn available. 2 | # 3 | # Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. 4 | # 5 | # Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | # in compliance with the License. You may obtain a copy of the License at 7 | # 8 | # https://opensource.org/licenses/BSD-3-Clause 9 | # 10 | # Unless required by applicable law or agreed to in writing, software distributed 11 | # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | # CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | # specific language governing permissions and limitations under the License. 14 | 15 | from .ncnn import * 16 | 17 | __version__ = ncnn.__version__ 18 | -------------------------------------------------------------------------------- /toolchains/host-c.gcc.toolchain.cmake: -------------------------------------------------------------------------------- 1 | # set cross-compiled system type, it's better not use the type which cmake cannot recognized. 2 | set(CMAKE_SYSTEM_NAME Linux) 3 | set(CMAKE_SYSTEM_PROCESSOR x86) 4 | # if gcc/g++ was installed: 5 | set(CMAKE_C_COMPILER "gcc") 6 | set(CMAKE_CXX_COMPILER "g++") 7 | 8 | # set searching rules 9 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 10 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 12 | 13 | # set ${CMAKE_C_FLAGS} and ${CMAKE_CXX_FLAGS}flag 14 | set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}") 15 | 16 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nodefaultlibs -fno-builtin -nostdinc++ -lc") 17 | 18 | # cache flags 19 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 20 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 21 | -------------------------------------------------------------------------------- /tools/pnnx/python/pnnx/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Tencent is pleased to support the open source community by making ncnn available. 2 | # 3 | # Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. 4 | # 5 | # Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | # in compliance with the License. You may obtain a copy of the License at 7 | # 8 | # https://opensource.org/licenses/BSD-3-Clause 9 | # 10 | # Unless required by applicable law or agreed to in writing, software distributed 11 | # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | # CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | # specific language governing permissions and limitations under the License. 14 | 15 | from .export import export 16 | from .convert import convert -------------------------------------------------------------------------------- /toolchains/host-c.clang.toolchain.cmake: -------------------------------------------------------------------------------- 1 | # set cross-compiled system type, it's better not use the type which cmake cannot recognized. 2 | set(CMAKE_SYSTEM_NAME Linux) 3 | set(CMAKE_SYSTEM_PROCESSOR x86) 4 | # if gcc/g++ was installed: 5 | set(CMAKE_C_COMPILER "clang") 6 | set(CMAKE_CXX_COMPILER "clang++") 7 | 8 | # set searching rules 9 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 10 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 12 | 13 | # set ${CMAKE_C_FLAGS} and ${CMAKE_CXX_FLAGS}flag 14 | set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}") 15 | 16 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nodefaultlibs -fno-builtin -nostdinc++ -lc") 17 | 18 | # cache flags 19 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 20 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 21 | -------------------------------------------------------------------------------- /python/ncnn/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Tencent is pleased to support the open source community by making ncnn available. 2 | # 3 | # Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. 4 | # 5 | # Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | # in compliance with the License. You may obtain a copy of the License at 7 | # 8 | # https://opensource.org/licenses/BSD-3-Clause 9 | # 10 | # Unless required by applicable law or agreed to in writing, software distributed 11 | # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | # CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | # specific language governing permissions and limitations under the License. 14 | 15 | from .download import download, check_sha1 16 | from .visual import * 17 | from .objects import * 18 | -------------------------------------------------------------------------------- /python/examples/model_zoo.py: -------------------------------------------------------------------------------- 1 | # Tencent is pleased to support the open source community by making ncnn available. 2 | # 3 | # Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. 4 | # 5 | # Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | # in compliance with the License. You may obtain a copy of the License at 7 | # 8 | # https://opensource.org/licenses/BSD-3-Clause 9 | # 10 | # Unless required by applicable law or agreed to in writing, software distributed 11 | # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | # CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | # specific language governing permissions and limitations under the License. 14 | 15 | from ncnn.model_zoo import get_model_list 16 | 17 | if __name__ == "__main__": 18 | print(get_model_list()) 19 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level4/canonicalize.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void canonicalize(Graph& graph); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /toolchains/mipsel-linux-gnu.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR mipsel) 3 | 4 | set(CMAKE_C_COMPILER "mipsel-linux-gnu-gcc") 5 | set(CMAKE_CXX_COMPILER "mipsel-linux-gnu-g++") 6 | 7 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | endif() 10 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | endif() 13 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | endif() 16 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | endif() 19 | 20 | set(CMAKE_C_FLAGS "-march=mips32") 21 | set(CMAKE_CXX_FLAGS "-march=mips32") 22 | 23 | # cache flags 24 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 26 | -------------------------------------------------------------------------------- /toolchains/aarch64-linux-gnu.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR aarch64) 3 | 4 | set(CMAKE_C_COMPILER "aarch64-linux-gnu-gcc") 5 | set(CMAKE_CXX_COMPILER "aarch64-linux-gnu-g++") 6 | 7 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | endif() 10 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | endif() 13 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | endif() 16 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | endif() 19 | 20 | set(CMAKE_C_FLAGS "-march=armv8-a") 21 | set(CMAKE_CXX_FLAGS "-march=armv8-a") 22 | 23 | # cache flags 24 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 26 | -------------------------------------------------------------------------------- /toolchains/powerpc-linux-gnu.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR powerpc) 3 | 4 | set(CMAKE_C_COMPILER "powerpc-linux-gnu-gcc") 5 | set(CMAKE_CXX_COMPILER "powerpc-linux-gnu-g++") 6 | 7 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | endif() 10 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | endif() 13 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | endif() 16 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | endif() 19 | 20 | set(CMAKE_C_FLAGS "-mcpu=powerpc") 21 | set(CMAKE_CXX_FLAGS "-mcpu=powerpc") 22 | 23 | # cache flags 24 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 26 | -------------------------------------------------------------------------------- /toolchains/riscv64-linux-gnu.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR riscv64) 3 | 4 | set(CMAKE_C_COMPILER "riscv64-linux-gnu-gcc") 5 | set(CMAKE_CXX_COMPILER "riscv64-linux-gnu-g++") 6 | 7 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | endif() 10 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | endif() 13 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | endif() 16 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | endif() 19 | 20 | set(CMAKE_C_FLAGS "-march=rv64gc") 21 | set(CMAKE_CXX_FLAGS "-march=rv64gc") 22 | 23 | # cache flags 24 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 26 | -------------------------------------------------------------------------------- /toolchains/mips-mti-linux-gnu.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR mips) 3 | 4 | set(CMAKE_C_COMPILER "mips-mti-linux-gnu-gcc") 5 | set(CMAKE_CXX_COMPILER "mips-mti-linux-gnu-g++") 6 | 7 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | endif() 10 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | endif() 13 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | endif() 16 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | endif() 19 | 20 | set(CMAKE_C_FLAGS "-march=mips32r6") 21 | set(CMAKE_CXX_FLAGS "-march=mips32r6") 22 | 23 | # cache flags 24 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level4/dead_code_elimination.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void dead_code_elimination(Graph& graph); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level3/fuse_rnn_unpack.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_rnn_unpack(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level4/fuse_custom_op.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_custom_op(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/eval_expression.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void eval_expression(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_layernorm.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_layernorm(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_pad_conv1d.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_pad_conv1d(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_pad_conv2d.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_pad_conv2d(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_slice_copy.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_slice_copy(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level3/rename_F_convmode.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void rename_F_convmode(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/attribute_unpooling.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void attribute_unpooling(Graph& g); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/eliminate_dropout.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void eliminate_dropout(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/eliminate_type_as.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void eliminate_type_as(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_static_conv.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_static_conv(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/unroll_rnn_op.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_level5.h" 16 | 17 | namespace pnnx { 18 | 19 | void unroll_rnn_op(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /src/blob.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "blob.h" 16 | 17 | namespace ncnn { 18 | 19 | Blob::Blob() 20 | { 21 | producer = -1; 22 | consumer = -1; 23 | } 24 | 25 | } // namespace ncnn 26 | -------------------------------------------------------------------------------- /toolchains/mips64el-linux-gnuabi64.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR mips64el) 3 | 4 | set(CMAKE_C_COMPILER "mips64el-linux-gnuabi64-gcc") 5 | set(CMAKE_CXX_COMPILER "mips64el-linux-gnuabi64-g++") 6 | 7 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | endif() 10 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | endif() 13 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | endif() 16 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | endif() 19 | 20 | set(CMAKE_C_FLAGS "-march=mips64") 21 | set(CMAKE_CXX_FLAGS "-march=mips64") 22 | 23 | # cache flags 24 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level3/assign_unique_name.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void assign_unique_name(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level3/eliminate_noop_math.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void eliminate_noop_math(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level3/eliminate_tuple_pair.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void eliminate_tuple_pair(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level3/fuse_einsum_operands.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_einsum_operands(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level3/fuse_maxpool_unpack.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_maxpool_unpack(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level3/fuse_op1ton_unpack.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_op1ton_unpack(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level3/fuse_opnto1_tensors.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_opnto1_tensors(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level3/rename_F_dropoutnd.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void rename_F_dropoutnd(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/eliminate_noop_cat.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void eliminate_noop_cat(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/eliminate_noop_pad.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void eliminate_noop_pad(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/eliminate_noop_slice.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void eliminate_noop_slice(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_channel_shuffle.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_channel_shuffle(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_contiguous_view.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_contiguous_view(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_pixel_unshuffle.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_pixel_unshuffle(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_slice_indices.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_slice_indices(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_static_linear.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_static_linear(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /python/ncnn/model_zoo/__init__.py: -------------------------------------------------------------------------------- 1 | # Tencent is pleased to support the open source community by making ncnn available. 2 | # 3 | # Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. 4 | # 5 | # Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | # in compliance with the License. You may obtain a copy of the License at 7 | # 8 | # https://opensource.org/licenses/BSD-3-Clause 9 | # 10 | # Unless required by applicable law or agreed to in writing, software distributed 11 | # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | # CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | # specific language governing permissions and limitations under the License. 14 | 15 | # coding: utf-8 16 | """Predefined and pretrained models.""" 17 | 18 | from . import model_store 19 | 20 | from .model_zoo import get_model, get_model_list 21 | -------------------------------------------------------------------------------- /toolchains/mipsisa32r6el-linux-gnu.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR mipsisa32r6el) 3 | 4 | set(CMAKE_C_COMPILER "mipsisa32r6el-linux-gnu-gcc") 5 | set(CMAKE_CXX_COMPILER "mipsisa32r6el-linux-gnu-g++") 6 | 7 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | endif() 10 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | endif() 13 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | endif() 16 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | endif() 19 | 20 | set(CMAKE_C_FLAGS "-march=mips32r6") 21 | set(CMAKE_CXX_FLAGS "-march=mips32r6") 22 | 23 | # cache flags 24 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 26 | -------------------------------------------------------------------------------- /toolchains/powerpc64le-linux-gnu.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR powerpc64le) 3 | 4 | set(CMAKE_C_COMPILER "powerpc64le-linux-gnu-gcc") 5 | set(CMAKE_CXX_COMPILER "powerpc64le-linux-gnu-g++") 6 | 7 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | endif() 10 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | endif() 13 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | endif() 16 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | endif() 19 | 20 | set(CMAKE_C_FLAGS "-mcpu=powerpc64le") 21 | set(CMAKE_CXX_FLAGS "-mcpu=powerpc64le") 22 | 23 | # cache flags 24 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level3/fuse_index_expression.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_index_expression(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/eliminate_noop_einsum.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void eliminate_noop_einsum(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/eliminate_noop_expand.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void eliminate_noop_expand(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_adjacent_reshape.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_adjacent_reshape(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_select_to_unbind.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_select_to_unbind(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_static_batchnorm.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_static_batchnorm(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_static_embedding.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_static_embedding(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_static_groupnorm.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_static_groupnorm(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_static_layernorm.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_static_layernorm(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/F_conv3d.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | } // namespace ncnn 22 | 23 | } // namespace pnnx 24 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/F_linear.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | } // namespace ncnn 22 | 23 | } // namespace pnnx 24 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level3/rename_F_conv_transposend.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void rename_F_conv_transposend(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/eliminate_maxpool_indices.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void eliminate_maxpool_indices(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/eliminate_noop_expression.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void eliminate_noop_expression(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/eliminate_noop_upsample.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void eliminate_noop_upsample(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_constant_expression.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_constant_expression(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_conv1d_batchnorm1d.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_conv1d_batchnorm1d(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_conv2d_batchnorm2d.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_conv2d_batchnorm2d(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_conv3d_batchnorm3d.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_conv3d_batchnorm3d(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_linear_batchnorm1d.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_linear_batchnorm1d(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_multiheadattention.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_multiheadattention(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_static_convtranspose.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_static_convtranspose(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_static_instancenorm.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_static_instancenorm(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/normalize_einsum_equation.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void normalize_einsum_equation(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level3/expand_quantization_modules.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void expand_quantization_modules(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level3/fuse_dynamic_adaptive_pool.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_dynamic_adaptive_pool(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/eliminate_identity_operator.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void eliminate_identity_operator(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/eliminate_noop_view_reshape.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void eliminate_noop_view_reshape(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_slice_to_tensor_split.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_slice_to_tensor_split(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/F_conv_transpose3d.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | } // namespace ncnn 22 | 23 | } // namespace pnnx 24 | -------------------------------------------------------------------------------- /toolchains/pi3.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR armv7l) 3 | 4 | set(CMAKE_C_COMPILER "gcc") 5 | set(CMAKE_CXX_COMPILER "g++") 6 | 7 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | endif() 10 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | endif() 13 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | endif() 16 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | endif() 19 | 20 | set(CMAKE_C_FLAGS "-march=native -mfpu=neon -mfloat-abi=hard ${CMAKE_C_FLAGS}") 21 | set(CMAKE_CXX_FLAGS "-march=native -mfpu=neon -mfloat-abi=hard ${CMAKE_CXX_FLAGS}") 22 | 23 | # cache flags 24 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level3/fuse_multiheadattention_unpack.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_multiheadattention_unpack(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level0/convert_half_to_float.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include 16 | 17 | namespace pnnx { 18 | 19 | void convert_half_to_float(torch::jit::Module& mod); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level0/flatten_input.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include 16 | 17 | namespace pnnx { 18 | 19 | void flatten_input(std::shared_ptr& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_convtranspose1d_batchnorm1d.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_convtranspose1d_batchnorm1d(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_convtranspose2d_batchnorm2d.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_convtranspose2d_batchnorm2d(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_convtranspose3d_batchnorm3d.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_convtranspose3d_batchnorm3d(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/eliminate_reshape_shape_expression.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void eliminate_reshape_shape_expression(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fuse_scaled_dot_product_attention.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_scaled_dot_product_attention(Graph& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /toolchains/mips32r2-linux-gnu.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR mips32el) 3 | 4 | set(CMAKE_C_COMPILER "mips-linux-gnu-gcc") 5 | set(CMAKE_CXX_COMPILER "mips-linux-gnu-g++") 6 | 7 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | endif() 10 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | endif() 13 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | endif() 16 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | endif() 19 | 20 | set(CMAKE_C_FLAGS "-march=mips32r2 -mabi=32 -mnan=2008 -mfp64") 21 | set(CMAKE_CXX_FLAGS "-march=mips32r2 -mabi=32 -mnan=2008 -mfp64") 22 | 23 | # cache flags 24 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level0/constant_unpooling.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include 16 | 17 | namespace pnnx { 18 | 19 | void constant_unpooling(std::shared_ptr& graph); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /toolchains/arm-linux-gnueabihf.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR arm) 3 | 4 | set(CMAKE_C_COMPILER "arm-linux-gnueabihf-gcc") 5 | set(CMAKE_CXX_COMPILER "arm-linux-gnueabihf-g++") 6 | 7 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | endif() 10 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | endif() 13 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | endif() 16 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | endif() 19 | 20 | set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon") 21 | set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=neon") 22 | 23 | # cache flags 24 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 26 | -------------------------------------------------------------------------------- /.github/workflows/sync-wiki.yml: -------------------------------------------------------------------------------- 1 | name: sync-wiki 2 | on: 3 | push: 4 | branches: [master] 5 | paths: 6 | - '.github/workflows/sync-wiki.yml' 7 | - 'docs/**' 8 | concurrency: 9 | group: sync-wiki-${{ github.ref }} 10 | cancel-in-progress: true 11 | 12 | permissions: 13 | contents: read 14 | 15 | jobs: 16 | sync-wiki: 17 | permissions: 18 | contents: write # for Git to git push 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v4 22 | - name: sync 23 | run: | 24 | cp -r docs $GITHUB_WORKSPACE/ncnn.wiki 25 | cd $GITHUB_WORKSPACE/ncnn.wiki 26 | git config --global user.name "wiki-sync-bot" 27 | git config --global user.email "wiki-sync-bot@qq.com" 28 | git init 29 | git add . 30 | git commit -m "sync" 31 | git remote add upstream https://${{ secrets.WIKI_SYNC_BOT_TOKEN }}@github.com/Tencent/ncnn.wiki.git 32 | git push upstream master -f 33 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level0/reset_device.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include 16 | 17 | namespace pnnx { 18 | 19 | void reset_device(std::shared_ptr& graph, const std::string& device); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/convert_input.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void convert_input(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/insert_split.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void insert_split(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/eliminate_noop.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void eliminate_noop(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /toolchains/arm-linux-gnueabihf-vfpv3-d16.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR arm) 3 | 4 | set(CMAKE_C_COMPILER "arm-linux-gnueabihf-gcc") 5 | set(CMAKE_CXX_COMPILER "arm-linux-gnueabihf-g++") 6 | 7 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | endif() 10 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | endif() 13 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | endif() 16 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | endif() 19 | 20 | set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=vfpv3-d16") 21 | set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=hard -mfpu=vfpv3-d16") 22 | 23 | # cache flags 24 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/chain_multi_output.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void chain_multi_output(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/convert_attribute.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void convert_attribute(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/convert_custom_op.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void convert_custom_op(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/convert_torch_cat.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void convert_torch_cat(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/eliminate_output.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void eliminate_output(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/expand_expression.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void expand_expression(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/fuse_binaryop_eltwise.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void fuse_binaryop_eltwise(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/fuse_transpose_matmul.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void fuse_transpose_matmul(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/solve_batch_index.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void solve_batch_index(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/convert_Tensor_slice.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void convert_Tensor_slice(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/convert_torch_chunk.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void convert_torch_chunk(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/convert_torch_einsum.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void convert_torch_einsum(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/convert_torch_split.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void convert_torch_split(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/convert_torch_stack.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void convert_torch_stack(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/convert_torch_unbind.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void convert_torch_unbind(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/convert_Tensor_select.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void convert_Tensor_select(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/convert_half_to_float.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void convert_half_to_float(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/insert_reshape_linear.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void insert_reshape_linear(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/insert_reshape_pooling.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void insert_reshape_pooling(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_onnx/canonicalize.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "onnx.pb.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace onnx2pnnx { 20 | 21 | void canonicalize(onnx::ModelProto& model); 22 | 23 | } // namespace onnx2pnnx 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level0/inline_block.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include 16 | 17 | namespace pnnx { 18 | 19 | void inline_block(std::shared_ptr& graph, const std::vector& module_operators); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/convert_Tensor_slice_copy.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void convert_Tensor_slice_copy(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/fuse_convolution1d_activation.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void fuse_convolution1d_activation(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/fuse_convolution_activation.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void fuse_convolution_activation(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/fuse_deconvolution_activation.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void fuse_deconvolution_activation(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/fuse_innerproduct_activation.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void fuse_innerproduct_activation(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_onnx/eliminate_noop.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "onnx.pb.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace onnx2pnnx { 20 | 21 | void eliminate_noop(onnx::ModelProto& model); 22 | 23 | } // namespace onnx2pnnx 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_onnx/fold_constants.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "onnx.pb.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace onnx2pnnx { 20 | 21 | void fold_constants(onnx::ModelProto& model); 22 | 23 | } // namespace onnx2pnnx 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_onnx/shape_inference.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "onnx.pb.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace onnx2pnnx { 20 | 21 | void shape_inference(onnx::ModelProto& model); 22 | 23 | } // namespace onnx2pnnx 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /toolchains/loongson2f-linux-gnuabi64.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR mips64el) 3 | 4 | set(CMAKE_C_COMPILER "mips64el-linux-gnuabi64-gcc") 5 | set(CMAKE_CXX_COMPILER "mips64el-linux-gnuabi64-g++") 6 | 7 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | endif() 10 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | endif() 13 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | endif() 16 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | endif() 19 | 20 | set(CMAKE_C_FLAGS "-mabi=64 -march=mips3 -mtune=loongson2f -mloongson-mmi") 21 | set(CMAKE_CXX_FLAGS "-mabi=64 -march=mips3 -mtune=loongson2f -mloongson-mmi") 22 | 23 | # cache flags 24 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level4.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef PNNX_PASS_LEVEL4_H 16 | #define PNNX_PASS_LEVEL4_H 17 | 18 | #include "ir.h" 19 | 20 | namespace pnnx { 21 | 22 | void pass_level4(Graph& g); 23 | 24 | } // namespace pnnx 25 | 26 | #endif // PNNX_PASS_LEVEL4_H 27 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/convert_torch_tensor_split.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void convert_torch_tensor_split(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_onnx/inline_containers.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "onnx.pb.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace onnx2pnnx { 20 | 21 | void inline_containers(onnx::ModelProto& model); 22 | 23 | } // namespace onnx2pnnx 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5/fold_constants.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fold_constants(Graph& graph, const std::set& foldable_constants, const std::string& foldable_constants_zippath); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/eliminate_tail_reshape_permute.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void eliminate_tail_reshape_permute(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/fuse_convert_shufflechannel_slice.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void fuse_convert_shufflechannel_slice(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/insert_reshape_global_pooling.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void insert_reshape_global_pooling(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_onnx/dead_code_elimination.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "onnx.pb.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace onnx2pnnx { 20 | 21 | void dead_code_elimination(onnx::ModelProto& model); 22 | 23 | } // namespace onnx2pnnx 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /toolchains/arm-linux-gnueabi.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR arm) 3 | 4 | set(CMAKE_C_COMPILER "arm-linux-gnueabi-gcc") 5 | set(CMAKE_CXX_COMPILER "arm-linux-gnueabi-g++") 6 | 7 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | endif() 10 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | endif() 13 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | endif() 16 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | endif() 19 | 20 | set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=softfp -mfpu=neon") 21 | set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=softfp -mfpu=neon") 22 | 23 | add_definitions(-D__STDC_CONSTANT_MACROS) 24 | 25 | # cache flags 26 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 27 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 28 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level3/fuse_expression.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | void fuse_expression(Graph& graph, const std::set& foldable_constants, const std::string& foldable_constants_zippath); 20 | 21 | } // namespace pnnx 22 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/fuse_convolutiondepthwise_activation.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void fuse_convolutiondepthwise_activation(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /toolchains/mipsisa64r6el-linux-gnuabi64.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR mipsisa64r6el) 3 | 4 | set(CMAKE_C_COMPILER "mipsisa64r6el-linux-gnuabi64-gcc") 5 | set(CMAKE_CXX_COMPILER "mipsisa64r6el-linux-gnuabi64-g++") 6 | 7 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | endif() 10 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | endif() 13 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | endif() 16 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | endif() 19 | 20 | set(CMAKE_C_FLAGS "-march=mips64r6 -mmsa -mhard-float -mfp64 -mnan=2008") 21 | set(CMAKE_CXX_FLAGS "-march=mips64r6 -mmsa -mhard-float -mfp64 -mnan=2008") 22 | 23 | # cache flags 24 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/load_onnx.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2024 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef PNNX_LOAD_ONNX_H 16 | #define PNNX_LOAD_ONNX_H 17 | 18 | #include "ir.h" 19 | 20 | namespace pnnx { 21 | 22 | int load_onnx(const std::string& onnxpath, Graph& g); 23 | 24 | } // namespace pnnx 25 | 26 | #endif // PNNX_LOAD_ONNX_H 27 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/fuse_convolutiondepthwise1d_activation.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void fuse_convolutiondepthwise1d_activation(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/fuse_deconvolutiondepthwise_activation.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "ir.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void fuse_deconvolutiondepthwise_activation(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/insert_reshape_numpy_binaryop_broadcast.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void insert_reshape_numpy_binaryop_broadcast(Graph& graph); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /tools/pnnx/src/save_onnx.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef PNNX_SAVE_ONNX_H 16 | #define PNNX_SAVE_ONNX_H 17 | 18 | #include "ir.h" 19 | 20 | namespace pnnx { 21 | 22 | int save_onnx(const Graph& g, const char* onnxpath, int fp16); 23 | 24 | } // namespace pnnx 25 | 26 | #endif // PNNX_SAVE_ONNX_H 27 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_ncnn/convert_module_op.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "pass_ncnn.h" 16 | 17 | namespace pnnx { 18 | 19 | namespace ncnn { 20 | 21 | void convert_module_op(Graph& graph, const std::vector& module_operators); 22 | 23 | } // namespace ncnn 24 | 25 | } // namespace pnnx 26 | -------------------------------------------------------------------------------- /toolchains/aarch64-linux-gnu-c.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR aarch64) 3 | 4 | set(CMAKE_C_COMPILER "aarch64-linux-gnu-gcc") 5 | set(CMAKE_CXX_COMPILER "aarch64-linux-gnu-g++") 6 | 7 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | endif() 10 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | endif() 13 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | endif() 16 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | endif() 19 | 20 | set(CMAKE_C_FLAGS "-march=armv8-a") 21 | set(CMAKE_CXX_FLAGS "-march=armv8-a") 22 | 23 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nodefaultlibs -fno-builtin -fno-stack-protector -nostdinc++ -mno-outline-atomics -lc") 24 | 25 | # cache flags 26 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 27 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 28 | -------------------------------------------------------------------------------- /toolchains/arm-linux-gnueabi-c.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR arm) 3 | 4 | set(CMAKE_C_COMPILER "arm-linux-gnueabi-gcc") 5 | set(CMAKE_CXX_COMPILER "arm-linux-gnueabi-g++") 6 | 7 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | endif() 10 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | endif() 13 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | endif() 16 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | endif() 19 | 20 | set(CMAKE_C_FLAGS "-march=armv7-a -mfloat-abi=softfp -mfpu=neon") 21 | set(CMAKE_CXX_FLAGS "-march=armv7-a -mfloat-abi=softfp -mfpu=neon") 22 | 23 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nodefaultlibs -fno-builtin -fno-stack-protector -nostdinc++ -lc") 24 | 25 | # cache flags 26 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 27 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 28 | -------------------------------------------------------------------------------- /toolchains/riscv64-unknown-elf.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Generic) 2 | set(CMAKE_SYSTEM_PROCESSOR riscv64) 3 | 4 | if(DEFINED ENV{RISCV_ROOT_PATH}) 5 | file(TO_CMAKE_PATH $ENV{RISCV_ROOT_PATH} RISCV_ROOT_PATH) 6 | else() 7 | message(FATAL_ERROR "RISCV_ROOT_PATH env must be defined") 8 | endif() 9 | 10 | set(RISCV_ROOT_PATH ${RISCV_ROOT_PATH} CACHE STRING "root path to riscv toolchain") 11 | 12 | set(CMAKE_C_COMPILER "${RISCV_ROOT_PATH}/bin/riscv64-unknown-elf-gcc") 13 | set(CMAKE_CXX_COMPILER "${RISCV_ROOT_PATH}/bin/riscv64-unknown-elf-g++") 14 | 15 | set(CMAKE_FIND_ROOT_PATH "${RISCV_ROOT_PATH}/riscv64-unknown-elf") 16 | 17 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 18 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 19 | endif() 20 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 21 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 22 | endif() 23 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 24 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 25 | endif() 26 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 27 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 28 | endif() -------------------------------------------------------------------------------- /src/layer_type.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef NCNN_LAYER_TYPE_H 16 | #define NCNN_LAYER_TYPE_H 17 | 18 | namespace ncnn { 19 | 20 | namespace LayerType { 21 | enum LayerType 22 | { 23 | #include "layer_type_enum.h" 24 | CustomBit = (1 << 8), 25 | }; 26 | } // namespace LayerType 27 | 28 | } // namespace ncnn 29 | 30 | #endif // NCNN_LAYER_TYPE_H 31 | -------------------------------------------------------------------------------- /toolchains/riscv32-unknown-elf.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Generic) 2 | set(CMAKE_SYSTEM_PROCESSOR riscv32) 3 | 4 | if(DEFINED ENV{RISCV_ROOT_PATH}) 5 | file(TO_CMAKE_PATH $ENV{RISCV_ROOT_PATH} RISCV_ROOT_PATH) 6 | else() 7 | message(FATAL_ERROR "RISCV_ROOT_PATH env must be defined") 8 | endif() 9 | 10 | set(RISCV_ROOT_PATH ${RISCV_ROOT_PATH} CACHE STRING "root path to riscv toolchain") 11 | 12 | set(CMAKE_C_COMPILER "${RISCV_ROOT_PATH}/bin/riscv32-unknown-elf-gcc") 13 | set(CMAKE_CXX_COMPILER "${RISCV_ROOT_PATH}/bin/riscv32-unknown-elf-g++") 14 | 15 | set(CMAKE_FIND_ROOT_PATH "${RISCV_ROOT_PATH}/riscv32-unknown-elf") 16 | 17 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 18 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 19 | endif() 20 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 21 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 22 | endif() 23 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 24 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 25 | endif() 26 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 27 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 28 | endif() 29 | -------------------------------------------------------------------------------- /tools/pnnx/src/save_ncnn.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef PNNX_SAVE_NCNN_H 16 | #define PNNX_SAVE_NCNN_H 17 | 18 | #include "ir.h" 19 | 20 | namespace pnnx { 21 | 22 | int save_ncnn(const Graph& g, const std::string& parampath, const std::string& binpath, const std::string& pypath, int fp16); 23 | 24 | } // namespace pnnx 25 | 26 | #endif // PNNX_SAVE_NCNN_H 27 | -------------------------------------------------------------------------------- /src/layer/arm/lrn_arm.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_LRN_ARM_H 16 | #define LAYER_LRN_ARM_H 17 | 18 | #include "lrn.h" 19 | 20 | namespace ncnn { 21 | 22 | class LRN_arm : public LRN 23 | { 24 | public: 25 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 26 | }; 27 | 28 | } // namespace ncnn 29 | 30 | #endif // LAYER_LRN_ARM_H 31 | -------------------------------------------------------------------------------- /src/layer/mips/bias_mips.h: -------------------------------------------------------------------------------- 1 | // Leo is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2019 Leo . All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_BIAS_MIPS_H 16 | #define LAYER_BIAS_MIPS_H 17 | 18 | #include "bias.h" 19 | 20 | namespace ncnn { 21 | 22 | class Bias_mips : public Bias 23 | { 24 | public: 25 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 26 | }; 27 | 28 | } // namespace ncnn 29 | 30 | #endif // LAYER_BIAS_MIPS_H 31 | -------------------------------------------------------------------------------- /src/layer/x86/lrn_x86.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_LRN_X86_H 16 | #define LAYER_LRN_X86_H 17 | 18 | #include "lrn.h" 19 | 20 | namespace ncnn { 21 | 22 | class LRN_x86 : public LRN 23 | { 24 | public: 25 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 26 | }; 27 | 28 | } // namespace ncnn 29 | 30 | #endif // LAYER_LRN_X86_H 31 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level3.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef PNNX_PASS_LEVEL3_H 16 | #define PNNX_PASS_LEVEL3_H 17 | 18 | #include "ir.h" 19 | 20 | namespace pnnx { 21 | 22 | void pass_level3(Graph& g, const std::set& foldable_constants, const std::string& foldable_constants_zippath); 23 | 24 | } // namespace pnnx 25 | 26 | #endif // PNNX_PASS_LEVEL3_H 27 | -------------------------------------------------------------------------------- /tools/pnnx/src/pass_level5.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef PNNX_PASS_LEVEL5_H 16 | #define PNNX_PASS_LEVEL5_H 17 | 18 | #include "ir.h" 19 | 20 | namespace pnnx { 21 | 22 | void pass_level5(Graph& g, const std::set& foldable_constants, const std::string& foldable_constants_zippath); 23 | 24 | } // namespace pnnx 25 | 26 | #endif // PNNX_PASS_LEVEL5_H 27 | -------------------------------------------------------------------------------- /src/layer/erf.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_ERF_H 16 | #define LAYER_ERF_H 17 | 18 | #include "layer.h" 19 | 20 | namespace ncnn { 21 | 22 | class Erf : public Layer 23 | { 24 | public: 25 | Erf(); 26 | 27 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 28 | }; 29 | 30 | } // namespace ncnn 31 | 32 | #endif // LAYER_ERF_H 33 | -------------------------------------------------------------------------------- /src/layer_shader_type.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef NCNN_LAYER_SHADER_TYPE_H 16 | #define NCNN_LAYER_SHADER_TYPE_H 17 | 18 | namespace ncnn { 19 | 20 | namespace LayerShaderType { 21 | enum LayerShaderType 22 | { 23 | #include "layer_shader_type_enum.h" 24 | }; 25 | } // namespace LayerShaderType 26 | 27 | } // namespace ncnn 28 | 29 | #endif // NCNN_LAYER_SHADER_TYPE_H 30 | -------------------------------------------------------------------------------- /toolchains/jetson.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR aarch64) 3 | 4 | set(CMAKE_C_COMPILER "aarch64-linux-gnu-gcc") 5 | set(CMAKE_CXX_COMPILER "aarch64-linux-gnu-g++") 6 | 7 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | endif() 10 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | endif() 13 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | endif() 16 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | endif() 19 | 20 | # set ${CMAKE_C_FLAGS} and ${CMAKE_CXX_FLAGS}flag for cross-compiled process 21 | # -march=armv8-a could work on Jetson, but will compile without some extra cpu features 22 | set(CMAKE_C_FLAGS "-march=native ${CMAKE_C_FLAGS}") 23 | set(CMAKE_CXX_FLAGS "-march=native ${CMAKE_CXX_FLAGS}") 24 | 25 | # cache flags 26 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 27 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 28 | -------------------------------------------------------------------------------- /src/layer/arm/bias_arm.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_BIAS_ARM_H 16 | #define LAYER_BIAS_ARM_H 17 | 18 | #include "bias.h" 19 | 20 | namespace ncnn { 21 | 22 | class Bias_arm : public Bias 23 | { 24 | public: 25 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 26 | }; 27 | 28 | } // namespace ncnn 29 | 30 | #endif // LAYER_BIAS_ARM_H 31 | -------------------------------------------------------------------------------- /src/layer/arm/selu_arm.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_SELU_ARM_H 16 | #define LAYER_SELU_ARM_H 17 | 18 | #include "selu.h" 19 | 20 | namespace ncnn { 21 | 22 | class SELU_arm : public SELU 23 | { 24 | public: 25 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 26 | }; 27 | 28 | } // namespace ncnn 29 | 30 | #endif // LAYER_SELU_ARM_H 31 | -------------------------------------------------------------------------------- /src/layer/mish.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_MISH_H 16 | #define LAYER_MISH_H 17 | 18 | #include "layer.h" 19 | 20 | namespace ncnn { 21 | 22 | class Mish : public Layer 23 | { 24 | public: 25 | Mish(); 26 | 27 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 28 | }; 29 | 30 | } // namespace ncnn 31 | 32 | #endif // LAYER_MISH_H 33 | -------------------------------------------------------------------------------- /src/layer/tanh.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_TANH_H 16 | #define LAYER_TANH_H 17 | 18 | #include "layer.h" 19 | 20 | namespace ncnn { 21 | 22 | class TanH : public Layer 23 | { 24 | public: 25 | TanH(); 26 | 27 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 28 | }; 29 | 30 | } // namespace ncnn 31 | 32 | #endif // LAYER_TANH_H 33 | -------------------------------------------------------------------------------- /src/layer/x86/bias_x86.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_BIAS_X86_H 16 | #define LAYER_BIAS_X86_H 17 | 18 | #include "bias.h" 19 | 20 | namespace ncnn { 21 | 22 | class Bias_x86 : public Bias 23 | { 24 | public: 25 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 26 | }; 27 | 28 | } // namespace ncnn 29 | 30 | #endif // LAYER_BIAS_X86_H 31 | -------------------------------------------------------------------------------- /src/layer/swish.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_SWISH_H 16 | #define LAYER_SWISH_H 17 | 18 | #include "layer.h" 19 | 20 | namespace ncnn { 21 | 22 | class Swish : public Layer 23 | { 24 | public: 25 | Swish(); 26 | 27 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 28 | }; 29 | 30 | } // namespace ncnn 31 | 32 | #endif // LAYER_SWISH_H 33 | -------------------------------------------------------------------------------- /src/layer/absval.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_ABSVAL_H 16 | #define LAYER_ABSVAL_H 17 | 18 | #include "layer.h" 19 | 20 | namespace ncnn { 21 | 22 | class AbsVal : public Layer 23 | { 24 | public: 25 | AbsVal(); 26 | 27 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 28 | }; 29 | 30 | } // namespace ncnn 31 | 32 | #endif // LAYER_ABSVAL_H 33 | -------------------------------------------------------------------------------- /src/layer/mips/softmax_mips.h: -------------------------------------------------------------------------------- 1 | // Leo is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2020 Leo . All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_SOFTMAX_MIPS_H 16 | #define LAYER_SOFTMAX_MIPS_H 17 | 18 | #include "softmax.h" 19 | 20 | namespace ncnn { 21 | 22 | class Softmax_mips : public Softmax 23 | { 24 | public: 25 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 26 | }; 27 | 28 | } // namespace ncnn 29 | 30 | #endif // LAYER_SOFTMAX_MIPS_H 31 | -------------------------------------------------------------------------------- /src/layer/noop.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_NOOP_H 16 | #define LAYER_NOOP_H 17 | 18 | #include "layer.h" 19 | 20 | namespace ncnn { 21 | 22 | class Noop : public Layer 23 | { 24 | public: 25 | Noop(); 26 | 27 | virtual int forward_inplace(std::vector& bottom_top_blobs, const Option& opt) const; 28 | }; 29 | 30 | } // namespace ncnn 31 | 32 | #endif // LAYER_NOOP_H 33 | -------------------------------------------------------------------------------- /src/layer/riscv/selu_riscv.h: -------------------------------------------------------------------------------- 1 | // Xavier Hsinyuan is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2021 Xavier Hsinyuan . All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_SELU_RISCV_H 16 | #define LAYER_SELU_RISCV_H 17 | 18 | #include "selu.h" 19 | 20 | namespace ncnn { 21 | 22 | class SELU_riscv : public SELU 23 | { 24 | public: 25 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 26 | }; 27 | 28 | } // namespace ncnn 29 | 30 | #endif // LAYER_SELU_RISCV_H 31 | -------------------------------------------------------------------------------- /src/layer/bnll.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_BNLL_H 16 | #define LAYER_BNLL_H 17 | 18 | #include "layer.h" 19 | 20 | namespace ncnn { 21 | 22 | class BNLL : public Layer 23 | { 24 | public: 25 | BNLL(); 26 | 27 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 28 | 29 | public: 30 | }; 31 | 32 | } // namespace ncnn 33 | 34 | #endif // LAYER_BNLL_H 35 | -------------------------------------------------------------------------------- /src/layer/mips/clip_mips.h: -------------------------------------------------------------------------------- 1 | // Leo is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2019 Leo . All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_CLIP_MIPS_H 16 | #define LAYER_CLIP_MIPS_H 17 | 18 | #include "clip.h" 19 | 20 | namespace ncnn { 21 | 22 | class Clip_mips : public Clip 23 | { 24 | public: 25 | Clip_mips(); 26 | 27 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 28 | }; 29 | 30 | } // namespace ncnn 31 | 32 | #endif // LAYER_CLIP_MIPS_H 33 | -------------------------------------------------------------------------------- /src/layer/mips/tanh_mips.h: -------------------------------------------------------------------------------- 1 | // Leo is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2020 Leo . All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_TANH_MIPS_H 16 | #define LAYER_TANH_MIPS_H 17 | 18 | #include "tanh.h" 19 | 20 | namespace ncnn { 21 | 22 | class TanH_mips : public TanH 23 | { 24 | public: 25 | TanH_mips(); 26 | 27 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 28 | }; 29 | 30 | } // namespace ncnn 31 | 32 | #endif // LAYER_TANH_MIPS_H 33 | -------------------------------------------------------------------------------- /src/layer/sigmoid.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_SIGMOID_H 16 | #define LAYER_SIGMOID_H 17 | 18 | #include "layer.h" 19 | 20 | namespace ncnn { 21 | 22 | class Sigmoid : public Layer 23 | { 24 | public: 25 | Sigmoid(); 26 | 27 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 28 | }; 29 | 30 | } // namespace ncnn 31 | 32 | #endif // LAYER_SIGMOID_H 33 | -------------------------------------------------------------------------------- /src/layer/x86/elu_x86.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_ELU_X86_H 16 | #define LAYER_ELU_X86_H 17 | 18 | #include "elu.h" 19 | 20 | namespace ncnn { 21 | 22 | class ELU_x86 : public ELU 23 | { 24 | public: 25 | ELU_x86(); 26 | 27 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 28 | }; 29 | 30 | } // namespace ncnn 31 | 32 | #endif // LAYER_ELU_X86_H 33 | -------------------------------------------------------------------------------- /toolchains/power8le-linux-gnu-vsx.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR powerpc64le) 3 | 4 | set(CMAKE_C_COMPILER "powerpc64le-linux-gnu-gcc") 5 | set(CMAKE_CXX_COMPILER "powerpc64le-linux-gnu-g++") 6 | 7 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | endif() 10 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | endif() 13 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | endif() 16 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | endif() 19 | 20 | set(CMAKE_C_FLAGS "-mcpu=power8 -mtune=power8 -DNO_WARN_X86_INTRINSICS -D__MMX__ -D__SSE__ -D__SSSE3__") 21 | set(CMAKE_CXX_FLAGS "-mcpu=power8 -mtune=power8 -DNO_WARN_X86_INTRINSICS -D__MMX__ -D__SSE__ -D__SSSE3__") 22 | 23 | # cache flags 24 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 26 | 27 | # Auto-translate SSE to VSX 28 | set(NCNN_PPC64LE_VSX ON) 29 | -------------------------------------------------------------------------------- /toolchains/power9le-linux-gnu-vsx.toolchain.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_SYSTEM_NAME Linux) 2 | set(CMAKE_SYSTEM_PROCESSOR powerpc64le) 3 | 4 | set(CMAKE_C_COMPILER "powerpc64le-linux-gnu-gcc") 5 | set(CMAKE_CXX_COMPILER "powerpc64le-linux-gnu-g++") 6 | 7 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PROGRAM) 8 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 9 | endif() 10 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_LIBRARY) 11 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 12 | endif() 13 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_INCLUDE) 14 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 15 | endif() 16 | if(NOT CMAKE_FIND_ROOT_PATH_MODE_PACKAGE) 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) 18 | endif() 19 | 20 | set(CMAKE_C_FLAGS "-mcpu=power9 -mtune=power9 -DNO_WARN_X86_INTRINSICS -D__MMX__ -D__SSE__ -D__SSSE3__") 21 | set(CMAKE_CXX_FLAGS "-mcpu=power9 -mtune=power9 -DNO_WARN_X86_INTRINSICS -D__MMX__ -D__SSE__ -D__SSSE3__") 22 | 23 | # cache flags 24 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "c flags") 25 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "c++ flags") 26 | 27 | # Auto-translate SSE to VSX 28 | set(NCNN_PPC64LE_VSX ON) 29 | -------------------------------------------------------------------------------- /src/layer/flatten.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_FLATTEN_H 16 | #define LAYER_FLATTEN_H 17 | 18 | #include "layer.h" 19 | 20 | namespace ncnn { 21 | 22 | class Flatten : public Layer 23 | { 24 | public: 25 | Flatten(); 26 | 27 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const; 28 | }; 29 | 30 | } // namespace ncnn 31 | 32 | #endif // LAYER_FLATTEN_H 33 | -------------------------------------------------------------------------------- /src/layer/softplus.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_SOFTPLUS_H 16 | #define LAYER_SOFTPLUS_H 17 | 18 | #include "layer.h" 19 | 20 | namespace ncnn { 21 | 22 | class Softplus : public Layer 23 | { 24 | public: 25 | Softplus(); 26 | 27 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 28 | }; 29 | 30 | } // namespace ncnn 31 | 32 | #endif // LAYER_SOFTPLUS_H 33 | -------------------------------------------------------------------------------- /src/layer/x86/clip_x86.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_CLIP_X86_H 16 | #define LAYER_CLIP_X86_H 17 | 18 | #include "clip.h" 19 | 20 | namespace ncnn { 21 | 22 | class Clip_x86 : public Clip 23 | { 24 | public: 25 | Clip_x86(); 26 | 27 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 28 | }; 29 | 30 | } // namespace ncnn 31 | 32 | #endif // LAYER_CLIP_X86_H 33 | -------------------------------------------------------------------------------- /src/layer/x86/mish_x86.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_MISH_X86_H 16 | #define LAYER_MISH_X86_H 17 | 18 | #include "mish.h" 19 | 20 | namespace ncnn { 21 | 22 | class Mish_x86 : public Mish 23 | { 24 | public: 25 | Mish_x86(); 26 | 27 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 28 | }; 29 | 30 | } // namespace ncnn 31 | 32 | #endif // LAYER_MISH_X86_H 33 | -------------------------------------------------------------------------------- /src/layer/x86/selu_x86.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_SELU_X86_H 16 | #define LAYER_SELU_X86_H 17 | 18 | #include "selu.h" 19 | 20 | namespace ncnn { 21 | 22 | class SELU_x86 : public SELU 23 | { 24 | public: 25 | SELU_x86(); 26 | 27 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 28 | }; 29 | 30 | } // namespace ncnn 31 | 32 | #endif // LAYER_SELU_X86_H 33 | -------------------------------------------------------------------------------- /src/layer/x86/tanh_x86.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making ncnn available. 2 | // 3 | // Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 4 | // 5 | // Licensed under the BSD 3-Clause License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // https://opensource.org/licenses/BSD-3-Clause 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef LAYER_TANH_X86_H 16 | #define LAYER_TANH_X86_H 17 | 18 | #include "tanh.h" 19 | 20 | namespace ncnn { 21 | 22 | class TanH_x86 : public TanH 23 | { 24 | public: 25 | TanH_x86(); 26 | 27 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const; 28 | }; 29 | 30 | } // namespace ncnn 31 | 32 | #endif // LAYER_TANH_X86_H 33 | --------------------------------------------------------------------------------