Mor*_*rty 5 c++-amp visual-studio-2015
我想尝试以下来自Microsoft文档的C ++ AMP代码示例:
(https://msdn.microsoft.com/zh-cn/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;
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,在编译(使用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.
Run Code Online (Sandbox Code Playgroud)
我想知道这样一个简单的代码示例如何会如此严重地失败。是示例代码错误还是编译器?当然这也可能是我的系统所特有的,因为毕竟使用C ++ AMP可能涉及与图形驱动程序等的低级交互,这可能会触发那里的错误。任何帮助将不胜感激!
这可能是关键:
“因为毕竟使用 C++ AMP 可能涉及与图形驱动程序等的低级交互,这可能会触发那里的错误。”
该示例应该可以工作,但您需要有正确的 DirectX11 驱动程序。
您可能有机会尝试使用软件模拟器调试构建。如果您使用的是 Windows 8 或更高版本,请尝试在解决方案资源管理器中的调试下编辑属性,并查看调试器类型列表中的可用选项。看看不使用 GPU Only 是否有助于尝试这个。
| 归档时间: |
|
| 查看次数: |
937 次 |
| 最近记录: |