2012-12-10 30 views
2

我想用C++ AMP在GPU上執行長時間運行的內核。這需要使用DirectX創建一個不會超時的設備。我正在設置標誌,但它仍然觸發超時檢測恢復。我的盒子裏沒有插入顯示器,我有一個專用的Radeon HD 7970。還有什麼我需要做的,以防止Windows 8在完成之前取消我的內核?DirectX 11.1試圖創建設備不觸發超時檢測恢復

#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 
}); 

回答

2

您的代碼片段看起來不錯,問題必須在其他地方。這裏有一些想法:

  • 請仔細檢查所有parallel_for_each調用,並確保 它們都使用accelerator_view與你 這個片段創建的設備(明確地傳遞accelerator_view作爲第一個參數parallel_for_each)。

  • 如果可能的話,請減少問題的大小,並查看您的代碼是否在沒有 TDR的情況下運行,也許別的東西導致TDR(例如,驅動程序錯誤是TDR的常見原因)。一旦您知道您的算法正確運行以解決較小的問題,您可以回到搜索爲何更大的問題大小觸發TDR。

  • 完全禁用TDR(see MSDN article on TDR registry keys)並查看您的大問題集 是否已完成,如果是,請返回第一個點。這將表明您的代碼在啓用了TDR的accelerator_view上運行。

祝你好運!

+0

Simon,作爲對第2點的迴應,如果我使用較小的實例大小,它不會導致TDR。只有當我擴展它並增加導致TDR的運行長度時。感謝您的幫助。 –

+0

當我回來的時候,我會提供更多的代碼來顯示Accelerator_View的創建以及parallel_for_each的調用,以確保我正確地做到了這一點。 –

+0

好的,我很期待。 @MatthewCrews –