What is: __host__ __device__

I’m seeing “host device” in some code samples.
Does this mean the code can run on either the host or the GPU?

Why would I use it? (How is this useful?)


Sometimes the same functionality is needed in both the host and the device portions of CUDA code. To avoid code duplication, CUDA allows such functions to carry both host and device attributes, which means the compiler places one copy of that function into the host compilation flow (to be compiled by the host compiler, e.g. gcc or MSVC), and a second copy into the device compilation flow (to be compiled with NVIDIA’s CUDA compiler).