本人新手,有个矩阵相乘的问题不太懂,想请教大家一下

这个历程是 NVIDIA 的sdk的例程

这里面,我有个地方不是很明白,
// Index of the first sub-matrix of A processed by the block
int aBegin = wA * BLOCK_SIZE * by;
这句话里, 它是求 子矩阵的索引,为啥用 A矩阵的宽度 乘以 每个BLOCK 的大小,然后再乘以 block的索引呢?
希望大家帮我解答一下

新手求帮助。

[attach]3257[/attach]
源程序在这

  • Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
  • Please refer to the NVIDIA end user license agreement (EULA) associated
  • with this source code for terms and conditions that govern your use of
  • this software. Any use, reproduction, disclosure, or distribution of
  • this software and related documentation outside the terms of the EULA
  • is strictly prohibited.

*/

/* Matrix multiplication: C = A * B.

  • Device code.
    */

#ifndef MATRIXMUL_KERNEL_H
#define MATRIXMUL_KERNEL_H

#include <stdio.h>
#include “matrixMul.h”

#define CHECK_BANK_CONFLICTS 0
#if CHECK_BANK_CONFLICTS
#define AS(i, j) cutilBankChecker(((float*)&As[0][0]), (BLOCK_SIZE * i + j))
#define BS(i, j) cutilBankChecker(((float*)&Bs[0][0]), (BLOCK_SIZE * i + j))
#else
#define AS(i, j) As[i][j]
#define BS(i, j) Bs[i][j]
#endif

////////////////////////////////////////////////////////////////////////////////
//! Matrix multiplication on the device: C = A * B
//! wA is A’s width and wB is B’s width
////////////////////////////////////////////////////////////////////////////////
global void
matrixMul( float* C, float* A, float* B, int wA, int wB) //3个矩阵的指针,及矩阵大小
{
// Block index
int bx = blockIdx.x;
int by = blockIdx.y;
[/i][/i]

LZ您好:

1:这里的宏BLOCK_SIZE并非是block的大小,而是方形block的边长。

2:这样wA*BLOCK_SIZE就是一个条带的元素数。再乘以by就是y方向越过的多个条带的总的偏移量。

3:这个例子是programming guide里面作为例子讲解的,您可以参照一下programming guide的内容。

祝您好运~

谢谢斑竹,我这几天又把那些东西,又看了一下,
对于初学者来说
这个例程有些难。
不过我还是坚持下来了,用了两天的时间,终于把这个东西理解了。
再次谢谢斑竹的帮助
斑竹大好人。

以后会继续请教版主问题的,

您客气了。服务您是ICE的荣幸。(请注意我不是ICE)

感谢您的来访,周末愉快。

LZ您好:

有一种说法表示:看懂这个矩阵相乘的例子等同于CUDA入门的一半,另外一半是reduction那个例子。
所以,恭喜您取得了可喜的进步。

也欢迎您常来论坛讨论问题~
同时,为您服务是我的荣幸,横扫斑竹说的没错,以及他的表示和我自己说具备同等效力。

祝您编码顺利~