├── .gitignore
├── .travis.yml
├── CMakeLists.txt
├── CONTRIBUTING.md
├── Info.plist
├── LICENSE.txt
├── README.md
├── arm.toolchain.cmake
├── benchmark
├── CMakeLists.txt
├── README.md
├── benchncnn-int8.cpp
└── benchncnn.cpp
├── build.sh
├── compiler.sh
├── examples
├── CMakeLists.txt
├── Python_NCNN
│ ├── Makefile
│ ├── ncnn.cpp
│ ├── ncnn.h
│ ├── ncnn2python.cpp
│ └── readme
├── Python_NCNN_JRfacessd
│ ├── Makefile
│ ├── ncnn.cpp
│ ├── ncnn.h
│ ├── ncnn2python.cpp
│ └── readme
├── fasterrcnn.cpp
├── mobilenetssd.cpp
├── mobilenetv2ssdlite.cpp
├── pose_demo.cpp
├── rfcn.cpp
├── shufflenetv2.cpp
├── squeezencnn
│ ├── AndroidManifest.xml
│ ├── ant.properties
│ ├── assets
│ │ └── synset_words.txt
│ ├── build.xml
│ ├── jni
│ │ ├── Android.mk
│ │ ├── Application.mk
│ │ ├── squeezencnn_jni.cpp
│ │ └── squeezenet_v1.1.id.h
│ ├── local.properties
│ ├── proguard-project.txt
│ ├── project.properties
│ ├── res
│ │ ├── layout
│ │ │ └── main.xml
│ │ └── values
│ │ │ └── strings.xml
│ └── src
│ │ └── com
│ │ └── tencent
│ │ └── squeezencnn
│ │ ├── MainActivity.java
│ │ └── SqueezeNcnn.java
├── squeezenet.cpp
├── squeezenetssd.cpp
├── synset_words.txt
├── yolov2.cpp
└── yolov3.cpp
├── images
├── 128-ncnn.png
├── 16-ncnn.png
├── 256-ncnn.png
├── 32-ncnn.png
└── 64-ncnn.png
├── package.sh
├── src
├── CMakeLists.txt
├── allocator.cpp
├── allocator.h
├── benchmark.cpp
├── benchmark.cpp.tq
├── benchmark.h
├── blob.cpp
├── blob.h
├── command.cpp
├── command.h
├── cpu.cpp
├── cpu.h
├── gpu.cpp
├── gpu.h
├── help.cpp
├── help.h
├── layer.cpp
├── layer.h
├── layer
│ ├── absval.cpp
│ ├── absval.h
│ ├── argmax.cpp
│ ├── argmax.h
│ ├── arm
│ │ ├── absval_arm.cpp
│ │ ├── absval_arm.h
│ │ ├── batchnorm_arm.cpp
│ │ ├── batchnorm_arm.h
│ │ ├── bias_arm.cpp
│ │ ├── bias_arm.h
│ │ ├── clip_arm.cpp
│ │ ├── clip_arm.h
│ │ ├── convolution_1x1.h
│ │ ├── convolution_1x1_int8.h
│ │ ├── convolution_2x2.h
│ │ ├── convolution_3x3.h
│ │ ├── convolution_3x3_e2e_int8.h
│ │ ├── convolution_3x3_int8.h
│ │ ├── convolution_4x4.h
│ │ ├── convolution_5x5.h
│ │ ├── convolution_5x5_int8.h
│ │ ├── convolution_7x7.h
│ │ ├── convolution_7x7_int8.h
│ │ ├── convolution_arm.cpp
│ │ ├── convolution_arm.h
│ │ ├── convolution_sgemm_int8.h
│ │ ├── convolutiondepthwise_3x3.h
│ │ ├── convolutiondepthwise_3x3_int8.h
│ │ ├── convolutiondepthwise_5x5.h
│ │ ├── convolutiondepthwise_arm.cpp
│ │ ├── convolutiondepthwise_arm.h
│ │ ├── deconvolution_3x3.h
│ │ ├── deconvolution_4x4.h
│ │ ├── deconvolution_arm.cpp
│ │ ├── deconvolution_arm.h
│ │ ├── deconvolutiondepthwise_arm.cpp
│ │ ├── deconvolutiondepthwise_arm.h
│ │ ├── dequantize_arm.cpp
│ │ ├── dequantize_arm.h
│ │ ├── eltwise_arm.cpp
│ │ ├── eltwise_arm.h
│ │ ├── innerproduct_arm.cpp
│ │ ├── innerproduct_arm.h
│ │ ├── interp_arm.cpp
│ │ ├── interp_arm.h
│ │ ├── lrn_arm.cpp
│ │ ├── lrn_arm.h
│ │ ├── neon_mathfun.h
│ │ ├── pooling_2x2.h
│ │ ├── pooling_3x3.h
│ │ ├── pooling_arm.cpp
│ │ ├── pooling_arm.h
│ │ ├── prelu_arm.cpp
│ │ ├── prelu_arm.h
│ │ ├── quantize_arm.cpp
│ │ ├── quantize_arm.h
│ │ ├── relu_arm.cpp
│ │ ├── relu_arm.h
│ │ ├── requantize_arm.cpp
│ │ ├── requantize_arm.h
│ │ ├── scale_arm.cpp
│ │ ├── scale_arm.h
│ │ ├── sigmoid_arm.cpp
│ │ ├── sigmoid_arm.h
│ │ ├── softmax_arm.cpp
│ │ └── softmax_arm.h
│ ├── batchnorm.cpp
│ ├── batchnorm.h
│ ├── bias.cpp
│ ├── bias.h
│ ├── binaryop.cpp
│ ├── binaryop.h
│ ├── bnll.cpp
│ ├── bnll.h
│ ├── cast.cpp
│ ├── cast.h
│ ├── clip.cpp
│ ├── clip.h
│ ├── concat.cpp
│ ├── concat.h
│ ├── convolution.cpp
│ ├── convolution.h
│ ├── convolutiondepthwise.cpp
│ ├── convolutiondepthwise.h
│ ├── crop.cpp
│ ├── crop.h
│ ├── deconvolution.cpp
│ ├── deconvolution.h
│ ├── deconvolutiondepthwise.cpp
│ ├── deconvolutiondepthwise.h
│ ├── dequantize.cpp
│ ├── dequantize.h
│ ├── detectionoutput.cpp
│ ├── detectionoutput.h
│ ├── dropout.cpp
│ ├── dropout.h
│ ├── eltwise.cpp
│ ├── eltwise.h
│ ├── elu.cpp
│ ├── elu.h
│ ├── embed.cpp
│ ├── embed.h
│ ├── exp.cpp
│ ├── exp.h
│ ├── expanddims.cpp
│ ├── expanddims.h
│ ├── flatten.cpp
│ ├── flatten.h
│ ├── innerproduct.cpp
│ ├── innerproduct.h
│ ├── input.cpp
│ ├── input.h
│ ├── instancenorm.cpp
│ ├── instancenorm.h
│ ├── interp.cpp
│ ├── interp.h
│ ├── log.cpp
│ ├── log.h
│ ├── lrn.cpp
│ ├── lrn.h
│ ├── lstm.cpp
│ ├── lstm.h
│ ├── memorydata.cpp
│ ├── memorydata.h
│ ├── mvn.cpp
│ ├── mvn.h
│ ├── normalize.cpp
│ ├── normalize.h
│ ├── packing.cpp
│ ├── packing.h
│ ├── padding.cpp
│ ├── padding.h
│ ├── permute.cpp
│ ├── permute.h
│ ├── pooling.cpp
│ ├── pooling.h
│ ├── power.cpp
│ ├── power.h
│ ├── prelu.cpp
│ ├── prelu.h
│ ├── priorbox.cpp
│ ├── priorbox.h
│ ├── proposal.cpp
│ ├── proposal.h
│ ├── psroipooling.cpp
│ ├── psroipooling.h
│ ├── quantize.cpp
│ ├── quantize.h
│ ├── reduction.cpp
│ ├── reduction.h
│ ├── relu.cpp
│ ├── relu.h
│ ├── reorg.cpp
│ ├── reorg.h
│ ├── requantize.cpp
│ ├── requantize.h
│ ├── reshape.cpp
│ ├── reshape.h
│ ├── rnn.cpp
│ ├── rnn.h
│ ├── roialign.cpp
│ ├── roialign.h
│ ├── roipooling.cpp
│ ├── roipooling.h
│ ├── scale.cpp
│ ├── scale.h
│ ├── shader
│ │ ├── absval.comp
│ │ ├── absval_pack4.comp
│ │ ├── batchnorm.comp
│ │ ├── batchnorm_pack4.comp
│ │ ├── binaryop.comp
│ │ ├── binaryop_pack4.comp
│ │ ├── cast_fp16_to_fp32.comp
│ │ ├── cast_fp16_to_fp32_pack4.comp
│ │ ├── cast_fp32_to_fp16.comp
│ │ ├── cast_fp32_to_fp16_pack4.comp
│ │ ├── clip.comp
│ │ ├── clip_pack4.comp
│ │ ├── concat.comp
│ │ ├── concat_pack4.comp
│ │ ├── concat_pack4to1.comp
│ │ ├── convolution.comp
│ │ ├── convolution_1x1s1d1.comp
│ │ ├── convolution_pack1to4.comp
│ │ ├── convolution_pack4.comp
│ │ ├── convolution_pack4to1.comp
│ │ ├── convolutiondepthwise.comp
│ │ ├── convolutiondepthwise_group.comp
│ │ ├── convolutiondepthwise_group_pack1to4.comp
│ │ ├── convolutiondepthwise_group_pack4.comp
│ │ ├── convolutiondepthwise_group_pack4to1.comp
│ │ ├── convolutiondepthwise_pack4.comp
│ │ ├── crop.comp
│ │ ├── crop_pack4.comp
│ │ ├── deconvolution.comp
│ │ ├── deconvolution_pack1to4.comp
│ │ ├── deconvolution_pack4.comp
│ │ ├── deconvolution_pack4to1.comp
│ │ ├── deconvolutiondepthwise.comp
│ │ ├── deconvolutiondepthwise_group.comp
│ │ ├── deconvolutiondepthwise_group_pack1to4.comp
│ │ ├── deconvolutiondepthwise_group_pack4.comp
│ │ ├── deconvolutiondepthwise_group_pack4to1.comp
│ │ ├── deconvolutiondepthwise_pack4.comp
│ │ ├── dropout.comp
│ │ ├── dropout_pack4.comp
│ │ ├── eltwise.comp
│ │ ├── eltwise_pack4.comp
│ │ ├── flatten.comp
│ │ ├── flatten_pack4.comp
│ │ ├── innerproduct.comp
│ │ ├── innerproduct_pack1to4.comp
│ │ ├── innerproduct_pack4.comp
│ │ ├── innerproduct_pack4to1.comp
│ │ ├── interp.comp
│ │ ├── interp_bicubic.comp
│ │ ├── interp_bicubic_coeffs.comp
│ │ ├── interp_bicubic_pack4.comp
│ │ ├── interp_pack4.comp
│ │ ├── lrn_norm.comp
│ │ ├── lrn_norm_across_channel_pack4.comp
│ │ ├── lrn_norm_within_channel_pack4.comp
│ │ ├── lrn_square_pad.comp
│ │ ├── lrn_square_pad_across_channel_pack4.comp
│ │ ├── lrn_square_pad_within_channel_pack4.comp
│ │ ├── packing_1to4.comp
│ │ ├── packing_4to1.comp
│ │ ├── padding.comp
│ │ ├── padding_pack4.comp
│ │ ├── permute.comp
│ │ ├── permute_pack4to1.comp
│ │ ├── pooling.comp
│ │ ├── pooling_global.comp
│ │ ├── pooling_global_pack4.comp
│ │ ├── pooling_pack4.comp
│ │ ├── prelu.comp
│ │ ├── prelu_pack4.comp
│ │ ├── priorbox.comp
│ │ ├── priorbox_mxnet.comp
│ │ ├── relu.comp
│ │ ├── relu_pack4.comp
│ │ ├── reorg.comp
│ │ ├── reorg_pack1to4.comp
│ │ ├── reorg_pack4.comp
│ │ ├── reshape.comp
│ │ ├── reshape_pack1to4.comp
│ │ ├── reshape_pack4.comp
│ │ ├── reshape_pack4to1.comp
│ │ ├── scale.comp
│ │ ├── scale_pack4.comp
│ │ ├── shufflechannel.comp
│ │ ├── shufflechannel_pack4.comp
│ │ ├── sigmoid.comp
│ │ ├── sigmoid_pack4.comp
│ │ ├── softmax_div_sum.comp
│ │ ├── softmax_div_sum_pack4.comp
│ │ ├── softmax_exp_sub_max.comp
│ │ ├── softmax_exp_sub_max_pack4.comp
│ │ ├── softmax_reduce_max.comp
│ │ ├── softmax_reduce_max_pack4.comp
│ │ ├── softmax_reduce_sum.comp
│ │ ├── softmax_reduce_sum_pack4.comp
│ │ ├── tanh.comp
│ │ ├── tanh_pack4.comp
│ │ ├── unaryop.comp
│ │ └── unaryop_pack4.comp
│ ├── shufflechannel.cpp
│ ├── shufflechannel.h
│ ├── sigmoid.cpp
│ ├── sigmoid.h
│ ├── slice.cpp
│ ├── slice.h
│ ├── softmax.cpp
│ ├── softmax.h
│ ├── split.cpp
│ ├── split.h
│ ├── spp.cpp
│ ├── spp.h
│ ├── squeeze.cpp
│ ├── squeeze.h
│ ├── tanh.cpp
│ ├── tanh.h
│ ├── threshold.cpp
│ ├── threshold.h
│ ├── tile.cpp
│ ├── tile.h
│ ├── unaryop.cpp
│ ├── unaryop.h
│ ├── x86
│ │ ├── avx_mathfun.h
│ │ ├── convolution_1x1.h
│ │ ├── convolution_1x1_int8.h
│ │ ├── convolution_3x3.h
│ │ ├── convolution_3x3_int8.h
│ │ ├── convolution_5x5.h
│ │ ├── convolution_5x5_int8.h
│ │ ├── convolution_7x7_int8.h
│ │ ├── convolution_sgemm_int8.h
│ │ ├── convolution_x86.cpp
│ │ ├── convolution_x86.h
│ │ ├── convolutiondepthwise_3x3.h
│ │ ├── convolutiondepthwise_3x3_int8.h
│ │ ├── convolutiondepthwise_x86.cpp
│ │ ├── convolutiondepthwise_x86.h
│ │ └── sse_mathfun.h
│ ├── yolodetectionoutput.cpp
│ ├── yolodetectionoutput.h
│ ├── yolov3detectionoutput.cpp
│ └── yolov3detectionoutput.h
├── layer_declaration.h.in
├── layer_registry.h.in
├── layer_shader_registry.h.in
├── layer_shader_spv_data.h.in
├── layer_type.h
├── layer_type_enum.h.in
├── mat.cpp
├── mat.h
├── mat_pixel.cpp
├── mat_pixel_resize.cpp
├── modelbin.cpp
├── modelbin.h
├── net.cpp
├── net.h
├── opencv.cpp
├── opencv.h
├── paramdict.cpp
├── paramdict.h
├── pipeline.cpp
├── pipeline.h
└── platform.h.in
├── toolchains
├── aarch64-linux-gnu.toolchain.cmake
├── arm-linux-gnueabi.toolchain.cmake
├── arm-linux-gnueabihf.toolchain.cmake
├── himix100.toolchain.cmake
├── hisiv300.toolchain.cmake
├── hisiv500.toolchain.cmake
├── host.gcc.toolchain.cmake
├── ios.toolchain.cmake
├── iossimxc-x64.toolchain.cmake
├── iossimxc.toolchain.cmake
├── iosxc-arm64.toolchain.cmake
├── iosxc.toolchain.cmake
└── pi3.toolchain.cmake
└── tools
├── CMakeLists.txt
├── caffe
├── CMakeLists.txt
├── caffe.proto
└── caffe2ncnn.cpp
├── darknet
└── readme.txt
├── mxnet
├── CMakeLists.txt
└── mxnet2ncnn.cpp
├── ncnn2mem.cpp
├── onnx
├── CMakeLists.txt
├── onnx.proto
└── onnx2ncnn.cpp
├── plugin
├── ImageWatchNCNN.natvis
├── README.md
└── snapshot.png
├── pytorch
└── readme.txt
└── tensorflow
├── CMakeLists.txt
├── attr_value.proto
├── function.proto
├── graph.proto
├── node_def.proto
├── op_def.proto
├── resource_handle.proto
├── tensor.proto
├── tensor_shape.proto
├── tensorflow2ncnn.cpp
├── types.proto
└── versions.proto
/.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 | # vscode
41 | .vscode
42 |
43 | # model file
44 | *.param
45 | *.bin
46 | *.caffemodel
47 | *.prototxt
48 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | dist: trusty
3 |
4 | language: cpp
5 |
6 | compiler:
7 | - g++
8 |
9 | addons:
10 | apt:
11 | sources:
12 | - ubuntu-toolchain-r-test
13 | packages:
14 | - cmake
15 |
16 | install:
17 | - wget https://github.com/google/protobuf/archive/v3.5.1.tar.gz
18 | - tar -xzvf v3.5.1.tar.gz
19 | - pushd protobuf-3.5.1 && ./autogen.sh && ./configure --prefix=/usr && make -j2 && sudo make install && sudo ldconfig && popd
20 |
21 | script:
22 | - mkdir build
23 | - cd build
24 | - cmake ..
25 | - make -j2
26 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 |
2 | ## Acknowledgements
3 | - Thanks to bug1989 [https://github.com/bug1989] for contributing the initial quantized int8 inference code and a large variety of device benchmark
4 |
--------------------------------------------------------------------------------
/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleName
6 | ncnn
7 | CFBundleIdentifier
8 | com.tencent.ncnn
9 | CFBundleVersion
10 | 1.0
11 | CFBundleShortVersionString
12 | 1.0
13 | CFBundleSignature
14 | ????
15 | CFBundlePackageType
16 | FMWK
17 |
18 |
19 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ncnn-int8-e2e
2 |
3 | ncnn-int8-e2e 是基于ncnn int8社区版本低比特(小于8bit)量化魔改版
4 |
5 |
6 | # 目标
7 |
8 | * 支持activation 7bit、weight 6bit量化
9 | * inference time缩减为float32的50%
10 | * x86 simulator int8 inference
11 | * arm runtime int8 inference
12 |
13 |
14 | ---
15 |
16 | ### x86平台编译
17 | ```
18 | ./compiler.sh linux
19 |
20 | ```
21 |
22 | ### caffe2ncnn使用说明
23 |
24 | 主要区分float32与int8网络模型转换时的差异,以pose_hrnet101为例子
25 |
26 | #### float32的ncnn模型
27 | ```
28 | ./caffe2ncnn pose_hrnet101.prototxt pose_hrnet101.caffemodel pose_hrnet101-fp32.param pose_hrnet101-fp32.bin
29 | ```
30 |
31 | #### int8的ncnn模型
32 | 其中的pose_hrnet101.table文件由PyTorch int8 e2e量化工具生成
33 | ```
34 | ./caffe2ncnn pose_hrnet101.prototxt pose_hrnet101.caffemodel pose_hrnet101-int8.param pose_hrnet101-int8.bin 0 pose_hrnet101.table
35 | ```
36 |
37 | #### pose example
38 | ```
39 | ./compiler.sh linux
40 |
41 | ```
42 | 编译完成后,pose位于dg-ncnn/build-linux/install/bin/
43 | 运行float32的模型
44 | ```
45 | $ ./pose pose.jpg pose_hrnet101-fp32.param pose_hrnet101-fp32.bin 1 1 2
46 | --- DeepGlint ncnn post demo --- 10:20:05 Apr 22 2019
47 | iter cost 0/1: 192.42602539ms
48 | 40 40 7
49 | now value: 0.855324(8,6)
50 | now value: 0.746584(16,7)
51 | now value: 0.488715(4,13)
52 | now value: 0.600376(24,11)
53 | now value: 0.573444(4,22)
54 | now value: 0.556145(30,13)
55 | now value: 0.147505(6,28)
56 |
57 | ```
58 | 运行int8的模型
59 | ```
60 | $ ./pose pose.jpg pose_hrnet101-int8.param pose_hrnet101-int8.bin 1 1 2
61 | --- DeepGlint ncnn post demo --- 10:20:05 Apr 22 2019
62 | iter cost 0/1: 283.76904297ms
63 | 40 40 7
64 | now value: 0.848378(8,6)
65 | now value: 0.720524(16,7)
66 | now value: 0.485292(4,13)
67 | now value: 0.537115(24,11)
68 | now value: 0.571759(4,22)
69 | now value: 0.555397(30,13)
70 | now value: 0.175053(7,28)
71 |
72 | ```
73 |
74 |
75 |
--------------------------------------------------------------------------------
/arm.toolchain.cmake:
--------------------------------------------------------------------------------
1 | SET( CMAKE_SYSTEM_NAME Linux )
2 | SET( CMAKE_BUILD_TYPE "Release" )
3 | SET( ANDROID true)
4 | SET( CMAKE_C_COMPILER "arm-hisiv500-linux-gcc" )
5 | SET( CMAKE_CXX_COMPILER "arm-hisiv500-linux-g++" )
6 | SET( CMAKE_SYSTEM_PROCESSOR "armv7-a" )
7 | SET( ARM_C_CXX_FLAGS "-O3 -mfloat-abi=softfp -mfpu=neon-vfpv4 -mcpu=cortex-a17.cortex-a7 -fopenmp" )
8 | SET( ARM_C_CXX_FLAGS "${ARM_C_CXX_FLAGS} -ffast-math -ftree-vectorize" )
9 | SET( CMAKE_CXX_FLAGS "${ARM_C_CXX_FLAGS} " CACHE STRING "c++ flags" )
10 | SET( CMAKE_C_FLAGS "${ARM_C_CXX_FLAGS} " CACHE STRING "c flags" )
--------------------------------------------------------------------------------
/benchmark/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src)
3 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/../src)
4 |
5 | add_executable(benchncnn benchncnn.cpp)
6 | set_property(TARGET benchncnn PROPERTY COMPILE_FLAGS "-fpie")
7 | set_property(TARGET benchncnn PROPERTY LINK_FLAGS "-pie")
8 | target_link_libraries(benchncnn PRIVATE ncnn)
9 |
10 | if(NCNN_VULKAN)
11 | target_link_libraries(benchncnn PRIVATE ${Vulkan_LIBRARY})
12 | endif()
13 |
--------------------------------------------------------------------------------
/examples/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | find_package(OpenCV QUIET COMPONENTS core highgui imgproc imgcodecs)
3 | if(NOT OpenCV_FOUND)
4 | find_package(OpenCV REQUIRED COMPONENTS core highgui imgproc)
5 | endif()
6 |
7 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src)
8 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/../src)
9 |
10 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -std=c++11" )
11 | set(NCNN_EXAMPLE_LINK_LIBRARIES ncnn ${OpenCV_LIBS})
12 | if(NCNN_VULKAN)
13 | list(APPEND NCNN_EXAMPLE_LINK_LIBRARIES ${Vulkan_LIBRARY})
14 | endif()
15 |
16 | add_executable(pose pose_demo.cpp)
17 | target_link_libraries(pose ${NCNN_EXAMPLE_LINK_LIBRARIES})
18 |
19 | install(TARGETS
20 | pose
21 | RUNTIME DESTINATION bin
22 | )
--------------------------------------------------------------------------------
/examples/Python_NCNN/Makefile:
--------------------------------------------------------------------------------
1 | BOOST_INCLUDE_PATH=/usr/include
2 | BOOST_LIB_PATH=/usr/lib/x86_64-linux-gpu
3 | NCNN_INCLUDE_PATH=/train/trainset/1/docker_run/dg-ncnn-ncnn-int8-e2e-20190507/build/install/include
4 | NCNN_LIB_PATH=/train/trainset/1/docker_run/dg-ncnn-ncnn-int8-e2e-20190507/build/install/lib
5 | PYTHON_LIB_PATH=/usr/lib/x86_64-linux-gpu
6 | PYTHON_INCLUDE_PATH=/usr/include/python2.7
7 | NUMPY_INCLUDE_PATH=/usr/local/lib/python2.7/dist-packages/numpy/core/include
8 |
9 | all:
10 | g++ -fPIC -fpermissive -I ${BOOST_INCLUDE_PATH} -I ${PYTHON_INCLUDE_PATH} -I ${NUMPY_INCLUDE_PATH} -I ${NCNN_INCLUDE_PATH} -c ncnn.cpp
11 | g++ -fPIC -fpermissive -I ${BOOST_INCLUDE_PATH} -I ${PYTHON_INCLUDE_PATH} -I ${NUMPY_INCLUDE_PATH} -I ${NCNN_INCLUDE_PATH} -c ncnn2python.cpp
12 | g++ -shared -o ncnn.so ncnn.o ncnn2python.o -L ${BOOST_LIB_PATH} -lboost_python -L ${PYTHON_LIB_PATH} -lpython2.7 -L ${NCNN_LIB_PATH} -lncnn
13 | cp ncnn.so /usr/local/lib/python2.7/dist-packages/
14 |
15 |
16 | clean:
17 | rm ncnn.so ncnn.o ncnn2python.o
18 |
--------------------------------------------------------------------------------
/examples/Python_NCNN/ncnn.h:
--------------------------------------------------------------------------------
1 | #include "net.h"
2 | #include "cpu.h"
3 | #include "benchmark.h"
4 | #include
5 | #include
6 | #include
7 |
8 | using namespace boost::python;
9 | namespace bp = boost::python;
10 | using namespace std;
11 |
12 |
13 | class Net{
14 | public:
15 | Net();
16 | ~Net();
17 | int load_param(const char * paramPath);
18 | int load_model(const char * modelPath);
19 | void setInputBlobName(string name);
20 | void setOutputBlobName(string name);
21 | int inference(object & input_object,object & output_object,int inputHeight,int inputWidth);
22 | int inference_debug_writeOutputBlob2File(object & input_object,object & output_object,int inputHeight,int inputWidth);
23 | private:
24 | ncnn::Net net;
25 | string inputBlobNmae;
26 | string outputBlobName;
27 |
28 | };
--------------------------------------------------------------------------------
/examples/Python_NCNN/ncnn2python.cpp:
--------------------------------------------------------------------------------
1 | #include "ncnn.h"
2 |
3 | BOOST_PYTHON_MODULE(ncnn)
4 | {
5 | class_("net",init<>())
6 | .def("load_param",&Net::load_param)
7 | .def("load_model",&Net::load_model)
8 | .def("setInputBlobName",&Net::setInputBlobName)
9 | .def("setOutputBlobName",&Net::setOutputBlobName)
10 | .def("inference",&Net::inference)
11 | .def("inference_debug_writeOutputBlob2File",&Net::inference_debug_writeOutputBlob2File)
12 | ;
13 | }
--------------------------------------------------------------------------------
/examples/Python_NCNN/readme:
--------------------------------------------------------------------------------
1 | 1. 安装依赖包
2 | sudo apt-get install libboost-python-dev
3 |
4 | 2. 修改Makefile开头的变量路径
5 |
6 |
7 | 3. 执行make命令编译ncnn.so
8 |
9 | 4. 把ncnn.so放到site-packages目录下(/home/zyy/anaconda3/lib/python3.7/site-packages),在python 环境下import ncnn 进行测试,不报错即加载成功
10 |
11 |
--------------------------------------------------------------------------------
/examples/Python_NCNN_JRfacessd/Makefile:
--------------------------------------------------------------------------------
1 | BOOST_INCLUDE_PATH=/usr/include
2 | BOOST_LIB_PATH=/usr/lib
3 | NCNN_INCLUDE_PATH=../../build-linux/install/include
4 | NCNN_LIB_PATH=../../build-linux/install/lib
5 | PYTHON_INCLUDE_PATH=/root/anaconda3/include/python3.6m
6 | PYTHON_LIB_PATH=/root/anaconda3/lib
7 |
8 | all:
9 | g++ -fPIC -std=c++11 -fpermissive -I ${BOOST_INCLUDE_PATH} -I ${PYTHON_INCLUDE_PATH} -I ${NCNN_INCLUDE_PATH} -c ncnn.cpp
10 | g++ -fPIC -std=c++11 -fpermissive -I ${BOOST_INCLUDE_PATH} -I ${PYTHON_INCLUDE_PATH} -I ${NCNN_INCLUDE_PATH} -c ncnn2python.cpp
11 | g++ -shared -std=c++11 -o ncnn.so ncnn.o ncnn2python.o -L ${BOOST_LIB_PATH} -lboost_python-py35 -L ${PYTHON_LIB_PATH} -lpython3.6m -L ${NCNN_LIB_PATH} -lncnn
12 | cp ncnn.so /root/anaconda3/lib/python3.6/site-packages/
13 |
14 |
15 | clean:
16 | rm ncnn.so ncnn.o ncnn2python.o
17 |
--------------------------------------------------------------------------------
/examples/Python_NCNN_JRfacessd/ncnn.h:
--------------------------------------------------------------------------------
1 | #include "net.h"
2 | #include "cpu.h"
3 | #include "benchmark.h"
4 | #include
5 | #include
6 | #include
7 |
8 | using namespace boost::python;
9 | namespace bp = boost::python;
10 | using namespace std;
11 |
12 |
13 | class Net{
14 | public:
15 | Net();
16 | ~Net();
17 | int load_param(const char * paramPath);
18 | int load_model(const char * modelPath);
19 | void setInputBlobName(string name);
20 | void setOutputBlobName(string name);
21 | int inference(object & input_object,object & output_object,int inputHeight,int inputWidth);
22 | int Net::inferenceJRfaceDet(object & input_object,object & output_object,int inputHeight,int inputWidth);//测试景润人脸检测模型
23 | int inference_debug_writeOutputBlob2File(object &input_object,int inputHeight, int inputWidth,string typeName,int beginLayerIndex,int endLayerIndex,string imagename);
24 | private:
25 | ncnn::Net net;
26 | string inputBlobNmae;
27 | string outputBlobName;
28 |
29 | };
--------------------------------------------------------------------------------
/examples/Python_NCNN_JRfacessd/ncnn2python.cpp:
--------------------------------------------------------------------------------
1 | #include "ncnn.h"
2 |
3 | BOOST_PYTHON_MODULE(ncnn)
4 | {
5 | class_("net",init<>())
6 | .def("load_param",&Net::load_param)
7 | .def("load_model",&Net::load_model)
8 | .def("setInputBlobName",&Net::setInputBlobName)
9 | .def("setOutputBlobName",&Net::setOutputBlobName)
10 | .def("inference",&Net::inference)
11 | .def("inferenceJRfaceDet",&Net::inferenceJRfaceDet)
12 | .def("inference_debug_writeOutputBlob2File",&Net::inference_debug_writeOutputBlob2File)
13 | ;
14 | }
--------------------------------------------------------------------------------
/examples/Python_NCNN_JRfacessd/readme:
--------------------------------------------------------------------------------
1 | 1. 安装依赖包
2 | sudo apt-get install libboost-python-dev
3 |
4 | 2. 修改Makefile开头的变量路径
5 |
6 |
7 | 3. 执行make命令编译ncnn.so
8 |
9 | 4. 把ncnn.so放到site-packages目录下(/home/zyy/anaconda3/lib/python3.7/site-packages),在python 环境下import ncnn 进行测试,不报错即加载成功
10 |
11 |
--------------------------------------------------------------------------------
/examples/squeezencnn/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/examples/squeezencnn/ant.properties:
--------------------------------------------------------------------------------
1 | # This file is used to override default values used by the Ant build system.
2 | #
3 | # This file must be checked into Version Control Systems, as it is
4 | # integral to the build system of your project.
5 |
6 | # This file is only used by the Ant script.
7 |
8 | # You can use this to override default values such as
9 | # 'source.dir' for the location of your java source folder and
10 | # 'out.dir' for the location of your output folder.
11 |
12 | # You can also use it define how the release builds are signed by declaring
13 | # the following properties:
14 | # 'key.store' for the location of your keystore and
15 | # 'key.alias' for the name of the key to use.
16 | # The password will be asked during the build when you use the 'release' target.
17 |
18 | key.store=/home/nihui/osd/nihuini-release-key.keystore
19 | key.alias=nihuini
20 | key.store.password=nihuini
21 | key.alias.password=nihuini
22 |
--------------------------------------------------------------------------------
/examples/squeezencnn/assets/synset_words.txt:
--------------------------------------------------------------------------------
1 | ../../synset_words.txt
--------------------------------------------------------------------------------
/examples/squeezencnn/jni/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 |
3 | # change this folder path to yours
4 | NCNN_INSTALL_PATH := /home/nihui/osd/ncnn-release/ncnn-android-vulkan-lib
5 |
6 | include $(CLEAR_VARS)
7 | LOCAL_MODULE := ncnn
8 | LOCAL_SRC_FILES := $(NCNN_INSTALL_PATH)/$(TARGET_ARCH_ABI)/libncnn.a
9 | include $(PREBUILT_STATIC_LIBRARY)
10 |
11 | include $(CLEAR_VARS)
12 |
13 | LOCAL_MODULE := squeezencnn
14 | LOCAL_SRC_FILES := squeezencnn_jni.cpp
15 |
16 | LOCAL_C_INCLUDES := $(NCNN_INSTALL_PATH)/include
17 |
18 | LOCAL_STATIC_LIBRARIES := ncnn
19 |
20 | LOCAL_CFLAGS := -O2 -fvisibility=hidden -fomit-frame-pointer -fstrict-aliasing -ffunction-sections -fdata-sections -ffast-math
21 | LOCAL_CPPFLAGS := -O2 -fvisibility=hidden -fvisibility-inlines-hidden -fomit-frame-pointer -fstrict-aliasing -ffunction-sections -fdata-sections -ffast-math
22 | LOCAL_LDFLAGS += -Wl,--gc-sections
23 |
24 | LOCAL_CFLAGS += -fopenmp
25 | LOCAL_CPPFLAGS += -fopenmp
26 | LOCAL_LDFLAGS += -fopenmp
27 |
28 | LOCAL_LDLIBS := -lz -llog -ljnigraphics -lvulkan
29 |
30 | include $(BUILD_SHARED_LIBRARY)
31 |
--------------------------------------------------------------------------------
/examples/squeezencnn/jni/Application.mk:
--------------------------------------------------------------------------------
1 | APP_STL := c++_static
2 | APP_ABI := armeabi-v7a arm64-v8a
3 | APP_PLATFORM := android-24
4 |
--------------------------------------------------------------------------------
/examples/squeezencnn/local.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must *NOT* be checked into Version Control Systems,
5 | # as it contains information specific to your local configuration.
6 |
7 | # location of the SDK. This is only used by Ant
8 | # For customization when using a Version Control System, please read the
9 | # header note.
10 | sdk.dir=/home/nihui/osd/android-sdk-linux
11 |
--------------------------------------------------------------------------------
/examples/squeezencnn/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/examples/squeezencnn/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-24
15 |
--------------------------------------------------------------------------------
/examples/squeezencnn/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
17 |
22 |
27 |
28 |
29 |
34 |
35 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/examples/squeezencnn/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | squeezencnn
4 |
5 |
--------------------------------------------------------------------------------
/examples/squeezencnn/src/com/tencent/squeezencnn/SqueezeNcnn.java:
--------------------------------------------------------------------------------
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 | package com.tencent.squeezencnn;
16 |
17 | import android.graphics.Bitmap;
18 | import android.content.Context;
19 |
20 | public class SqueezeNcnn
21 | {
22 | public native boolean Init(byte[] param, byte[] bin, byte[] words);
23 |
24 | public native String Detect(Bitmap bitmap, boolean use_gpu);
25 |
26 | static {
27 | System.loadLibrary("squeezencnn");
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/images/128-ncnn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deepglint/eq-ncnn/64ba809318b272d549a356182a7b4b945838693d/images/128-ncnn.png
--------------------------------------------------------------------------------
/images/16-ncnn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deepglint/eq-ncnn/64ba809318b272d549a356182a7b4b945838693d/images/16-ncnn.png
--------------------------------------------------------------------------------
/images/256-ncnn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deepglint/eq-ncnn/64ba809318b272d549a356182a7b4b945838693d/images/256-ncnn.png
--------------------------------------------------------------------------------
/images/32-ncnn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deepglint/eq-ncnn/64ba809318b272d549a356182a7b4b945838693d/images/32-ncnn.png
--------------------------------------------------------------------------------
/images/64-ncnn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deepglint/eq-ncnn/64ba809318b272d549a356182a7b4b945838693d/images/64-ncnn.png
--------------------------------------------------------------------------------
/src/benchmark.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_BENCHMARK_H
16 | #define NCNN_BENCHMARK_H
17 |
18 | #include "platform.h"
19 | #include "mat.h"
20 | #include "layer.h"
21 |
22 | namespace ncnn {
23 |
24 | // get now timestamp in ms
25 | double get_current_time();
26 |
27 | #if NCNN_BENCHMARK
28 |
29 | void benchmark(const Layer* layer, double start, double end);
30 | void benchmark(const Layer* layer, const Mat& bottom_blob, Mat& top_blob, double start, double end);
31 |
32 | #endif // NCNN_BENCHMARK
33 |
34 | } // namespace ncnn
35 |
36 | #endif // NCNN_BENCHMARK_H
37 |
--------------------------------------------------------------------------------
/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 | }
23 |
24 | } // namespace ncnn
25 |
--------------------------------------------------------------------------------
/src/blob.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_BLOB_H
16 | #define NCNN_BLOB_H
17 |
18 | #include
19 | #include
20 | #include "platform.h"
21 |
22 | namespace ncnn {
23 |
24 | class Blob
25 | {
26 | public:
27 | // empty
28 | Blob();
29 |
30 | public:
31 | #if NCNN_STRING
32 | // blob name
33 | std::string name;
34 | #endif // NCNN_STRING
35 | // layer index which produce this blob as output
36 | int producer;
37 | // layer index which need this blob as input
38 | std::vector consumers;
39 | };
40 |
41 | } // namespace ncnn
42 |
43 | #endif // NCNN_BLOB_H
44 |
--------------------------------------------------------------------------------
/src/cpu.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_CPU_H
16 | #define NCNN_CPU_H
17 |
18 | namespace ncnn {
19 |
20 | // test optional cpu features
21 | // neon = armv7 neon or aarch64 asimd
22 | int cpu_support_arm_neon();
23 | // vfpv4 = armv7 fp16 + fma
24 | int cpu_support_arm_vfpv4();
25 | // asimdhp = aarch64 asimd half precision
26 | int cpu_support_arm_asimdhp();
27 |
28 | // cpu info
29 | int get_cpu_count();
30 |
31 | // bind all threads on little clusters if powersave enabled
32 | // affacts HMP arch cpu like ARM big.LITTLE
33 | // only implemented on android at the moment
34 | // switching powersave is expensive and not thread-safe
35 | // 0 = all cores enabled(default)
36 | // 1 = only little clusters enabled
37 | // 2 = only big clusters enabled
38 | // return 0 if success for setter function
39 | int get_cpu_powersave();
40 | int set_cpu_powersave(int powersave);
41 |
42 | // misc function wrapper for openmp routines
43 | int get_omp_num_threads();
44 | void set_omp_num_threads(int num_threads);
45 |
46 | int get_omp_dynamic();
47 | void set_omp_dynamic(int dynamic);
48 |
49 | } // namespace ncnn
50 |
51 | #endif // NCNN_CPU_H
52 |
--------------------------------------------------------------------------------
/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 | #if NCNN_VULKAN
30 | virtual int create_pipeline();
31 | virtual int destroy_pipeline();
32 |
33 | virtual int forward_inplace(VkMat& bottom_top_blob, VkCompute& cmd, const Option& opt) const;
34 | #endif // NCNN_VULKAN
35 |
36 | public:
37 |
38 | #if NCNN_VULKAN
39 | Pipeline* pipeline_absval;
40 | Pipeline* pipeline_absval_pack4;
41 | #endif // NCNN_VULKAN
42 | };
43 |
44 | } // namespace ncnn
45 |
46 | #endif // LAYER_ABSVAL_H
47 |
--------------------------------------------------------------------------------
/src/layer/argmax.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_ARGMAX_H
16 | #define LAYER_ARGMAX_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class ArgMax : public Layer
23 | {
24 | public:
25 | ArgMax();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
30 |
31 | public:
32 | int out_max_val;
33 | int topk;
34 | };
35 |
36 | } // namespace ncnn
37 |
38 | #endif // LAYER_ARGMAX_H
39 |
--------------------------------------------------------------------------------
/src/layer/arm/absval_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_ABSVAL_ARM_H
16 | #define LAYER_ABSVAL_ARM_H
17 |
18 | #include "absval.h"
19 |
20 | namespace ncnn {
21 |
22 | class AbsVal_arm : public AbsVal
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_ABSVAL_ARM_H
31 |
--------------------------------------------------------------------------------
/src/layer/arm/batchnorm_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_BATCHNORM_ARM_H
16 | #define LAYER_BATCHNORM_ARM_H
17 |
18 | #include "batchnorm.h"
19 |
20 | namespace ncnn {
21 |
22 | class BatchNorm_arm : public BatchNorm
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_BATCHNORM_ARM_H
31 |
--------------------------------------------------------------------------------
/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/clip_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_CLIP_ARM_H
16 | #define LAYER_CLIP_ARM_H
17 |
18 | #include "clip.h"
19 |
20 | namespace ncnn {
21 |
22 | class Clip_arm : public Clip
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_CLIP_ARM_H
31 |
--------------------------------------------------------------------------------
/src/layer/arm/convolution_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_CONVOLUTION_ARM_H
16 | #define LAYER_CONVOLUTION_ARM_H
17 |
18 | #include "convolution.h"
19 |
20 | namespace ncnn {
21 |
22 | typedef void (*conv_func)(const Mat&, Mat&, const Mat&, const Mat&, const Option&);
23 |
24 | class Convolution_arm : public Convolution
25 | {
26 | public:
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int load_model(const ModelBin& mb);
30 |
31 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
32 | virtual int forwardDilation(const Mat& bottom_blob, Mat& top_blob, conv_func conv, const Option& opt) const;
33 |
34 | public:
35 | bool use_winograd3x3;
36 | bool use_sgemm1x1;
37 | Mat weight_3x3_winograd64_data;
38 | Mat weight_1x1_sgemm_data;
39 | Mat weight_3x3s2_data;
40 | Mat weight_3x3s2_int8_data;
41 | Mat weight_1x1s1_sgemm_int8_data;
42 | Mat weight_3x3_winograd23_data;
43 | Mat weight_sgemm_int8_data;
44 | std::vector weight_3x3_winograd23_int8_data;
45 | };
46 |
47 | } // namespace ncnn
48 |
49 | #endif // LAYER_CONVOLUTION_ARM_H
50 |
--------------------------------------------------------------------------------
/src/layer/arm/convolutiondepthwise_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_CONVOLUTIONDEPTHWISE_ARM_H
16 | #define LAYER_CONVOLUTIONDEPTHWISE_ARM_H
17 |
18 | #include "convolutiondepthwise.h"
19 |
20 | namespace ncnn {
21 |
22 | class ConvolutionDepthWise_arm : public ConvolutionDepthWise
23 | {
24 | public:
25 | ConvolutionDepthWise_arm();
26 | virtual ~ConvolutionDepthWise_arm();
27 |
28 | virtual int load_model(const ModelBin& mb);
29 |
30 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
31 |
32 | public:
33 | std::vector group_ops;
34 | };
35 |
36 | } // namespace ncnn
37 |
38 | #endif // LAYER_CONVOLUTIONDEPTHWISE_ARM_H
39 |
--------------------------------------------------------------------------------
/src/layer/arm/deconvolution_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_DECONVOLUTION_ARM_H
16 | #define LAYER_DECONVOLUTION_ARM_H
17 |
18 | #include "deconvolution.h"
19 |
20 | namespace ncnn {
21 |
22 | class Deconvolution_arm : public Deconvolution
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
26 | };
27 |
28 | } // namespace ncnn
29 |
30 | #endif // LAYER_DECONVOLUTION_ARM_H
31 |
--------------------------------------------------------------------------------
/src/layer/arm/deconvolutiondepthwise_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_DECONVOLUTIONDEPTHWISE_ARM_H
16 | #define LAYER_DECONVOLUTIONDEPTHWISE_ARM_H
17 |
18 | #include "deconvolutiondepthwise.h"
19 |
20 | namespace ncnn {
21 |
22 | class DeconvolutionDepthWise_arm : public DeconvolutionDepthWise
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
26 | };
27 |
28 | } // namespace ncnn
29 |
30 | #endif // LAYER_DECONVOLUTIONDEPTHWISE_ARM_H
31 |
--------------------------------------------------------------------------------
/src/layer/arm/dequantize_arm.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2018 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_DEQUANTIZE_ARM_H
16 | #define LAYER_DEQUANTIZE_ARM_H
17 |
18 | #include "dequantize.h"
19 |
20 | namespace ncnn {
21 |
22 | class Dequantize_arm : public Dequantize
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_DEQUANTIZE_ARM_H
31 |
--------------------------------------------------------------------------------
/src/layer/arm/eltwise_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_ELTWISE_ARM_H
16 | #define LAYER_ELTWISE_ARM_H
17 |
18 | #include "eltwise.h"
19 |
20 | namespace ncnn {
21 |
22 | class Eltwise_arm : public Eltwise
23 | {
24 | public:
25 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs, const Option& opt) const;
26 | };
27 |
28 | } // namespace ncnn
29 |
30 | #endif // LAYER_ELTWISE_ARM_H
31 |
--------------------------------------------------------------------------------
/src/layer/arm/innerproduct_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_INNERPRODUCT_ARM_H
16 | #define LAYER_INNERPRODUCT_ARM_H
17 |
18 | #include "innerproduct.h"
19 |
20 | namespace ncnn {
21 |
22 | class InnerProduct_arm : public InnerProduct
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
26 | };
27 |
28 | } // namespace ncnn
29 |
30 | #endif // LAYER_INNERPRODUCT_ARM_H
31 |
--------------------------------------------------------------------------------
/src/layer/arm/interp_arm.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_INTERP_ARM_H
16 | #define LAYER_INTERP_ARM_H
17 |
18 | #include "interp.h"
19 |
20 | namespace ncnn {
21 |
22 | class Interp_arm : public Interp
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
26 | };
27 |
28 | } // namespace ncnn
29 |
30 | #endif // LAYER_INTERP_ARM_H
31 |
--------------------------------------------------------------------------------
/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/arm/pooling_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_POOLING_ARM_H
16 | #define LAYER_POOLING_ARM_H
17 |
18 | #include "pooling.h"
19 |
20 | namespace ncnn {
21 |
22 | class Pooling_arm : public Pooling
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
26 | };
27 |
28 | } // namespace ncnn
29 |
30 | #endif // LAYER_POOLING_ARM_H
31 |
--------------------------------------------------------------------------------
/src/layer/arm/prelu_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_PRELU_ARM_H
16 | #define LAYER_PRELU_ARM_H
17 |
18 | #include "prelu.h"
19 |
20 | namespace ncnn {
21 |
22 | class PReLU_arm : public PReLU
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_PRELU_ARM_H
31 |
--------------------------------------------------------------------------------
/src/layer/arm/quantize_arm.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2018 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_QUANTIZE_ARM_H
16 | #define LAYER_QUANTIZE_ARM_H
17 |
18 | #include "quantize.h"
19 |
20 | namespace ncnn {
21 |
22 | class Quantize_arm : public Quantize
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
26 | };
27 |
28 | } // namespace ncnn
29 |
30 | #endif // LAYER_QUANTIZE_ARM_H
31 |
--------------------------------------------------------------------------------
/src/layer/arm/relu_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_RELU_ARM_H
16 | #define LAYER_RELU_ARM_H
17 |
18 | #include "relu.h"
19 |
20 | namespace ncnn {
21 |
22 | class ReLU_arm : public ReLU
23 | {
24 | public:
25 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const;
26 | virtual int forward_inplace_int8(Mat& bottom_top_blob, const Option& opt) const;
27 | };
28 |
29 | } // namespace ncnn
30 |
31 | #endif // LAYER_RELU_ARM_H
32 |
--------------------------------------------------------------------------------
/src/layer/arm/requantize_arm.h:
--------------------------------------------------------------------------------
1 | // BUG1989 is pleased to support the open source community by supporting ncnn available.
2 | //
3 | // Copyright (C) 2019 BUG1989. 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_REQUANTIZE_ARM_H
16 | #define LAYER_REQUANTIZE_ARM_H
17 |
18 | #include "requantize.h"
19 |
20 | namespace ncnn {
21 |
22 | class Requantize_arm : public Requantize
23 | {
24 | public:
25 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
26 | };
27 |
28 | } // namespace ncnn
29 |
30 | #endif // LAYER_REQUANTIZE_ARM_H
--------------------------------------------------------------------------------
/src/layer/arm/scale_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_SCALE_ARM_H
16 | #define LAYER_SCALE_ARM_H
17 |
18 | #include "scale.h"
19 |
20 | namespace ncnn {
21 |
22 | class Scale_arm : public Scale
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_SCALE_ARM_H
31 |
--------------------------------------------------------------------------------
/src/layer/arm/sigmoid_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_SIGMOID_ARM_H
16 | #define LAYER_SIGMOID_ARM_H
17 |
18 | #include "sigmoid.h"
19 |
20 | namespace ncnn {
21 |
22 | class Sigmoid_arm : public Sigmoid
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_SIGMOID_ARM_H
31 |
--------------------------------------------------------------------------------
/src/layer/arm/softmax_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_SOFTMAX_ARM_H
16 | #define LAYER_SOFTMAX_ARM_H
17 |
18 | #include "softmax.h"
19 |
20 | namespace ncnn {
21 |
22 | class Softmax_arm : 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_ARM_H
31 |
--------------------------------------------------------------------------------
/src/layer/batchnorm.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_BATCHNORM_H
16 | #define LAYER_BATCHNORM_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class BatchNorm : public Layer
23 | {
24 | public:
25 | BatchNorm();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int load_model(const ModelBin& mb);
30 |
31 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const;
32 |
33 | #if NCNN_VULKAN
34 | virtual int upload_model(VkTransfer& cmd);
35 |
36 | virtual int create_pipeline();
37 | virtual int destroy_pipeline();
38 |
39 | virtual int forward_inplace(VkMat& bottom_top_blob, VkCompute& cmd, const Option& opt) const;
40 | #endif // NCNN_VULKAN
41 |
42 | public:
43 | // param
44 | int channels;
45 | float eps;
46 |
47 | // model
48 | Mat slope_data;
49 | Mat mean_data;
50 | Mat var_data;
51 | Mat bias_data;
52 |
53 | Mat a_data;
54 | Mat b_data;
55 |
56 | #if NCNN_VULKAN
57 | VkMat a_data_gpu;
58 | VkMat b_data_gpu;
59 | Pipeline* pipeline_batchnorm;
60 |
61 | VkMat a_data_gpu_pack4;
62 | VkMat b_data_gpu_pack4;
63 | Pipeline* pipeline_batchnorm_pack4;
64 | #endif // NCNN_VULKAN
65 |
66 | };
67 |
68 | } // namespace ncnn
69 |
70 | #endif // LAYER_BATCHNORM_H
71 |
--------------------------------------------------------------------------------
/src/layer/bias.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 "bias.h"
16 |
17 | namespace ncnn {
18 |
19 | DEFINE_LAYER_CREATOR(Bias)
20 |
21 | Bias::Bias()
22 | {
23 | one_blob_only = true;
24 | support_inplace = true;
25 | }
26 |
27 | int Bias::load_param(const ParamDict& pd)
28 | {
29 | bias_data_size = pd.get(0, 0);
30 |
31 | return 0;
32 | }
33 |
34 | int Bias::load_model(const ModelBin& mb)
35 | {
36 | bias_data = mb.load(bias_data_size, 1);
37 | if (bias_data.empty())
38 | return -100;
39 |
40 | return 0;
41 | }
42 |
43 | int Bias::forward_inplace(Mat& bottom_top_blob, const Option& opt) const
44 | {
45 | int w = bottom_top_blob.w;
46 | int h = bottom_top_blob.h;
47 | int channels = bottom_top_blob.c;
48 | int size = w * h;
49 |
50 | #pragma omp parallel for num_threads(opt.num_threads)
51 | for (int q=0; q
17 |
18 | namespace ncnn {
19 |
20 | DEFINE_LAYER_CREATOR(BNLL)
21 |
22 | BNLL::BNLL()
23 | {
24 | one_blob_only = true;
25 | support_inplace = true;
26 | }
27 |
28 | int BNLL::forward_inplace(Mat& bottom_top_blob, const Option& opt) const
29 | {
30 | int w = bottom_top_blob.w;
31 | int h = bottom_top_blob.h;
32 | int channels = bottom_top_blob.c;
33 | int size = w * h;
34 |
35 | #pragma omp parallel for num_threads(opt.num_threads)
36 | for (int q=0; q 0)
43 | ptr[i] = ptr[i] + log(1.f + exp(-ptr[i]));
44 | else
45 | ptr[i] = log(1.f + exp(ptr[i]));
46 | }
47 | }
48 |
49 | return 0;
50 | }
51 |
52 | } // namespace ncnn
53 |
--------------------------------------------------------------------------------
/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/cast.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_CAST_H
16 | #define LAYER_CAST_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Cast : public Layer
23 | {
24 | public:
25 | Cast();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
30 |
31 | #if NCNN_VULKAN
32 | virtual int create_pipeline();
33 | virtual int destroy_pipeline();
34 |
35 | virtual int forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute& cmd, const Option& opt) const;
36 | #endif // NCNN_VULKAN
37 |
38 | public:
39 | // element type
40 | // 0 = auto
41 | // 1 = float32
42 | // 2 = float16
43 | // 3 = int8
44 | int type_from;
45 | int type_to;
46 |
47 | #if NCNN_VULKAN
48 | Pipeline* pipeline_cast_fp32_to_fp16;
49 | Pipeline* pipeline_cast_fp32_to_fp16_pack4;
50 | Pipeline* pipeline_cast_fp16_to_fp32;
51 | Pipeline* pipeline_cast_fp16_to_fp32_pack4;
52 | #endif // NCNN_VULKAN
53 | };
54 |
55 | } // namespace ncnn
56 |
57 | #endif // LAYER_CAST_H
58 |
--------------------------------------------------------------------------------
/src/layer/clip.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2018 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_H
16 | #define LAYER_CLIP_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Clip : public Layer
23 | {
24 | public:
25 | Clip();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const;
30 |
31 | #if NCNN_VULKAN
32 | virtual int create_pipeline();
33 | virtual int destroy_pipeline();
34 |
35 | virtual int forward_inplace(VkMat& bottom_top_blob, VkCompute& cmd, const Option& opt) const;
36 | #endif // NCNN_VULKAN
37 |
38 | public:
39 | float min;
40 | float max;
41 |
42 | #if NCNN_VULKAN
43 | Pipeline* pipeline_clip;
44 | Pipeline* pipeline_clip_pack4;
45 | #endif // NCNN_VULKAN
46 | };
47 |
48 | } // namespace ncnn
49 |
50 | #endif // LAYER_CLIP_H
51 |
--------------------------------------------------------------------------------
/src/layer/concat.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_CONCAT_H
16 | #define LAYER_CONCAT_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Concat : public Layer
23 | {
24 | public:
25 | Concat();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs, const Option& opt) const;
30 |
31 | #if NCNN_VULKAN
32 | virtual int create_pipeline();
33 | virtual int destroy_pipeline();
34 |
35 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs, VkCompute& cmd, const Option& opt) const;
36 | #endif // NCNN_VULKAN
37 |
38 | public:
39 | int axis;
40 |
41 | #if NCNN_VULKAN
42 | Pipeline* pipeline_concat[2];
43 | Pipeline* pipeline_concat_pack4[2];
44 | Pipeline* pipeline_concat_pack4to1[2];
45 | #endif // NCNN_VULKAN
46 |
47 | };
48 |
49 | } // namespace ncnn
50 |
51 | #endif // LAYER_CONCAT_H
52 |
--------------------------------------------------------------------------------
/src/layer/crop.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_CROP_H
16 | #define LAYER_CROP_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Crop : public Layer
23 | {
24 | public:
25 | Crop();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
30 |
31 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs, const Option& opt) const;
32 |
33 | #if NCNN_VULKAN
34 | virtual int create_pipeline();
35 | virtual int destroy_pipeline();
36 |
37 | virtual int forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute& cmd, const Option& opt) const;
38 |
39 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs, VkCompute& cmd, const Option& opt) const;
40 | #endif // NCNN_VULKAN
41 |
42 | public:
43 | int woffset;
44 | int hoffset;
45 | int coffset;
46 |
47 | // -233 = remaining
48 | // -234 = remaining - 1
49 | int outw;
50 | int outh;
51 | int outc;
52 |
53 | #if NCNN_VULKAN
54 | Pipeline* pipeline_crop;
55 | Pipeline* pipeline_crop_pack4;
56 | #endif // NCNN_VULKAN
57 | };
58 |
59 | } // namespace ncnn
60 |
61 | #endif // LAYER_CROP_H
62 |
--------------------------------------------------------------------------------
/src/layer/dequantize.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2018 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_DEQUANTIZE_H
16 | #define LAYER_DEQUANTIZE_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Dequantize : public Layer
23 | {
24 | public:
25 | Dequantize();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int load_model(const ModelBin& mb);
30 |
31 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const;
32 |
33 | public:
34 | float scale;
35 | int bias_term;
36 | int bias_data_size;
37 |
38 | Mat bias_data;
39 | };
40 |
41 | } // namespace ncnn
42 |
43 | #endif // LAYER_DEQUANTIZE_H
44 |
--------------------------------------------------------------------------------
/src/layer/detectionoutput.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_DETECTIONOUTPUT_H
16 | #define LAYER_DETECTIONOUTPUT_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class DetectionOutput : public Layer
23 | {
24 | public:
25 | DetectionOutput();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs, const Option& opt) const;
30 |
31 | public:
32 | int num_class;
33 | float nms_threshold;
34 | int nms_top_k;
35 | int keep_top_k;
36 | float confidence_threshold;
37 | float variances[4];
38 | };
39 |
40 | } // namespace ncnn
41 |
42 | #endif // LAYER_DETECTIONOUTPUT_H
43 |
--------------------------------------------------------------------------------
/src/layer/dropout.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_DROPOUT_H
16 | #define LAYER_DROPOUT_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Dropout : public Layer
23 | {
24 | public:
25 | Dropout();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const;
30 |
31 | #if NCNN_VULKAN
32 | virtual int create_pipeline();
33 | virtual int destroy_pipeline();
34 |
35 | virtual int forward_inplace(VkMat& bottom_top_blob, VkCompute& cmd, const Option& opt) const;
36 | #endif // NCNN_VULKAN
37 |
38 | public:
39 | float scale;
40 |
41 | #if NCNN_VULKAN
42 | Pipeline* pipeline_dropout;
43 | Pipeline* pipeline_dropout_pack4;
44 | #endif // NCNN_VULKAN
45 | };
46 |
47 | } // namespace ncnn
48 |
49 | #endif // LAYER_DROPOUT_H
50 |
--------------------------------------------------------------------------------
/src/layer/eltwise.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_ELTWISE_H
16 | #define LAYER_ELTWISE_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Eltwise : public Layer
23 | {
24 | public:
25 | Eltwise();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs, const Option& opt) const;
30 |
31 | #if NCNN_VULKAN
32 | virtual int create_pipeline();
33 | virtual int destroy_pipeline();
34 |
35 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs, VkCompute& cmd, const Option& opt) const;
36 | #endif // NCNN_VULKAN
37 |
38 | enum { Operation_PROD = 0, Operation_SUM = 1, Operation_MAX = 2 };
39 |
40 | public:
41 | // param
42 | int op_type;
43 | Mat coeffs;
44 |
45 | #if NCNN_VULKAN
46 | Pipeline* pipeline_eltwise[2];
47 | Pipeline* pipeline_eltwise_pack4[2];
48 | #endif // NCNN_VULKAN
49 | };
50 |
51 | } // namespace ncnn
52 |
53 | #endif // LAYER_ELTWISE_H
54 |
--------------------------------------------------------------------------------
/src/layer/elu.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 "elu.h"
16 | #include
17 |
18 | namespace ncnn {
19 |
20 | DEFINE_LAYER_CREATOR(ELU)
21 |
22 | ELU::ELU()
23 | {
24 | one_blob_only = true;
25 | support_inplace = true;
26 | }
27 |
28 | int ELU::load_param(const ParamDict& pd)
29 | {
30 | alpha = pd.get(0, 0.1f);
31 |
32 | return 0;
33 | }
34 |
35 | int ELU::forward_inplace(Mat& bottom_top_blob, const Option& opt) const
36 | {
37 | int w = bottom_top_blob.w;
38 | int h = bottom_top_blob.h;
39 | int channels = bottom_top_blob.c;
40 | int size = w * h;
41 |
42 | #pragma omp parallel for num_threads(opt.num_threads)
43 | for (int q=0; q& bottom_blobs, std::vector& top_blobs, const Option& opt) const;
32 |
33 | public:
34 | // param
35 | int num_output;
36 | int weight_data_size;
37 |
38 | // model
39 | Mat weight_hc_data;
40 | Mat weight_xc_data;
41 | Mat bias_c_data;
42 | };
43 |
44 | } // namespace ncnn
45 |
46 | #endif // LAYER_LSTM_H
47 |
--------------------------------------------------------------------------------
/src/layer/memorydata.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 "memorydata.h"
16 |
17 | namespace ncnn {
18 |
19 | DEFINE_LAYER_CREATOR(MemoryData)
20 |
21 | MemoryData::MemoryData()
22 | {
23 | one_blob_only = false;
24 | support_inplace = false;
25 | }
26 |
27 | int MemoryData::load_param(const ParamDict& pd)
28 | {
29 | w = pd.get(0, 0);
30 | h = pd.get(1, 0);
31 | c = pd.get(2, 0);
32 |
33 | return 0;
34 | }
35 |
36 | int MemoryData::load_model(const ModelBin& mb)
37 | {
38 | if (c != 0)
39 | {
40 | data = mb.load(w, h, c, 1);
41 | }
42 | else if (h != 0)
43 | {
44 | data = mb.load(w, h, 1);
45 | }
46 | else if (w != 0)
47 | {
48 | data = mb.load(w, 1);
49 | }
50 | else // 0 0 0
51 | {
52 | data.create(1);
53 | }
54 | if (data.empty())
55 | return -100;
56 |
57 | return 0;
58 | }
59 |
60 | int MemoryData::forward(const std::vector& /*bottom_blobs*/, std::vector& top_blobs, const Option& opt) const
61 | {
62 | Mat& top_blob = top_blobs[0];
63 |
64 | top_blob = data.clone(opt.blob_allocator);
65 | if (top_blob.empty())
66 | return -100;
67 |
68 | return 0;
69 | }
70 |
71 | } // namespace ncnn
72 |
--------------------------------------------------------------------------------
/src/layer/memorydata.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_MEMORYDATA_H
16 | #define LAYER_MEMORYDATA_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class MemoryData : public Layer
23 | {
24 | public:
25 | MemoryData();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int load_model(const ModelBin& mb);
30 |
31 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs, const Option& opt) const;
32 |
33 | public:
34 | int w;
35 | int h;
36 | int c;
37 |
38 | Mat data;
39 | };
40 |
41 | } // namespace ncnn
42 |
43 | #endif // LAYER_MEMORYDATA_H
44 |
--------------------------------------------------------------------------------
/src/layer/mvn.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_MVN_H
16 | #define LAYER_MVN_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class MVN : public Layer
23 | {
24 | public:
25 | MVN();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
30 |
31 | public:
32 | int normalize_variance;
33 | int across_channels;
34 | float eps;
35 | };
36 |
37 | } // namespace ncnn
38 |
39 | #endif // LAYER_MVN_H
40 |
--------------------------------------------------------------------------------
/src/layer/normalize.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_NORMALIZE_H
16 | #define LAYER_NORMALIZE_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Normalize : public Layer
23 | {
24 | public:
25 | Normalize();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int load_model(const ModelBin& mb);
30 |
31 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
32 |
33 | public:
34 | // param
35 | int across_spatial;
36 | int across_channel;
37 | int channel_shared;
38 | float eps;
39 | int scale_data_size;
40 |
41 | Mat scale_data;
42 | };
43 |
44 | } // namespace ncnn
45 |
46 | #endif // LAYER_NORMALIZE_H
47 |
--------------------------------------------------------------------------------
/src/layer/packing.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_PACKING_H
16 | #define LAYER_PACKING_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Packing : public Layer
23 | {
24 | public:
25 | Packing();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
30 |
31 | #if NCNN_VULKAN
32 | virtual int create_pipeline();
33 | virtual int destroy_pipeline();
34 |
35 | virtual int forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute& cmd, const Option& opt) const;
36 | #endif // NCNN_VULKAN
37 |
38 | private:
39 | int out_packing;
40 | int use_padding;
41 |
42 | #if NCNN_VULKAN
43 | Pipeline* pipeline_packing_1to4;
44 | Pipeline* pipeline_packing_4to1;
45 | #endif // NCNN_VULKAN
46 | };
47 |
48 | } // namespace ncnn
49 |
50 | #endif // LAYER_PACKING_H
51 |
--------------------------------------------------------------------------------
/src/layer/padding.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_PADDING_H
16 | #define LAYER_PADDING_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Padding : public Layer
23 | {
24 | public:
25 | Padding();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
30 |
31 | #if NCNN_VULKAN
32 | virtual int create_pipeline();
33 | virtual int destroy_pipeline();
34 |
35 | virtual int forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute& cmd, const Option& opt) const;
36 | #endif // NCNN_VULKAN
37 |
38 | public:
39 | int top;
40 | int bottom;
41 | int left;
42 | int right;
43 | int type;// 0=BORDER_CONSTANT 1=BORDER_REPLICATE
44 | float value;
45 |
46 | #if NCNN_VULKAN
47 | Pipeline* pipeline_padding;
48 | Pipeline* pipeline_padding_pack4;
49 | #endif // NCNN_VULKAN
50 | };
51 |
52 | } // namespace ncnn
53 |
54 | #endif // LAYER_PADDING_H
55 |
--------------------------------------------------------------------------------
/src/layer/permute.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_PERMUTE_H
16 | #define LAYER_PERMUTE_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Permute : public Layer
23 | {
24 | public:
25 | Permute();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
30 |
31 | #if NCNN_VULKAN
32 | virtual int create_pipeline();
33 | virtual int destroy_pipeline();
34 |
35 | virtual int forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute& cmd, const Option& opt) const;
36 | #endif // NCNN_VULKAN
37 |
38 | public:
39 | int order_type;
40 |
41 | #if NCNN_VULKAN
42 | Pipeline* pipeline_permute;
43 | Pipeline* pipeline_permute_pack4to1;
44 | #endif // NCNN_VULKAN
45 | };
46 |
47 | } // namespace ncnn
48 |
49 | #endif // LAYER_PERMUTE_H
50 |
--------------------------------------------------------------------------------
/src/layer/power.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 "power.h"
16 | #include
17 |
18 | namespace ncnn {
19 |
20 | DEFINE_LAYER_CREATOR(Power)
21 |
22 | Power::Power()
23 | {
24 | one_blob_only = true;
25 | support_inplace = true;
26 | }
27 |
28 | int Power::load_param(const ParamDict& pd)
29 | {
30 | power = pd.get(0, 1.f);
31 | scale = pd.get(1, 1.f);
32 | shift = pd.get(2, 0.f);
33 |
34 | return 0;
35 | }
36 |
37 | int Power::forward_inplace(Mat& bottom_top_blob, const Option& opt) const
38 | {
39 | int w = bottom_top_blob.w;
40 | int h = bottom_top_blob.h;
41 | int channels = bottom_top_blob.c;
42 | int size = w * h;
43 |
44 | #pragma omp parallel for num_threads(opt.num_threads)
45 | for (int q=0; q& bottom_blobs, std::vector& top_blobs, const Option& opt) const;
30 |
31 | #if NCNN_VULKAN
32 | virtual int upload_model(VkTransfer& cmd);
33 |
34 | virtual int create_pipeline();
35 | virtual int destroy_pipeline();
36 |
37 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs, VkCompute& cmd, const Option& opt) const;
38 | #endif // NCNN_VULKAN
39 |
40 | public:
41 | Mat min_sizes;
42 | Mat max_sizes;
43 | Mat aspect_ratios;
44 | float variances[4];
45 | int flip;
46 | int clip;
47 | int image_width;
48 | int image_height;
49 | float step_width;
50 | float step_height;
51 | float offset;
52 |
53 | #if NCNN_VULKAN
54 | VkMat min_sizes_gpu;
55 | VkMat max_sizes_gpu;
56 | VkMat aspect_ratios_gpu;
57 | Pipeline* pipeline_priorbox;
58 | Pipeline* pipeline_priorbox_mxnet;
59 | #endif // NCNN_VULKAN
60 | };
61 |
62 | } // namespace ncnn
63 |
64 | #endif // LAYER_PRIORBOX_H
65 |
--------------------------------------------------------------------------------
/src/layer/proposal.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_PROPOSAL_H
16 | #define LAYER_PROPOSAL_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Proposal : public Layer
23 | {
24 | public:
25 | Proposal();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs, const Option& opt) const;
30 |
31 | public:
32 | // param
33 | int feat_stride;
34 | int base_size;
35 | int pre_nms_topN;
36 | int after_nms_topN;
37 | float nms_thresh;
38 | int min_size;
39 |
40 | Mat ratios;
41 | Mat scales;
42 |
43 | Mat anchors;
44 | };
45 |
46 | } // namespace ncnn
47 |
48 | #endif // LAYER_PROPOSAL_H
49 |
--------------------------------------------------------------------------------
/src/layer/psroipooling.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2018 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_PSROIPOOLING_H
16 | #define LAYER_PSROIPOOLING_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class PSROIPooling : public Layer
23 | {
24 | public:
25 | PSROIPooling();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs, const Option& opt) const;
30 |
31 | public:
32 | int pooled_width;
33 | int pooled_height;
34 | float spatial_scale;
35 | int output_dim;
36 | };
37 |
38 | } // namespace ncnn
39 |
40 | #endif // LAYER_PSROIPOOLING_H
41 |
--------------------------------------------------------------------------------
/src/layer/quantize.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2018 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_QUANTIZE_H
16 | #define LAYER_QUANTIZE_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Quantize : public Layer
23 | {
24 | public:
25 | Quantize();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
30 |
31 | public:
32 | float scale;
33 | };
34 |
35 | } // namespace ncnn
36 |
37 | #endif // LAYER_QUANTIZE_H
38 |
--------------------------------------------------------------------------------
/src/layer/reduction.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_REDUCTION_H
16 | #define LAYER_REDUCTION_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Reduction : public Layer
23 | {
24 | public:
25 | Reduction();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
30 |
31 | enum {
32 | ReductionOp_SUM = 0,
33 | ReductionOp_ASUM = 1,
34 | ReductionOp_SUMSQ = 2,
35 | ReductionOp_MEAN = 3,
36 | ReductionOp_MAX = 4,
37 | ReductionOp_MIN = 5,
38 | ReductionOp_PROD = 6
39 | };
40 |
41 | public:
42 | // param
43 | int operation;
44 | int dim;
45 | float coeff;
46 | };
47 |
48 | } // namespace ncnn
49 |
50 | #endif // LAYER_REDUCTION_H
51 |
--------------------------------------------------------------------------------
/src/layer/relu.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_RELU_H
16 | #define LAYER_RELU_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class ReLU : public Layer
23 | {
24 | public:
25 | ReLU();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const;
30 | virtual int forward_inplace_int8(Mat& bottom_top_blob, const Option& opt) const;
31 |
32 | #if NCNN_VULKAN
33 | virtual int create_pipeline();
34 | virtual int destroy_pipeline();
35 |
36 | virtual int forward_inplace(VkMat& bottom_top_blob, VkCompute& cmd, const Option& opt) const;
37 | #endif // NCNN_VULKAN
38 |
39 | public:
40 | float slope;
41 |
42 | #if NCNN_VULKAN
43 | Pipeline* pipeline_relu;
44 | Pipeline* pipeline_relu_pack4;
45 | #endif // NCNN_VULKAN
46 | };
47 |
48 | } // namespace ncnn
49 |
50 | #endif // LAYER_RELU_H
51 |
--------------------------------------------------------------------------------
/src/layer/reorg.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2018 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_REORG_H
16 | #define LAYER_REORG_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Reorg : public Layer
23 | {
24 | public:
25 | Reorg();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
30 |
31 | #if NCNN_VULKAN
32 | virtual int create_pipeline();
33 | virtual int destroy_pipeline();
34 |
35 | virtual int forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute& cmd, const Option& opt) const;
36 | #endif // NCNN_VULKAN
37 |
38 | private:
39 | int stride;
40 |
41 | #if NCNN_VULKAN
42 | Pipeline* pipeline_reorg;
43 | Pipeline* pipeline_reorg_pack4;
44 | Pipeline* pipeline_reorg_pack1to4;
45 | #endif // NCNN_VULKAN
46 | };
47 |
48 | } // namespace ncnn
49 |
50 | #endif // LAYER_REORG_H
51 |
--------------------------------------------------------------------------------
/src/layer/requantize.h:
--------------------------------------------------------------------------------
1 | // BUG1989 is pleased to support the open source community by supporting ncnn available.
2 | //
3 | // Copyright (C) 2019 BUG1989. 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_REQUANTIZE_H
16 | #define LAYER_REQUANTIZE_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Requantize : public Layer
23 | {
24 | public:
25 | Requantize();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int load_model(const ModelBin& mb);
30 |
31 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
32 |
33 | public:
34 | float scale_in; // bottom_blob_scale * weight_scale
35 | float scale_out;// top_blob_scale / (bottom_blob_scale * weight_scale)
36 | int bias_term;
37 | int bias_data_size;
38 |
39 | bool fusion_relu;
40 |
41 | Mat bias_data;
42 | };
43 |
44 | } // namespace ncnn
45 |
46 | #endif // LAYER_REQUANTIZE_H
--------------------------------------------------------------------------------
/src/layer/reshape.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_RESHAPE_H
16 | #define LAYER_RESHAPE_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Reshape : public Layer
23 | {
24 | public:
25 | Reshape();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
30 |
31 | #if NCNN_VULKAN
32 | virtual int create_pipeline();
33 | virtual int destroy_pipeline();
34 |
35 | virtual int forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute& cmd, const Option& opt) const;
36 | #endif // NCNN_VULKAN
37 |
38 | private:
39 | // reshape flag
40 | // 0 = copy from bottom
41 | // -1 = remaining
42 | // -233 = drop this dim (default)
43 | int w;
44 | int h;
45 | int c;
46 | int permute;
47 | int ndim;
48 |
49 | #if NCNN_VULKAN
50 | Pipeline* pipeline_reshape;
51 | Pipeline* pipeline_reshape_pack4;
52 | Pipeline* pipeline_reshape_pack1to4;
53 | Pipeline* pipeline_reshape_pack4to1;
54 | #endif // NCNN_VULKAN
55 | };
56 |
57 | } // namespace ncnn
58 |
59 | #endif // LAYER_RESHAPE_H
60 |
--------------------------------------------------------------------------------
/src/layer/rnn.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_RNN_H
16 | #define LAYER_RNN_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class RNN : public Layer
23 | {
24 | public:
25 | RNN();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int load_model(const ModelBin& mb);
30 |
31 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs, const Option& opt) const;
32 |
33 | public:
34 | // param
35 | int num_output;
36 | int weight_data_size;
37 |
38 | // model
39 | Mat weight_hh_data;
40 | Mat weight_xh_data;
41 | Mat weight_ho_data;
42 | Mat bias_h_data;
43 | Mat bias_o_data;
44 | };
45 |
46 | } // namespace ncnn
47 |
48 | #endif // LAYER_RNN_H
49 |
--------------------------------------------------------------------------------
/src/layer/roialign.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2018 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_ROIALIGN_H
16 | #define LAYER_ROIALIGN_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class ROIAlign : public Layer
23 | {
24 | public:
25 | ROIAlign();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs, const Option& opt) const;
30 |
31 | public:
32 | int pooled_width;
33 | int pooled_height;
34 | float spatial_scale;
35 | };
36 |
37 | } // namespace ncnn
38 |
39 | #endif // LAYER_ROIALIGN_H
40 |
--------------------------------------------------------------------------------
/src/layer/roipooling.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_ROIPOOLING_H
16 | #define LAYER_ROIPOOLING_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class ROIPooling : public Layer
23 | {
24 | public:
25 | ROIPooling();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs, const Option& opt) const;
30 |
31 | public:
32 | int pooled_width;
33 | int pooled_height;
34 | float spatial_scale;
35 | };
36 |
37 | } // namespace ncnn
38 |
39 | #endif // LAYER_ROIPOOLING_H
40 |
--------------------------------------------------------------------------------
/src/layer/shader/absval.comp:
--------------------------------------------------------------------------------
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 | #version 450
16 |
17 | #if NCNN_fp16_storage
18 | #extension GL_EXT_shader_16bit_storage: require
19 | #endif
20 | #if NCNN_fp16_arithmetic
21 | #extension GL_AMD_gpu_shader_half_float: require
22 | #endif
23 |
24 | layout (local_size_x_id = 233) in;
25 | layout (local_size_y_id = 234) in;
26 | layout (local_size_z_id = 235) in;
27 |
28 | layout (binding = 0) buffer bottom_top_blob { sfp bottom_top_blob_data[]; };
29 |
30 | layout (push_constant) uniform parameter
31 | {
32 | int dims;
33 | int w;
34 | int h;
35 | int c;
36 | int cstep;
37 | } p;
38 |
39 | void main()
40 | {
41 | int gx = int(gl_GlobalInvocationID.x);
42 | int gy = int(gl_GlobalInvocationID.y);
43 | int gz = int(gl_GlobalInvocationID.z);
44 |
45 | if (gx >= p.w || gy >= p.h || gz >= p.c)
46 | return;
47 |
48 | const int gi = gz * p.cstep + gy * p.w + gx;
49 |
50 | afp v = afp(bottom_top_blob_data[gi]);
51 |
52 | bottom_top_blob_data[gi] = sfp(abs(v));
53 | }
54 |
--------------------------------------------------------------------------------
/src/layer/shader/absval_pack4.comp:
--------------------------------------------------------------------------------
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 | #version 450
16 |
17 | #if NCNN_fp16_storage
18 | #extension GL_EXT_shader_16bit_storage: require
19 | #endif
20 | #if NCNN_fp16_arithmetic
21 | #extension GL_AMD_gpu_shader_half_float: require
22 | #endif
23 |
24 | layout (local_size_x_id = 233) in;
25 | layout (local_size_y_id = 234) in;
26 | layout (local_size_z_id = 235) in;
27 |
28 | layout (binding = 0) buffer bottom_top_blob { sfpvec4 bottom_top_blob_data[]; };
29 |
30 | layout (push_constant) uniform parameter
31 | {
32 | int dims;
33 | int w;
34 | int h;
35 | int c;
36 | int cstep;
37 | } p;
38 |
39 | void main()
40 | {
41 | int gx = int(gl_GlobalInvocationID.x);
42 | int gy = int(gl_GlobalInvocationID.y);
43 | int gz = int(gl_GlobalInvocationID.z);
44 |
45 | if (gx >= p.w || gy >= p.h || gz >= p.c)
46 | return;
47 |
48 | const int gi = gz * p.cstep + gy * p.w + gx;
49 |
50 | afpvec4 v = afpvec4(bottom_top_blob_data[gi]);
51 |
52 | bottom_top_blob_data[gi] = sfpvec4(abs(v));
53 | }
54 |
--------------------------------------------------------------------------------
/src/layer/shader/cast_fp16_to_fp32.comp:
--------------------------------------------------------------------------------
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 | #version 450
16 |
17 | #extension GL_AMD_gpu_shader_half_float: require
18 |
19 | layout (local_size_x_id = 233) in;
20 | layout (local_size_y_id = 234) in;
21 | layout (local_size_z_id = 235) in;
22 |
23 | layout (binding = 0) readonly buffer bottom_blob { float16_t bottom_blob_data[]; };
24 | layout (binding = 1) writeonly buffer top_blob { float top_blob_data[]; };
25 |
26 | layout (push_constant) uniform parameter
27 | {
28 | int dims;
29 | int w;
30 | int h;
31 | int c;
32 | int cstep;
33 |
34 | int outdims;
35 | int outw;
36 | int outh;
37 | int outc;
38 | int outcstep;
39 | } p;
40 |
41 | void main()
42 | {
43 | int gx = int(gl_GlobalInvocationID.x);
44 | int gy = int(gl_GlobalInvocationID.y);
45 | int gz = int(gl_GlobalInvocationID.z);
46 |
47 | if (gx >= p.w || gy >= p.h || gz >= p.c)
48 | return;
49 |
50 | float16_t v = bottom_blob_data[gz * p.cstep + gy * p.w + gx];
51 |
52 | top_blob_data[gz * p.outcstep + gy * p.outw + gx] = float(v);
53 | }
54 |
--------------------------------------------------------------------------------
/src/layer/shader/cast_fp16_to_fp32_pack4.comp:
--------------------------------------------------------------------------------
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 | #version 450
16 |
17 | #extension GL_AMD_gpu_shader_half_float: require
18 |
19 | layout (local_size_x_id = 233) in;
20 | layout (local_size_y_id = 234) in;
21 | layout (local_size_z_id = 235) in;
22 |
23 | layout (binding = 0) readonly buffer bottom_blob { f16vec4 bottom_blob_data[]; };
24 | layout (binding = 1) writeonly buffer top_blob { vec4 top_blob_data[]; };
25 |
26 | layout (push_constant) uniform parameter
27 | {
28 | int dims;
29 | int w;
30 | int h;
31 | int c;
32 | int cstep;
33 |
34 | int outdims;
35 | int outw;
36 | int outh;
37 | int outc;
38 | int outcstep;
39 | } p;
40 |
41 | void main()
42 | {
43 | int gx = int(gl_GlobalInvocationID.x);
44 | int gy = int(gl_GlobalInvocationID.y);
45 | int gz = int(gl_GlobalInvocationID.z);
46 |
47 | if (gx >= p.w || gy >= p.h || gz >= p.c)
48 | return;
49 |
50 | f16vec4 v = bottom_blob_data[gz * p.cstep + gy * p.w + gx];
51 |
52 | top_blob_data[gz * p.outcstep + gy * p.outw + gx] = vec4(v);
53 | }
54 |
--------------------------------------------------------------------------------
/src/layer/shader/cast_fp32_to_fp16.comp:
--------------------------------------------------------------------------------
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 | #version 450
16 |
17 | #extension GL_AMD_gpu_shader_half_float: require
18 |
19 | layout (local_size_x_id = 233) in;
20 | layout (local_size_y_id = 234) in;
21 | layout (local_size_z_id = 235) in;
22 |
23 | layout (binding = 0) readonly buffer bottom_blob { float bottom_blob_data[]; };
24 | layout (binding = 1) writeonly buffer top_blob { float16_t top_blob_data[]; };
25 |
26 | layout (push_constant) uniform parameter
27 | {
28 | int dims;
29 | int w;
30 | int h;
31 | int c;
32 | int cstep;
33 |
34 | int outdims;
35 | int outw;
36 | int outh;
37 | int outc;
38 | int outcstep;
39 | } p;
40 |
41 | void main()
42 | {
43 | int gx = int(gl_GlobalInvocationID.x);
44 | int gy = int(gl_GlobalInvocationID.y);
45 | int gz = int(gl_GlobalInvocationID.z);
46 |
47 | if (gx >= p.w || gy >= p.h || gz >= p.c)
48 | return;
49 |
50 | float v = bottom_blob_data[gz * p.cstep + gy * p.w + gx];
51 |
52 | top_blob_data[gz * p.outcstep + gy * p.outw + gx] = float16_t(v);
53 | }
54 |
--------------------------------------------------------------------------------
/src/layer/shader/cast_fp32_to_fp16_pack4.comp:
--------------------------------------------------------------------------------
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 | #version 450
16 |
17 | #extension GL_AMD_gpu_shader_half_float: require
18 |
19 | layout (local_size_x_id = 233) in;
20 | layout (local_size_y_id = 234) in;
21 | layout (local_size_z_id = 235) in;
22 |
23 | layout (binding = 0) readonly buffer bottom_blob { vec4 bottom_blob_data[]; };
24 | layout (binding = 1) writeonly buffer top_blob { f16vec4 top_blob_data[]; };
25 |
26 | layout (push_constant) uniform parameter
27 | {
28 | int dims;
29 | int w;
30 | int h;
31 | int c;
32 | int cstep;
33 |
34 | int outdims;
35 | int outw;
36 | int outh;
37 | int outc;
38 | int outcstep;
39 | } p;
40 |
41 | void main()
42 | {
43 | int gx = int(gl_GlobalInvocationID.x);
44 | int gy = int(gl_GlobalInvocationID.y);
45 | int gz = int(gl_GlobalInvocationID.z);
46 |
47 | if (gx >= p.w || gy >= p.h || gz >= p.c)
48 | return;
49 |
50 | vec4 v = bottom_blob_data[gz * p.cstep + gy * p.w + gx];
51 |
52 | top_blob_data[gz * p.outcstep + gy * p.outw + gx] = f16vec4(v);
53 | }
54 |
--------------------------------------------------------------------------------
/src/layer/shader/clip.comp:
--------------------------------------------------------------------------------
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 | #version 450
16 |
17 | #if NCNN_fp16_storage
18 | #extension GL_EXT_shader_16bit_storage: require
19 | #endif
20 | #if NCNN_fp16_arithmetic
21 | #extension GL_AMD_gpu_shader_half_float: require
22 | #endif
23 |
24 | layout (constant_id = 0) const float const_min = 0;
25 | layout (constant_id = 1) const float const_max = 0;
26 |
27 | layout (local_size_x_id = 233) in;
28 | layout (local_size_y_id = 234) in;
29 | layout (local_size_z_id = 235) in;
30 |
31 | layout (binding = 0) buffer bottom_top_blob { sfp bottom_top_blob_data[]; };
32 |
33 | layout (push_constant) uniform parameter
34 | {
35 | int dims;
36 | int w;
37 | int h;
38 | int c;
39 | int cstep;
40 | } p;
41 |
42 | void main()
43 | {
44 | int gx = int(gl_GlobalInvocationID.x);
45 | int gy = int(gl_GlobalInvocationID.y);
46 | int gz = int(gl_GlobalInvocationID.z);
47 |
48 | if (gx >= p.w || gy >= p.h || gz >= p.c)
49 | return;
50 |
51 | const int gi = gz * p.cstep + gy * p.w + gx;
52 |
53 | afp v = afp(bottom_top_blob_data[gi]);
54 |
55 | bottom_top_blob_data[gi] = sfp(clamp(v, afp(const_min), afp(const_max)));
56 | }
57 |
--------------------------------------------------------------------------------
/src/layer/shader/clip_pack4.comp:
--------------------------------------------------------------------------------
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 | #version 450
16 |
17 | #if NCNN_fp16_storage
18 | #extension GL_EXT_shader_16bit_storage: require
19 | #endif
20 | #if NCNN_fp16_arithmetic
21 | #extension GL_AMD_gpu_shader_half_float: require
22 | #endif
23 |
24 | layout (constant_id = 0) const float const_min = 0;
25 | layout (constant_id = 1) const float const_max = 0;
26 |
27 | layout (local_size_x_id = 233) in;
28 | layout (local_size_y_id = 234) in;
29 | layout (local_size_z_id = 235) in;
30 |
31 | layout (binding = 0) buffer bottom_top_blob { sfpvec4 bottom_top_blob_data[]; };
32 |
33 | layout (push_constant) uniform parameter
34 | {
35 | int dims;
36 | int w;
37 | int h;
38 | int c;
39 | int cstep;
40 | } p;
41 |
42 | void main()
43 | {
44 | int gx = int(gl_GlobalInvocationID.x);
45 | int gy = int(gl_GlobalInvocationID.y);
46 | int gz = int(gl_GlobalInvocationID.z);
47 |
48 | if (gx >= p.w || gy >= p.h || gz >= p.c)
49 | return;
50 |
51 | const int gi = gz * p.cstep + gy * p.w + gx;
52 |
53 | afpvec4 v = afpvec4(bottom_top_blob_data[gi]);
54 |
55 | bottom_top_blob_data[gi] = sfpvec4(clamp(v, afp(const_min), afp(const_max)));
56 | }
57 |
--------------------------------------------------------------------------------
/src/layer/shader/dropout.comp:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2018 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 | #version 450
16 |
17 | #if NCNN_fp16_storage
18 | #extension GL_EXT_shader_16bit_storage: require
19 | #endif
20 | #if NCNN_fp16_arithmetic
21 | #extension GL_AMD_gpu_shader_half_float: require
22 | #endif
23 |
24 | layout (constant_id = 0) const float scale = 1;
25 |
26 | layout (local_size_x_id = 233) in;
27 | layout (local_size_y_id = 234) in;
28 | layout (local_size_z_id = 235) in;
29 |
30 | layout (binding = 0) buffer bottom_top_blob { sfp bottom_top_blob_data[]; };
31 |
32 | layout (push_constant) uniform parameter
33 | {
34 | int dims;
35 | int w;
36 | int h;
37 | int c;
38 | int cstep;
39 | } p;
40 |
41 | void main()
42 | {
43 | int gx = int(gl_GlobalInvocationID.x);
44 | int gy = int(gl_GlobalInvocationID.y);
45 | int gz = int(gl_GlobalInvocationID.z);
46 |
47 | if (gx >= p.w || gy >= p.h || gz >= p.c)
48 | return;
49 |
50 | const int gi = gz * p.cstep + gy * p.w + gx;
51 |
52 | afp v = afp(bottom_top_blob_data[gi]);
53 |
54 | v *= afp(scale);
55 |
56 | bottom_top_blob_data[gi] = sfp(v);
57 | }
58 |
--------------------------------------------------------------------------------
/src/layer/shader/dropout_pack4.comp:
--------------------------------------------------------------------------------
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 | #version 450
16 |
17 | #if NCNN_fp16_storage
18 | #extension GL_EXT_shader_16bit_storage: require
19 | #endif
20 | #if NCNN_fp16_arithmetic
21 | #extension GL_AMD_gpu_shader_half_float: require
22 | #endif
23 |
24 | layout (constant_id = 0) const float scale = 1;
25 |
26 | layout (local_size_x_id = 233) in;
27 | layout (local_size_y_id = 234) in;
28 | layout (local_size_z_id = 235) in;
29 |
30 | layout (binding = 0) buffer bottom_top_blob { sfpvec4 bottom_top_blob_data[]; };
31 |
32 | layout (push_constant) uniform parameter
33 | {
34 | int dims;
35 | int w;
36 | int h;
37 | int c;
38 | int cstep;
39 | } p;
40 |
41 | void main()
42 | {
43 | int gx = int(gl_GlobalInvocationID.x);
44 | int gy = int(gl_GlobalInvocationID.y);
45 | int gz = int(gl_GlobalInvocationID.z);
46 |
47 | if (gx >= p.w || gy >= p.h || gz >= p.c)
48 | return;
49 |
50 | const int gi = gz * p.cstep + gy * p.w + gx;
51 |
52 | afpvec4 v = afpvec4(bottom_top_blob_data[gi]);
53 |
54 | v *= afp(scale);
55 |
56 | bottom_top_blob_data[gi] = sfpvec4(v);
57 | }
58 |
--------------------------------------------------------------------------------
/src/layer/shader/flatten.comp:
--------------------------------------------------------------------------------
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 | #version 450
16 |
17 | #if NCNN_fp16_storage
18 | #extension GL_EXT_shader_16bit_storage: require
19 | #endif
20 | #if NCNN_fp16_arithmetic
21 | #extension GL_AMD_gpu_shader_half_float: require
22 | #endif
23 |
24 | layout (local_size_x_id = 233) in;
25 | layout (local_size_y_id = 234) in;
26 | layout (local_size_z_id = 235) in;
27 |
28 | layout (binding = 0) readonly buffer bottom_blob { sfp bottom_blob_data[]; };
29 | layout (binding = 1) writeonly buffer top_blob { sfp top_blob_data[]; };
30 |
31 | layout (push_constant) uniform parameter
32 | {
33 | int dims;
34 | int w;
35 | int h;
36 | int c;
37 | int cstep;
38 |
39 | int outdims;
40 | int outw;
41 | int outh;
42 | int outc;
43 | int outcstep;
44 | } p;
45 |
46 | void main()
47 | {
48 | int gx = int(gl_GlobalInvocationID.x);
49 | int gy = int(gl_GlobalInvocationID.y);
50 | int gz = int(gl_GlobalInvocationID.z);
51 |
52 | if (gx >= p.outw || gy >= 1 || gz >= 1)
53 | return;
54 |
55 | int size = p.w * p.h;
56 |
57 | int z = gx / size;
58 | int y = gx % size / p.w;
59 | int x = gx % size % p.w;
60 |
61 | int v_offset = z * p.cstep + y * p.w + x;
62 |
63 | top_blob_data[gx] = bottom_blob_data[v_offset];
64 | }
65 |
--------------------------------------------------------------------------------
/src/layer/shader/relu.comp:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2018 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 | #version 450
16 |
17 | #if NCNN_fp16_storage
18 | #extension GL_EXT_shader_16bit_storage: require
19 | #endif
20 | #if NCNN_fp16_arithmetic
21 | #extension GL_AMD_gpu_shader_half_float: require
22 | #endif
23 |
24 | layout (constant_id = 0) const float slope = 0;
25 |
26 | layout (local_size_x_id = 233) in;
27 | layout (local_size_y_id = 234) in;
28 | layout (local_size_z_id = 235) in;
29 |
30 | layout (binding = 0) buffer bottom_top_blob { sfp bottom_top_blob_data[]; };
31 |
32 | layout (push_constant) uniform parameter
33 | {
34 | int dims;
35 | int w;
36 | int h;
37 | int c;
38 | int cstep;
39 | } p;
40 |
41 | void main()
42 | {
43 | int gx = int(gl_GlobalInvocationID.x);
44 | int gy = int(gl_GlobalInvocationID.y);
45 | int gz = int(gl_GlobalInvocationID.z);
46 |
47 | if (gx >= p.w || gy >= p.h || gz >= p.c)
48 | return;
49 |
50 | const int gi = gz * p.cstep + gy * p.w + gx;
51 |
52 | afp v = afp(bottom_top_blob_data[gi]);
53 |
54 | if (slope == 0)
55 | v = max(v, afp(0.f));
56 | else
57 | v = v < afp(0.f) ? v * afp(slope) : v;
58 |
59 | bottom_top_blob_data[gi] = sfp(v);
60 | }
61 |
--------------------------------------------------------------------------------
/src/layer/shader/relu_pack4.comp:
--------------------------------------------------------------------------------
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 | #version 450
16 |
17 | #if NCNN_fp16_storage
18 | #extension GL_EXT_shader_16bit_storage: require
19 | #endif
20 | #if NCNN_fp16_arithmetic
21 | #extension GL_AMD_gpu_shader_half_float: require
22 | #endif
23 |
24 | layout (constant_id = 0) const float slope = 0;
25 |
26 | layout (local_size_x_id = 233) in;
27 | layout (local_size_y_id = 234) in;
28 | layout (local_size_z_id = 235) in;
29 |
30 | layout (binding = 0) buffer bottom_top_blob { sfpvec4 bottom_top_blob_data[]; };
31 |
32 | layout (push_constant) uniform parameter
33 | {
34 | int dims;
35 | int w;
36 | int h;
37 | int c;
38 | int cstep;
39 | } p;
40 |
41 | void main()
42 | {
43 | int gx = int(gl_GlobalInvocationID.x);
44 | int gy = int(gl_GlobalInvocationID.y);
45 | int gz = int(gl_GlobalInvocationID.z);
46 |
47 | if (gx >= p.w || gy >= p.h || gz >= p.c)
48 | return;
49 |
50 | const int gi = gz * p.cstep + gy * p.w + gx;
51 |
52 | afpvec4 v = afpvec4(bottom_top_blob_data[gi]);
53 |
54 | if (slope == 0)
55 | v = max(v, afp(0.f));
56 | else
57 | v = mix(v, v * afp(slope), lessThan(v, afpvec4(0.f)));
58 |
59 | bottom_top_blob_data[gi] = sfpvec4(v);
60 | }
61 |
--------------------------------------------------------------------------------
/src/layer/shader/sigmoid.comp:
--------------------------------------------------------------------------------
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 | #version 450
16 |
17 | #if NCNN_fp16_storage
18 | #extension GL_EXT_shader_16bit_storage: require
19 | #endif
20 | #if NCNN_fp16_arithmetic
21 | #extension GL_AMD_gpu_shader_half_float: require
22 | #endif
23 |
24 | layout (local_size_x_id = 233) in;
25 | layout (local_size_y_id = 234) in;
26 | layout (local_size_z_id = 235) in;
27 |
28 | layout (binding = 0) buffer bottom_top_blob { sfp bottom_top_blob_data[]; };
29 |
30 | layout (push_constant) uniform parameter
31 | {
32 | int dims;
33 | int w;
34 | int h;
35 | int c;
36 | int cstep;
37 | } p;
38 |
39 | void main()
40 | {
41 | int gx = int(gl_GlobalInvocationID.x);
42 | int gy = int(gl_GlobalInvocationID.y);
43 | int gz = int(gl_GlobalInvocationID.z);
44 |
45 | if (gx >= p.w || gy >= p.h || gz >= p.c)
46 | return;
47 |
48 | const int gi = gz * p.cstep + gy * p.w + gx;
49 |
50 | afp v = afp(bottom_top_blob_data[gi]);
51 |
52 | v = afp(1.f) / (afp(1.f) + exp(-v));
53 |
54 | bottom_top_blob_data[gi] = sfp(v);
55 | }
56 |
--------------------------------------------------------------------------------
/src/layer/shader/sigmoid_pack4.comp:
--------------------------------------------------------------------------------
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 | #version 450
16 |
17 | #if NCNN_fp16_storage
18 | #extension GL_EXT_shader_16bit_storage: require
19 | #endif
20 | #if NCNN_fp16_arithmetic
21 | #extension GL_AMD_gpu_shader_half_float: require
22 | #endif
23 |
24 | layout (local_size_x_id = 233) in;
25 | layout (local_size_y_id = 234) in;
26 | layout (local_size_z_id = 235) in;
27 |
28 | layout (binding = 0) buffer bottom_top_blob { sfpvec4 bottom_top_blob_data[]; };
29 |
30 | layout (push_constant) uniform parameter
31 | {
32 | int dims;
33 | int w;
34 | int h;
35 | int c;
36 | int cstep;
37 | } p;
38 |
39 | void main()
40 | {
41 | int gx = int(gl_GlobalInvocationID.x);
42 | int gy = int(gl_GlobalInvocationID.y);
43 | int gz = int(gl_GlobalInvocationID.z);
44 |
45 | if (gx >= p.w || gy >= p.h || gz >= p.c)
46 | return;
47 |
48 | const int gi = gz * p.cstep + gy * p.w + gx;
49 |
50 | afpvec4 v = afpvec4(bottom_top_blob_data[gi]);
51 |
52 | v = afp(1.f) / (afp(1.f) + exp(-v));
53 |
54 | bottom_top_blob_data[gi] = sfpvec4(v);
55 | }
56 |
--------------------------------------------------------------------------------
/src/layer/shader/tanh.comp:
--------------------------------------------------------------------------------
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 | #version 450
16 |
17 | #if NCNN_fp16_storage
18 | #extension GL_EXT_shader_16bit_storage: require
19 | #endif
20 | #if NCNN_fp16_arithmetic
21 | #extension GL_AMD_gpu_shader_half_float: require
22 | #endif
23 |
24 | layout (local_size_x_id = 233) in;
25 | layout (local_size_y_id = 234) in;
26 | layout (local_size_z_id = 235) in;
27 |
28 | layout (binding = 0) buffer bottom_top_blob { sfp bottom_top_blob_data[]; };
29 |
30 | layout (push_constant) uniform parameter
31 | {
32 | int dims;
33 | int w;
34 | int h;
35 | int c;
36 | int cstep;
37 | } p;
38 |
39 | void main()
40 | {
41 | int gx = int(gl_GlobalInvocationID.x);
42 | int gy = int(gl_GlobalInvocationID.y);
43 | int gz = int(gl_GlobalInvocationID.z);
44 |
45 | if (gx >= p.w || gy >= p.h || gz >= p.c)
46 | return;
47 |
48 | const int gi = gz * p.cstep + gy * p.w + gx;
49 |
50 | afp v = afp(bottom_top_blob_data[gi]);
51 |
52 | bottom_top_blob_data[gi] = sfp(tanh(v));
53 | }
54 |
--------------------------------------------------------------------------------
/src/layer/shader/tanh_pack4.comp:
--------------------------------------------------------------------------------
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 | #version 450
16 |
17 | #if NCNN_fp16_storage
18 | #extension GL_EXT_shader_16bit_storage: require
19 | #endif
20 | #if NCNN_fp16_arithmetic
21 | #extension GL_AMD_gpu_shader_half_float: require
22 | #endif
23 |
24 | layout (local_size_x_id = 233) in;
25 | layout (local_size_y_id = 234) in;
26 | layout (local_size_z_id = 235) in;
27 |
28 | layout (binding = 0) buffer bottom_top_blob { sfpvec4 bottom_top_blob_data[]; };
29 |
30 | layout (push_constant) uniform parameter
31 | {
32 | int dims;
33 | int w;
34 | int h;
35 | int c;
36 | int cstep;
37 | } p;
38 |
39 | void main()
40 | {
41 | int gx = int(gl_GlobalInvocationID.x);
42 | int gy = int(gl_GlobalInvocationID.y);
43 | int gz = int(gl_GlobalInvocationID.z);
44 |
45 | if (gx >= p.w || gy >= p.h || gz >= p.c)
46 | return;
47 |
48 | const int gi = gz * p.cstep + gy * p.w + gx;
49 |
50 | afpvec4 v = afpvec4(bottom_top_blob_data[gi]);
51 |
52 | bottom_top_blob_data[gi] = sfpvec4(tanh(v));
53 | }
54 |
--------------------------------------------------------------------------------
/src/layer/shufflechannel.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_SHUFFLECHANNEL_H
16 | #define LAYER_SHUFFLECHANNEL_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class ShuffleChannel : public Layer
23 | {
24 | public:
25 | ShuffleChannel();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
30 |
31 | #if NCNN_VULKAN
32 | virtual int create_pipeline();
33 | virtual int destroy_pipeline();
34 |
35 | virtual int forward(const VkMat& bottom_blob, VkMat& top_blob, VkCompute& cmd, const Option& opt) const;
36 | #endif // NCNN_VULKAN
37 |
38 | public:
39 | int group;
40 |
41 | #if NCNN_VULKAN
42 | Pipeline* pipeline_shufflechannel;
43 | Pipeline* pipeline_shufflechannel_pack4;
44 | #endif // NCNN_VULKAN
45 | };
46 |
47 | } // namespace ncnn
48 |
49 | #endif // LAYER_SHUFFLECHANNEL_H
50 |
--------------------------------------------------------------------------------
/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 | #if NCNN_VULKAN
30 | virtual int create_pipeline();
31 | virtual int destroy_pipeline();
32 |
33 | virtual int forward_inplace(VkMat& bottom_top_blob, VkCompute& cmd, const Option& opt) const;
34 | #endif // NCNN_VULKAN
35 |
36 | public:
37 |
38 | #if NCNN_VULKAN
39 | Pipeline* pipeline_sigmoid;
40 | Pipeline* pipeline_sigmoid_pack4;
41 | #endif // NCNN_VULKAN
42 | };
43 |
44 | } // namespace ncnn
45 |
46 | #endif // LAYER_SIGMOID_H
47 |
--------------------------------------------------------------------------------
/src/layer/slice.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_SLICE_H
16 | #define LAYER_SLICE_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Slice : public Layer
23 | {
24 | public:
25 | Slice();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs, const Option& opt) const;
30 |
31 | public:
32 | Mat slices;
33 | int axis;
34 | };
35 |
36 | } // namespace ncnn
37 |
38 | #endif // LAYER_SLICE_H
39 |
--------------------------------------------------------------------------------
/src/layer/softmax.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_SOFTMAX_H
16 | #define LAYER_SOFTMAX_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Softmax : public Layer
23 | {
24 | public:
25 | Softmax();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const;
30 |
31 | #if NCNN_VULKAN
32 | virtual int create_pipeline();
33 | virtual int destroy_pipeline();
34 |
35 | virtual int forward_inplace(VkMat& bottom_top_blob, VkCompute& cmd, const Option& opt) const;
36 | #endif // NCNN_VULKAN
37 |
38 | public:
39 | int axis;
40 |
41 | #if NCNN_VULKAN
42 | Pipeline* pipeline_softmax_reduce_max;
43 | Pipeline* pipeline_softmax_exp_sub_max;
44 | Pipeline* pipeline_softmax_reduce_sum;
45 | Pipeline* pipeline_softmax_div_sum;
46 |
47 | Pipeline* pipeline_softmax_reduce_max_pack4;
48 | Pipeline* pipeline_softmax_exp_sub_max_pack4;
49 | Pipeline* pipeline_softmax_reduce_sum_pack4;
50 | Pipeline* pipeline_softmax_div_sum_pack4;
51 | #endif // NCNN_VULKAN
52 | };
53 |
54 | } // namespace ncnn
55 |
56 | #endif // LAYER_SOFTMAX_H
57 |
--------------------------------------------------------------------------------
/src/layer/split.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 "split.h"
16 |
17 | namespace ncnn {
18 |
19 | DEFINE_LAYER_CREATOR(Split)
20 |
21 | Split::Split()
22 | {
23 | one_blob_only = false;
24 | support_inplace = false;
25 | support_vulkan = true;
26 | }
27 |
28 | int Split::forward(const std::vector& bottom_blobs, std::vector& top_blobs, const Option& /*opt*/) const
29 | {
30 | const Mat& bottom_blob = bottom_blobs[0];
31 | for (size_t i=0; i& bottom_blobs, std::vector& top_blobs, VkCompute& /*cmd*/, const Option& /*opt*/) const
41 | {
42 | // fprintf(stderr, "Split::forward %p\n", bottom_blobs[0].buffer());
43 |
44 | const VkMat& bottom_blob = bottom_blobs[0];
45 | for (size_t i=0; i& bottom_blobs, std::vector& top_blobs, const Option& opt) const;
28 |
29 | #if NCNN_VULKAN
30 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs, VkCompute& cmd, const Option& opt) const;
31 | #endif // NCNN_VULKAN
32 |
33 | public:
34 | };
35 |
36 | } // namespace ncnn
37 |
38 | #endif // LAYER_SPLIT_H
39 |
--------------------------------------------------------------------------------
/src/layer/spp.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_SPP_H
16 | #define LAYER_SPP_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class SPP : public Layer
23 | {
24 | public:
25 | SPP();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
30 |
31 | enum { PoolMethod_MAX = 0, PoolMethod_AVE = 1 };
32 |
33 | public:
34 | // param
35 | int pooling_type;
36 | int pyramid_height;
37 | };
38 |
39 | } // namespace ncnn
40 |
41 | #endif // LAYER_SPP_H
42 |
--------------------------------------------------------------------------------
/src/layer/squeeze.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_SQUEEZE_H
16 | #define LAYER_SQUEEZE_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Squeeze : public Layer
23 | {
24 | public:
25 | Squeeze();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
30 |
31 | public:
32 | int squeeze_w;
33 | int squeeze_h;
34 | int squeeze_c;
35 | };
36 |
37 | } // namespace ncnn
38 |
39 | #endif // LAYER_SQUEEZE_H
40 |
--------------------------------------------------------------------------------
/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 | #if NCNN_VULKAN
30 | virtual int create_pipeline();
31 | virtual int destroy_pipeline();
32 |
33 | virtual int forward_inplace(VkMat& bottom_top_blob, VkCompute& cmd, const Option& opt) const;
34 | #endif // NCNN_VULKAN
35 |
36 | public:
37 |
38 | #if NCNN_VULKAN
39 | Pipeline* pipeline_tanh;
40 | Pipeline* pipeline_tanh_pack4;
41 | #endif // NCNN_VULKAN
42 | };
43 |
44 | } // namespace ncnn
45 |
46 | #endif // LAYER_TANH_H
47 |
--------------------------------------------------------------------------------
/src/layer/threshold.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 "threshold.h"
16 |
17 | namespace ncnn {
18 |
19 | DEFINE_LAYER_CREATOR(Threshold)
20 |
21 | Threshold::Threshold()
22 | {
23 | one_blob_only = true;
24 | support_inplace = true;
25 | }
26 |
27 | int Threshold::load_param(const ParamDict& pd)
28 | {
29 | threshold = pd.get(0, 0.f);
30 |
31 | return 0;
32 | }
33 |
34 | int Threshold::forward_inplace(Mat& bottom_top_blob, const Option& opt) const
35 | {
36 | int w = bottom_top_blob.w;
37 | int h = bottom_top_blob.h;
38 | int channels = bottom_top_blob.c;
39 | int size = w * h;
40 |
41 | #pragma omp parallel for num_threads(opt.num_threads)
42 | for (int q=0; q threshold ? 1.f : 0.f;
49 | }
50 | }
51 |
52 | return 0;
53 | }
54 |
55 | } // namespace ncnn
56 |
--------------------------------------------------------------------------------
/src/layer/threshold.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_THRESHOLD_H
16 | #define LAYER_THRESHOLD_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Threshold : public Layer
23 | {
24 | public:
25 | Threshold();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward_inplace(Mat& bottom_top_blob, const Option& opt) const;
30 |
31 | public:
32 | float threshold;
33 | };
34 |
35 | } // namespace ncnn
36 |
37 | #endif // LAYER_THRESHOLD_H
38 |
--------------------------------------------------------------------------------
/src/layer/tile.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_TILE_H
16 | #define LAYER_TILE_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Tile : public Layer
23 | {
24 | public:
25 | Tile();
26 |
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
30 |
31 | public:
32 | int dim;
33 | int tiles;
34 | };
35 |
36 | } // namespace ncnn
37 |
38 | #endif // LAYER_TILE_H
39 |
--------------------------------------------------------------------------------
/src/layer/x86/convolution_5x5_int8.h:
--------------------------------------------------------------------------------
1 | // BUG1989 is pleased to support the open source community by supporting ncnn available.
2 | //
3 | // Copyright (C) 2019 BUG1989. 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 | static void conv5x5s1_int8_e2e_sse(const Mat &bottom_blob, Mat &top_blob, const Mat &_kernel, const Option& opt)
16 | {
17 | int kernel_w = 5;
18 | int kernel_h = 5;
19 |
20 | int stride_w = 1;
21 | int stride_h = 1;
22 |
23 | conv_im2col_sgemm_int8_e2e_sse(bottom_blob, top_blob, _kernel, kernel_w, kernel_h, stride_w, stride_h, opt);
24 | }
25 |
26 | static void conv5x5s2_int8_e2e_sse(const Mat &bottom_blob, Mat &top_blob, const Mat &_kernel, const Option& opt)
27 | {
28 | int kernel_w = 5;
29 | int kernel_h = 5;
30 |
31 | int stride_w = 2;
32 | int stride_h = 2;
33 |
34 | conv_im2col_sgemm_int8_e2e_sse(bottom_blob, top_blob, _kernel, kernel_w, kernel_h, stride_w, stride_h, opt);
35 | }
36 |
--------------------------------------------------------------------------------
/src/layer/x86/convolution_7x7_int8.h:
--------------------------------------------------------------------------------
1 | // BUG1989 is pleased to support the open source community by supporting ncnn available.
2 | //
3 | // Copyright (C) 2019 BUG1989. 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 | static void conv7x7s1_int8_e2e_sse(const Mat &bottom_blob, Mat &top_blob, const Mat &_kernel, const Option& opt)
16 | {
17 | int kernel_w = 7;
18 | int kernel_h = 7;
19 |
20 | int stride_w = 1;
21 | int stride_h = 1;
22 |
23 | conv_im2col_sgemm_int8_e2e_sse(bottom_blob, top_blob, _kernel, kernel_w, kernel_h, stride_w, stride_h, opt);
24 | }
25 |
26 | static void conv7x7s2_int8_e2e_sse(const Mat &bottom_blob, Mat &top_blob, const Mat &_kernel, const Option& opt)
27 | {
28 | int kernel_w = 7;
29 | int kernel_h = 7;
30 |
31 | int stride_w = 2;
32 | int stride_h = 2;
33 |
34 | conv_im2col_sgemm_int8_e2e_sse(bottom_blob, top_blob, _kernel, kernel_w, kernel_h, stride_w, stride_h, opt);
35 | }
36 |
--------------------------------------------------------------------------------
/src/layer/x86/convolution_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_CONVOLUTION_X86_H
16 | #define LAYER_CONVOLUTION_X86_H
17 |
18 | #include "convolution.h"
19 |
20 | namespace ncnn {
21 |
22 | typedef void (*conv_func)(const Mat&, Mat&, const Mat&, const Mat&, const Option&);
23 |
24 | class Convolution_x86 : public Convolution
25 | {
26 | public:
27 | virtual int load_param(const ParamDict& pd);
28 |
29 | virtual int load_model(const ModelBin& mb);
30 |
31 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
32 | virtual int forwardDilation(const Mat& bottom_blob, Mat &top_blob, conv_func conv, const Option& opt) const;
33 |
34 | public:
35 | bool use_winograd3x3;
36 | Mat weight_3x3_winograd23_data;
37 | };
38 |
39 | } // namespace ncnn
40 |
41 | #endif // LAYER_CONVOLUTION_X86_H
42 |
--------------------------------------------------------------------------------
/src/layer/x86/convolutiondepthwise_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_CONVOLUTIONDEPTHWISE_X86_H
16 | #define LAYER_CONVOLUTIONDEPTHWISE_X86_H
17 |
18 | #include "convolutiondepthwise.h"
19 |
20 | namespace ncnn {
21 |
22 | class ConvolutionDepthWise_x86 : public ConvolutionDepthWise
23 | {
24 | public:
25 | ConvolutionDepthWise_x86();
26 | virtual ~ConvolutionDepthWise_x86();
27 |
28 | virtual int load_model(const ModelBin& mb);
29 |
30 | virtual int forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) const;
31 |
32 | public:
33 | std::vector group_ops;
34 | };
35 |
36 | } // namespace ncnn
37 |
38 | #endif // LAYER_CONVOLUTIONDEPTHWISE_X86_H
39 |
--------------------------------------------------------------------------------
/src/layer/yolodetectionoutput.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2018 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_YOLODETECTIONOUTPUT_H
16 | #define LAYER_YOLODETECTIONOUTPUT_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class YoloDetectionOutput : public Layer
23 | {
24 | public:
25 | YoloDetectionOutput();
26 | ~YoloDetectionOutput();
27 |
28 | virtual int load_param(const ParamDict& pd);
29 |
30 | virtual int forward_inplace(std::vector& bottom_top_blobs, const Option& opt) const;
31 |
32 | public:
33 | int num_class;
34 | int num_box;
35 | float confidence_threshold;
36 | float nms_threshold;
37 | Mat biases;
38 |
39 | ncnn::Layer* softmax;
40 | };
41 |
42 | } // namespace ncnn
43 |
44 | #endif // LAYER_YOLODETECTIONOUTPUT_H
45 |
--------------------------------------------------------------------------------
/src/layer/yolov3detectionoutput.h:
--------------------------------------------------------------------------------
1 | // Tencent is pleased to support the open source community by making ncnn available.
2 | //
3 | // Copyright (C) 2018 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_YOLOV3DETECTIONOUTPUT_H
16 | #define LAYER_YOLOV3DETECTIONOUTPUT_H
17 |
18 | #include "layer.h"
19 |
20 | namespace ncnn {
21 |
22 | class Yolov3DetectionOutput : public Layer
23 | {
24 | public:
25 | Yolov3DetectionOutput();
26 | ~Yolov3DetectionOutput();
27 |
28 | virtual int load_param(const ParamDict& pd);
29 |
30 | virtual int forward(const std::vector& bottom_blobs, std::vector& top_blobs, const Option& opt) const;
31 |
32 | public:
33 | int num_class;
34 | int num_box;
35 | float confidence_threshold;
36 | float nms_threshold;
37 | Mat biases;
38 | Mat mask;
39 | Mat anchors_scale;
40 | int mask_group_num;
41 | ncnn::Layer* softmax;
42 | };
43 |
44 | } // namespace ncnn
45 |
46 | #endif // LAYER_YOLODETECTIONOUTPUT_H
47 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/src/layer_registry.h.in:
--------------------------------------------------------------------------------
1 | // Layer Registry header
2 | //
3 | // This file is auto-generated by cmake, don't edit it.
4 |
5 | @layer_registry@
6 |
--------------------------------------------------------------------------------
/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 |
7 |
--------------------------------------------------------------------------------
/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 |
7 |
--------------------------------------------------------------------------------
/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
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 |
--------------------------------------------------------------------------------
/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/platform.h.in:
--------------------------------------------------------------------------------
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_PLATFORM_H
16 | #define NCNN_PLATFORM_H
17 |
18 | #cmakedefine01 NCNN_STDIO
19 | #cmakedefine01 NCNN_STRING
20 | #cmakedefine01 NCNN_OPENCV
21 | #cmakedefine01 NCNN_BENCHMARK
22 | #cmakedefine01 NCNN_PIXEL
23 | #cmakedefine01 NCNN_PIXEL_ROTATE
24 | #cmakedefine01 NCNN_VULKAN
25 | #cmakedefine01 NCNN_REQUANT
26 | #cmakedefine01 NCNN_IM2COL_SGEMM
27 |
28 | #endif // NCNN_PLATFORM_H
29 |
--------------------------------------------------------------------------------
/toolchains/aarch64-linux-gnu.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 aarch64 )
4 | # for the reason of aarch64-linux-gnu-gcc DONOT need to be installed, make sure aarch64-linux-gnu-gcc and aarch64-linux-gnu-g++ can be found in $PATH:
5 | SET ( CMAKE_C_COMPILER "aarch64-linux-gnu-gcc" )
6 | SET ( CMAKE_CXX_COMPILER "aarch64-linux-gnu-g++" )
7 |
8 | # set searching rules for cross-compiler
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 for cross-compiled process
14 | SET ( CMAKE_CXX_FLAGS "-std=c++11 -march=armv8-a -fopenmp ${CMAKE_CXX_FLAGS}" )
15 |
16 | # other settings
17 | add_definitions(-D__ARM_NEON)
18 | add_definitions(-D__ANDROID__)
19 | SET ( ANDROID true)
20 |
--------------------------------------------------------------------------------
/toolchains/arm-linux-gnueabi.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 arm )
4 | # when hislicon SDK was installed, toolchain was installed in the path as below:
5 | SET ( CMAKE_C_COMPILER "arm-linux-gnueabi-gcc" )
6 | SET ( CMAKE_CXX_COMPILER "arm-linux-gnueabi-g++" )
7 |
8 | # set searching rules for cross-compiler
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 for cross-compiled process
14 | SET ( CMAKE_CXX_FLAGS "-std=c++11 -march=armv7-a -mfloat-abi=softfp -mfpu=neon-vfpv4 -fopenmp ${CMAKE_CXX_FLAGS}" )
15 |
16 | # other settings
17 | add_definitions(-D__ARM_NEON)
18 | add_definitions(-D__ANDROID__)
19 | SET ( ANDROID true)
20 |
--------------------------------------------------------------------------------
/toolchains/arm-linux-gnueabihf.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 arm )
4 | # when hislicon SDK was installed, toolchain was installed in the path as below:
5 | SET ( CMAKE_C_COMPILER "arm-linux-gnueabihf-gcc" )
6 | SET ( CMAKE_CXX_COMPILER "arm-linux-gnueabihf-g++" )
7 |
8 | # set searching rules for cross-compiler
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 for cross-compiled process
14 | SET ( CMAKE_CXX_FLAGS "-std=c++11 -march=armv7-a -mfloat-abi=hard -mfpu=neon-vfpv4 -fopenmp ${CMAKE_CXX_FLAGS}" )
15 |
16 | # other settings
17 | add_definitions(-D__ARM_NEON)
18 | add_definitions(-D__ANDROID__)
19 | SET ( ANDROID true)
20 |
--------------------------------------------------------------------------------
/toolchains/himix100.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 aarch64 )
4 | # when hislicon SDK was installed, toolchain was installed in the path as below:
5 | SET ( CMAKE_C_COMPILER "/opt/hisi-linux/x86-arm/aarch64-himix100-linux/bin/aarch64-himix100-linux-gcc" )
6 | SET ( CMAKE_CXX_COMPILER "/opt/hisi-linux/x86-arm/aarch64-himix100-linux/bin/aarch64-himix100-linux-g++" )
7 | SET ( CMAKE_FIND_ROOT_PATH "/opt/hisi-linux/x86-arm/aarch64-himix100-linux" )
8 |
9 | # set searching rules for cross-compiler
10 | SET ( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
11 | SET ( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
12 | SET ( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
13 |
14 | # set ${CMAKE_C_FLAGS} and ${CMAKE_CXX_FLAGS}flag for cross-compiled process
15 | SET ( CMAKE_CXX_FLAGS "-std=c++11 -march=armv8-a -fopenmp ${CMAKE_CXX_FLAGS}" )
16 |
17 | # other settings
18 | add_definitions(-D__ARM_NEON)
19 | add_definitions(-D__ANDROID__)
20 | SET ( ANDROID true)
21 |
--------------------------------------------------------------------------------
/toolchains/hisiv300.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 arm )
4 | # when hislicon SDK was installed, toolchain was installed in the path as below:
5 | SET ( CMAKE_C_COMPILER "/opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/bin/arm-hisiv300-linux-gcc" )
6 | SET ( CMAKE_CXX_COMPILER "/opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/bin/arm-hisiv300-linux-g++" )
7 | SET ( CMAKE_FIND_ROOT_PATH "/opt/hisi-linux/x86-arm/arm-hisiv300-linux" )
8 |
9 | # set searching rules for cross-compiler
10 | SET ( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
11 | SET ( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
12 | SET ( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
13 |
14 | # set ${CMAKE_C_FLAGS} and ${CMAKE_CXX_FLAGS}flag for cross-compiled process
15 | SET ( CMAKE_CXX_FLAGS "-std=c++11 -march=armv7-a -mfloat-abi=softfp -mfpu=neon-vfpv4 -fopenmp ${CMAKE_CXX_FLAGS}" )
16 |
17 | # other settings
18 | add_definitions(-D__ARM_NEON)
19 | add_definitions(-D__ANDROID__)
20 | SET ( ANDROID true)
21 |
--------------------------------------------------------------------------------
/toolchains/hisiv500.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 arm )
4 | # when hislicon SDK was installed, toolchain was installed in the path as below:
5 | SET ( CMAKE_C_COMPILER "/opt/hisi-linux/x86-arm/arm-hisiv500-linux/target/bin/arm-hisiv500-linux-gcc" )
6 | SET ( CMAKE_CXX_COMPILER "/opt/hisi-linux/x86-arm/arm-hisiv500-linux/target/bin/arm-hisiv500-linux-g++" )
7 | SET ( CMAKE_FIND_ROOT_PATH "/opt/hisi-linux/x86-arm/arm-hisiv500-linux" )
8 |
9 | # set searching rules for cross-compiler
10 | SET ( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
11 | SET ( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
12 | SET ( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
13 |
14 | # set ${CMAKE_C_FLAGS} and ${CMAKE_CXX_FLAGS}flag for cross-compiled process
15 | SET ( CMAKE_CXX_FLAGS "-std=c++11 -march=armv7-a -mfloat-abi=softfp -mfpu=neon-vfpv4 -fopenmp ${CMAKE_CXX_FLAGS}" )
16 |
17 | # other settings
18 | add_definitions(-D__ARM_NEON)
19 | add_definitions(-D__ANDROID__)
20 | SET ( ANDROID true)
21 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/toolchains/iossimxc-x64.toolchain.cmake:
--------------------------------------------------------------------------------
1 | # Standard settings
2 | # set(UNIX True)
3 | # set(Darwin True)
4 | # set(IOS True)
5 | set (CMAKE_SYSTEM_NAME Darwin)
6 | set (CMAKE_SYSTEM_VERSION 1)
7 | set (UNIX True)
8 | set (APPLE True)
9 | set (IOS True)
10 |
11 | # suppress -rdynamic
12 | # set(CMAKE_SYSTEM_NAME Generic)
13 |
14 | set(CMAKE_C_COMPILER i386-apple-darwin11-clang)
15 | set(CMAKE_CXX_COMPILER i386-apple-darwin11-clang++)
16 |
17 | set(_CMAKE_TOOLCHAIN_PREFIX i386-apple-darwin11-)
18 |
19 | set(CMAKE_IOS_SDK_ROOT "/home/nihui/osd/cctools-port/usage_examples/ios_toolchain/target-sim/SDK/iPhoneSimulator10.2.sdk")
20 |
21 | # Set the sysroot default to the most recent SDK
22 | set(CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS Simulator support")
23 |
24 | # set the architecture for iOS
25 | set(IOS_ARCH x86_64)
26 |
27 | set(CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS Simulator")
28 |
29 | # Set the find root to the iOS developer roots and to user defined paths
30 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string "iOS Simulator find search path root")
31 |
32 | # searching for frameworks only
33 | set(CMAKE_FIND_FRAMEWORK FIRST)
34 |
35 | # set up the default search directories for frameworks
36 | set(CMAKE_SYSTEM_FRAMEWORK_PATH
37 | ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
38 | )
39 |
--------------------------------------------------------------------------------
/toolchains/iossimxc.toolchain.cmake:
--------------------------------------------------------------------------------
1 | # Standard settings
2 | # set(UNIX True)
3 | # set(Darwin True)
4 | # set(IOS True)
5 | set (CMAKE_SYSTEM_NAME Darwin)
6 | set (CMAKE_SYSTEM_VERSION 1)
7 | set (UNIX True)
8 | set (APPLE True)
9 | set (IOS True)
10 |
11 | # suppress -rdynamic
12 | # set(CMAKE_SYSTEM_NAME Generic)
13 |
14 | set(CMAKE_C_COMPILER i386-apple-darwin11-clang)
15 | set(CMAKE_CXX_COMPILER i386-apple-darwin11-clang++)
16 |
17 | set(_CMAKE_TOOLCHAIN_PREFIX i386-apple-darwin11-)
18 |
19 | set(CMAKE_IOS_SDK_ROOT "/home/nihui/osd/cctools-port/usage_examples/ios_toolchain/target-sim/SDK/iPhoneSimulator10.2.sdk")
20 |
21 | # Set the sysroot default to the most recent SDK
22 | set(CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS Simulator support")
23 |
24 | # set the architecture for iOS
25 | # set(IOS_ARCH i386)
26 | # set(IOS_ARCH x86_64)
27 | set(IOS_ARCH i386;x86_64)
28 |
29 | set(CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS Simulator")
30 |
31 | # Set the find root to the iOS developer roots and to user defined paths
32 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string "iOS Simulator find search path root")
33 |
34 | # searching for frameworks only
35 | set(CMAKE_FIND_FRAMEWORK FIRST)
36 |
37 | # set up the default search directories for frameworks
38 | set(CMAKE_SYSTEM_FRAMEWORK_PATH
39 | ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
40 | )
41 |
--------------------------------------------------------------------------------
/toolchains/iosxc-arm64.toolchain.cmake:
--------------------------------------------------------------------------------
1 | # Standard settings
2 | # set(UNIX True)
3 | # set(Darwin True)
4 | # set(IOS True)
5 | set (CMAKE_SYSTEM_NAME Darwin)
6 | set (CMAKE_SYSTEM_VERSION 1)
7 | set (UNIX True)
8 | set (APPLE True)
9 | set (IOS True)
10 |
11 | # suppress -rdynamic
12 | # set(CMAKE_SYSTEM_NAME Generic)
13 |
14 | set(CMAKE_C_COMPILER arm-apple-darwin11-clang)
15 | set(CMAKE_CXX_COMPILER arm-apple-darwin11-clang++)
16 |
17 | set(_CMAKE_TOOLCHAIN_PREFIX arm-apple-darwin11-)
18 |
19 | set(CMAKE_IOS_SDK_ROOT "/home/nihui/osd/cctools-port/usage_examples/ios_toolchain/target/SDK/iPhoneOS10.2.sdk")
20 |
21 | # Set the sysroot default to the most recent SDK
22 | set(CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
23 |
24 | # set the architecture for iOS
25 | set(IOS_ARCH arm64)
26 |
27 | set(CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS")
28 |
29 | # Set the find root to the iOS developer roots and to user defined paths
30 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string "iOS find search path root")
31 |
32 | # searching for frameworks only
33 | set(CMAKE_FIND_FRAMEWORK FIRST)
34 |
35 | # set up the default search directories for frameworks
36 | set(CMAKE_SYSTEM_FRAMEWORK_PATH
37 | ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
38 | )
39 |
--------------------------------------------------------------------------------
/toolchains/iosxc.toolchain.cmake:
--------------------------------------------------------------------------------
1 | # Standard settings
2 | # set(UNIX True)
3 | # set(Darwin True)
4 | # set(IOS True)
5 | set (CMAKE_SYSTEM_NAME Darwin)
6 | set (CMAKE_SYSTEM_VERSION 1)
7 | set (UNIX True)
8 | set (APPLE True)
9 | set (IOS True)
10 |
11 | # suppress -rdynamic
12 | # set(CMAKE_SYSTEM_NAME Generic)
13 |
14 | set(CMAKE_C_COMPILER arm-apple-darwin11-clang)
15 | set(CMAKE_CXX_COMPILER arm-apple-darwin11-clang++)
16 |
17 | set(_CMAKE_TOOLCHAIN_PREFIX arm-apple-darwin11-)
18 |
19 | set(CMAKE_IOS_SDK_ROOT "/home/nihui/osd/cctools-port/usage_examples/ios_toolchain/target/SDK/iPhoneOS10.2.sdk")
20 |
21 | # Set the sysroot default to the most recent SDK
22 | set(CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
23 |
24 | # set the architecture for iOS
25 | # set(IOS_ARCH arm64)
26 | set(IOS_ARCH armv7;arm64)
27 |
28 | set(CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS")
29 |
30 | # Set the find root to the iOS developer roots and to user defined paths
31 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string "iOS find search path root")
32 |
33 | # searching for frameworks only
34 | set(CMAKE_FIND_FRAMEWORK FIRST)
35 |
36 | # set up the default search directories for frameworks
37 | set(CMAKE_SYSTEM_FRAMEWORK_PATH
38 | ${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
39 | )
40 |
--------------------------------------------------------------------------------
/toolchains/pi3.toolchain.cmake:
--------------------------------------------------------------------------------
1 | SET(CMAKE_SYSTEM_NANE Android)
2 | SET(CMAKE_SYSTEM_PROCESSOR "armv7l")
3 | SET(ANDROID_ARCH_NAME "arm")
4 | SET(UNIX true)
5 | SET(CMAKE_C_COMPILER "gcc")
6 | SET(CMAKE_CXX_COMPILER "g++")
7 |
--------------------------------------------------------------------------------
/tools/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_subdirectory(caffe)
3 | add_subdirectory(mxnet)
4 | add_subdirectory(onnx)
5 |
6 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../src)
7 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/../src)
8 |
9 | include_directories(${CMAKE_SOURCE_DIR}/src)
10 |
11 | add_executable(ncnn2mem ncnn2mem.cpp)
12 |
13 | target_link_libraries(ncnn2mem PRIVATE ncnn)
14 |
15 | if(NCNN_VULKAN)
16 | target_link_libraries(ncnn2mem PRIVATE ${Vulkan_LIBRARY})
17 | endif()
18 |
--------------------------------------------------------------------------------
/tools/caffe/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | find_package(Protobuf)
3 |
4 | if(PROTOBUF_FOUND)
5 | include_directories(${PROTOBUF_INCLUDE_DIR})
6 | include_directories(${CMAKE_CURRENT_BINARY_DIR})
7 | protobuf_generate_cpp(CAFFE_PROTO_SRCS CAFFE_PROTO_HDRS caffe.proto)
8 | add_executable(caffe2ncnn caffe2ncnn.cpp ${CAFFE_PROTO_SRCS} ${CAFFE_PROTO_HDRS})
9 | set_target_properties(caffe2ncnn PROPERTIES CXX_STANDARD 11)
10 | target_link_libraries(caffe2ncnn ${PROTOBUF_LIBRARIES})
11 | else()
12 | message(WARNING "Protobuf not found, caffe model convert tool won't be built")
13 | endif()
14 |
--------------------------------------------------------------------------------
/tools/darknet/readme.txt:
--------------------------------------------------------------------------------
1 | You can find darknet2ncnn tool here
2 |
3 | https://github.com/xiangweizeng/darknet2ncnn
4 |
--------------------------------------------------------------------------------
/tools/mxnet/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_executable(mxnet2ncnn mxnet2ncnn.cpp)
3 |
--------------------------------------------------------------------------------
/tools/onnx/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | find_package(Protobuf)
3 |
4 | if(PROTOBUF_FOUND)
5 | include_directories(${PROTOBUF_INCLUDE_DIR})
6 | include_directories(${CMAKE_CURRENT_BINARY_DIR})
7 | protobuf_generate_cpp(ONNX_PROTO_SRCS ONNX_PROTO_HDRS onnx.proto)
8 | add_executable(onnx2ncnn onnx2ncnn.cpp ${ONNX_PROTO_SRCS} ${ONNX_PROTO_HDRS})
9 | set_target_properties(onnx2ncnn PROPERTIES CXX_STANDARD 11)
10 | target_link_libraries(onnx2ncnn ${PROTOBUF_LIBRARIES})
11 | else()
12 | message(WARNING "Protobuf not found, onnx model convert tool won't be built")
13 | endif()
14 |
--------------------------------------------------------------------------------
/tools/plugin/ImageWatchNCNN.natvis:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | {{FLOAT32, {c} x {w} x {h}}}
13 | {{FLOAT16, {c} x {w} x {h}}}
14 | {{INT8, {c} x {w} x {h}}}
15 |
16 |
17 | FLOAT32
18 |
19 |
20 | FLOAT16
21 |
22 |
23 | INT8
24 |
25 | c
26 | w
27 | h
28 | c
29 | ((float*)(data))
30 | data
31 | data
32 | w
33 | w*2
34 | w*4
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/tools/plugin/README.md:
--------------------------------------------------------------------------------
1 |
2 | ## NCNN Image Watch Plugin for Visual Studio
3 | Image Watch plugin is a good tool for better understanding insight of images. This tiny work offer a ".natvis" file which could add ncnn::Mat class support for Image Watch, and users could debug ncnn::Mat image just like debuging cv::Mat via Image Watch.
4 |
5 | To use this plugin, please move this "ImageWatchNCNN.natvis" file to "C:/user/${your user name}/Documents/Visual Studio ${VS_Version}/Visualizers" folder. If not exist this folder, create it(such as: "C:\Users\nihui\Documents\Visual Studio 2017\Visualizers").
6 |
7 | 
8 |
9 | See [Image Watch Help](https://imagewatch.azurewebsites.net/ImageWatchHelp/ImageWatchHelp.htm) page for more advanced using tips of Image Watch(For example, get single channel from channels, such as getting confidence heatmap from forward result list {confidence, x1, y1, x2, y2}).
--------------------------------------------------------------------------------
/tools/plugin/snapshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deepglint/eq-ncnn/64ba809318b272d549a356182a7b4b945838693d/tools/plugin/snapshot.png
--------------------------------------------------------------------------------
/tools/pytorch/readme.txt:
--------------------------------------------------------------------------------
1 | You can find pytorch2ncnn tool here
2 |
3 | https://github.com/starimeL/PytorchConverter
4 |
--------------------------------------------------------------------------------
/tools/tensorflow/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | find_package(Protobuf REQUIRED)
3 |
4 | if(PROTOBUF_FOUND)
5 | include_directories(${PROTOBUF_INCLUDE_DIR})
6 | include_directories(${CMAKE_CURRENT_BINARY_DIR})
7 | protobuf_generate_cpp(TENSORFLOW_PROTO_SRCS TENSORFLOW_PROTO_HDRS
8 | attr_value.proto
9 | function.proto
10 | graph.proto
11 | node_def.proto
12 | op_def.proto
13 | resource_handle.proto
14 | tensor.proto
15 | tensor_shape.proto
16 | types.proto
17 | versions.proto
18 | )
19 | add_executable(tensorflow2ncnn tensorflow2ncnn.cpp ${TENSORFLOW_PROTO_SRCS} ${TENSORFLOW_PROTO_HDRS})
20 | set_target_properties(tensorflow2ncnn PROPERTIES CXX_STANDARD 11)
21 | target_link_libraries(tensorflow2ncnn ${PROTOBUF_LIBRARIES})
22 | else()
23 | message(WARNING "Protobuf not found, tensorflow model convert tool won't be built")
24 | endif()
25 |
--------------------------------------------------------------------------------
/tools/tensorflow/resource_handle.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | package tensorflow;
4 | option cc_enable_arenas = true;
5 | option java_outer_classname = "ResourceHandle";
6 | option java_multiple_files = true;
7 | option java_package = "org.tensorflow.framework";
8 |
9 | // Protocol buffer representing a handle to a tensorflow resource. Handles are
10 | // not valid across executions, but can be serialized back and forth from within
11 | // a single run.
12 | message ResourceHandleProto {
13 | // Unique name for the device containing the resource.
14 | string device = 1;
15 |
16 | // Container in which this resource is placed.
17 | string container = 2;
18 |
19 | // Unique name of this resource.
20 | string name = 3;
21 |
22 | // Hash code for the type of the resource. Is only valid in the same device
23 | // and in the same execution.
24 | uint64 hash_code = 4;
25 |
26 | // For debug-only, the name of the type pointed to by this handle, if
27 | // available.
28 | string maybe_type_name = 5;
29 | };
30 |
--------------------------------------------------------------------------------
/tools/tensorflow/tensor_shape.proto:
--------------------------------------------------------------------------------
1 | // Protocol buffer representing the shape of tensors.
2 |
3 | syntax = "proto3";
4 | option cc_enable_arenas = true;
5 | option java_outer_classname = "TensorShapeProtos";
6 | option java_multiple_files = true;
7 | option java_package = "org.tensorflow.framework";
8 |
9 | package tensorflow;
10 |
11 | // Dimensions of a tensor.
12 | message TensorShapeProto {
13 | // One dimension of the tensor.
14 | message Dim {
15 | // Size of the tensor in that dimension.
16 | // This value must be >= -1, but values of -1 are reserved for "unknown"
17 | // shapes (values of -1 mean "unknown" dimension). Certain wrappers
18 | // that work with TensorShapeProto may fail at runtime when deserializing
19 | // a TensorShapeProto containing a dim value of -1.
20 | int64 size = 1;
21 |
22 | // Optional name of the tensor dimension.
23 | string name = 2;
24 | };
25 |
26 | // Dimensions of the tensor, such as {"input", 30}, {"output", 40}
27 | // for a 30 x 40 2D tensor. If an entry has size -1, this
28 | // corresponds to a dimension of unknown size. The names are
29 | // optional.
30 | //
31 | // The order of entries in "dim" matters: It indicates the layout of the
32 | // values in the tensor in-memory representation.
33 | //
34 | // The first entry in "dim" is the outermost dimension used to layout the
35 | // values, the last entry is the innermost dimension. This matches the
36 | // in-memory layout of RowMajor Eigen tensors.
37 | //
38 | // If "dim.size()" > 0, "unknown_rank" must be false.
39 | repeated Dim dim = 2;
40 |
41 | // If true, the number of dimensions in the shape is unknown.
42 | //
43 | // If true, "dim.size()" must be 0.
44 | bool unknown_rank = 3;
45 | };
46 |
--------------------------------------------------------------------------------
/tools/tensorflow/versions.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto3";
2 |
3 | package tensorflow;
4 | option cc_enable_arenas = true;
5 | option java_outer_classname = "VersionsProtos";
6 | option java_multiple_files = true;
7 | option java_package = "org.tensorflow.framework";
8 |
9 | // Version information for a piece of serialized data
10 | //
11 | // There are different types of versions for each type of data
12 | // (GraphDef, etc.), but they all have the same common shape
13 | // described here.
14 | //
15 | // Each consumer has "consumer" and "min_producer" versions (specified
16 | // elsewhere). A consumer is allowed to consume this data if
17 | //
18 | // producer >= min_producer
19 | // consumer >= min_consumer
20 | // consumer not in bad_consumers
21 | //
22 | message VersionDef {
23 | // The version of the code that produced this data.
24 | int32 producer = 1;
25 |
26 | // Any consumer below this version is not allowed to consume this data.
27 | int32 min_consumer = 2;
28 |
29 | // Specific consumer versions which are disallowed (e.g. due to bugs).
30 | repeated int32 bad_consumers = 3;
31 | };
32 |
--------------------------------------------------------------------------------