Can I use user-defined types with C++ AMP?

Hi everyone,
I posted this on the MSDN Forums (http://social.msdn.microsoft.com/Forums/en-US/parallelcppnative/thread/545f5b0f-d97c-4f7d-b94c-f8f789fbd27f) but didn't get an answer, so I thought I'd try here. I don't know if this would be considered outside of the scope of this forum, but I'm trying to modify my code to start using it GPGPUs, and would like to know if I can use user-defined types.

Based on my understanding I can create arrays of structs as long as those structs don't contain any pointers or other user defined/non fundamental types or types that aren't AMP-supported (such as char, short, etc). So for example, would the following be ok?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <amp.h>
#include <iostream>
using namespace concurrency;

struct data
{
    data(float var1,float var2,size_t idx) :
        var1(var1),var2(var2),idx(idx)
    {}
    // ... a whole bunch of constructors and functions that shouldn't matter, right?

    // these are all AMP-supported types, right?
    float var1;
    float var2;
    int idx;
};

void MyFirstAmpFunction() 
{
    size_t size = 5;

    std::array<data,size> myarr1
    // fill myarr1 with stuff

    std::array<data,size> myarr2
    // fill myarr2 with stuff

    int resultarr[size];
    
    // Create C++ AMP objects.
    array_view<const data, 1> a1(size, myarr1);
    array_view<const data, 1> a2(size, myarr2);
    array_view<int, 1> result(size, resultarr);
    result.discard_data();

    parallel_for_each(
        result.extent,
        [=](index<1> idx) restrict(amp)
        {
            result[idx] = a1.idx * (int) (a1.var1 + a2.var2);
        }
    );
}
Last edited on
Topic archived. No new replies allowed.