1.School of Physics and Electronic Science,Changsha University of Science and Technology,Changsha 410011,China
2.School of Computer Science,National University of Defense Technology,Changsha 410003,China
Show less
文章历史+
Received
Published
2024-09-06
2025-08-25
Issue Date
2026-02-12
PDF (3076K)
摘要
VLIW(very long instruction word)架构的DSP在图像处理和计算机视觉等实时性应用场景得到广泛应用,高并行性的多方向Sobel算法是这些应用领域的重要算法之一,面向VLIW DSP实现和优化多方向Sobel算法具有重要意义.本文提出了基于VLIW的数据重排Im2col(image to column)加矩阵乘GEMM(general matrix multiplication)优化卷积计算的方法,并采用DMA(direct memory access)双缓冲机制实现数据传输与内核计算的并行,减少了等待数据传输的时间开销,使用该方法在FT-Matrix DSP上实现并优化了多方向Sobel算法.实验结果显示,优化后的算法相比于OpenCV图像库中算法,实现了4.96~8.76倍的加速;比TMS320C6678处理器提升了3.26~6.60倍.这些结果表明,采用VLIW架构的DSP在密集型数据处理方面具有显著优势,在VLIW DSP上实现与优化的图像检测算法具有广阔应用前景.
Abstract
DSPs (digital signal processors) using VLIW (very long instruction word) architecture are widely used in high real-time application scenarios, such as image processing and computer vision. One of the important algorithms in these application areas is the highly parallel multi-directional Sobel algorithm. Implementing and optimizing this algorithm for VLIW DSPs is of great significance. In this paper, we propose a method of optimizing convolutional computation based on VLIW data rearrangement Im2col (image to column) plus matrix multiplication GEMM (general matrix multiplication), and use DMA (direct memory access) double buffer mechanism to realize the parallelism of data transmission and kernel computation, which reduces the time overhead of waiting for data transmission and the time overhead of kernel computation. The time overhead of waiting for data transmission is reduced, and the multi-directional Sobel algorithm is implemented and optimized on FT-Matrix DSP using this method. The experimental results show that the optimized algorithm achieves 4.96~8.76 times speedup compared with the algorithm in OpenCV image library, and 3.26~6.60 times improvement compared with the TMS320C6678 processor. These results show that the DSP with VLIW architecture has significant advantages in intensive data processing, and the image detection algorithm implemented and optimized on VLIW DSP has a broad application prospect.
传统的GEMM,其基本算法形式是 C=A × B,矩阵 A 的规模是M×N,矩阵 B 的规模是N×K,则结果矩阵 C 的规模M×K,矩阵 C 的元素Cij 的值如式(8)所示.
计算某个Cij 元素的时候,需要对 A 矩阵和 B 矩阵进行内积运算,累加会对数据产生依赖,无法充分使用所有MAC(multiply accumulate)单元,因此,在VLIW DSP平台实现矩阵乘需要改变计算方式,充分发掘向量单元的并行性.本文采取的方法是将 B 矩阵按列进行划分,每个VPE(vector processing element)中的每个MAC单元都处理不同的列数据,从而计算出 C 矩阵中不同列的结果,这样的并行化的优势在于每个MAC单元处理数据之间不存在任何依赖,可以将所有MAC单元的效率最大化,如图5所示.由于 A 矩阵是卷积核,数据规模不大,可以放置在标量存储单元SM(scalar memory)内,通过全局共享寄存器广播给所有VPE,可以减少占用AM(array memory)空间,同时也能避免VPE读取相同的 A 矩阵数据.
2.2 DMA传输优化
通常AM空间一般只有几百千字节,图片的像素矩阵空间远大于AM空间,需要将像素矩阵存储在DDR(double data rate)中,通过DMA分块将数据传输到AM空间进行向量运算.DMA传输的时间会影响整个算法的执行效率,因此需要对DMA传输进行优化.如图6所示,采用DMA双缓冲机制,将AM空间划分为AM0,AM1,AM2,AM3四部分.
算法核心是先给偏移量or0赋值(算法1第5~9行),然后通过偏移量读取源地址指定的数据,再存储到目的地址(算法1第10~11行).FT-Matrix DSP一个指令包最多并行来自11个功能部件的11条指令,但读/存标量功能部件只有一个标量读/存SLDST(scalar load and store)功能部件,同一个功能单元的指令不能并行,并且对偏移量or0具有依赖性,一次循环只能完全一个数据的重排,没有使用向量指令的功能单元,极大地浪费了寄存器资源,导致不能够充分发挥架构的并行性,严重增加访存次数.
针对这个问题,需要将算法向量化,充分发挥VLIW架构的优势.一个指令包包含两个向量读/存功能单元VLDST0(vector load and store)和VLDST1,支持核内两条Load/Store指令的并行访存,一个VLDDW(vector load double word)指令表示读取的向量数据单位是双字(64位),一次可以最多支持64个32位数据的并行存取.以3×3的卷积核与10×640大小的像素矩阵、步长为1的卷积为例,具体实现的部分算法如算法2所示.核心循环是从源地址读取数据存入目的地址,每次循环对64个窗口的同一位置的元素进行重排(算法2第5~8行);某一位置元素完成重排之后,跳出循环,并且调整读取和存储的地址(算法2第11~14、17~20行).
3.4 FT-Matrix DSP上的GEMM
在FT-Matrix DSP上实现适用VLIW的优化版GEMM,以3×3的卷积核与10×640大小的像素矩阵、步长为1的卷积为例,具体实现的部分代码如算法3所示.核心循环是先从SM中读取卷积矩阵中的一个元素,广播到向量寄存器中(算法3第9~10行).然后两个VLDDW并行读取64个32位数据(算法3第11~12行).接着是4个MAC单元并行4条乘加操作(vector floating-point multiply signed add 32-bit),一次可以完成64个数计算(算法3第13~16行).每跳出一次内层循环相当于做完64次卷积(算法3第17~18行).然后将矩阵乘结果双字VSTDW(vector store double word)存储到目的地址(算法3第19~20行).最后调整读取和存储的寄存器地址(算法3第21~23行).完成所有的计算之后,使用DMA双缓冲将AM空间的结果传回DDR的结果地址.
YANGS H, HSIAOS J .266/VVC fast intra prediction using Sobel edge features[J].Electronics Letters,2021,57(1):11-13.
[2]
AHMEDA S. Comparative study among sobel, Prewitt and Canny edge detection operators used in image processing[J]. Journal of Theoretical and Applied Information Technology, 2018, 96(19):6517-6525.
[3]
LIL, WANGS Q, ZENGW J, et al .Research on zero watermarking technique based on improved Sobel operator[C]//2021 IEEE International Conference on Artificial Intelligence and Industrial Design (AIID). Guangzhou, China.IEEE,2021:594-597.
[4]
TANGX L, WANGX G, HOUJ, et al. An improved sobel face gray image edge detection algorithm[C]//2020 39th Chinese Control Conference (CCC). Shenyang, China. IEEE, 2020: 6639-6643.
[5]
SHIL, ZHAOY F. Edge detection of high-resolution remote sensing image based on multi-directional improved sobel operator[J]. IEEE Access, 2023, 11: 135979-135993.
[6]
赵一霈.DSP的发展与应用[J]. 电子技术与软件工程, 2018(6): 92.
[7]
ZHAOY P. Development and application of DSP[J]. Electronic Technology & Software Engineering,2018(6):92.(in Chinese)
ZHOUF D, HANS Y, QIZ W,et al .Digital processing system for shallow surface frequency-domain electromagnetic detection based on FPGA+DSP[J].Journal of Hunan University (Natural Sciences),2016,43(10):94-101.(in Chinese)
MUTOV, ANDREOZZIE, CAPPELLIC, et al .Real-time implementation of a frequency shifter for enhancement of heart sounds perception on VLIW DSP platform[J].Electronics,2023,12(20): 4359.
ZHANGF, GEY Z, DOUY .Optimization methods of digital image process algorithm on VLIW DSP[J]. Microcomputer Applications,2008(10):1-6.(in Chinese)
[14]
CHANGQ, LIX, LIY, et al. Multi-directional sobel operator kernel on GPUs[J].Journal of Parallel and Distributed Computing,2023,177:160-170
[15]
ZHANGH, HANL, XIEJ M, et al. Realization and optimization of Sobel edge detection algorithm for Domestic DCU accelerators[C]//MEMAT 2022;2nd International Conference on Mechanical Engineering, Intelligent Manufacturing and Automation Technology. Guilin,China. VDE, 2022: 1-7
[16]
陈凯,张涛 .多核DSP并行软件设计技术研究[J].信息技术,2015,39(7):5-8.
[17]
CHENK, ZHANGT .Research on concurrent software design based on multicore DSP[J]. Information Technology,2015, 39(7): 5-8.(in Chinese)
WANGW. Research on acceleration of image processing algorithms based on ARM-FPGA heterogeneous multi-core platform [D]. Xi’an: Xidian University, 2019. (in Chinese)
FANM L, GUOZ H, CHAIX N,et al .Optimized realization of sobel edge detection algorithm for FT-M7002[J]. Computer Engineering, 2022,48(6):193-199.(in Chinese)
[22]
HADI SAPUTRAV, HERWINDIATID E, SUTRISNOT .Car shape clustering using sobel edge detection with divisive average linkage and single linkage algorithm (case:bus,Sedan,citycar,mpv,and truck)[J].IOP Conference Series:Materials Science and Engineering,2020,1007(1):012136.
LID Y. A optimization design of edge detection based on soble algorithm[J]. Digital Technology and Application,2017,35(11):137-138.(in Chinese)
[25]
TIANR, SUNG L, LIUX C, et al .Sobel edge detection based on weighted nuclear norm minimization image denoising[J].Electronics,2021,10(6):655.
[26]
RAVIVARMAG, GAVASKARK, MALATHID, et al .Implementation of Sobel operator based image edge detection on FPGA[J].Materials Today:Proceedings,2021,45:2401-2407.
WANGQ L, PEIX D, LIAOL Y, et al .Evaluating matrix multiplication-based convolution algorithm on multi-core digital signal processors[J].Journal of National University of Defense Technology,2023,45(1):86-94.(in Chinese)
GUOH L, CHAIX N, HANL, et al .Implementation and optimization of canny edge detection algorithm on FT platform[J].Computer Engineering,2021,47(7):37-43.(in Chinese)
[35]
王梦园. 面向飞腾平台图像滤波算法的实现与优化[D]. 郑州:郑州大学, 2021.
[36]
WANGM Y. Implementation and optimization of image filtering algorithm for Phytium Platform [D]. Zhengzhou:Zhengzhou University, 2021. (in Chinese)