2017-03-13 12 views
0
1 #include<stdlib.h> 
    2 #include<stdio.h> 
    3 #include"cuda.h" 
    4 __global__ void malloctest() 
    5 { 
    6   char * ptr=(char *)malloc(123); 
    7   printf("thread %d got a pointer:%p\n",threadIdx.x,ptr); 
    8   free(ptr); 
    9 } 
10 int main() 
11 { 
12   cudaDeviceSetLimit(cudaLimitMallocHeapSize,128*1024*1024); 
13   malloctest<<<1,5>>>(); 
14   cudaDeviceSynchronize(); 
15   return 0; 
16 } 



nvcc warning : The 'compute_10' and 'sm_10' architectures are deprecated, and may be removed in a future release. 
malloctest.cu(6) (col. 9): error: calling a __host__ function("malloc") from a __global__ function("malloctest") is not allowed 

malloctest.cu(7): error: calling a __host__ function("printf") from a __global__ function("malloctest") is not allowed 

malloctest.cu(8): error: calling a __host__ function("free") from a __global__ function("malloctest") is not allowed 

どのようにして利用できるようにしますか?おかげCUDA:グローバル関数からホスト関数を呼び出す方法

答えて

1

eが、私は答えを見つける、私は3.0

nvcc malloctest.cu -o 1 -gencode=arch=compute_30,code=\"sm_30,compute_30\" 
にGPUのアーチを変更する必要があります
関連する問題