locked
Memory leak in C++Amp using direct3d_warp? RRS feed

  • Question

  • I am a relative novice using C++Amp, and am having a problem with runaway memory usage using the Warp accelerator in debug builds in my application.  I am using Visual Studio 2015 14.0.25431.01 Update 3, running on Windows 7.

    I've reduced the problem to the following test code, which quickly causes memory usage to explode using the emulated Warp accelerator (but not the default, non-emulated accelerator, tested on NVidia Ti650 Boost and NV Ti1050):

    #include <amp.h>
    #include <iostream>
    
    int main()
    {
        std::vector<concurrency::accelerator> accls = concurrency::accelerator::get_all();
        std::wcout << L"Found " << accls.size() << L" C++ AMP accelerator(s):" << std::endl;
        std::for_each(accls.cbegin(), accls.cend(), [](const concurrency::accelerator& a)
        {
            std::wcout << L"  " << a.device_path << L"    " << a.description << (a.is_emulated ? L"(emulated" : L"") << std::endl;
        });
        std::wcout << std::endl;
    
        // If we change this #if 1 to #if 0, memory usage stabilizes around 350 MB
    #if 1
        // Filter out non-emulated accelerators (we want direct3dwarp)
        accls.erase(std::remove_if(accls.begin(), accls.end(), [](concurrency::accelerator& a)
        {
            return !a.is_emulated;
        }), accls.end());
        if ( !accls.empty() )
        {
            concurrency::accelerator::set_default(accls[0].device_path);
        }
    #endif
    
        concurrency::accelerator defaultAccelerator;
        std::wcout << L"C++AMP: Device:     " << defaultAccelerator.device_path << std::endl;
        std::wcout << L"C++AMP: Memory:     " << defaultAccelerator.get_dedicated_memory() / 1024 << " MB" << std::endl;
        std::wcout << L"C++AMP: IsEmulated: " << (defaultAccelerator.get_is_emulated() ? L"True" : L"False") << std::endl;
        std::wcout << L"C++AMP: SharedMem:  " << (defaultAccelerator.get_supports_cpu_shared_memory() ? L"True" : L"False") << std::endl;
        std::wcout << L"C++AMP: " << (defaultAccelerator.supports_double_precision ?
            L"Double precision: true" : L"Double precision: false") << std::endl;
    
        concurrency::array<int, 2>      theArray( int(16*1024*1024), 4 );
        concurrency::array_view<int, 2> theView( theArray );
    
        for (;;)
        {
            concurrency::extent<2> computeExtent( theView.extent[0], 1 );
    
            parallel_for_each(computeExtent, [=](concurrency::index<2> idx) restrict(amp)
            {
            });
        }
    }
    
    

    Any clues to understanding why this is happening would be appreciated.  Is it a memory leak, or my improper usage?  Something else?

    Thanks.

    Tuesday, December 19, 2017 5:54 PM