Jump to content

C++ AMP - System.Runtime.InteropServices.SEHException

DXMember

I have this wierd issue, whenever I try to use large numbers for my C++ AMP code, I get an exception.

I found this number '28931225' which fives me a 50/50 chance to return exception or a correct answer within 2 seconds.

If I go larger than this number the chance to get an exception increases exponentially.

If I go smaller than this number the cnance to get an exception decreases exponentially.

 

The exception it self is quite generic as well.

I am now confus...

 

I really hope for some help.

 

A picture is worth a thousand words:

JU2O40U.png

 

using System;using System.Threading.Tasks;using System.Linq;using System.Collections.Generic;using System.Runtime.InteropServices;class Program{/// <summary>/// Function defined in CPP_AMP.dll to square an array using C++ AMP/// </summary>[DllImport("CPP_AMP", CallingConvention = CallingConvention.StdCall)]extern unsafe static void square_array(float* array, int length);[DllImport("CPP_AMP", CallingConvention = CallingConvention.StdCall)]extern unsafe static void find_primes(int* array, int length);static unsafe void Main(){//// Allocate an array//float[] arr = new[] { 1.0f, 2.0f, 3.0f, 4.0f };//// Square the array elements using C++ AMP//fixed (float* arrPt = &arr[0])//{// square_array(arrPt, arr.Length);//}//// Enumerate the results//foreach (var x in arr)//{// Console.WriteLine(x);//}//Console.ReadKey();again:Console.Clear();Console.WriteLine("Specify the outer bound to search primes for: ");int range;int.TryParse(Console.ReadLine(), out range);range = range < 3 ? 3 : range; Console.ForegroundColor = ConsoleColor.Blue;Console.BackgroundColor= ConsoleColor.White;DateTime start;Console.WriteLine("\nUSING CPU\nSearching primes from \t{0}\tto\t{1}", 3, range);start = DateTime.Now;IEnumerable<int> numbers = Enumerable.Range(3, range-2);var parallelQuery =from n in numbers.AsParallel()where Enumerable.Range(2, (int)Math.Sqrt(n)).All(i => n % i > 0)select n;int[] primes_cpu = parallelQuery.ToArray(); Console.WriteLine("\n\nTime to execute: " + (DateTime.Now - start) + "\nPrimes found: " + primes_cpu.Count() + "\nLargest prime found: " + primes_cpu.Max());Console.ReadKey(true); Console.ForegroundColor = ConsoleColor.Red;Console.BackgroundColor = ConsoleColor.White;Console.WriteLine("\n\nUSING AMP\nSearching primes from \t{0}\tto\t{1}", 3, range);start = DateTime.Now; int[] primes_amp=numbers.ToArray();fixed (int* primePtr = &primes_amp[0]){find_primes(primePtr, primes_amp.Length);}Console.WriteLine("\n\nTime to execute: " + (DateTime.Now - start) + "\nPrimes found: " + primes_amp.Count(x => x != 0) + "\nLargest prime found: " + primes_amp.Max());Console.ResetColor(); try_again:Console.WriteLine("Do you want to run again?\ty/n");ConsoleKeyInfo key=Console.ReadKey(true);if (ConsoleKey.Y == key.Key)goto again;else if (ConsoleKey.N == key.Key)return;elsegoto try_again;}}
#include "stdafx.h"#include "amp.h"#include <iostream>#include <string>using namespace concurrency;using namespace std;extern "C" __declspec (dllexport) void _stdcall square_array(float* arr, int n){// Create a view over the data on the CPUarray_view<float, 1> dataView(n, &arr[0]);// Run code on the GPUparallel_for_each(dataView.extent, [=](index<1> idx) restrict(amp){dataView[idx] = dataView[idx] * dataView[idx];});// Copy data from GPU to CPUdataView.synchronize();}extern "C" __declspec (dllexport) void _stdcall find_primes(int* arr, int n){//Create a view over the data on CPUarray_view<int, 1> dataView(n, &arr[0]);//Run code on GPUparallel_for_each(dataView.extent, [=](index<1> idx) restrict(amp){for (int c = 2; c*c <= dataView[idx]; c++){if (dataView[idx] % c == 0)dataView[idx] = 0;}});//Copy data from GPU to CPUdataView.synchronize();}

CPU: Intel i7 5820K @ 4.20 GHz | MotherboardMSI X99S SLI PLUS | RAM: Corsair LPX 16GB DDR4 @ 2666MHz | GPU: Sapphire R9 Fury (x2 CrossFire)
Storage: Samsung 950Pro 512GB // OCZ Vector150 240GB // Seagate 1TB | PSU: Seasonic 1050 Snow Silent | Case: NZXT H440 | Cooling: Nepton 240M
FireStrike // Extreme // Ultra // 8K // 16K

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×