我是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