ncnn.cmake 4.1 KB

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