次の方法で共有


runtime_exception of C++ AMP

This blog post assumes you have read the introduction to C++ AMP exceptions.

The runtime_exception is the base class of the all other C++ AMP exceptions. Hence this exception can be treated as the exception to be caught by default. The table below lists various scenarios that result in runtime exceptions. These scenarios throw runtime_exception as they don’t have a more specific exception defined for their requirement.

   

Scenario

Exception Message

Code Snippet

Failure to create the accelerator

No accelerator with the specified path available

/* Executing the below code on a machine that does not have the DirectX SDK or Visual Studio 11 installed, throws runtime_exception */

try

{

  accelerator a(accelerator::direct3d_ref);

}

catch(runtime_exception& ex)

{

  std::cout << ex.what() << std::endl;

}

Mismatched accelerators

At least one of the array or texture objects referenced in the entry function of the parallel_for_each call is not on the specified target accelerator_view

/* Array object is created using default accelerator ( assuming Direct3D reference device is not default ) and p_f_e is executed on Direct3d Ref accelerator. */

accelerator a;

accelerator ref_a(accelerator::direct3d_ref);

concurrency::extent<1> ext(256);

array<int,1> intArr(ext, a.default_view);

try

{

  parallel_for_each(ref_a.default_view,ext,[&](index<1> idx) restrict(amp){

     intArr[idx] += idx[0];

  });

}

catch(runtime_exception& ex)

{

  std::cout << ex.what() << std::endl;

}

Failed to Create Huge Data Container

Failed to create buffer

/* Creation of huge ‘int’ array of size 1024 * 1024 * 1024 on a GPU machine, that doesn’t have enough memory, throws runtime exception */

try

{

  concurrency::extent<1> ext(1024 * 1024 * 1024);

  array<int, 1> src( ext);

}

catch(runtime_exception& ex)

{

  std::cout<< ex.what() << std::endl;

}

Invalid Extent

Invalid - values for each dimension must be > 0

try

{

  concurrency::extent<2> ext(20,0);

  array<int,2> src(ext); //throws

}

catch(runtime_exception& ex)

{

   std::cout<< ex.what() << std::endl;

}

Mismatched Extents of src and dest in copy/copy async apis

Failed to copy because extents do not match

std::vector<int> intVect(15);

array_view<int, 2> srcArrayView1(3, 5, intVect);

array_view<int, 2> destArrayView1(5, 3, intVect);

try

{

  copy(srcArrayView1, destArrayView1);

}

catch(runtime_exception& ex)

{

  std::cout<< ex.what() << std::endl;

}

Invalid sizes for copy operation

Invalid _Src argument(s). _Src size exceeds total size of the _Dest.

std::vector<int> initVector(257,0);

array<int,1> intArr(256);

try

{

  copy(initVector.begin(),initVector.end(),intArr);

}

catch(runtime_exception& ex)

{

  std::cout<< ex.what() << std::endl;

}

Limited/Full double_precision support

concurrency::parallel_for_each uses features (full double_precision)unsupported by the selected accelerator.

/*Execution of below code on an accelerator that does n’t support doubles throws runtime exception */

accelerator a;

accelerator_view av = a.default_view;

concurrency::extent<1> ext(1024);

array<double,1> arr(ext, av);

try

{

  parallel_for_each(ext,[&](index<1> idx) restrict(amp)

  {

    arr[idx] /= 1.1;

  });

}

catch(runtime_exception& ex)

{

  std::cout<< ex.what() << std::endl;

}

 

This is all the information about runtime_exception. My next blog post will cover invalid_compute_domain exception.