2013-06-20 72 views
2

構造函數是否需要包含restrict(amp)才能用於需要使用的結構?例如:C++ AMP構造函數

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

還是應像...

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

回答

1

是。如果你想在AMP內核中構建這些對象。在以下示例中,stuff實例在amp限制parallel_for_each內創建。構造函數需要標記爲restrict(amp)才能正確編譯。

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(); 
    }; 
}; 

我也寫這篇文章作爲博客帖子,Using C++ Classes with C++ AMP