CUDA: Calling a __device__ function from a kernel

后端 未结 1 926
心在旅途
心在旅途 2021-02-12 12:16

I have a kernel that calls a device function inside an if statement. The code is as follows:

__device__ void SetValues(int *ptr,int id)
{
    if         


        
相关标签:
1条回答
  • 2021-02-12 13:08

    CUDA actually inlines all functions by default (although Fermi and newer architectures do also support a proper ABI with function pointers and real function calls). So your example code gets compiled to something like this

    __global__ void Kernel(int *ptr)
    {
        if(threadIdx.x<2)
            if(ptr[threadIdx.x]==threadIdx.x)
                ptr[threadIdx.x]++;
    }
    

    Execution happens in parallel, just like normal code. If you engineer a memory race into a function, there is no serialization mechanism that can save you.

    0 讨论(0)
提交回复
热议问题