2

我正在尝试使用 C++ AMP 在 GPU 上执行长时间运行的内核。这需要使用 DirectX 创建一个不会超时的设备。我正在设置标志,但它仍在触发超时检测恢复。我的盒子里有一个专用的 Radeon HD 7970,没有插入显示器。我还需要做些什么来防止 Windows 8 在内核完成之前取消它吗?

#include <amp.h>
#include <amp_math.h>
#include <amp_graphics.h>
#include <d3d11.h>
#include <dxgi.h>

#include <vector>
#include <iostream>
#include <iomanip>
#include "amp_tinymt_rng.h"
#include "timer.h"
#include <assert.h>

#pragma comment(lib, "d3d11")
#pragma comment(lib, "dxgi")

//Inside Main()
    unsigned int createDeviceFlags = D3D11_CREATE_DEVICE_DISABLE_GPU_TIMEOUT;
    ID3D11Device * pDevice = nullptr;
    ID3D11DeviceContext * pContext = nullptr;
    D3D_FEATURE_LEVEL targetFeatureLevels = D3D_FEATURE_LEVEL_11_1;
    D3D_FEATURE_LEVEL featureLevel;
    auto hr = D3D11CreateDevice(pAdapter, 
                            D3D_DRIVER_TYPE_UNKNOWN, 
                            nullptr, 
                            createDeviceFlags, 
                            &targetFeatureLevels, 
                            1, 
                            D3D11_SDK_VERSION, 
                            &pDevice, 
                            &featureLevel, 
                            &pContext);

    if (FAILED( hr) || 
        ( featureLevel != D3D_FEATURE_LEVEL_11_1))
    { 
        std:: wcerr << "Failed to create Direct3D 11 device" << std:: endl; 
        return 10; 
    }

accelerator_view noTimeoutAcclView = concurrency::direct3d::create_accelerator_view(pDevice);
wcout << noTimeoutAcclView.accelerator.description;

//Setup kernal here
concurrency::parallel_for_each(noTimeoutAcclView, e_size, [=] (index<1> idx) restrict(amp) {
   //Execute kernel here
});
4

1 回答 1

2

您的代码段看起来不错,问题必须出在其他地方。这里有几个想法:

  • 请仔细检查所有parallel_for_each 调用,并确保它们都使用您使用此代码段创建的设备的Accelerator_view(显式将Accelerator_view 作为第一个参数传递给parallel_for_each)。

  • If possible reduce the problem size and see if your code runs without TDR, perhaps something else is causing a TDR (e.g. driver bugs are common cause of TDRs). Once you will know that your algorithm runs correctly for smaller problem you can go back to searching why is TDR triggered for larger problem size.

  • Disable TDR completely (see MSDN article on TDR registry keys) and see if your large problem set ever completes, if so go back to first point. This will indicate that your code runs on accelerator_view that has TDR enabled.

Good luck!

于 2012-12-10T17:20:25.543 回答