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!

[code]// 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)
...[/code]

Thanx for helping!

Cheers Le-o
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

#1
Posted 05/24/2009 05:57 PM   
The constant pointer A contains the starting address of allocated memory which holds the matrix.
The constant pointer A contains the starting address of allocated memory which holds the matrix.

#2
Posted 05/24/2009 07:31 PM   
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:

[code]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![/code]

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

Thanks for further help
Le-o

[quote name='avidday' post='544796' date='May 24 2009, 08:31 PM']The constant pointer A contains the starting address of allocated memory which holds the matrix.[/quote]
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

Le-o



[quote name='avidday' post='544796' date='May 24 2009, 08:31 PM']The constant pointer A contains the starting address of allocated memory which holds the matrix.

#3
Posted 05/25/2009 10:33 AM   
[quote name='Le-o' post='545000' date='May 25 2009, 01:33 PM']I know that fact. Unfortunately I could not use this fact to implement a solution.[/quote]
Of course you can. The solution is contained in my reply. Rereading what I wrote:
[quote]The constant pointer A contains the [b]starting address[/b] of allocated memory which holds the matrix.[/quote]

So what is the starting address of your two dimensional array?
[code]&Matrix1[0][0][/code]
[quote name='Le-o' post='545000' date='May 25 2009, 01:33 PM']I know that fact. Unfortunately I could not use this fact to implement a solution.

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

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




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

&Matrix1[0][0]

#4
Posted 05/25/2009 10:47 AM   
Thank you very much! Now it works :D

Cheers Le-o
Thank you very much! Now it works :D



Cheers Le-o

#5
Posted 05/25/2009 11:49 AM   
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.
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.

#6
Posted 05/25/2009 12:09 PM   
Scroll To Top