parallel_for_each 不支持的类型错误
我正在使用 C++ AMP,但由于某种原因,最简单的代码无法编译。这
concurrency::extent<2> e(2,2);
concurrency::parallel_for_each(grid<2>(e), [](index<2> i) restrict(direct3d) {
});
会导致以下错误:
错误 C3576:“wmain::”: Concurrency::details::_Parallel_for_each 参数 #3 不受支持 输入 c:\program files (x86)\microsoft Visual Studio 11.0\vc\include\amp.h
它似乎不喜欢为 const _Kernel_type& 传递 lambda 表达式。 _Kernel
注意;我正在使用包含 AMP 支持的 Visual Studio 11 开发人员预览版。 “restrict(direct3d)”是一个新关键字,用于支持控制哪个加速器运行相关代码。
有什么想法吗?我尝试复制几个不同的示例,但没有任何效果,所以我有点困惑。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
传递给parallel_for_each 的 lambda 是一个空类(没有捕获任何变量,因此没有数据成员)。如果没有数据,你就无法进行任何有用的计算,这就是你收到错误的原因。
请将 concurrency::array 或 concurrency::array_view 添加到您的示例中,如下所示:
注意: 这仅适用于 Visual Studio 11 开发人员预览版。该行为将在即将发布的 Beta 版本中发生变化。您的代码将按原样编译,不会出现任何错误。通过空类根本不会做任何事情。
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:
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.
嗯,据我所知 restrict 关键字是 Microsoft 为 C++ AMP 引入的扩展。 Visual Studio 2010 之后的 Visual Studio C++ 编译器将支持该关键字。
目前我还不知道 2012 年的测试版,所以我的猜测是您找到了描述新 C++ AMP 的示例、博客等您正在尝试查看它是否适用于您自己,但适用于 Visual Studio 2010。
然而,据我所知,Visual Studio 2010 附带的 C++ 编译器不支持 limit 关键字。这就是您收到错误的原因。
所以我想对于 C++ AMP,我们将不得不等待 VS2012 beta 版本,直到我们可以使用它。当我在 Channel 9 上看到 Daniel Moth 的一些演示时,我的手指当然也很痒:-)...并不是说我在日常工作中需要 C++ AMP,但它看起来非常有趣(玩)的东西。
EDIT1:实际上我环顾四周,似乎有一个
“Visual Studio 11 开发人员预览版”版本,其中 C++ AMP 似乎可用(库,我假设还有带有已实现扩展的 C++ 编译器)。
EDIT2 现在再次查看您的错误消息,您似乎正在使用 VS11 (我根据包含文件的路径进行了猜测(它包含 microsoft Visual Studio 11.0 :-) )。也许您应该尝试指定 lambda 的捕获模式以按值捕获并使其可变:
至少这是在大多数 C++ AMP 示例中编写 lambda 的方式...
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:
At least this is how the lambda is written in most C++ AMP examples...