Difference between global and device functions

后端 未结 9 1613
渐次进展
渐次进展 2021-01-29 20:10

Can anyone describe the differences between __global__ and __device__ ?

When should I use __device__, and when to use __glob

9条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-29 21:00

    I will explain it with an example:

    main()
    {
        // Your main function. Executed by CPU
    }
    
    __global__ void calledFromCpuForGPU(...)
    {
      //This function is called by CPU and suppose to be executed on GPU
    }
    
    __device__ void calledFromGPUforGPU(...)
    {
      // This function is called by GPU and suppose to be executed on GPU
    }
    

    i.e. when we want a host(CPU) function to call a device(GPU) function, then 'global' is used. Read this: "https://code.google.com/p/stanford-cs193g-sp2010/wiki/TutorialGlobalFunctions"

    And when we want a device(GPU) function (rather kernel) to call another kernel function we use 'device'. Read this "https://code.google.com/p/stanford-cs193g-sp2010/wiki/TutorialDeviceFunctions"

    This should be enough to understand the difference.

提交回复
热议问题