2

Do constructors for a struct that will be used in amp code need to have restrict(amp) included? Ex:

struct Foo { inline Foo(void) { } float a; }; 

Or should it be like...

struct Foo { inline Foo(void) restrict(amp) { } float a; }; 

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.