Yes. If you want to construct those objects within an AMP kernel. In the example below stuff
instances are created on within the amp
restricted parallel_for_each
. The constructor needs to be marked as restrict(amp)
in order to compile correctly.
class stuff
{
public:
int a;
stuff(int v) restrict(amp, cpu)
: a(v) { }
};
class test_case
{
public:
test_case() { }
void test_amp()
{
concurrency::array_view<stuff, 1> data(100);
concurrency::parallel_for_each(data.extent,
[data](concurrency::index<1> idx) restrict(amp)
{
data[idx] = stuff(s.a * s.a);
});
data.synchronize();
};
};
I also wrote this up as a blog post, Using C++ Classes with C++ AMP.