ncnn icon indicating copy to clipboard operation
ncnn copied to clipboard

Cpu 部署速度差异

Open fuerpy opened this issue 2 years ago • 6 comments

detail | 详细描述 | 詳細な説明

最近在做tee环境部署的问题,tee下是cpu单线程,ree中亦设置为cpu单线程(.set_num_threads(1);) 模型在这里不是很关键,以squeezenet为例,在速度上慢了大概30%(5-7ms)左右。 ` #define _OPENMP 1 #define NCNN_SIMPLEOMP 1

#define NCNN_SIMPLESTL 0 #define NCNN_THREADS 1 #define NCNN_BENCHMARK 0 #define NCNN_C_API 1 #define NCNN_PLATFORM_API 1 #define NCNN_PIXEL 1 #define NCNN_PIXEL_ROTATE 1 #define NCNN_PIXEL_AFFINE 1 #define NCNN_PIXEL_DRAWING 1 #define NCNN_VULKAN 0 // used by GPU #define NCNN_SYSTEM_GLSLANG 0 #define NCNN_RUNTIME_CPU 1 #define NCNN_GNU_INLINE_ASM 1 // *** used for x86 #define NCNN_AVX 0 #define NCNN_XOP 0 #define NCNN_FMA 0 #define NCNN_F16C 0 #define NCNN_AVX2 0 #define NCNN_AVXVNNI 0 #define NCNN_AVX512 0 #define NCNN_AVX512VNNI 0 #define NCNN_AVX512BF16 0 #define NCNN_AVX512FP16 0 // *** #define NCNN_VFPV4 1

#if aarch64 #define NCNN_ARM82 1 #define NCNN_ARM82DOT 1 #define NCNN_ARM82FP16FML 1 #define NCNN_ARM84BF16 1 #define NCNN_ARM84I8MM 1 // *** below are not used #define NCNN_ARM86SVE 0 #define NCNN_ARM86SVE2 0 #define NCNN_ARM86SVEBF16 0 #define NCNN_ARM86SVEI8MM 0 #define NCNN_ARM86SVEF32MM 0 // *** #endif // aarch64

// *** other arch #define NCNN_MSA 0 #define NCNN_LSX 0 #define NCNN_MMI 0 #define NCNN_RVV 0 // *** #define NCNN_INT8 1 #define NCNN_BF16 1 #define NCNN_FORCE_INLINE 1 `

请问一下这个配置有什么问题吗? 我该从什么方向去查一下速度问题呢

fuerpy avatar Mar 06 '23 03:03 fuerpy

  1. 这些宏最好是在cmake构建和编译的时候 "-DNCNN_AVX=ON" 这样的形式打开或者关闭 "-DXXX=OFF".
  2. 速度差异对比的是什么,感觉没有描述清楚

Yoh-Z avatar Mar 06 '23 04:03 Yoh-Z

Hi,Yoh-Z 感谢你的回复

  1. 因为我现在的环境并不是能够直接通过ncnn原生编译推进去运行,所以我修改了编译方式。如果我通过宏定义方式会影响速度吗?
  2. 对比的是一样的模型 相同平台通过ncnn cmake编译的apk运行,也就是我所说REE环境。

fuerpy avatar Mar 06 '23 06:03 fuerpy

相同平台,如果硬件完全相同,应该不会有速度的差别。用修改宏定义的方式不一定可行,建议最好还是通过cmake。(首先你得确保宏在所有算子编译之前就修改好,而且cmakelist里也有一些额外的操作。如果一定要用这种方式,推荐调试一下,看是否能进入写了simd优化的代码)

Yoh-Z avatar Mar 06 '23 06:03 Yoh-Z

好的,我从这个方向入手,有了一点发现。 项目我是中途接手,发现编译时为了躲过错误关闭了一些宏定义。 https://github.com/Tencent/ncnn/issues/2133 然后我照着这个 issus查看了两个编译器的区别,没有发现什么明显区别,但是还是有几个宏没有出现,不知道是哪里定义的比如“__ARM_FEATURE_SIMD32”

我又打印了些LOG 看上去 和 __ARM_FEATURE_SIMD32 这个宏相关的函数并没有走到

fuerpy avatar Mar 06 '23 11:03 fuerpy

猜测是你编译进去了你没有的指令集,所以还是建议尽量用cmake的方式。。

Yoh-Z avatar Mar 11 '23 19:03 Yoh-Z

请问使用的是什么tee呐?tee本身确实存在一些性能衰减,而且可能对neon的支持有限

Zillior avatar Jan 03 '24 08:01 Zillior