out_of_memory exception of C++ AMP

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

An instance of the out_of_memory exception type is thrown when an underlying OS/DirectX API call fails due to failure to allocate system or device memory. Operations like parallel_for_each execution, copying data, accelerator.wait , Stage buffer creations, Data buffer creations etc. involve calling underlying OS/DirectX APIs.


Exception Message

Code Snippet

Stage buffer creation between two accelerators.

Failed to create staging buffer

/* The below code creates large stagingbuffer of size 1024 * 1024 * 512 (2GB) between cpu accelerator and default accelerator.out_of_memory exception is thrown based on the availability of memory */



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

    accelerator gpu;

    accelerator cpu(accelerator::cpu_accelerator);

    array<int, 1> src(ext,cpu.default_view,gpu.default_view);


catch(out_of_memory& ex)


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



My next blog post covers accelerator_view_removed exception, the last one of C++ AMP Exceptions.

Comments (0)