【问题标题】:CUDA:how to call a host function from a global function [duplicate]CUDA:如何从全局函数调用主机函数[重复]
【发布时间】:2017-03-13 02:28:02
【问题描述】:
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,我找到了答案,我应该将 gpu arch 更改为 3.0

    nvcc malloctest.cu -o 1 -gencode=arch=compute_30,code=\"sm_30,compute_30\"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-23
      • 2012-04-13
      • 2012-08-26
      • 1970-01-01
      • 2014-04-11
      • 1970-01-01
      • 1970-01-01
      • 2017-10-29
      相关资源
      最近更新 更多