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]

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)

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]

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.

[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]

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.

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

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!

Thanx for helping!

Cheers Le-o

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]

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:

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.

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]

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?

Cheers Le-o

Cheers Le-o