且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

优化CUDA矩阵汉明距离

更新时间:2023-02-27 10:50:41

你是对的, gemm()代码。 CUDA示例有一个简单的实现 gemm(),但它太简单了。性能受限于共享内存访问,在Kepler设备上只能提供〜250 Gflops。为了更高的性能,您可能需要检查MAGMA中的 gemm()代码。



http:// icl。 cs.utk.edu/magma/index.html



这两篇文章还告诉你如何实现和调整 gemm()



http://staff.kfupm.edu.sa/ics/ahkhan/Resources/Papers/Autotuning/Au​​totuning%2520GEMM%2520Kernels%2520for%2520the%2520Fermi%2520GPU。 pdf



http ://www.netlib.org/lapack/lawnspdf/lawn267.pdf



不同gemm()其具有用于快速乘法和加法操作的FMA指令的硬件支持,所期望的操作比较和添加可能需要更多指令,因此性能应该更低。考虑到Kepler的 gemm()的最高性能是〜3 Tflops。你可以得到0.5〜2 Tflops汉明距离矩阵计算。


Is anyone aware of an optimized CUDA kernel for computing a GEMM style hamming distance between two matrices of dimension A x N and N x B? The problem is nearly identical to GEMM, but instead computes the sum( a_n != b_n ) for each vector {1 ... N}, instead of multiplying and summing each vector element.

I wanted to verify before writing my own, since this problem is relatively common, but I haven't had success in finding code for it yet. Suggestions for code to modify would be excellent as well.

EDIT:

In addition to kangshiyin's suggestions below, I found this walk-through of an optimized SGEMM implementation to be extraordinarily helpful in understanding steps beyond the basic shared memory matrix multiplication example in the CUDA C Programming Guide.

You are right that you could write your kernel by modifying gemm() code. CUDA examples have a simple implementation of gemm(), but it is too simple. The performance is bounded by shared memory access, giving only ~250 Gflops on Kepler devices. For higher performance, you may want to check the gemm() code in MAGMA.

http://icl.cs.utk.edu/magma/index.html

These two papers also tell you how to implement and tune gemm().

http://staff.kfupm.edu.sa/ics/ahkhan/Resources/Papers/Autotuning/Autotuning%2520GEMM%2520Kernels%2520for%2520the%2520Fermi%2520GPU.pdf

http://www.netlib.org/lapack/lawnspdf/lawn267.pdf

Unlike gemm() which has hardware support with the FMA instruction for fast multiply-and-add operation, your desired operation compare-and-add may need more instructions, thus the performance should be lower. Considering the peak performance of gemm() is ~3 Tflops on Kepler. You may be able to get 0.5~2 Tflops for hamming distance matrix calculation.