技术开发 频道

cyrosly:CUDA 3.0 初体验

  【IT168文档】看了CUDA3.0的beta的Guide,实在没什么大的改动,很多fermi的改变没有充分体现在新的paper中,看起来只是在2.3基础上加了点对C++支持的描述,估计更详细完整的要等正式版发布时吧。不过有了驱动我们还是可以试用(不过可惜,函数指针和函数模版参数目前不被支持)。

  实验代码:

class floatx2
{
public:
inline floatx2(
float f=0.f);
inline floatx2(
float,float);
inline floatx2(
const floatx2&);
public:
inline floatx2
& operator+=(const floatx2&);
private:
float x;
float y;
};

inline floatx2::floatx2(
float s):x(s),y(s){}
inline floatx2::floatx2(
float f0,float f1):x(f0),y(f1){}
inline floatx2::floatx2(
const floatx2& v)
{
x
=v.x;
y
=v.y;
}
inline floatx2
& floatx2::operator+=(const floatx2& v)
{
x
+=v.x;
y
+=v.y;
return *this;
}

extern "C" __global__
void kernel_vadd(floatx2* d,const floatx2* s)
{
const unsigned int idx=blockDim.x*blockIdx.x+threadIdx.x;

d[idx]
+=s[idx]
}

  在编译栏中将arch设置为sm_20,编译成功。

  说明fermi确实支持了对象模式编程,支持了*this指针(C++中,每个对象本身具有一个隐含的对自身引用的this指针).

  但有一点很不爽,就是cubin文件改变了,变成了下面的形式:

0
相关文章