【发布时间】:2015-09-13 20:35:37
【问题描述】:
我想试用 Microsoft 文档中的以下 C++ AMP 代码示例:
(https://msdn.microsoft.com/en-us/library/hh265136.aspx 上的第二个代码示例,稍作修改以将其变成程序):
#include "stdafx.h"
#include <amp.h>
#include <iostream>
using namespace concurrency;
const int size = 5;
void CppAmpMethod() {
int aCPP[] = { 1, 2, 3, 4, 5 };
int bCPP[] = { 6, 7, 8, 9, 10 };
int sumCPP[size];
// Create C++ AMP objects.
array_view<const int, 1> a(size, aCPP);
array_view<const int, 1> b(size, bCPP);
array_view<int, 1> sum(size, sumCPP);
sum.discard_data();
parallel_for_each(
// Define the compute domain, which is the set of threads that are created.
sum.extent,
// Define the code to run on each thread on the accelerator.
[=](index<1> idx) restrict(amp)
{
sum[idx] = a[idx] + b[idx];
}
);
// Print the results. The expected output is "7, 9, 11, 13, 15".
for (int i = 0; i < size; i++) {
std::cout << sum[i] << "\n";
}
}
int main()
{
CppAmpMethod();
return 0;
}
不幸的是,在编译(使用 Visual Studio 2015)并执行时,这会导致第一个 array_view 构造出现运行时异常。
'ConsoleApplication2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\nvwgf2um.dll'. Cannot find or open the PDB file.
'ConsoleApplication2.exe' (Win32): Loaded 'C:\Windows\SysWOW64\psapi.dll'. Cannot find or open the PDB file.
Exception thrown at 0x0F9CC933 (vcamp140d.dll) in ConsoleApplication2.exe: 0xC0000005: Access violation reading location 0xCDCDCDCD.
我想知道这么简单的代码示例怎么会失败得如此严重。是错误的示例代码还是编译器?当然,它也可能是我的系统特有的东西,因为毕竟使用 C++ AMP 可能涉及与图形驱动程序等的低级交互,这可能会触发那里的错误。任何帮助将不胜感激!
【问题讨论】:
-
此处与 Windows 7 和 Visual Studio 2015 版本 14.0.23107.0 D14REL 相同。在 Release 下运行。
-
在另一台装有 Windows 7 和 Visual Studio 2015 版本 14.0.24720.00 更新 1 的机器上正常。
-
4 年过去了,没什么变化,Win10 上的 VS2019。
-
悲哀 - 即使驱动程序等涉及错误现象,这仍然意味着AMP API对于任何客户端应用程序的使用基本上没有用,因为微软最简单的示例程序在主流机器上失败了。
-
好吧,4 年过去了,所以在 VS2019 中再次尝试。现在它甚至无法编译(amp.h(2616): error C3861: '_Access': identifier not found)! IE。 amp.h 头文件本身存在语法错误。该错误无法通过重新排序或首先包含 Windows.h 或类似内容来解决。显然正在修复(2019 年 5 月):developercommunity.visualstudio.com/content/problem/200035/…。想知道有多少人在使用 C++ AMP?它接受了多少测试? ;)
标签: visual-studio-2015 c++-amp