cudaMemcpyToSymbol使用或不使用字符串 [英] cudaMemcpyToSymbol using or not using string

查看:908
本文介绍了cudaMemcpyToSymbol使用或不使用字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图以这种方式复制到恒定存储器的结构:

 结构美孚{
    诠释A,B,C;
};__constant__富CDATA;诠释主(){
    美孚HDATA = {1,2,3};
    cudaMemcpyToSymbol(CDATA,&安培; HDATA,sizeof的(富));
    // ...
}

这工作得很好,在我的内核,我可以直接访问常量数据:

  __ global__无效的内核(){
    的printf(数据是:%D%d个\\ N,cData.a,cData.b,cData.c); // 1 2 3
}

但后来我尝试着用为const char * 为符号的名称,事情停止工作:

  cudaMemcpyToSymbol(CDATA,&安培; HDATA,sizeof的(富)); //输出0 0 0

我觉得这两个版本相似,但看来我错了。

这是怎么回事?

编辑:
我要报告与cudaGetSymbolAddress,而如果不使用为const char * 对我的作品同样的行为:

  __ constant__ INT someData [10];
__constant__为int * ptrToData;INT * dataPosition;
cudaGetSymbolAddress((无效**)及dataPosition,someData); //作品
// cudaGetSymbolAddress((无效**)及dataPositionsomeData); // 不工作
cudaMemcpyToSymbol(ptrToData,&安培; dataPosition,sizeof的为(int *));


解决方案

随着CUDA 5,不再支持使用字符串符号名。这是包括在CUDA 5发行说明这里


  

•使用字符串来指示设备符号,它是可能的某些API函数,不再支持。相反,符号应可直接使用。


其中的一个原因这与实现一个真正连接的设备,这是在CUDA 5的新功能做。

I was trying to copy a structure to constant memory in this way:

struct Foo {
    int a, b, c;
};

__constant__ Foo cData;

int main() {
    Foo hData = {1, 2, 3};
    cudaMemcpyToSymbol(cData, &hData, sizeof(Foo));
    // ...
}

And this worked fine, in my kernel I could access the constant data directly:

__global__ void kernel() {
    printf("Data is: %d %d %d\n", cData.a, cData.b, cData.c); // 1 2 3
}

But then I tried to use a const char * as symbol name, and things stopped working:

cudaMemcpyToSymbol("cData", &hData, sizeof(Foo)); // prints 0 0 0

I thought both versions were similar, but it seems I was wrong.

What is happening?

EDIT: I'd like to report this same behavior with cudaGetSymbolAddress, which works for me if no const char * is used:

__constant__ int someData[10];
__constant__ int *ptrToData;

int *dataPosition;
cudaGetSymbolAddress((void **)&dataPosition, someData); // Works
// cudaGetSymbolAddress((void **)&dataPosition, "someData"); // Do not work
cudaMemcpyToSymbol(ptrToData, &dataPosition, sizeof(int *));

解决方案

As of CUDA 5, using a string for symbol names is no longer supported. This is covered in the CUDA 5 release notes here

•The use of a character string to indicate a device symbol, which was possible with certain API functions, is no longer supported. Instead, the symbol should be used directly.

One of the reasons for this has to do with enabling of a true device linker, which is new functionality in CUDA 5.

这篇关于cudaMemcpyToSymbol使用或不使用字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆