available functions / quickref request

Hello all,

I haven’t actually started CUDA programming, but I was wondering if there is are dot product and cross product functions? It doesn’t seem so from…clnk&cd=3&gl=us. I assume it’s slower defining them manually for float3/float4’s?

I have found the GLSL quick ref very helpful (www.opengl.org/sdk/libs/OpenSceneGraph/glsl_quickref.pdf); if someone could make one for CUDA (a nVidia employee?) I (and hopefully many others) would appreciate it.


CUDA-capable GPUs are treated as large collection of scalar processors, so there are no intrinsic vector operations.

If you are dealing with small vectors (3 or 4 component), you can define your own operations:

#include "vector_functions.h"

__device__ float3 operator+(const float3 &a, const float3 &b)


  return make_float3(a.x+b.x, a.y+b.y, a.z+b.z);


That code is compiled to a sequence of scalar operations run sequentially.

If you are dealing with longer vectors (hundreds of elements), then you might (depending on your algorithm) want to distribute computation over the processors. The CUDA SDK project “scalarProd” has an example of how to do that.

EDIT: I guess I need to read more…thanks for replying.