example code matrix multiplication

Hi all,

I have a problem with the understanding of the subroutine’s parameter in the example code for the matrix multiplication (NVIDIA_CUDA_Programming_Guide_2.1 - page 77) - the header of the subroutine is posted below.

A should be a matrix. But the soubroutine will get a constant pointer to a float A… and not to a matrix.

Now my problem: how exactly do I have to call this subroutine Mul from my main-routine? How does the declaration of the matrix in the main-routine looks like? I tried out a lot of different ways but I could never call the subroutine with a matrix … I appreciate any help!

// Host multiplication function

// Compute C = A * B

// hA is the height of A

// wA is the width of A

// wB is the width of B

void Mul(const float* A, const float* B, int hA, int wA, int wB, float* C)


Thanx for helping!

Cheers Le-o

The constant pointer A contains the starting address of allocated memory which holds the matrix.

Hi avvidday!

I know that fact. Unfortunately I could not use this fact to implement a solution. I always got errors concerning unmatching format of the parameter while calling the subroutine…

I defined the matrix in the main routine:

float Matrix1[N][N];				  // N is defined as a constant integer value


Mul(Matrix1);						 // call of subroutine Mul with Matrix1... 

									  // in c the Arrays are always call by reference therefore Matrix1 should be a Pointer to the Array, isn't it? 

									  // I also tried &Matrix1 -> did not work either!

I am mistaking something? Can someone give me a running solution?!

Thanks for further help


Of course you can. The solution is contained in my reply. Rereading what I wrote:

So what is the starting address of your two dimensional array?


Thank you very much! Now it works :D

Cheers Le-o

You are welcome, but might I suggest a spot of revision on pointers and arrays in C and/or C++. It is pretty central to being able to write expressive, functional code in CUDA.