我是Java程序员,也是C++和Cuda的新手。在我CudaRun.cu
分割错误C++ Cuda
void mainRun(Input in) {
Input *deviceIn;
deviceIn = new Input(NULL, NULL, NULL, NULL, 0.0, NULL,0.0,0.0,NULL,0.0,NULL,0.0);
//line-a
printf("Started. Just abt to call cuda \n");
int size = sizeof(Input);
cudaMalloc((void**) &deviceIn, size);
cudaMemcpy(deviceIn, &in, size, cudaMemcpyHostToDevice);
cudaMalloc((void**) deviceIn->sellingPrice, 4 * sizeof(LucyDecimal));
//line-b
....
}
我得到一个分段错误在
Input.h
类输入{
public:
const LucyDecimal * sellingPrice; //Ri
const LucyDecimal qc;
public:
Input(
const LucyDecimal * _sellingPrice,
const LucyDecimal _qc);
virtual ~Input();
};
Input::Input(
const LucyDecimal * _sellingPrice, //Ri
const LucyDecimal _qc):sellingPrice(_sellingPrice),qc(_qc)
{};
Input::~Input() {
}
现在:我得到一个分段错误下面做line-b
。它是否与line-a
初始化有关?
但是“sellingPrice_temp”如何获得值? – Jatin
sellingPrice_temp'的'的指针值(http://stackoverflow.com/questions/12936986/why-does-cudamalloc-use-pointer-to-pointer/12937162#12937162)的'cudaMalloc'操作[由设置]为在我的答案中,正如在主机代码中声明'sellingPrice_temp'之后,'malloc'操作返回一个指针值。 –
你这个答案帮助:http://stackoverflow.com/questions/22156536/cudamalloc-of-a-structure-and-an-element-of-same-structure 但在这个问题的答案,你是不是做'cudeMemcpy'为结构。那么它是如何得到'foo'值的呢? – Jatin