Unsupported type error with parallel_for_each

921 Views Asked by At

I'm playing around with C++ AMP but for some reason the most dumbed down code won't compile. This:

concurrency::extent<2> e(2,2);

concurrency::parallel_for_each(grid<2>(e), [](index<2> i) restrict(direct3d) {
});

results in the following error:

error C3576: 'wmain::': Concurrency::details::_Parallel_for_each argument #3 has unsupported type c:\program files (x86)\microsoft visual studio 11.0\vc\include\amp.h

It just doesn't appear to like the lambda expression being passed for const _Kernel_type& _Kernel

Note; I'm using Visual Studio 11 Developer Preview which includes AMP support. "restrict(direct3d)" is a new keyword to support controlling which accelerator runs the code in question.

Any ideas? I've tried copying from a few different examples but nothing works so I'm a bit stumped.

2

There are 2 best solutions below

2
On BEST ANSWER

Your lambda passed to parallel_for_each is an empty class (no variables are captured, therefore there are no data members). You cannot have any useful computation without data, that is why you are getting an error.

Please add concurrency::array or concurrency::array_view to your example, like so:

using namespace concurrency;
extent<2> e(2,2);
array<int, 2> a(e);

parallel_for_each(grid<2>(e), [&a](index<2> i) restrict(direct3d) {
    a[i] = 1;
});

Note: This applies only to Visual Studio 11 Developer Preview. The behavior will change in upcoming Beta release. Your code will compile as is, without any errors. Passing empty class would simply not do anything.

4
On

Well, as far as I know the restrict keyword is an extension Microsoft introduced for C++ AMP. The keyword will be supported by the Visual Studio C++ compiler that comes after Visual Studio 2010.

I am unaware at this time of a beta release of 2012, so my guess is that you found examples, blogs and so on describing the new C++ AMP and you are trying to see it working for yourself but with Visual Studio 2010.

The C++ compiler that ships with the Visual Studio 2010 however does not support the restrict keyword as far as I know. This is why you are getting the error.

So I guess for C++ AMP we will have to wait a little for a VS2012 beta release until we can play with it. My fingers certainly itched also when I saw some demo by Daniel Moth on Channel 9 :-)... Not that I need C++ AMP in my daily work, but it looks like pretty interesting (play) stuff.

EDIT1: Actually I looked around and it seems that there is a "Visual Studio 11 Developer Preview" release where C++ AMP seems to be available (library and I assume also the C++ compiler with the implemented extensions).

EDIT2 Now looking again at your error message it would seem that you are using VS11 (I made that guess based on the path to the include file (it contains microsoft visual studio 11.0 :-) ). Maybe you should try to specify the capture mode of the lambda to capture by value and make it mutable like this:

[=](index<2> i) mutable restrict(direct3d) {}

At least this is how the lambda is written in most C++ AMP examples...