Download CUDA C PROGRAMMING GUIDE

Transcript
Programming Interface
Frame Rendering) mode: cudaD3D[9|10|11]GetDevices(). A call to
cudaD3D[9|10|11]GetDevices()can be used to obtain a list of CUDA device
handles that can be passed as the (optional) last parameter to cudaD3D[9|10|
11]SetDirect3DDevice().
The application has the choice to either create multiple CPU threads, each using
a different CUDA context, or a single CPU thread using multiple CUDA context.
If using separate CPU threads for each GPU each of the CUDA contexts would be
created by the CUDA runtime by calling in a separate CPU thread cudaD3D[9|10|
11]SetDirect3DDevice() using one of the CUDA device handles returned by
cudaD3D[9|10|11]GetDevices().
If using a single CPU thread the CUDA contexts would have to be created using the
CUDA driver API context creation functions for interoperability with Direct3D devices
that use NVIDIA SLI (cuD3D[9|10|11]CtxCreateOnDevice()). The application
relies on the interoperability between CUDA driver and runtime APIs (Interoperablility
between Runtime and Driver APIs), which allows it to call cuCtxPushCurrent() and
cuCtxPopCurrent() to change the CUDA context active at a given time.
The Direct3D resources that may be mapped into the address space of
CUDA are Direct3D buffers, textures, and surfaces. These resources
are registered using cudaGraphicsD3D9RegisterResource(),
cudaGraphicsD3D10RegisterResource(), and
cudaGraphicsD3D11RegisterResource().
The following code sample uses a kernel to dynamically modify a 2D width x height
grid of vertices stored in a vertex buffer object.
3.2.11.2.1 Direct3D 9 Version
IDirect3D9* D3D;
IDirect3DDevice9* device;
struct CUSTOMVERTEX {
FLOAT x, y, z;
DWORD color;
};
IDirect3DVertexBuffer9* positionsVB;
struct cudaGraphicsResource* positionsVB_CUDA;
int main()
{
// Initialize Direct3D
D3D = Direct3DCreate9(D3D_SDK_VERSION);
// Get a CUDA-enabled adapter
unsigned int adapter = 0;
for (; adapter < g_pD3D->GetAdapterCount(); adapter++) {
D3DADAPTER_IDENTIFIER9 adapterId;
g_pD3D->GetAdapterIdentifier(adapter, 0, &adapterId);
int dev;
if (cudaD3D9GetDevice(&dev, adapterId.DeviceName)
== cudaSuccess)
break;
}
// Create device
...
D3D->CreateDevice(adapter, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&params, &device);
www.nvidia.com
CUDA C Programming Guide
PG-02829-001_v5.0 | 54