BLAS dgemm 中 LDA 参数的目的?

发布于 2024-12-16 21:00:01 字数 406 浏览 1 评论 0原文

Fortran 参考实现文档指出:

*  LDA    - INTEGER.
*           On entry, LDA specifies the first dimension of A as declared
*           in the calling (sub) program. When  TRANSA = 'N' or 'n' then
*           LDA must be at least  max( 1, m ), otherwise  LDA must be at
*           least  max( 1, k ).
*           Unchanged on exit.

然而,给定 m 和 k 我不应该能够导出 LDA 吗?什么时候LDA允许大于n(或k)?

The Fortran reference implementation documentation states:

*  LDA    - INTEGER.
*           On entry, LDA specifies the first dimension of A as declared
*           in the calling (sub) program. When  TRANSA = 'N' or 'n' then
*           LDA must be at least  max( 1, m ), otherwise  LDA must be at
*           least  max( 1, k ).
*           Unchanged on exit.

However, given m and k shouldn't I be able to derive LDA? When is LDA permitted to be bigger than n (or k)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤云独去闲 2024-12-23 21:00:01

BLAS 中的 LDA 参数实际上是矩阵的步幅,因为它布置在线性存储器中。 LDA 值大于正在操作的矩阵的主维是完全有效的。使用较大 LDA 值有用或必要的典型情况是,当您对较大密集矩阵的子矩阵进行操作时,以及当硬件或算法在存储填充到某个最佳大小的舍入倍数时提供性能优势时(例如,缓存行或 GPU 内存事务大小,或多处理器实现中的负载平衡)。

The LDA parameter in BLAS is effectively the stride of the matrix as it is laid out in linear memory. It is perfectly valid to have an LDA value which is larger than the leading dimension of the matrix which is being operated on. Typical cases where it is either useful or necessary to use a larger LDA value are when you are operating on a sub matrix from a larger dense matrix, and when hardware or algorithms offer performance advantages when storage is padded to round multiples of some optimal size (cache lines or GPU memory transaction size, or load balance in multiprocessor implementations, for example).

删除会话 2024-12-23 21:00:01

区别在于数组 A 和 B 的第一维的逻辑大小与物理大小之间。第一个是您正在使用的数组的大小,第二个是声明中的值或使用的物理内存量。由于 Fortran 是列主要语言,因此必须知道除最后一个索引之外的所有索引的声明大小,以便计算数组元素的位置。请注意 FORTRAN 77 样式声明“A(LDA,),B(LDB,),C(LDC,*)”。数组的声明大小可以大于您正在使用的部分;当然不能再小了。

The distinction is between the logical size of the first dimensions of the arrays A and B and the physical size. The first is the size of the array that you are using, the second is the value in the declaration, or the physical amount of memory used. Since Fortran is a column major language, the declared sizes of all indices except the last must be known in order to calculate the location of an array element. Notice the FORTRAN 77 style declarations of "A(LDA,),B(LDB,),C(LDC,*)". The declared size of the array can be larger than the portion that you are using; of course it can't be smaller.

伊面 2024-12-23 21:00:01

另一种看待它的方式是 LDA 是 y 步幅,这意味着在行主布局中,元素 A[y,x] 的地址计算为 x+LDA*y。对于“打包”内存布局,x 数据的相邻行之间没有间隙 LDA=xSize。

Another way to look at it is LDA is the y-stride, meaning in a row-major layout your address for element A[y,x] is computed as x+LDA*y. For a "packed" memory layout without gaps between adjacent lines of x-data LDA=xSize.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文