Zero-copy / pinned mapping (one address space: device ptr == host ptr)#

Defined in code/simulator.h.

This page documents 3 symbols: 3 functions.

Functions#

Signature

Description

Availability

Location

Example

inline cudaError_t cudaHostGetDevicePointer(T** pDevice, void* pHost, unsigned )

sim only

simulator.h:2360

View

inline cudaError_t cudaHostRegister(void* , size_t , unsigned )

sim only

simulator.h:2363

inline cudaError_t cudaHostUnregister(void* )

sim only

simulator.h:2364

Examples#

Code from the repository’s example corpus (code\*.cu); the highlighted line is the call site. These blocks are what the View links above open.

cudaHostGetDevicePointer (test_web_eeg_mapped.cu:79)
69}
70
71void onDevice(Vector<float> h_a, Vector<float> h_b) {
72    Vector<float> d_a, d_b;
73
74    cudaStream_t stream1;
75    cudaStreamCreate(&stream1);
76
77    // Map the pinned host buffers into the device address space.
78#ifdef __CUDACC__
79    cudaHostGetDevicePointer(&d_a.elements, h_a.elements, 0);
80    cudaHostGetDevicePointer(&d_b.elements, h_b.elements, 0);
81#else
82    d_a.elements = h_a.elements;   // [SIM] one address space: alias the host ptr
83    d_b.elements = h_b.elements;
84#endif
85
86    LAUNCH(functionKernel1, DIMGRID, DIMBLOCK, d_a, FULL_DATA_SIZE);   // [SIM] was <<<...,0,stream1>>>
87    LAUNCH(functionKernel2, DIMGRID, DIMBLOCK, d_b, FULL_DATA_SIZE);   // [SIM]
88
89    cudaStreamSynchronize(stream1);
90    cudaStreamDestroy(stream1);