Search code examples
cudaoverloadingnvcc

Cannot overload make_uint4 function


I'm trying to overload make_uint4 in the following manner:

namespace A {
  namespace B {
    inline __host__ __device__ uint4 make_uint4(uint2 a, uint2 b) {                                                                                                         
      return make_uint4(a.x, a.y, b.x, b.y);                                                                                                                              
    }
  }
}

But when I try to compile it, nvcc returns an error:

error: no suitable constructor exists to convert from "unsigned int" to "uint2"
error: no suitable constructor exists to convert from "unsigned int" to "uint2"
error: too many arguments in function call

All these errors point to the "return…" line.


Solution

  • I was able to get a partial repro on VS 2010 and CUDA 4.0 (the compiler built the code OK but Intellisense flagged the error you are seeing). Try the following:

    #include "vector_functions.h"
    
    inline __host__ __device__ uint4 make_uint4(uint2 a, uint2 b)    
    {        
        return ::make_uint4(a.x, a.y, b.x, b.y);
    }
    

    This fixed it for me.