biaodiluer
biaodiluer

Reputation: 121

What's the meaning of the params x,y,z,w in function cudaCreateChannelDesc

cudaCreateChannelDesc(int x, int y, int z, int w, enum cudaChannelFormatKind f);

Now i have an example code:

cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);

I have no idea about why x=32,y=z=w=0. Could explain why the channel description is done in that way and what the resulting texture type is?

Upvotes: 11

Views: 4138

Answers (2)

Jonathan Olson
Jonathan Olson

Reputation: 1186

There is a separate C, and C++ API for that function (the C++ API being overloaded).

For the C API function those are the number of bits for each channel. These can be colors channels or spatial dimensions or really anything you want to use them for. The example you copied from is only using scalar values. 32 bits being appropriate for float data type.

__host__ ​cudaChannelFormatDesc cudaCreateChannelDesc ( int  x, int  y, int  z, int  w, cudaChannelFormatKind f )

From the cuda docs, "Returns a channel descriptor with format f and number of bits of each component x, y, z, and w."

The C++ API is overloaded and looks like this... If you are compiling on windows with visual studio or g++ for a .cu file you should use this form. For c files, use the above.

__inline__ __host__ cudaChannelFormatDesc cudaCreateChannelDesc<float>(void)
__inline__ __host__ cudaChannelFormatDesc cudaCreateChannelDesc<float2>(void)
__inline__ __host__ cudaChannelFormatDesc cudaCreateChannelDesc<float4>(void)
etc.

Upvotes: 9

Martin Beckett
Martin Beckett

Reputation: 96139

Returns a channel descriptor with format f and number of bits of each component x, y, z, and w.

The x,y,z,w are the number of bits in the x,y,z dimensions and 'w'. In your example the 'x' data is 32bits and the other dimensions aren't used.

(The 'w' is used to make the math easier for applying transformations to 3d data)

Upvotes: 5

Related Questions