聲明一個結構,內帶動態數組如何聲明在裝置一個結構即它的一個成員,是該數組,然後動態分配的內存。例如在下面的代碼中,編譯器說:error : calling a __host__ function("malloc") from a __global__ function("kernel_ScoreMatrix") is not allowed
。有沒有另一種方法來執行此操作?如何在設備
dev_size_idx_threads
的類型是int*
和它的值,發送給內核並用於分配內存。
struct struct_matrix
{
int *idx_threads_x;
int *idx_threads_y;
int thread_diag_length;
int idx_length;
};
struct struct_matrix matrix[BLOCK_SIZE_Y];
matrix->idx_threads_x= (int *) malloc ((*(dev_size_idx_threads) * sizeof(int)));
謝謝。我的設備CC是2.1,如何在Nsight visual studio中設置這個參數?從主機分配,你能舉一個簡單的例子嗎? – mahdimb
我在[link]中找到了更改'sm'參數的答案(http://stackoverflow.com/questions/14411435/how-to-set-cuda-compiler-flags-in-visual-studio-2010) – mahdimb