ncnn.cmake 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. function(download_ncnn)
  2. include(FetchContent)
  3. # We use a modified version of NCNN.
  4. # The changed code is in
  5. # https://github.com/csukuangfj/ncnn/pull/7
  6. # Please also change ../pack-for-embedded-systems.sh
  7. # the latest master as of 2024.03.05
  8. set(ncnn_URL "https://github.com/Tencent/ncnn/archive/964ed7a56a573c5046cc177a6cd95580ecddcddf.zip")
  9. set(ncnn_URL2 "https://hub.nuaa.cf/Tencent/ncnn/archive/964ed7a56a573c5046cc177a6cd95580ecddcddf.zip")
  10. set(ncnn_HASH "SHA256=7a02ca37bc4137862efca0627430884db21f0c7491f8f7b98f909cf4a404792e")
  11. # If you don't have access to the Internet, please download it to your
  12. # local drive and modify the following line according to your needs.
  13. set(possible_file_locations
  14. $ENV{HOME}/Downloads/ncnn-964ed7a56a573c5046cc177a6cd95580ecddcddf.zip
  15. $ENV{HOME}/asr/ncnn-964ed7a56a573c5046cc177a6cd95580ecddcddf.zip
  16. ${PROJECT_SOURCE_DIR}/ncnn-964ed7a56a573c5046cc177a6cd95580ecddcddf.zip
  17. ${PROJECT_BINARY_DIR}/ncnn-964ed7a56a573c5046cc177a6cd95580ecddcddf.zip
  18. /tmp/ncnn-964ed7a56a573c5046cc177a6cd95580ecddcddf.zip
  19. )
  20. foreach(f IN LISTS possible_file_locations)
  21. if(EXISTS ${f})
  22. set(ncnn_URL "${f}")
  23. file(TO_CMAKE_PATH "${ncnn_URL}" ncnn_URL)
  24. set(ncnn_URL2)
  25. break()
  26. endif()
  27. endforeach()
  28. if(NOT WIN32)
  29. FetchContent_Declare(ncnn
  30. URL
  31. ${ncnn_URL}
  32. ${ncnn_URL2}
  33. URL_HASH ${ncnn_HASH}
  34. PATCH_COMMAND
  35. sed -i.bak "/ncnn PROPERTIES VERSION/d" "src/CMakeLists.txt"
  36. )
  37. else()
  38. FetchContent_Declare(ncnn
  39. URL
  40. ${ncnn_URL}
  41. ${ncnn_URL2}
  42. URL_HASH ${ncnn_HASH}
  43. )
  44. endif()
  45. set(NCNN_PIXEL OFF CACHE BOOL "" FORCE)
  46. set(NCNN_PIXEL_ROTATE OFF CACHE BOOL "" FORCE)
  47. set(NCNN_PIXEL_AFFINE OFF CACHE BOOL "" FORCE)
  48. set(NCNN_PIXEL_DRAWING OFF CACHE BOOL "" FORCE)
  49. set(NCNN_BUILD_BENCHMARK OFF CACHE BOOL "" FORCE)
  50. set(NCNN_SHARED_LIB ${BUILD_SHARED_LIBS} CACHE BOOL "" FORCE)
  51. set(NCNN_BUILD_TOOLS OFF CACHE BOOL "" FORCE)
  52. set(NCNN_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
  53. set(NCNN_BUILD_TESTS OFF CACHE BOOL "" FORCE)
  54. # For RNN-T with ScaledLSTM, the following operators are not sued,
  55. # so we keep them from compiling.
  56. #
  57. # CAUTION: If you switch to a different model, please change
  58. # the following disabled layers accordingly; otherwise, you
  59. # will get segmentation fault during runtime.
  60. set(disabled_layers
  61. AbsVal
  62. ArgMax
  63. BatchNorm
  64. Bias
  65. BNLL
  66. # Concat
  67. # Convolution
  68. # Crop
  69. Deconvolution
  70. # Dropout
  71. Eltwise
  72. ELU
  73. # Embed
  74. Exp
  75. # Flatten # needed by innerproduct
  76. # InnerProduct
  77. # Input
  78. Log
  79. LRN
  80. # MemoryData
  81. MVN
  82. Pooling
  83. Power
  84. PReLU
  85. Proposal
  86. # Reduction
  87. # ReLU
  88. # Reshape
  89. ROIPooling
  90. Scale
  91. # Sigmoid
  92. # Slice
  93. # Softmax
  94. # Split
  95. SPP
  96. # TanH
  97. Threshold
  98. Tile
  99. # RNN
  100. # LSTM
  101. # BinaryOp
  102. # UnaryOp
  103. ConvolutionDepthWise
  104. # Padding # required by innerproduct and convolution
  105. # Squeeze
  106. # ExpandDims
  107. Normalize
  108. # Permute
  109. PriorBox
  110. DetectionOutput
  111. Interp
  112. DeconvolutionDepthWise
  113. ShuffleChannel
  114. InstanceNorm
  115. Clip
  116. Reorg
  117. YoloDetectionOutput
  118. # Quantize
  119. # Dequantize
  120. Yolov3DetectionOutput
  121. PSROIPooling
  122. ROIAlign
  123. # Packing
  124. # Requantize
  125. # Cast # needed InnerProduct
  126. HardSigmoid
  127. SELU
  128. HardSwish
  129. Noop
  130. PixelShuffle
  131. DeepCopy
  132. Mish
  133. StatisticsPooling
  134. Swish
  135. # Gemm
  136. GroupNorm
  137. LayerNorm
  138. Softplus
  139. GRU
  140. MultiHeadAttention
  141. GELU
  142. # Convolution1D
  143. Pooling1D
  144. # ConvolutionDepthWise1D
  145. Convolution3D
  146. ConvolutionDepthWise3D
  147. Pooling3D
  148. # MatMul
  149. Deconvolution1D
  150. # DeconvolutionDepthWise1D
  151. Deconvolution3D
  152. DeconvolutionDepthWise3D
  153. Einsum
  154. DeformableConv2D
  155. # GLU
  156. Fold
  157. Unfold
  158. GridSample
  159. CumulativeSum
  160. CopyTo
  161. Erf
  162. Diag
  163. CELU
  164. Shrink
  165. RelPositionalEncoding
  166. MakePadMask
  167. RelShift
  168. )
  169. foreach(layer IN LISTS disabled_layers)
  170. string(TOLOWER ${layer} name)
  171. set(WITH_LAYER_${name} OFF CACHE BOOL "" FORCE)
  172. endforeach()
  173. FetchContent_GetProperties(ncnn)
  174. if(NOT ncnn_POPULATED)
  175. message(STATUS "Downloading ncnn from ${ncnn_URL}")
  176. FetchContent_Populate(ncnn)
  177. endif()
  178. message(STATUS "ncnn is downloaded to ${ncnn_SOURCE_DIR}")
  179. message(STATUS "ncnn's binary dir is ${ncnn_BINARY_DIR}")
  180. add_subdirectory(${ncnn_SOURCE_DIR} ${ncnn_BINARY_DIR} EXCLUDE_FROM_ALL)
  181. if(SHERPA_NCNN_ENABLE_PYTHON AND WIN32)
  182. install(TARGETS ncnn DESTINATION ..)
  183. else()
  184. install(TARGETS ncnn DESTINATION lib)
  185. endif()
  186. endfunction()
  187. download_ncnn()