Hi, i am new to CUDA development and i am facing a problem in my code using Driver-API for D3D interoperability.
The Error is CUDA_ERROR_UNKNOWN (Runtime Error) while using the function cuD3D9CtxCreate(CUcontext *pCtx, CUdevice * pCuDevice, unsigned int flags,IDirect3DDevice9 *pDxDevice);
Platform used : Windows XP 64 bit
Graphics Library used is : Microsoft DirectX SDK (November 2008)
CUDA version : CUDA 2.2
The values of flags used is =0.
ALL other functions like cuD3D9GetDevice(&dev, adapterId.DeviceName);
are returning CUDA_SUCCESS.
a small part of my code is :-
int main()
{
CUresult resu;
CUdevice dev;
//////////////////////////////////////////////////////////////////////////
// Create a window
//////////////////////////////////////////////////////////////////////////
WNDCLASSEX winClass = {0};
MSG uMsg;
memset(&uMsg,0,sizeof(uMsg));
winClass.lpszClassName = "MY_WINDOWS_CLASS";
winClass.cbSize = sizeof(WNDCLASSEX);
winClass.style = CS_HREDRAW | CS_VREDRAW;
winClass.lpfnWndProc = WindowProc;
winClass.hIcon = NULL;
winClass.hIconSm = NULL;
winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winClass.lpszMenuName = NULL;
winClass.cbClsExtra = 0;
winClass.cbWndExtra = 0;
if( !RegisterClassEx(&winClass) )
return E_FAIL;
HWND hWnd = CreateWindowEx( NULL, “MY_WINDOWS_CLASS”,
"D3D Interoperability ",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0, 0, _fractalSize, _fractalSize, NULL, NULL, NULL, NULL );
if(hWnd == NULL)
{
std::cout<<"Failed to create a window here";
return(1);
}
ShowWindow(hWnd, SW_SHOWNORMAL );
UpdateWindow(hWnd );
resu = cuInit(0);
if(resu != CUDA_SUCCESS)
{
std::cout<<"Error in Driver API Initialization \n";
}
D3D = Direct3DCreate9(D3D_SDK_VERSION);
// Initialize Direct3D
if(D3D == NULL)
std::cout<<"Error: Could not Create D3D device \n";
// Get a CUDA capable adapter
unsigned int adapter = 0;
unsigned int count = D3D->GetAdapterCount();
for (; adapter < D3D->GetAdapterCount(); adapter++)
{
D3DADAPTER_IDENTIFIER9 adapterId;
D3D->GetAdapterIdentifier(adapter, 0, &adapterId);
char *name = adapterId.DeviceName;
resu = cuD3D9GetDevice(&dev, adapterId.DeviceName);
if(resu == CUDA_SUCCESS)
break;
}
ZeroMemory(&d3dpp ,sizeof(d3dpp));
// Set up the structure used to create the D3DDevice
d3dpp.Windowed = TRUE;
d3dpp.BackBufferCount = 1;
//d3dpp.hDeviceWindow = hWnd;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
//d3dpp.FullScreen_RefreshRateInHz = 60;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
d3dpp.EnableAutoDepthStencil = FALSE;
d3dpp.BackBufferWidth = g_WindowWidth;
d3dpp.BackBufferHeight = g_WindowHeight;
// Create device
result = D3D->CreateDevice(adapter, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device);
if(result != D3D_OK)
{
std::cout<<"Failed to Create Device \n";
return(1);
}
// Initialize driver API
// Create context
CUcontext cuContext;
resu = cuD3D9CtxCreate(&cuContext, &dev, 0, device); //Error at this point in the code resu returns CUDA_ERROR_UNKNOWN
if(resu != CUDA_SUCCESS)
{
std::cout<<"Context not Created \n";
}
// Create module from binary file
CUmodule cuModule;
cuModuleLoad(&cuModule, “matrixMul_kernel.cubin”);
// Get function handle from module
cuModuleGetFunction(&matrixMul_kernel, cuModule, “matrixMul_kernel”);
// Create vertex buffer and register it with CUDA
unsigned int size = width * height * sizeof(CUSTOMVERTEX);
device->CreateVertexBuffer(size, 0, D3DFVF_XYZ|D3DFVF_TEX1, D3DPOOL_DEFAULT, &positionsVB, 0);
cuD3D9RegisterResource(positionsVB, CU_D3D9_REGISTER_FLAGS_NONE);
cuD3D9ResourceSetMapFlags(positionsVB, CU_D3D9_MAPRESOURCE_FLAGS_WRITEDISCARD);
// Launch rendering loop
//unsigned int temp =0;
while (1)
{
Render();
//temp++;
}
}
All initializations of Devices have been done correctly.
While Running the program a window is also created with an exception.
Thanks in Advance. :rolleyes: