device/host function with the same name

Is it somehow possible to define different implementation for the host and the device function?
nvcc keeps complaining about invalid redeclaration of member function “A::foo()”.

struct A {
device void foo() {
// implementation device
}
host void foo() {
// implementation host
}
};

If disallowing same names on the device and the host is a good design feature could someone explain why this would be good to have?

Frank

struct A {

    __host__ __device__ void foo()

    {

#ifdef __CUDA_ARCH__

        // device implementation

#else

        // host implementation

#endif

    }

};
1 Like