【问题标题】:C++ AMP in Visual Studio 2015: Compiler/runtime bug or buggy sample?Visual Studio 2015 中的 C++ AMP:编译器/运行时错误或错误示例?
【发布时间】: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


【解决方案1】:

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

请看截图:

【讨论】:

    【解决方案2】:

    这可能是关键:

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

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

    您可能有机会尝试使用软件模拟器调试构建。如果您使用的是 Windows 8 或更高版本,请尝试在解决方案资源管理器中的调试下编辑属性,然后查看调试器类型列表中可用的选项。看看不使用 GPU 是否有助于尝试这一点。

    【讨论】:

    • 嗨,谢谢 - 不幸的是,我在解决方案资源管理器中找不到仅涉及 GPU 等的选项。我在调试时唯一能找到的是设置“Amp 默认加速器”,它可以设置为“WARP 软件加速器”(它已经存在)或“使用 C++ AMP 运行时默认值”。我尝试将其更改为后者,但完全相同的错误仍然存​​在。此外,原来的设置似乎已经是使用软件了(可能是因为项目处于调试模式)。
    • 任何人都可以在他们的系统上尝试上述示例吗?谢谢!
    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-25
      • 1970-01-01
      • 2016-08-30
      • 1970-01-01
      • 1970-01-01
      • 2010-10-09
      相关资源
      最近更新 更多