Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ AMP in Visual Studio 2015: Compiler/runtime bug or buggy sample?

I would like to try out the following C++ AMP code sample from Microsoft's documentation:

(Second code sample on https://msdn.microsoft.com/en-us/library/hh265136.aspx, slightly adapted to turn it into a program):

#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;
}

Unfortunately when compiled (using Visual Studio 2015) and executed this causes a run-time exception on the first of the array_view constructions.

'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.

I am wondering how such a simple code sample could fail so badly. Is it the sample code that is wrong or is it the compiler? It could of course also be something particular to my system, since after all using C++ AMP might involve low-level interaction with the graphics driver etc. which could trigger bugs there. Any help would be greatly appreciated!

like image 574
Morty Avatar asked Oct 20 '22 02:10

Morty


1 Answers

You should change the Debugger Type to GPU Only.

Please see the screenshot:

enter image description here

like image 119
Cloud Wu Avatar answered Jan 04 '23 06:01

Cloud Wu