I'm using VC++11 and would like to know how I can create an array of arbitrary length in an amp restricted function:
1 2 3 4 5
void mystruct::memberfun(unsignedint size) restrict(amp)
{
int arr1[size]; // ERROR Expression must have a constant value
int arr2[10]; // ok, but I don't want it to be constant!
}
Were you expecting line 3 to work with Visual C++?
While GCC lets you do that, as it supports C99's variable length arrays, this is one language feature where Visual C++ has always agreed with the Ansi C++ standard: that the size of an array must be const, unless it's dynamically allocated.
From what I've seen, the AMP retrictions say nothing about operator new. So plexus suggestion should be fine, though std::vector would be better (which I've seen it used the AMP samples.)
You cannot "new" anything in amp restricted functions unfortunately...
Were you expecting line 3 to work with Visual C++?
No, I'm grasping at straws. I've tried asking over at the MSDN forums but they don't seem to actually respond to questions.
Vectors are completely forbidden, as are concurrrency::array constructors. As far as I can tell it's not possible to declare arrays of arbitrary length on the accelerator, which is somewhat of a crippling restriction.
If anyone finds anything to the contrary please do post back!
That function is not amp-restricted, so it won't work either. I think you just can't do it... It's ok because there are ways of working around it, but it's quite cumbersome.