gpt4 book ai didi

visual-studio-2015 - Visual Studio 2015 中的 C++ AMP : Compiler/runtime bug or buggy sample?

转载 作者:行者123 更新时间:2023-12-04 20:37:35 25 4
gpt4 key购买 nike

我想尝试以下来自 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 可能涉及与图形驱动程序等的低级交互,这可能会触发那里的错误。任何帮助将不胜感激!

最佳答案

您应该将调试器类型更改为 仅 GPU .

请看截图:

enter image description here

关于visual-studio-2015 - Visual Studio 2015 中的 C++ AMP : Compiler/runtime bug or buggy sample?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32554295/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com