我想尝试一下微软文档中的以下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 Studio2015)并执行时,这会在第一个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可能会涉及到与图形驱动程序等的低级交互,这可能会在那里触发错误。任何帮助都将不胜感激!
发布于 2015-11-19 17:48:56
您应该将调试器类型更改为GPU Only。
请看截图:
发布于 2015-09-14 04:50:52
这可能是关键:
“因为毕竟使用C++ AMP可能涉及到与图形驱动程序等的低级交互,这可能会在那里触发错误。”
示例应该可以工作,但您需要有正确的DirectX11驱动程序。
您可能会尝试使用软件仿真器来调试构建。如果使用的是Windows8或更高版本,请尝试在解决方案资源管理器中的“调试”下编辑属性,并查看调试器类型列表中的可用选项。看看不使用GPU是否只会帮助你尝试一下。
发布于 2016-11-16 05:12:49
我有完全相同的问题,调试构建抛出异常(发布构建没有),对我有效的解决方案是,更新(修复安装) Visual studio,即使我有最新的构建2015更新3,然后安装最新的图形驱动程序。我不知道主要原因是什么,但我认为图形驱动程序...
https://stackoverflow.com/questions/32554295
复制相似问题