首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Visual Studio2015中的C++ AMP :编译器/运行时错误还是错误示例?

Visual Studio2015中的C++ AMP :编译器/运行时错误还是错误示例?
EN

Stack Overflow用户
提问于 2015-09-14 04:35:38
回答 3查看 1.2K关注 0票数 5

我想尝试一下微软文档中的以下C++ AMP代码示例:

( https://msdn.microsoft.com/en-us/library/hh265136.aspx上的第二个代码示例,稍作调整以将其转换为程序):

代码语言:javascript
运行
复制
#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构造上导致运行时异常。

代码语言:javascript
运行
复制
'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可能会涉及到与图形驱动程序等的低级交互,这可能会在那里触发错误。任何帮助都将不胜感激!

EN

回答 3

Stack Overflow用户

发布于 2015-11-19 17:48:56

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

请看截图:

票数 2
EN

Stack Overflow用户

发布于 2015-09-14 04:50:52

这可能是关键:

“因为毕竟使用C++ AMP可能涉及到与图形驱动程序等的低级交互,这可能会在那里触发错误。”

示例应该可以工作,但您需要有正确的DirectX11驱动程序。

您可能会尝试使用软件仿真器来调试构建。如果使用的是Windows8或更高版本,请尝试在解决方案资源管理器中的“调试”下编辑属性,并查看调试器类型列表中的可用选项。看看不使用GPU是否只会帮助你尝试一下。

票数 1
EN

Stack Overflow用户

发布于 2016-11-16 05:12:49

我有完全相同的问题,调试构建抛出异常(发布构建没有),对我有效的解决方案是,更新(修复安装) Visual studio,即使我有最新的构建2015更新3,然后安装最新的图形驱动程序。我不知道主要原因是什么,但我认为图形驱动程序...

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32554295

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档