How to make a kernel function which callable from both the host and device?

前端 未结 2 1866
忘掉有多难
忘掉有多难 2021-01-13 15:58

The following trial presents my intention, which failed to compile:

__host__ __device__ void f(){}

int main()
{
    f<<<1,1>>>();
}
         


        
2条回答
  •  清歌不尽
    2021-01-13 16:09

    The tutorial you are looking at is so old, 2008? It might not be compatible with the version of CUDA you are using.

    You can use __global__ and that means __host__ __device__, this works:

    __global__ void f()
    {
        const int tid = threadIdx.x + blockIdx.x * blockDim.x;
    }
    
    int main()
    {
        f<<<1,1>>>();
    }
    

提交回复
热议问题