mathematical operation in built-in vector type?

Hi All,

I am writing a code using built-in vector type (i.e char4, uchar4, float4, etc…).But what is the point here :

does CUDA define mathematical operations such as +/-/*/dot/normalize on vector types (float3/float4 etc.) ???

Take a look at section B.3.1 of the 2.2 manual.

N.

I have read section B.3.1 of the 2.2 manual but here only thing that include is Built-in vector types come with a constructor function of the

form make_. But not about the basic operations on that buil-in vector types.

True, you’ll have to implement the operations yourself or include “cutil_math.h”, but you were also asking what the point was of these types.

Because of these builtin type definitions, you don’t have to worry about good device alignment so much.

N.

I have implemented some operator function they all working except assignment operator.

My code of assignment operator is:

inline __host__ __device__ void operator=( short4& a, int4 s)

{

   a.x = s.x; a.y = s.y; a.z = s.z; a.w = s.w;

}

I still got error

Could you tell the cause?

short and int are not the same type. You need to either to overlay the assignment operator with a definition for the assignment or do an explicit cast.

if we define our own function function such as

inline __host__ __device__ short4 operator*(short int s, short4 a)

{

	return make_short4(__mul24(a.x , s), __mul24(a.y , s), __mul24(a.z , s), __mul24(a.w, s));

}

can I call it from device function?

when I calling it from device function I get an error

But what I read in CUDA SDK 2.2 pdf is

Then what is the cause of this error?

The error is that there is no make_short function defined for the host in cutil_math.h, so you’ll have to define one yourself.
Right now you’re calling a device only function (make_short) within a function that can be run on both the host and device, but since there is no
definition of make_short for the host, it generates an error.

N.

But in section B.3.1 of CUDA SDK 2.2 pdf , it is written that :

Try including vector_functions.h

N.