ncnn.cmake 4.4 KB

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