ncnn.cmake 4.0 KB

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