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:%pn",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
如何使其可用?谢谢
e,我找到答案,我应该将gpu拱门更改为3.0
nvcc malloctest.cu -o 1 -gencode=arch=compute_30,code="sm_30,compute_30"