So I read the article here http://blogs.msdn.com/b/nativeconcurrency/archive/2012/03/29/function-overloading-with-restrict-in-c-amp.aspx that was very useful.
However I had an issue with overloading and restrict when namespaces are used. I was using the erfc function which is in Concurrency::precise_math but not in the VS12 standard C++ library yet. So I was going to implement my own for restrict(cpu) and then
write a restrict(amp,cpu) function that would call either depending on restriction. So the following
#include <amp_math.h>
using namespace concurrency::precise_math;
double erfc( double x )
{
return( x * 100.0 ); // Do something useful in reality
}
double foo( double x ) restrict(amp,cpu)
{
double y = erfc( x );
return( y );
}
compiled fine. However the following
#include <amp_math.h>
using namespace concurrency::precise_math;
namespace Bar
{
double erfc( double x )
{
return( x * 100.0 );
}
double foo( double x ) restrict(amp,cpu)
{
double y = erfc( x );
return( y );
}
}
which just has the extra namespace added gives the following error
error C3930: 'Bar::erfc' : no overloaded function has restriction specifiers that are compatible with the ambient context 'Bar::foo'
Which I think seems to be wrong as foo should still be able to find both the amp and the cpu restricted versions of erfc.
Note that If I move my restrict(cpu) erfc outside of the Bar namespace and leave foo inside it compiles fine. This seems to imply foo isn't looking up the erfc restrict(cpu) variant correctly. It also causes a lot of problem because I can't start writing
all my low level functions in the global namespace!