__shared__float declarations

I try to understand the examples in the book of Kirk/Hwu. In Chapter 5.3 they
introduced tiled matrix multiplication and the example 5.7.
Taking it as it stands my compiler produced an error concerning the
declaration

__shared__float Mds[TILE_WIDTH][TILE_WIDTH]; (1)

(Nds likewise)

I find these declarations in all subsequent publications and related lectures.

What works is

shared float Mds[TILE_WIDTH][TILE_WIDTH]; (2)

But then TILE_WIDTH must be declared as a constant int before

const int TILE_WIDTH=16;

shared float Mds[TILE_WIDTH][TILE_WIDTH];

(as an example)

  • is (1) a typo only?
  • Have I declare TILE_WIDTH indeed as a constant value before - which is not
    described in the book in this way?

I would think that the (1) and (2) are references to something in a text paragraph and you are supposed to not put them in your code.

Also

__shared__float

is missing a space before the ‘float’

In my code I have the following, which works fine

#define ThreadsPerBlock 96

shared float2 flowForDay[ThreadsPerBlock];

Similarly

#define ROWS 16

#define COLUMNS 16

shared int3 shPosnArray[ROWS][COLUMNS];

I’m all for using either #define or const to make the code more readable. and usually have all my #define right after any #include

Hi,

I have the following for my code:

__shared__ float Mds[TILE_WIDTH][TILE_WIDTH];

	__shared__ float Nds[TILE_WIDTH][TILE_WIDTH];

and also, he mentions that TILE_WIDTH should be 16 in the book, because a 16x16 block would use 256 threads per block. So towards the top define:

#define TILE_WIDTH 16

Cheers,

Craig

Thanks, I think that helps!

Thanks - that will help!

Holger