当尝试使用cudaMemcpy分配的值打印arrary的值时,我得到了一个核心转储。以下是代码。
我使用CUDA10在Unbuntu中运行此代码
#include <iostream>
using namespace std;
int main() {
int numMat = 2;
int* data = (int*)malloc(numMat * sizeof(int));
data[0]= 1;
data[1]= 3;
int* d_data;
cudaMalloc(&d_data, numMat*sizeof(int));
cudaMemcpy(d_data, data, numMat*sizeof(int), cudaMemcpyHostToDevice);
cout<<"---- Here the core-dump happens ----"<<endl;
for (int i=0; i<numMat; i++){
cout<<d_data[i]<<endl;
}
return 0;
}
输出为:
1 3
---- Here the core-dump happens ----
Segmentation fault (core dumped)