NVIDIA CUDA Compute Unified Device Architecture

Reference Manual

Version 2.0
June 2008

Contents
1 RuntimeApiReference 1.1 DeviceManagement RT 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 3 4 5 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

cudaGetDeviceCount

cudaSetDevice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cudaGetDevice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cudaGetDeviceProperties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cudaChooseDevice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ThreadManagement RT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2.1 1.2.2 cudaThreadSynchronize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cudaThreadExit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.3

StreamManagement RT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.3.1 1.3.2 1.3.3 1.3.4 cudaStreamCreate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cudaStreamQuery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cudaStreamSynchronize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cudaStreamDestroy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.4

EventManagement RT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 cudaEventCreate cudaEventRecord . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

cudaEventQuery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cudaEventSynchronize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

cudaEventDestroy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cudaEventElapsedTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.5

MemoryManagement RT 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9

cudaMalloc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cudaMallocPitch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cudaFree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

cudaMallocArray

cudaFreeArray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cudaMallocHost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cudaFreeHost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

cudaMemset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cudaMemset2D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

i

1.5.10 cudaMemcpy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5.11 cudaMemcpy2D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

34 35 36 37 38 39 40 41 42 43 44 45 46 48 50 52 54 55 63 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

1.5.12 cudaMemcpyToArray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5.13 cudaMemcpy2DToArray 1.5.14 cudaMemcpyFromArray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.5.15 cudaMemcpy2DFromArray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5.16 cudaMemcpyArrayToArray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5.17 cudaMemcpy2DArrayToArray 1.5.18 cudaMemcpyToSymbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.5.19 cudaMemcpyFromSymbol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5.20 cudaGetSymbolAddress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5.21 cudaGetSymbolSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5.22 cudaMalloc3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5.23 cudaMalloc3DArray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.5.24 cudaMemset3D 1.5.25 cudaMemcpy3D 1.6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

TextureReferenceManagement RT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.6.1 1.6.2 LowLevelApi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . HighLevelApi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.7

ExecutionControl RT 1.7.1 1.7.2 1.7.3

cudaConfigureCall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cudaLaunch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

cudaSetupArgument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.8

OpenGlInteroperability RT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 cudaGLSetGLDevice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

cudaGLRegisterBufferObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cudaGLMapBufferObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cudaGLUnmapBufferObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

cudaGLUnregisterBufferObject . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.9

Direct3dInteroperability RT 1.9.1 1.9.2 1.9.3 1.9.4 cudaD3D9GetDevice

cudaD3D9SetDirect3DDevice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cudaD3D9GetDirect3DDevice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

cudaD3D9RegisterResource . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ii

1.9.5 1.9.6 1.9.7 1.9.8 1.9.9

cudaD3D9UnregisterResource cudaD3D9MapResources

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

84 85 86 87 89 90 91 92 94 95 97 98 99

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

cudaD3D9UnmapResources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cudaD3D9ResourceSetMapFlags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . cudaD3D9ResourceGetSurfaceDimensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.9.10 cudaD3D9ResourceGetMappedPointer 1.9.11 cudaD3D9ResourceGetMappedSize

. . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.9.12 cudaD3D9ResourceGetMappedPitch . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.10 ErrorHandling RT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.10.1 cudaGetLastError . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.10.2 cudaGetErrorString . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 DriverApiReference 2.1 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.1 2.2

cuInit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

DeviceManagement 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7

cuDeviceComputeCapability

cuDeviceGet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 cuDeviceGetAttribute . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 cuDeviceGetCount . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 cuDeviceGetName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 cuDeviceGetProperties cuDeviceTotalMem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110

2.3

ContextManagement 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

cuCtxAttach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 cuCtxCreate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 cuCtxDestroy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115

cuCtxDetach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 cuCtxGetDevice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 cuCtxPopCurrent cuCtxPushCurrent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119

cuCtxSynchronize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

2.4

ModuleManagement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 2.4.1 cuModuleGetFunction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122

iii

. 126 cuModuleLoadFatBinary .5 . . . . . . . . . . . . . . . . . . .6. . . . . . . . . .7. . . . .5.4 2. . . . . . . . . . . . . . . . . . . . . . 140 . . . 129 2. . . . . . . . . 158 iv . . . . . . . . . . . . . . .4. . . . . . . . . . . .4 2. . . . . . . . . . . . . . .6 2. . . . . . . . . . . . . . .8.6. . . . . . . . . . . . . . . . . . . . . . . .2. . . . . . . . . . . . . . . . . . .5 cuModuleGetGlobal . . . . .5. . . . . . . . . .6 2. . . . . . . . . . . . . .6 cuEventCreate . . . . . . . . . . . . . .3 2. . . . . . . . . . . . . . . . . . . . . . . 154 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7. . .7. . . . . . . . . . 151 cuArrayCreate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8. . . . . . . . . . . . . . . . 152 cuArray3DCreate cuArrayDestroy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4. . . . . . . . . . . . . . . . . . . 147 cuParamSetv . . . . . . .5 2. . . . . . . . . . . . . . . . .7 ExecutionControl 2. . . . . . . 135 cuEventDestroy . . . . .6. . . . . . . . . .8. . . 132 . . . . . . . . . . . . . . . . . .5. . . . . . . . . . . . . . . . . . . . . . . . . . . .4 2. . . . . . . . . . . . . . . . . . . 139 cuEventSynchronize . . . . . . . . . . . . . . . . .3 2.9 cuLaunch . . . . . . . . . . .8 MemoryManagement 2. . . .7. . 133 cuStreamSynchronize 2. . . . . . . . . . . . . . .7 2. . . . . . . . . . . . . . . . . . .3 2. . . . . . . .8 2. . . . . . . . 156 cuArrayGetDescriptor . .1 2. . .6 EventManagement .7. . . .6. . . . . . . . . . . . 146 cuParamSeti . . . . . . . . . . . . . . . . . . . . .2 2.7. . . . . . . . . . . . . . .3 2. . . . . . . . . . . . . . . 123 cuModuleGetTexRef . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 cuLaunchGrid cuParamSetSize . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4. . . . . . . . . . . . . . . . . 130 . . 148 cuFuncSetBlockShape . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5. . .5 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4 cuStreamCreate cuStreamDestroy cuStreamQuery . . . . . . . . . . . . . . . . . . . .8. . . . .1 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 2. . . .3 2. . . . . . . . . . . . . . 131 . . . . . . . . . .7. . . 127 cuModuleUnload . . . . . . . . . . . . . . . . . 157 cuArray3DGetDescriptor . . . . . . . . . . . . . . . . . . 143 . . .7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 .1 2. . . . . . . .4. . . . . . . . . . .1 2. . . . . . .5 2. . . . . . .4 2. . . . . . . . .6. . . . . . 136 . . . . . . . 149 cuFuncSetSharedSize . .4. . . . . . . 137 cuEventElapsedTime cuEventQuery . . . . . . . . . . . . . . . . . . . . . .2 2. . . . . . . . . . . . . . . 138 cuEventRecord . . . . . . . . . . . .8. . . . . . .4. . . . . . . . . . . . . 124 cuModuleLoad .6. . 145 cuParamSetTexRef cuParamSetf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2 2. . . . . . . . . .7 2. . . . . . . .2 2. . . . . . . . . . . . . . . . . . . . . . 128 StreamManagement . . .2 2. . 125 cuModuleLoadData . . . . . .7. . . . . . . . . . . . . . . . . . . .

.8. . . . . . . . . . . . . . . . . . . . . . . . . . . .2 2. . .10 cuTexRefSetAddressMode 2. . .9. . . . . . . . 193 2. . . . . . . . . . . . . . . . . . . . . . . .9 cuMemAlloc . . . . . . . . . . . . . . 170 2. . . . . . . . . . . . . . .8. 191 cuTexRefSetAddress . . . . . . . . . . . . . . . . . 167 . . . 165 2. . . . . . .8. . . . . . . . . . . . . . . . . . . 188 . .9 cuTexRefCreate cuTexRefDestroy . . . . . . . . . . . . .3 2. . .16 cuMemcpyAtoD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8. . . . . .19 cuMemcpyDtoD . . . . .9. . . . . . . . .9. . . . . . .8. . . . . . .8. . . . . . . . . . . . . . . . . .15 cuMemcpyAtoA . . .13 cuMemcpy2D 2. . . . . . . . . . . . . . 164 2. . . . . . . . . . 180 2. . . . .12 cuTexRefSetFilterMode . . . .12 cuMemGetInfo . . . . . . . . . . . .4 2. . . . . . .9. . . . . . 184 . . . . . . . . . . . . . . . . . 177 2. . . . . . . . . . 160 . . . . . .9. . . . . . . . . . . . . . . . . . . . . . . . . . .8. . . 187 cuTexRefGetAddress cuTexRefGetAddressMode cuTexRefGetArray . . . . . . . . . . . . . . .11 cuTexRefSetArray . . . . . . . . . . .7 2. . . . . . . . . . . . . . . . .6 2. . .14 cuTexRefSetFormat . . . . . . 186 .8. .8. . . . . . . . . . . . . .9. . . . . . . . . . . 185 . . . . . . . . .10 cuMemFreeHost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2. . . . . . . . . . . . . . . . . . . . . . .9. . . . . . . . . .9 TextureReferenceManagement 2. . . . 179 2. . . .21 cuMemcpyHtoA . . . . . . . . . . . . . . . . . . . . . . . 194 2. . . . . . . . . . . . . . . . . . 190 cuTexRefGetFormat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 2. . . . . . . . . . .9. . . . . . . . . . . . . 174 2. . . . . . . .8. . . . . . .9. . . . . . . . . .8. . 178 2. . . . . . . . . . . . . . . . . . . . . . . . . .18 cuMemcpyDtoA . . . . . . . . . . . . . . . . .8. . . . . . . 166 2. . . . . . . . . . . . . . . . 173 2. . .9.8. . . . . . . . . . . . . . . . . . . . . . .8. . . . . . .5 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 . . . . . . . . . . . 197 v . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8. . . . . . . . . . . . . . . . . . . . . . . . . . . .9. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8 2. . . . . . . . . . . . . . . . . . . . . . 196 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11 cuMemGetAddressRange . . . .14 cuMemcpy3D . . . . . . . . . .7 2. .17 cuMemcpyAtoH . . . . . . . . . . . . 176 2. . . . .6 2. . . . . . . . . . . . . . . . . . . . .8. . . . . . .1 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 2. . . . . . . . .9. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 2. . . . . 163 2.9. . . .8. . . . . . . . . . . . . 192 . . . . . . . . . . .24 cuMemset2D . . . . . . . .13 cuTexRefSetFlags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20 cuMemcpyDtoH .8 2. .8. . . . . . .23 cuMemset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9. . . . . . . . 175 2. . . . . 189 cuTexRefGetFilterMode cuTexRefGetFlags . . . . 183 . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 cuMemAllocHost cuMemAllocPitch cuMemFree . . . . . .22 cuMemcpyHtoD . . . . . . . . . . . .

. . . . . . . . . . 209 2. . . . .1. .5 cuD3D9UnregisterResource . . . . . . . . .6 cuD3D9MapResources . . . . . . . . 203 2. . . . . .7 cuD3D9UnmapResources . . . . . . . . . . . . .4 cuGLRegisterBufferObject 2. . . . . . . . . . . . . . . . . . . . . . . . .10 OpenGlInteroperability . . . . . . . 228 atomicInc . . . . . .4 cuD3D9RegisterResource . . . . . . . . . . . . . . . . . . . .6 3. . . . . . . . . . . . . . . . .11. . . .8 cuD3D9ResourceSetMapFlags . . . . . . 211 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2. . . . . . . . . . . . . . . . 234 vi . . . . . . . . . . . . . . . . . . . . . . . . .10. . . . . . . . . . . 231 3. . . . . . . . 223 3. . . . . . . . . . . . . . . . .11. . . . . . . . . . . .10. . . . . . . . . . . . . . .2 atomicAnd . . . . . . . . . . . .11. . 214 2. . . . . . . . . .11. . . . . . . . . . . . . 230 atomicCAS . . . .1. . . . . . . . . . . . . . 207 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8 atomicAdd . . . . 226 . . . . . . . . . . . . . . . . . . 204 2. . 200 2.1. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2. . . . . . . . . . . . . . . . . . . . . . . . .1 222 ArithmeticFunctions . . . . . . . . . . . . . . . . . . . . . . . . . . . .10. . . . . . . . . . . . . . . . . . . . . . . . . . .1. .1. . . . . 208 2. . . 219 2. . . . .11. . . . . . . . . . . . . .1 3.5 3. . . . . . . . . . . . . . . . 227 atomicMax . . . . . . . . . . . . . . . . . . . . . . . . .12 cuD3D9ResourceGetMappedPitch . . . . . . . . . . . . . .7 3. . . . . . .5 cuGLUnmapBufferObject . . . . . . . .11. . . . . . . . .2 cuD3D9CtxCreate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11. . . . . . . . . . . . . . . . . . . . . . . . . .1. . . . . . .11. . . . . . . . . . . 220 3 AtomicFunctions 3. . . . . . . . .11. . . . . 198 2. . . . . . . . . . . . . . . . .4 3. . . . . . .1 3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 cuGLMapBufferObject . . . .11. . . 217 2. . . . . . . . . . . . .11. . . . . . . . . . . . . . 232 3. . . . 205 2. . . . . . . . . . . . . . . . . . . . . . . . . 216 2. . . . . .11. . . . . . . . . . . .2 3.11 cuD3D9ResourceGetMappedSize . . . . . . 213 2. 212 2. . . . . . . . .9 cuD3D9ResourceGetSurfaceDimensions . .10. .10 cuD3D9ResourceGetMappedPointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202 2. . . . . .1 cuD3D9GetDevice . . . . . . . . . . . . . . . . . . . . .6 cuGLUnregisterBufferObject . . . . . . . 229 atomicDec . . . .1. . . . . . . . . . . . . . . . . . . . . . . . . . . 224 atomicSub atomicExch atomicMin . . . . . . . . . . . . . . . . . . 201 . . . . . . . . . . . . . .2. . . . . . . . . . .3 cuD3D9GetDirect3DDevice . . . . . . . . . . . . . . . . . . . . .2 BitwiseFunctions . . . . . . . . . 199 2. . . . . . . . . . . . . . . . .10. . . . . . . . . . . . . . . .3 3. .1 cuGLCtxCreate . . . . . . . . . . . . . . . 233 atomicOr . .10. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11 Direct3dInteroperability . . . . 206 2. . . . . . . . . . . . . . . . . . . 225 . . . . . . . . . .2 cuGLInit . . . . . . . . . . . .1. . . . . . . . . . . . . . . . . . .

. . . 235 vii . . . . .3. . . . . . . . . .2. . . . . . . . . . . . . . . . . .3 atomicXor . . . . . . . . .

1 RuntimeApiReference NAME Runtime API Reference DESCRIPTION There are two levels for the runtime API. The low-level API (cuda_runtime_api. textures. Texture Reference Management. references and default arguments. These wrappers can be used from C++ code and can be compiled with any C++ compiler. Event Management. Error Handling 1 . Thread Management. The high-level API (cuda_runtime.h) is a C++-style interface built on top of the low-level API. Direct3D Interoperability. using overloading. For example. Memory Management. the execution configuration syntax to invoke kernels is only available in source code compiled with nvcc. SEE ALSO Device Management. and device functions. It wraps some of the low level API routines. Stream Management. These wrappers require the use of nvcc because they depend on code being generated by the compiler. Execution Management. OpenGL Interoperability.h) is a C-style interface that does not require compiling with nvcc. The high-level API also has some CUDA-specific wrappers that wrap low-level routines that deal with symbols.

Stream Management. Error Handling 2 . OpenGL Interoperability. Memory Management.1. Execution Management. Thread Management. cudaGetDeviceCount cudaSetDevice cudaGetDevice cudaGetDeviceProperties cudaChooseDevice SEE ALSO Device Management. Texture Reference Management. Event Management.1 DeviceManagement RT NAME Device Management DESCRIPTION This section describes the CUDA runtime application programming interface. Direct3D Interoperability.

returns the number of compute-capable devices SYNOPSIS cudaError_t cudaGetDeviceCount( int* count ) DESCRIPTION Returns in *count the number of devices with compute capability greater or equal to 1. cudaSetDevice. cudaChooseDevice 3 .1.1 cudaGetDeviceCount NAME cudaGetDeviceCount . this device will report major and minor compute capability versions of 9999. asynchronous launches. cudaGetDeviceProperties. Since this device will be able to emulate all hardware features.1. SEE ALSO cudaGetDevice.0 that are available for execution. If there is no such device. RETURN VALUE Relevant return values: cudaSuccess Note that this function may also return error codes from previous. cudaGetDeviceCount() returns 1 and device 0 only supports device emulation mode.

SEE ALSO cudaGetDeviceCount. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidDevice Note that this function may also return error codes from previous. cudaGetDeviceProperties.1. asynchronous launches.sets device to be used for GPU executions SYNOPSIS cudaError_t cudaSetDevice( int dev ) DESCRIPTION Records dev as the device on which the active host thread executes the device code.1. cudaGetDevice. cudaChooseDevice 4 .2 cudaSetDevice NAME cudaSetDevice .

cudaChooseDevice 5 . cudaSetDevice.returns which device is currently being used SYNOPSIS cudaError_t cudaGetDevice( int* dev ) DESCRIPTION Returns in *dev the device on which the active host thread executes the device code. asynchronous launches.1. RETURN VALUE Relevant return values: cudaSuccess Note that this function may also return error codes from previous. cudaGetDeviceProperties.1.3 cudaGetDevice NAME cudaGetDevice . SEE ALSO cudaGetDeviceCount.

int dev ) DESCRIPTION Returns in *prop the properties of device dev. int deviceOverlap. int maxThreadsPerBlock. int warpSize. int clockRate. size_t totalConstMem.returns information on the compute-device SYNOPSIS cudaError_t cudaGetDeviceProperties( struct cudaDeviceProp* prop. size_t sharedMemPerBlock. regsPerBlock is the maximum number of 32-bit registers available to a thread block. int regsPerBlock. totalGlobalMem is the total amount of global memory available on the device in bytes.4 cudaGetDeviceProperties NAME cudaGetDeviceProperties .1. sharedMemPerBlock is the maximum amount of shared memory available to a thread block in bytes. The cudaDeviceProp structure is defined as: struct cudaDeviceProp { char name[256]. size_t memPitch. this number is shared by all thread blocks simultaneously resident on a multiprocessor. size_t totalGlobalMem. 6 . this amount is shared by all thread blocks simultaneously resident on a multiprocessor. size_t textureAlignment. int major. } where: name is an ASCII string identifying the device.1. int maxGridSize[3]. int minor. warpSize is the warp size in threads. int multiProcessorCount. int maxThreadsDim[3].

SEE ALSO cudaGetDeviceCount. cudaGetDevice. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidDevice Note that this function may also return error codes from previous. maxGridSize[3] is the maximum sizes of each dimension of a grid. major. deviceOverlap is 1 if the device can concurrently copy memory between host and device while executing a kernel. cudaSetDevice. maxThreadsPerBlock is the maximum number of threads per block. textureAlignment is the alignment requirement. cudaChooseDevice 7 . asynchronous launches. minor are the major and minor revision numbers defining the device’s compute capability. or 0 if not.memPitch is the maximum pitch in bytes allowed by the memory copy functions that involve memory regions allocated through cudaMallocPitch(). totalConstMem is the total amount of constant memory available on the device in bytes. clockRate is the clock frequency in kilohertz. multiProcessorCount is the number of multiprocessors on the device. texture base addresses that are aligned to textureAlignment bytes do not need an offset applied to texture fetches. maxThreadsDim[3] is the maximum sizes of each dimension of a block.

cudaGetDeviceProperties 8 . const struct cudaDeviceProp* prop ) DESCRIPTION Returns in *dev the device which properties best match *prop.1.1.5 cudaChooseDevice NAME cudaChooseDevice . RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue Note that this function may also return error codes from previous. asynchronous launches. SEE ALSO cudaGetDeviceCount. cudaSetDevice.select compute-device which best matches criteria SYNOPSIS cudaError_t cudaChooseDevice( int* dev. cudaGetDevice.

2 ThreadManagement RT NAME Thread Management DESCRIPTION This section describes the CUDA runtime application programming interface. Stream Management. Texture Reference Management. Error Handling 9 . OpenGL Interoperability. Memory Management. Direct3D Interoperability.1. Event Management. Thread Management. Execution Management. cudaThreadSynchronize cudaThreadExit SEE ALSO Device Management.

1 cudaThreadSynchronize NAME cudaThreadSynchronize . asynchronous launches. RETURN VALUE Relevant return values: cudaSuccess Note that this function may also return error codes from previous. SEE ALSO cudaThreadExit 10 .2.wait for compute-device to finish SYNOPSIS cudaError_t cudaThreadSynchronize(void) DESCRIPTION Blocks until the device has completed all preceding requested tasks. cudaThreadSynchronize() returns an error if one of the preceding tasks failed.1.

exit and clean-up from CUDA launches SYNOPSIS cudaError_t cudaThreadExit(void) DESCRIPTION Explicitly cleans up all runtime-related resources associated with the calling host thread.2 cudaThreadExit NAME cudaThreadExit . RETURN VALUE Relevant return values: cudaSuccess Note that this function may also return error codes from previous.1. asynchronous launches. cudaThreadExit() is implicitly called on host thread exit.2. SEE ALSO cudaThreadSynchronize 11 . Any subsequent API call reinitializes the runtime.

Direct3D Interoperability. Error Handling 12 . Execution Management. cudaStreamCreate cudaStreamQuery cudaStreamSynchronize cudaStreamDestroy SEE ALSO Device Management. Stream Management.3 StreamManagement RT NAME Stream Management DESCRIPTION This section describes the CUDA runtime application programming interface. Texture Reference Management. Thread Management. OpenGL Interoperability.1. Event Management. Memory Management.

3. cudaStreamSynchronize. SEE ALSO cudaStreamQuery. cudaStreamDestroy 13 .create an async stream SYNOPSIS cudaError_t cudaStreamCreate( cudaStream_t* stream ) DESCRIPTION Creates a stream.1 cudaStreamCreate NAME cudaStreamCreate . RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue Note that this function may also return error codes from previous. asynchronous launches.1.

SEE ALSO cudaStreamCreate.3.2 cudaStreamQuery NAME cudaStreamQuery . asynchronous launches. RETURN VALUE Relevant return values: cudaSuccess cudaErrorNotReady cudaErrorInvalidResourceHandle Note that this function may also return error codes from previous. cudaStreamSynchronize 14 . cudaStreamDestroy.1. or cudaErrorNotReady if not.queries a stream for completion-status SYNOPSIS cudaError_t cudaStreamQuery(cudaStream_t stream) DESCRIPTION Returns cudaSuccess if all operations in the stream have completed.

1.waits for stream tasks to complete SYNOPSIS cudaError_t cudaStreamSynchronize( cudaStream_t stream ) DESCRIPTION Blocks until the device has completed all operations in the stream. asynchronous launches.3 cudaStreamSynchronize NAME cudaStreamSynchronize . RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidResourceHandle Note that this function may also return error codes from previous.3. cudaStreamQuery 15 . cudaStreamDestroy. SEE ALSO cudaStreamCreate.

destroys and cleans-up a stream object SYNOPSIS cudaError_t cudaStreamDestroy( cudaStream_t stream ) DESCRIPTION Destroys a stream object.4 cudaStreamDestroy NAME cudaStreamDestroy . RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidResourceHandle Note that this function may also return error codes from previous.3. asynchronous launches. SEE ALSO cudaStreamCreate. cudaStreamSychronize.1. cudaStreamDestroy 16 .

Thread Management. Event Management.1. Direct3D Interoperability. Error Handling 17 . Texture Reference Management. OpenGL Interoperability. Stream Management. Memory Management. cudaEventCreate cudaEventRecord cudaEventQuery cudaEventSynchronize cudaEventDestroy cudaEventElapsedTime SEE ALSO Device Management.4 EventManagement RT NAME Event Management DESCRIPTION This section describes the CUDA runtime application programming interface. Execution Management.

creates an event-object SYNOPSIS cudaError_t cudaEventCreate( cudaEvent_t* event ) DESCRIPTION Creates an event object.1. cudaEventElapsedTime 18 . cudaEventQuery.1 cudaEventCreate NAME cudaEventCreate .4. SEE ALSO cudaEventRecord. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInitializationError cudaErrorPriorLaunchFailure cudaErrorInvalidValue cudaErrorMemoryAllocation Note that this function may also return error codes from previous. cudaEventDestroy. asynchronous launches. cudaEventSynchronzie.

this function returns cudaErrorInvalidValue. cudaEventQuery() and/or cudaEventSynchronize() must be used to determine when the event has actually been recorded. the event is recorded after all preceding operations in the stream have been completed. SEE ALSO cudaEventCreate.2 cudaEventRecord NAME cudaEventRecord . it is recorded after all preceding operations in the CUDA context have been completed. cudaEventSynchronize.4. asynchronous launches. cudaEventDestroy. Since this operation is asynchronous. cudaEventQuery.records an event SYNOPSIS cudaError_t cudaEventRecord( cudaEvent_t event. If cudaEventRecord() has previously been called and the event has not been recorded yet. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInitializationError cudaErrorPriorLaunchFailure cudaErrorInvalidResourceHandle Note that this function may also return error codes from previous. otherwise. cudaEventElapsedTime 19 . CUstream stream ) DESCRIPTION Records an event. If stream is non-zero.1.

RETURN VALUE Relevant return values: cudaSuccess cudaErrorNotReady cudaErrorInitializationError cudaErrorPriorLaunchFailure cudaErrorInvalidValue cudaErrorInvalidResourceHandle Note that this function may also return error codes from previous. SEE ALSO cudaEventCreate. If cudaEventRecord() has not been called on this event. cudaEventDestroy.4. cudaEventElapsedTime 20 .query if an event has been recorded SYNOPSIS cudaError_t cudaEventQuery( cudaEvent_t event ) DESCRIPTION Returns cudaSuccess if the event has actually been recorded.3 cudaEventQuery NAME cudaEventQuery . cudaEventSynchronize. asynchronous launches. or cudaErrorNotReady if not. the function returns cudaErrorInvalidValue.1. cudaEventRecord.

the function returns cudaErrorInvalidValue. If cudaEventRecord() has not been called on this event. cudaEventQuery.wait for an event to be recorded SYNOPSIS cudaError_t cudaEventSynchronize( cudaEvent_t event ) DESCRIPTION Blocks until the event has actually been recorded. cudaEventElapsedTime 21 . cudaEventDestroy.4. asynchronous launches. SEE ALSO cudaEventCreate.4 cudaEventSynchronize NAME cudaEventSynchronize . RETURN VALUE Relevant return values: cudaSuccess cudaErrorInitializationError cudaErrorPriorLaunchFailure cudaErrorInvalidValue cudaErrorInvalidResourceHandle Note that this function may also return error codes from previous.1. cudaEventRecord.

RETURN VALUE Relevant return values: cudaSuccess cudaErrorInitializationError cudaErrorPriorLaunchFailure cudaErrorInvalidValue Note that this function may also return error codes from previous. cudaEventRecord. asynchronous launches. SEE ALSO cudaEventCreate. cudaEventElapsedTime 22 .5 cudaEventDestroy NAME cudaEventDestroy .1.destroys an event-object SYNOPSIS cudaError_t cudaEventDestroy( cudaEvent_t event ) DESCRIPTION Destroys the event-object.4. cudaEventQuery. cudaEventSynchronize.

cudaEventSynchronize. the result is undefined. cudaEventDestroy.6 cudaEventElapsedTime NAME cudaEventElapsedTime . SEE ALSO cudaEventCreate.5 microseconds). cudaEventQuery. If either event has not been recorded yet.computes the elapsed time between events SYNOPSIS cudaError_t cudaEventElapsedTime( float* time. DESCRIPTION Computes the elapsed time between two events (in milliseconds with a resolution of around 0. asynchronous launches. cudaEvent_t start. cudaEventRecord 23 .4. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInitializationError cudaErrorPriorLaunchFailure cudaErrorInvalidValue cudaErrorInvalidResourceHandle Note that this function may also return error codes from previous. this function returns cudaErrorInvalidValue.1. cudaEvent_t end ). If either event has been recorded with a non-zero stream.

5 MemoryManagement RT NAME Memory Management DESCRIPTION This section describes the CUDA runtime application programming interface. Event Management. Stream Management. cudaMalloc cudaMallocPitch cudaFree cudaMallocArray cudaFreeArray cudaMallocHost cudaFreeHost cudaMemset cudaMemset2D cudaMemcpy cudaMemcpy2D cudaMemcpyToArray cudaMemcpy2DToArray cudaMemcpyFromArray cudaMemcpy2DFromArray cudaMemcpyArrayToArray cudaMemcpy2DArrayToArray cudaMemcpyToSymbol cudaMemcpyFromSymbol cudaGetSymbolAddress cudaGetSymbolSize SEE ALSO Device Management. Memory Management. Texture Reference Management. Thread Management. OpenGL Interoperability.1. Direct3D Interoperability. Execution Management. Error Handling 24 .

5.allocate memory on the GPU SYNOPSIS cudaError_t cudaMalloc( void** devPtr. cudaFreeArray. cudaMallocHost. cudaFreeHost 25 . asynchronous launches. cudaMallocArray. cudaFree. The allocated memory is suitably aligned for any kind of variable. cudaMalloc() returns cudaErrorMemoryAllocation in case of failure.1. RETURN VALUE Relevant return values: cudaSuccess cudaErrorMemoryAllocation Note that this function may also return error codes from previous. size_t count ) DESCRIPTION Allocates count bytes of linear memory on the device and returns in *devPtr a pointer to the allocated memory.1 cudaMalloc NAME cudaMalloc . The memory is not cleared. SEE ALSO cudaMallocPitch.

SEE ALSO cudaMalloc. Due to pitch alignment restrictions in the hardware. it is recommended that programmers consider performing pitch allocations using cudaMallocPitch().allocates memory on the GPU SYNOPSIS cudaError_t cudaMallocPitch( void** devPtr. this is especially true if the application will be performing 2D memory copies between different regions of device memory (whether linear memory or CUDA arrays). Given the row and column of an array element of type T. cudaMallocHost. cudaMallocArray. For allocations of 2D arrays. the address is computed as T* pElement = (T*)((char*)BaseAddress + Row * pitch) + Column. size_t height ) DESCRIPTION Allocates at least widthInBytes*height bytes of linear memory on the device and returns in *devPtr a pointer to the allocated memory.2 cudaMallocPitch NAME cudaMallocPitch . asynchronous launches.5. The function may pad the allocation to ensure that corresponding pointers in any given row will continue to meet the alignment requirements for coalescing as the address is updated from row to row.1. cudaFreeArray. size_t* pitch. cudaFree. size_t widthInBytes. The pitch returned in *pitch by cudaMallocPitch() is the width in bytes of the allocation. RETURN VALUE Relevant return values: cudaSuccess cudaErrorMemoryAllocation Note that this function may also return error codes from previous. used to compute addresses within the 2D array. cudaFreeHost 26 . The intended usage of pitch is as a separate parameter of the allocation.

cudaFreeHost 27 . Otherwise. or if cudaFree(devPtr) has already been called before.3 cudaFree NAME cudaFree . cudaFreeArray. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidDevicePointer cudaErrorInitializationError Note that this function may also return error codes from previous. an error is returned. no operation is performed. cudaMallocHost. cudaFree() returns cudaErrorInvalidDevicePointer in case of failure. asynchronous launches. cudaMallocPitch.5. cudaMallocArray. which must have been returned by a previous call to cudaMalloc() or cudaMallocPitch(). If devPtr is 0. SEE ALSO cudaMalloc.1.frees memory on the GPU SYNOPSIS cudaError_t cudaFree(void* devPtr) DESCRIPTION Frees the memory space pointed to by devPtr.

cudaMallocHost. asynchronous launches.allocate an array on the GPU SYNOPSIS cudaError_t cudaMallocArray( struct cudaArray** array. SEE ALSO cudaMalloc. cudaFreeArray. RETURN VALUE Relevant return values: cudaSuccess cudaErrorMemoryAllocation Note that this function may also return error codes from previous. const struct cudaChannelFormatDesc* desc. enum cudaChannelFormatKind f. z.1. w. cudaFreeHost 28 . The cudaChannelFormatDesc is defined as: struct cudaChannelFormatDesc { int x. size_t height ) DESCRIPTION Allocates a CUDA array according to the cudaChannelFormatDesc structure desc and returns a handle to the new CUDA array in *array. cudaMallocPitch. cudaChannelFormatKindUnsigned. where cudaChannelFormatKind is one of cudaChannelFormatKindSigned. cudaChannelFormatKindFloat.5. size_t width. cudaFree. }. y.4 cudaMallocArray NAME cudaMallocArray .

SEE ALSO cudaMalloc.1. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInitializationError Note that this function may also return error codes from previous. cudaFreeHost 29 . cudaMallocPitch. cudaFree.5 cudaFreeArray NAME cudaFreeArray . asynchronous launches. no operation is performed. If array is 0. cudaMallocArray. cudaMallocHost.5.frees an array on the GPU SYNOPSIS cudaError_t cudaFreeArray( struct cudaArray* array ) DESCRIPTION Frees the CUDA array array.

The driver tracks the virtual memory ranges allocated with this function and automatically accelerates calls to functions such as cudaMemcpy*(). cudaMallocArray.allocates page-locked memory on the host SYNOPSIS cudaError_t cudaMallocHost( void** hostPtr. since it reduces the amount of memory available to the system for paging.1. asynchronous launches. RETURN VALUE Relevant return values: cudaSuccess cudaErrorMemoryAllocation Note that this function may also return error codes from previous. cudaFreeArray. size_t size ) DESCRIPTION Allocates size bytes of host memory that is page-locked and accessible to the device. it can be read or written with much higher bandwidth than pageable memory obtained with functions such as malloc(). Since the memory can be accessed directly by the device. cudaFreeHost 30 . SEE ALSO cudaMalloc. As a result.6 cudaMallocHost NAME cudaMallocHost . cudaFree.5. Allocating excessive amounts of memory with cudaMallocHost() may degrade system performance. this function is best used sparingly to allocate staging areas for data exchange between host and device. cudaMallocPitch.

SEE ALSO cudaMalloc.frees page-locked memory SYNOPSIS cudaError_t cudaFreeHost( void* hostPtr ) DESCRIPTION Frees the memory space pointed to by hostPtr. cudaFreeArray. cudaFree.7 cudaFreeHost NAME cudaFreeHost .1.5. cudaMallocArray. cudaMallocPitch. which must have been returned by a previous call to cudaMallocHost(). RETURN VALUE Relevant return values: cudaSuccess cudaErrorInitializationError Note that this function may also return error codes from previous. asynchronous launches. cudaMallocHost 31 .

asynchronous launches.8 cudaMemset NAME cudaMemset . SEE ALSO cudaMemset2D. size_t count ) DESCRIPTION Fills the first count bytes of the memory area pointed to by devPtr with the constant byte value value. cudaMemset3D 32 . RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidDevicePointer Note that this function may also return error codes from previous.1.5. int value.initializes or sets GPU memory to a value SYNOPSIS cudaError_t cudaMemset( void* devPtr.

initializes or sets GPU memory to a value SYNOPSIS cudaError_t cudaMemset2D( void* dstPtr. pitch is the width in memory in bytes of the 2D array pointed to by dstPtr. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidDevicePointer Note that this function may also return error codes from previous.9 cudaMemset2D NAME cudaMemset2D . size_t width.5. size_t pitch.1. SEE ALSO cudaMemset. This function performs fastest when the pitch is one that has been passed back by cudaMallocPitch(). asynchronous launches. cudaMemset3D 33 . including any padding added to the end of each row. int value. size_t height ) DESCRIPTION Sets to the specified value value a matrix (height rows of width bytes each) pointed to by dstPtr.

where kind is one of cudaMemcpyHostToHost. const void* src. or cudaMemcpyDeviceToDevice. Calling cudaMemcpy() with dst and src pointers that do not match the direction of the copy results in an undefined behavior.10 cudaMemcpy NAME cudaMemcpy . size_t count. size_t count.5. and specifies the direction of the copy. SEE ALSO cudaMemcpy2D. It only works on page-locked host memory and returns an error if a pointer to pageable memory is passed as input. cudaMemcpyAsync() is asynchronous and can optionally be associated to a stream by passing a non-zero stream argument. cudaMemcpy2DArrayToArray. cudaMemcpy2DToArray. enum cudaMemcpyKind kind ) cudaError_t cudaMemcpyAsync( void* dst. cudaMemcpyFromArray.1.copies data between GPU and host SYNOPSIS cudaError_t cudaMemcpy( void* dst. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidDevicePointer cudaErrorInvalidMemcpyDirection Note that this function may also return error codes from previous. enum cudaMemcpyKind kind. cudaMemcpyToSymbol. cudaMemcpy2DFromArray. const void* src. The memory areas may not overlap. cudaMemcpyToArray. asynchronous launches. cudaMemcpyFromSymbol 34 . cudaMemcpyDeviceToHost. cudaMemcpyHostToDevice. cudaStream_t stream ) DESCRIPTION Copies count bytes from the memory area pointed to by src to the memory area pointed to by dst. cudaMemcpyArrayToArray.

size_t dpitch. dpitch and spitch are the widths in memory in bytes of the 2D arrays pointed to by dst and src. const void* src.copies data between host and device SYNOPSIS cudaError_t cudaMemcpy2D( void* dst. size_t dpitch. where kind is one of cudaMemcpyHostToHost.11 cudaMemcpy2D NAME cudaMemcpy2D . The memory areas may not overlap. cudaMemcpyArrayToArray. cudaMemcpyFromSymbol 35 . size_t spitch. cudaStream_t stream ) DESCRIPTION Copies a matrix (height rows of width bytes each) from the memory area pointed to by src to the memory area pointed to by dst. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidPitchValue cudaErrorInvalidDevicePointer cudaErrorInvalidMemcpyDirection Note that this function may also return error codes from previous. size_t height. size_t height. cudaMemcpy2DAsync() is asynchronous and can optionally be associated to a stream by passing a nonzero stream argument. and specifies the direction of the copy.1. cudaMemcpyToArray.5. size_t width. enum cudaMemcpyKind kind. or cudaMemcpyDeviceToDevice. cudaMemcpyFromArray. It only works on page-locked host memory and returns an error if a pointer to pageable memory is passed as input. size_t spitch. cudaMemcpyHostToDevice. Calling cudaMemcpy2D() with dst and src pointers that do not match the direction of the copy results in an undefined behavior. cudaMemcpyToSymbol. size_t width. cudaMemcpy2D() returns an error if dpitch or spitch is greater than the maximum allowed. cudaMemcpy2DFromArray. cudaMemcpyDeviceToHost. enum cudaMemcpyKind kind ) cudaError_t cudaMemcpy2DAsync( void* dst. including any padding added to the end of each row. const void* src. cudaMemcpy2DArrayToArray. asynchronous launches. cudaMemcpy2DToArray. SEE ALSO cudaMemcpy.

5. size_t count. cudaMemcpyHostToDevice. size_t count. It only works on page-locked host memory and returns an error if a pointer to pageable memory is passed as input. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidDevicePointer cudaErrorInvalidMemcpyDirection Note that this function may also return error codes from previous.12 cudaMemcpyToArray NAME cudaMemcpyToArray . asynchronous launches. enum cudaMemcpyKind kind) cudaError_t cudaMemcpyToArrayAsync(struct cudaArray* dstArray. cudaMemcpyArrayToArray. cudaMemcpyToSymbol. enum cudaMemcpyKind kind. SEE ALSO cudaMemcpy. where kind is one of cudaMemcpyHostToHost. dstY). size_t dstX. const void* src. cudaMemcpy2DArrayToArray. cudaMemcpy2DFromArray. cudaMemcpyToArrayAsync() is asynchronous and can optionally be associated to a stream by passing a non-zero stream argument. and specifies the direction of the copy. size_t dstX. cudaMemcpy2DToArray. cudaMemcpyDeviceToHost. cudaMemcpyFromArray. const void* src. or cudaMemcpyDeviceToDevice.1. cudaMemcpy2D. cudaMemcpyFromSymbol 36 .copies data between host and device SYNOPSIS cudaError_t cudaMemcpyToArray(struct cudaArray* dstArray. size_t dstY. cudaStream_t stream) DESCRIPTION Copies count bytes from the memory area pointed to by src to the CUDA array dstArray starting at the upper left corner (dstX. size_t dstY.

cudaMemcpyDeviceToHost. cudaMemcpyArrayToArray. enum cudaMemcpyKind kind). where kind is one of cudaMemcpyHostToHost. const void* src. size_t dstY. including any padding added to the end of each row. size_t dstY. const void* src. size_t width.13 cudaMemcpy2DToArray NAME cudaMemcpy2DToArray . size_t spitch. size_t height. cudaMemcpyToSymbol. spitch is the width in memory in bytes of the 2D array pointed to by src. or cudaMemcpyDeviceToDevice. cudaMemcpy2D. DESCRIPTION Copies a matrix (height rows of width bytes each) from the memory area pointed to by src to the CUDA array dstArray starting at the upper left corner (dstX.1. size_t spitch. cudaMemcpy2D() returns an error if spitch is greater than the maximum allowed. cudaMemcpyHostToDevice. SEE ALSO cudaMemcpy. size_t height. cudaMemcpyFromArray. cudaMemcpy2DArrayToArray. asynchronous launches. It only works on page-locked host memory and returns an error if a pointer to pageable memory is passed as input. cudaStream_t stream). cudaError_t cudaMemcpy2DToArrayAsync(struct cudaArray* dstArray.copies data between host and device SYNOPSIS cudaError_t cudaMemcpy2DToArray(struct cudaArray* dstArray. dstY). enum cudaMemcpyKind kind. cudaMemcpy2DToArrayAsync() is asynchronous and can optionally be associated to a stream by passing a non-zero stream argument. and specifies the direction of the copy.5. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidDevicePointer cudaErrorInvalidPitchValue cudaErrorInvalidMemcpyDirection Note that this function may also return error codes from previous. cudaMemcpy2DFromArray. size_t dstX. cudaMemcpyFromSymbol 37 . size_t dstX. size_t width. cudaMemcpyToArray.

srcY) to the memory area pointed to by dst. enum cudaMemcpyKind kind. cudaMemcpyFromSymbol 38 . cudaMemcpy2DToArray. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidDevicePointer cudaErrorInvalidMemcpyDirection Note that this function may also return error codes from previous. size_t srcY. cudaMemcpyHostToDevice. cudaMemcpyToArray. cudaMemcpyArrayToArray. size_t srcX. const struct cudaArray* srcArray. cudaMemcpyDeviceToHost. or cudaMemcpyDeviceToDevice. size_t srcX. cudaMemcpyFromArrayAsync() is asynchronous and can optionally be associated to a stream by passing a non-zero stream argument. cudaMemcpy2DArrayToArray. and specifies the direction of the copy. enum cudaMemcpyKind kind) cudaError_t cudaMemcpyFromArrayAsync(void* dst. const struct cudaArray* srcArray. cudaMemcpy2DFromArray.copies data between host and device SYNOPSIS cudaError_t cudaMemcpyFromArray(void* dst. cudaMemcpy2D. where kind is one of cudaMemcpyHostToHost. size_t count. asynchronous launches. cudaStream_t stream) DESCRIPTION Copies count bytes from the CUDA array srcArray starting at the upper left corner (srcX.5. size_t srcY. size_t count.1. It only works on page-locked host memory and returns an error if a pointer to pageable memory is passed as input.14 cudaMemcpyFromArray NAME cudaMemcpyFromArray . SEE ALSO cudaMemcpy. cudaMemcpyToSymbol.

enum cudaMemcpyKind kind) cudaError_t cudaMemcpy2DFromArrayAsync(void* dst. cudaMemcpyToArray. including any padding added to the end of each row. cudaMemcpyHostToDevice. size_t srcX. asynchronous launches.5. const struct cudaArray* srcArray. cudaMemcpy2DFromArrayAsync() is asynchronous and can optionally be associated to a stream by passing a non-zero stream argument. cudaMemcpy2DArrayToArray. size_t srcY. size_t width. size_t srcY. cudaMemcpyFromArray.copies data between host and device SYNOPSIS cudaError_t cudaMemcpy2DFromArray(void* dst. cudaMemcpyArrayToArray. cudaMemcpy2DToArray. cudaStream_t stream) DESCRIPTION Copies a matrix (height rows of width bytes each) from the CUDA array srcArray starting at the upper left corner (srcX. dpitch is the width in memory in bytes of the 2D array pointed to by dst. size_t srcX. size_t height.15 cudaMemcpy2DFromArray NAME cudaMemcpy2DFromArray . size_t dpitch. cudaMemcpyToSymbol. where kind is one of cudaMemcpyHostToHost. cudaMemcpyDeviceToHost. size_t width. It only works on page-locked host memory and returns an error if a pointer to pageable memory is passed as input. size_t height. enum cudaMemcpyKind kind. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidDevicePointer cudaErrorInvalidPitchValue cudaErrorInvalidMemcpyDirection Note that this function may also return error codes from previous. srcY) to the memory area pointed to by dst. const struct cudaArray* srcArray. or cudaMemcpyDeviceToDevice. and specifies the direction of the copy. SEE ALSO cudaMemcpy. size_t dpitch.1. cudaMemcpy2D. cudaMemcpyFromSymbol 39 . cudaMemcpy2D() returns an error if dpitch is greater than the maximum allowed.

cudaMemcpyToArray. and specifies the direction of the copy. where kind is one of cudaMemcpyHostToHost. cudaMemcpyFromArray. SEE ALSO cudaMemcpy. cudaMemcpy2DArrayToArray. dstY). cudaMemcpyDeviceToHost. size_t srcY. cudaMemcpyFromSymbol 40 .5. cudaMemcpy2DFromArray. const struct cudaArray* srcArray. or cudaMemcpyDeviceToDevice. srcY) to the CUDA array dstArray starting at the upper left corner (dstX. size_t dstY. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidMemcpyDirection Note that this function may also return error codes from previous. size_t count.1. asynchronous launches. cudaMemcpyToSymbol. cudaMemcpyHostToDevice. size_t dstX. cudaMemcpy2D. cudaMemcpy2DToArray.16 cudaMemcpyArrayToArray NAME cudaMemcpyArrayToArray . size_t srcX.copies data between host and device SYNOPSIS cudaError_t cudaMemcpyArrayToArray(struct cudaArray* dstArray. enum cudaMemcpyKind kind) DESCRIPTION Copies count bytes from the CUDA array srcArray starting at the upper left corner (srcX.

srcY) to the CUDA array dstArray starting at the upper left corner (dstX. size_t dstX. cudaMemcpyFromArray. cudaMemcpy2DToArray. cudaMemcpyHostToDevice. size_t srcX. size_t height. size_t srcY. cudaMemcpyToArray. or cudaMemcpyDeviceToDevice. const struct cudaArray* srcArray. cudaMemcpyDeviceToHost. and specifies the direction of the copy. cudaMemcpyToSymbol. dstY).17 cudaMemcpy2DArrayToArray NAME cudaMemcpy2DArrayToArray . enum cudaMemcpyKind kind) DESCRIPTION Copies a matrix (height rows of width bytes each) from the CUDA array srcArray starting at the upper left corner (srcX. asynchronous launches. cudaMemcpy2D. cudaMemcpyFromSymbol 41 . where kind is one of cudaMemcpyHostToHost. cudaMemcpyArrayToArray.5. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidMemcpyDirection Note that this function may also return error codes from previous.1. cudaMemcpy2DFromArray. size_t dstY. SEE ALSO cudaMemcpy. size_t width.copies data between host and device SYNOPSIS cudaError_t cudaMemcpy2DArrayToArray(struct cudaArray* dstArray.

The memory areas may not overlap. naming a variable that resides in global or constant memory space. const void* src.5. cudaMemcpyFromArray.18 cudaMemcpyToSymbol NAME cudaMemcpyToSymbol . cudaMemcpy2D. cudaMemcpyFromSymbol 42 . asynchronous launches.1. kind can be either cudaMemcpyHostToDevice or cudaMemcpyDeviceToDevice. cudaMemcpyArrayToArray. cudaMemcpy2DArrayToArray. cudaMemcpy2DToArray.copies data from host memory to GPU SYNOPSIS template < class T > cudaError_t cudaMemcpyToSymbol( const T& symbol. symbol can either be a variable that resides in global or constant memory space. cudaMemcpyToArray. enum cudaMemcpyKind kind) DESCRIPTION Copies count bytes from the memory area pointed to by src to the memory area pointed to by offset bytes from the start of symbol symbol. cudaMemcpy2DFromArray. SEE ALSO cudaMemcpy. size_t count. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidSymbol cudaErrorInvalidDevicePointer cudaErrorInvalidMemcpyDirection Note that this function may also return error codes from previous. or it can be a character string. size_t offset.

The memory areas may not overlap. cudaMemcpy2DArrayToArray. cudaMemcpy2DToArray. or it can be a character string. naming a variable that resides in global or constant memory space. const T& symbol. cudaMemcpy2D.copies data from GPU to host memory SYNOPSIS template < class T > cudaError_t cudaMemcpyFromSymbol( void *dst.19 cudaMemcpyFromSymbol NAME cudaMemcpyFromSymbol . SEE ALSO cudaMemcpy. asynchronous launches. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidSymbol cudaErrorInvalidDevicePointer cudaErrorInvalidMemcpyDirection Note that this function may also return error codes from previous. cudaMemcpyToSymbol 43 . cudaMemcpy2DFromArray. kind can be either cudaMemcpyDeviceToHost or cudaMemcpyDeviceToDevice. symbol can either be a variable that resides in global or constant memory space. cudaMemcpyFromArray. enum cudaMemcpyKind kind) DESCRIPTION Copies count bytes from the memory area pointed to by offset bytes from the start of symbol symbol to the memory area pointed to by dst. size_t offset.5. cudaMemcpyArrayToArray.1. cudaMemcpyToArray. size_t count.

20 cudaGetSymbolAddress NAME cudaGetSymbolAddress . naming a variable that resides in global memory space. const T& symbol) DESCRIPTION Returns in *devPtr the address of symbol symbol on the device.finds the address associated with a CUDA symbol SYNOPSIS template < class T > cudaError_t cudaGetSymbolAddress(void** devPtr. symbol can either be a variable that resides in global memory space. If symbol cannot be found. or it can be a character string. asynchronous launches. cudaGetSymbolAddress() returns cudaErrorInvalidSymbol in case of failure RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidSymbol cudaErrorAddressOfConstant Note that this function may also return error codes from previous. SEE ALSO cudaGetSymbolSize 44 .5. or if symbol is not declared in global memory space.1. *devPtr is unchanged and an error is returned.

RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidSymbol Note that this function may also return error codes from previous. SEE ALSO cudaGetSymbolAddress 45 . or if symbol is not declared in global or constant memory space. *size is unchanged and an error is returned. symbol can either be a variable that resides in global or constant memory space. const T& symbol) DESCRIPTION Returns in *size the size of symbol symbol.1. cudaGetSymbolSize() returns cudaErrorInvalidSymbol in case of failure. If symbol cannot be found.finds the size of the object associated with a CUDA symbol SYNOPSIS template < class T > cudaError_t cudaGetSymbolSize(size_t* size. naming a variable that resides in global or constant memory space. or it can be a character string.5. asynchronous launches.21 cudaGetSymbolSize NAME cudaGetSymbolSize .

22 cudaMalloc3D NAME cudaMalloc3D . this is especially true if the application will be performing memory copies involving 2D or 3D objects (whether linear memory or CUDA arrays). Due to alignment restrictions in the hardware. For allocations of 2D. which are equivalent to the width and height extent parameters provided by the programmer during allocation. }. The pitch returned in the pitch field of the pitchedDevPtr is the width in bytes of the allocation. The returned cudaPitchedPtr contains additional fields xsize and ysize. 46 .1.5. struct cudaExtent { size_t width. The function may pad the allocation to ensure hardware alignment requirements are met. cudaError_t cudaMalloc3D( struct cudaPitchedPtr* pitchDevPtr. 3D objects. asynchronous launches. size_t xsize. size_t height. the logical width and height of the allocation. 2D. size_t pitch. }. or 3D memory objects on the GPU SYNOPSIS struct cudaPitchedPtr { void *ptr. it is highly recommended that programmers perform allocations using cudaMalloc3D() or cudaMallocPitch(). size_t ysize. struct cudaExtent extent ) DESCRIPTION Allocates at least width*height*depth bytes of linear memory on the device and returns a pitchedDevPtr in which ptr is a pointer to the allocated memory. RETURN VALUE Relevant return values: cudaSuccess cudaErrorMemoryAllocation Note that this function may also return error codes from previous.allocates logical 1D. size_t depth.

cudaMalloc3DArray. cudaFreeArray. cudaFreeHost 47 . cudaFree. cudaMemset3D. cudaMallocHost.SEE ALSO cudaMallocPitch. cudaMallocArray. cudaMemcpy3D.

For instance. 0} . size_t height. • A 2D array is allocated if only the depth extent is zero. 2D. or 3D arrays. 0. (1. enum cudaChannelFormatKind f. y. • A 3D array is allocate if all three extents are non-zero. asynchronous launches. cudaError_t cudaMalloc3DArray( struct cudaArray** arrayPtr. 2048). cudaMalloc3DArray is able to allocate 1D.5. where cudaChannelFormatKind is one of cudaChannelFormatKindSigned.1. 2048).23 cudaMalloc3DArray NAME cudaMalloc3DArray . 8192). • A 1D array is allocated if the height and depth extent are both zero. For 3D arrays valid extents are {(1. cudaChannelFormatKindFloat. 32768). }. w. cudaChannelFormatKindUnsigned. a degenerate 2D array allows for significantly more linear storage than a 1D array.allocate an array on the GPU SYNOPSIS struct cudaExtent { size_t width. For 2D arrays valid extents are {(1. struct cudaExtent extent ) DESCRIPTION Allocates a CUDA array according to the cudaChannelFormatDesc structure desc and returns a handle to the new CUDA array in *arrayPtr. RETURN VALUE Relevant return values: cudaSuccess cudaErrorMemoryAllocation Note that this function may also return error codes from previous. 2048)}. For 1D arrays valid extents are {(1. The cudaChannelFormatDesc is defined as: struct cudaChannelFormatDesc { int x. Note: That because of the differing extent limits it may be advantageous to use a degenerate array (with unused dimensions set to one) of higher dimensionality. 65536). size_t depth. 48 . (1. z. }. const struct cudaChannelFormatDesc* desc. (1. 0}.

cudaMalloc. cudaFreeArray.SEE ALSO cudaMalloc3D. cudaFree. cudaMallocPitch. cudaFreeHost 49 . cudaMallocHost.

asynchronous launches. The extents of the initialized region are specified as a width in bytes. The object to initialize is defined by dstPitchPtr.1. size_t depth. The xsize field specifies the logical width of each row in bytes. cudaError_t cudaMemset3D( struct cudaPitchedPtr dstPitchPtr.5. including any padding added to the end of each row. while the ysize field specifies the height of each 2D slice in rows. size_t xsize. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidDevicePointer Note that this function may also return error codes from previous. extents with height equal to the ysize of dstPitchPtr will perform faster than when the hieght is shorter than the ysize. struct cudaExtent extent ) DESCRIPTION Initializes each element of a 3D array to the specified value value. size_t height.initializes or sets GPU memory to a value SYNOPSIS struct cudaPitchedPtr { void *ptr. 50 . Secondarily. int value. struct cudaExtent { size_t width. size_t ysize. This function performs fastest when the dstPitchPtr has been allocated by cudaMalloc3D(). a height in rows. The pitch field of dstPitchPtr is the width in memory in bytes of the 3D array pointed to by dstPitchPtr. size_t pitch. }. and a depth in slices. Extents with width greater than or equal to the xsize of dstPitchPtr may perform significantly faster than extents narrower than the xsize. }.24 cudaMemset3D NAME cudaMemset3D .

cudaMalloc3D 51 . cudaMemset2D.SEE ALSO cudaMemset.

y. The kind field defines the direction of the copy. The struct passed to cudaMemcpy3D() must specify one of srcArray or srcPtr and one of dstArray or dstPtr. struct cudaPos { size_t x. destination. or cudaMemcpyDeviceToDevice. struct cudaPos srcPos. struct cudaArray *dstArray. and kind of copy performed is specified by the cudaMemcpy3DParms struct which should be initialized to zero before use: cudaMemcpy3DParms myParms = {0}.copies data between between 3D objects SYNOPSIS struct cudaExtent { size_t width. height. struct cudaPos dstPos. }.25 cudaMemcpy3D NAME cudaMemcpy3D . The source.5. 52 . The source and destination objects may be in either host memory. z. }. The srcPos and dstPos fields are optional offsets into the source and destination objects and are defined in units of each object’s elements. 2048) for any dimension. or a CUDA array. device memory. positions must be in the range [0. If no CUDA array is participating in the copy then the extents are defined in elements of unsigned char. For CUDA arrays. The extent field defines the dimensions of the transferred area in elements. cudaError_t cudaMemcpy3D( const struct cudaMemcpy3DParms *p ) cudaError_t cudaMemcpy3DAsync( const struct cudaMemcpy3DParms *p. The element for a host or device pointer is assumed to be unsigned char. cudaMemcpyHostToDevice. cudaMemcpyDeviceToHost. cudaStream_t stream ) DESCRIPTION cudaMemcpy3D() copies data betwen two 3D objects. enum cudaMemcpyKind kind. struct cudaExtent extent. Passing more than one non-zero source or destination will cause cudaMemcpy3D() to return an error. struct cudaPitchedPtr dstPtr. It must be one of cudaMemcpyHostToHost. struct cudaMemcpy3DParms { struct cudaArray *srcArray. If a CUDA array is participating in the copy the extent is defined in terms of that array’s elements. }. struct cudaPitchedPtr srcPtr. extent. depth.1.

cudaMemcpy3DAsync() is an asynchronous copy operation and can optionally be associated to a stream by passing a non-zero stream argument. RETURN VALUE cudaSuccess SEE ALSO cudaMalloc3D. cudaMemcpyArrayToArray. cudaMemcpy. cudaMemcpy3D() returns an error if the pitch of srcPtr or dstPtr is greater than the maximum allowed. cudaMemset3D. cudaMalloc3DArray. If either the source or destination is a host object it must be allocated in page-locked memory returned from cudaMallocHost(). cudaMemcpyToSymbol.If the source and destination are both arrays cudaMemcpy3D() will return an error if they do not have the same element size. cudaMemcpy2DToArray. cudaMemcpy2DArrayToArray. cudaMemcpyFromSymbol 53 . The pitch of a cudaPitchedPtr allocated with cudaMalloc3D() will always be valid. The source and destination object may not overlap. If overlapping source and destination objects are specified undefined behavior will result. cudaMemcpyFromArray. It will return an error if a pointer to memory not allocated with cudaMallocHost() is passed as input. cudaMemcpyToArray. cudaMemcpy2DFromArray.

Event Management.1. Texture Reference Management. Stream Management. Thread Management. Error Handling 54 .6 TextureReferenceManagement RT NAME Texture Reference Management DESCRIPTION This section describes the CUDA runtime application programming interface. Low-Level API High-Level API SEE ALSO Device Management. Memory Management. Execution Management. Direct3D Interoperability. OpenGL Interoperability.

1.6.1 LowLevelApi NAME Low-Level Texture API DESCRIPTION This section describes the low-level CUDA run-time application programming interface for textures cudaCreateChannelDesc cudaGetChannelDesc cudaGetTextureReference cudaBindTexture cudaBindTextureToArray cudaUnbindTexture cudaGetTextureAlignmentOffset SEE ALSO High-Level API 55 .

cudaBindTextureToArray. The cudaChannelFormatDesc is defined as: struct cudaChannelFormatDesc { int x. enum cudaChannelFormatKin f). where cudaChannelFormatKind is one of cudaChannelFormatKindSigned. cudaUnbindTexture. cudaChannelFormatKindFloat. and w. RETURN VALUE Relevant return values: cudaSuccess Note that this function may also return error codes from previous. z.Low-level texture API SYNOPSIS struct cudaChannelFormatDesc cudaCreateChannelDesc(int x. y. w. }. cudaBindTexture.cudaCreateChannelDesc NAME cudaCreateChannelDesc . cudaGetTextureReference. DESCRIPTION Returns a channel descriptor with format f and number of bits of each component x. z. int w. asynchronous launches. cudaGetTextureAlignmentOffset 56 . int z. enum cudaChannelFormatKind f. y. cudaChannelFormatKindUnsigned. int y. SEE ALSO cudaGetChannelDesc.

cudaBindTexture. asynchronous launches.Low-level texture API SYNOPSIS cudaError_t cudaGetChannelDesc(struct cudaChannelFormatDesc* desc. cudaGetTextureAlignmentOffset 57 . SEE ALSO cudaCreateChannelDesc. cudaUnbindTexture. cudaBindTextureToArray. const struct cudaArray* array). cudaGetTextureReference. DESCRIPTION Returns in *desc the channel descriptor of the CUDA array array.cudaGetChannelDesc NAME cudaGetChannelDesc . RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue Note that this function may also return error codes from previous.

asynchronous launches. cudaBindTexture. cudaGetChannelDesc. cudaBindTextureToArray. const char* symbol) DESCRIPTION Returns in *texRef the structure associated to the texture reference defined by symbol symbol.cudaGetTextureReference NAME cudaGetTextureReference .Low-level texture API SYNOPSIS cudaError_t cudaGetTextureReference( struct textureReference** texRef. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidTexture Note that this function may also return error codes from previous. cudaGetTextureAlignmentOffset 58 . cudaUnbindTexture. SEE ALSO cudaCreateChannelDesc.

Low-level texture API SYNOPSIS cudaError_t cudaBindTexture(size_t* offset. cudaGetTextureAlignmentOffset 59 . the offset is guaranteed to be 0 and NULL may be passed as the offset parameter. DESCRIPTION Binds size bytes of the memory area pointed to by devPtr to the texture reference texRef.cudaBindTexture NAME cudaBindTexture . size_t size = UINT_MAX). cudaGetTextureReference. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidDevicePointer cudaErrorInvalidTexture Note that this function may also return error codes from previous. cudaUnbindTexture. const void* devPtr. Any memory previously bound to texRef is unbound. Since the hardware enforces an alignment requirement on texture base addresses. asynchronous launches. const struct textureReference* texRef. desc describes how the memory is interpreted when fetching values from the texture. cudaGetChannelDesc. cudaBindTexture() returns in *offset a byte offset that must be applied to texture fetches in order to read from the desired memory. const struct cudaChannelFormatDesc* desc. If the device memory pointer was returned from cudaMalloc(). This offset must be divided by the texel size and passed to kernels that read from the texture so they can be applied to the tex1Dfetch() function. SEE ALSO cudaCreateChannelDesc. cudaBindTextureToArray.

const struct cudaChannelFormatDesc* desc).cudaBindTextureToArray NAME cudaBindTextureToArray . const struct cudaArray* array.Low-level texture API SYNOPSIS cudaError_t cudaBindTextureToArray( const struct textureReference* texRef. cudaGetChannelDesc. asynchronous launches. DESCRIPTION Binds the CUDA array array to the texture reference texRef. cudaBindTexture. cudaUnbindTexture. SEE ALSO cudaCreateChannelDesc. cudaGetTextureAlignmentOffset 60 . cudaGetTextureReference. Any CUDA array previously bound to texRef is unbound. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidDevicePointer cudaErrorInvalidTexture Note that this function may also return error codes from previous. desc describes how the memory is interpreted when fetching values from the texture.

DESCRIPTION Unbinds the texture bound to texture reference texRef. cudaBindTextureToArray. cudaGetChannelDesc. cudaGetTextureAlignmentOffset 61 . cudaBindTexture. RETURN VALUE Relevant return values: cudaSuccess Note that this function may also return error codes from previous.Low-level texture API SYNOPSIS cudaError_t cudaUnbindTexture( const struct textureReference* texRef). SEE ALSO cudaCreateChannelDesc.cudaUnbindTexture NAME cudaUnbindTexture . asynchronous launches. cudaGetTextureReference.

Low-level texture API SYNOPSIS cudaError_t cudaGetTextureAlignmentOffset(size_t* offset. cudaGetChannelDesc. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidTexture cudaErrorInvalidTextureBinding Note that this function may also return error codes from previous. asynchronous launches. const struct textureReference* texRef). cudaBindTexture. DESCRIPTION Returns in *offset the offset that was returned when texture reference texRef was bound. cudaUnbindTexture 62 . SEE ALSO cudaCreateChannelDesc. cudaGetTextureReference. cudaBindTextureToArray.cudaGetTextureAlignmentOffset NAME cudaGetTextureAlignmentOffset .

1.6.2 HighLevelApi NAME High-Level Texture API DESCRIPTION This section describes the high-level CUDA run-time application programming interface for textures cudaCreateChannelDesc cudaBindTexture cudaBindTextureToArray cudaUnbindTexture SEE ALSO Low-Level API 63 .

DESCRIPTION Returns a channel descriptor with format f and number of bits of each component x. y. cudaChannelFormatKindFloat. y. z. and w. enum cudaChannelFormatKind f. RETURN VALUE Relevant return values: cudaSuccess Note that this function may also return error codes from previous. w. where cudaChannelFormatKind is one of cudaChannelFormatKindSigned. The cudaChannelFormatDesc is defined as: struct cudaChannelFormatDesc { int x. }.High-level texture API SYNOPSIS template < class T > struct cudaChannelFormatDesc cudaCreateChannelDesc <T >().cudaCreateChannelDesc HL NAME cudaCreateChannelDesc . SEE ALSO 64 . z. cudaChannelFormatKindUnsigned. asynchronous launches.

int dim. int dim. readMode >& texRef.High-level texture API SYNOPSIS template < class T. const void* devPtr. desc describes how the memory is interpreted when fetching values from the texture. const struct texture < T. size_t size = UINT_MAX). size_t size = UINT_MAX) DESCRIPTION Binds size bytes of the memory area pointed to by devPtr to texture reference texRef.cudaBindTexture HL NAME cudaBindTexture . asynchronous launches. template E<lt> class T. const struct texture E<lt> T. readMode E<gt>& texRef. binds size bytes of the memory area pointed to by devPtr to texture reference texRef. The offset parameter is an optional byte offset as with the lowlevel cudaBindTexture() function described RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidDevicePointer cudaErrorInvalidTexture Note that this function may also return error codes from previous. const struct cudaChannelFormatDesc& desc. dim. enum cudaTextureReadMode readMode > static __inline__ __host__ cudaError_t cudaBindTexture(size_t* offset. SEE ALSO 65 . The offset parameter is an optional byte offset as with the low-level cudaBindTexture() function. const void* devPtr. Any memory previously bound to texRef is unbound. enum cudaTextureReadMode readMode E<gt> static __inline__ __host__ cudaError_t cudaBindTexture( size_t* offset. dim. The channel descriptor is inherited from the texture reference type.

const struct cudaArray* cuArray). Any CUDA array previously bound to texRef is unbound. readMode >& texRef. The channel descriptor is inherited from the CUDA array. int dim. dim. dim. enum cudaTextureReadMode readMode > static __inline__ __host__ cudaError_t cudaBindTextureToArray( const struct texture < T. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidDevicePointer cudaErrorInvalidTexture Note that this function may also return error codes from previous. asynchronous launches. const struct cudaChannelFormatDesc& desc) DESCRIPTION Binds the CUDA array array to texture reference texRef. const struct cudaArray* cuArray.High-level texture API SYNOPSIS template < class T. Any CUDA array previously bound to texRef is unbound. binds the CUDA array array to texture reference texRef. enum cudaTextureReadMode readMode E<gt> static __inline__ __host__ cudaError_t cudaBindTextureToArray( const struct texture E<lt> T. template E<lt> class T. SEE ALSO cudaCreateChannelDesc_HL 66 . readMode E<gt>& texRef. int dim.cudaBindTextureToArray HL NAME cudaBindTextureToArray . desc describes how the memory is interpreted when fetching values from the texture.

RETURN VALUE Relevant return values: cudaSuccess Note that this function may also return error codes from previous. dim. readMode >& texRef) DESCRIPTION Unbinds the texture bound to texture reference texRef. enum cudaTextureReadMode readMode > static __inline__ __host__ cudaError_t cudaUnbindTexture(const struct texture < T. int dim. asynchronous launches.High-level texture API SYNOPSIS template < class T. SEE ALSO 67 .cudaUnbindTexture HL NAME cudaUnbindTexture .

Texture Reference Management.7 ExecutionControl RT NAME Execution Control DESCRIPTION This section describes the CUDA runtime application programming interface. Execution Management. Error Handling 68 . Event Management. Stream Management. Direct3D Interoperability. Memory Management. Thread Management. cudaConfigureCall cudaLaunch cudaSetupArgument SEE ALSO Device Management. OpenGL Interoperability.1.

size_t sharedMem = 0. together with any arguments for the call.1. This data contains the dimension for the grid and thread blocks. dim3 blockDim. cudaSetupArgument 69 .1 cudaConfigureCall NAME cudaConfigureCall .configure a device-launch SYNOPSIS cudaError_t cudaConfigureCall(dim3 gridDim. Each call pushes data on top of an execution stack. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidConfiguration Note that this function may also return error codes from previous. asynchronous launches. SEE ALSO cudaLaunch. int tokens = 0) DESCRIPTION Specifies the grid and block dimensions for the device call to be executed similar to the execution configuration syntax. cudaConfigureCall() is stack based.7.

cudaLaunch() must be preceded by a call to cudaConfigureCall() since it pops the data that was pushed by cudaConfigureCall() from the execution stack. SEE ALSO cudaConfigureCall. naming a function that executes on the device. or it can be a character string.2 cudaLaunch NAME cudaLaunch . entry must be declared as a __global__ function.7. cudaSetupArgument 70 . RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidDeviceFunction cudaErrorInvalidConfiguration Note that this function may also return error codes from previous. asynchronous launches.1. entry can either be a function that executes on the device.launches a device function SYNOPSIS template < class T > cudaError_t cudaLaunch(T entry) DESCRIPTION Launches the function entry on the device.

cudaSetupArgument() must be preceded by a call to cudaConfigureCall(). which starts at offset 0. size_t offset) DESCRIPTION Pushes count bytes of the argument pointed to by arg at offset bytes from the start of the parameter passing area.1.3 cudaSetupArgument NAME cudaSetupArgument .configure a device-launch SYNOPSIS cudaError_t cudaSetupArgument(void* arg. asynchronous launches. size_t offset) template < class T > cudaError_t cudaSetupArgument(T arg. SEE ALSO cudaConfigureCall. RETURN VALUE Relevant return values: cudaSuccess Note that this function may also return error codes from previous. size_t count.7. The arguments are stored in the top of the execution stack. cudaLaunch 71 .

1.8 OpenGlInteroperability RT NAME OpenGL Interoperability DESCRIPTION This section describes the CUDA runtime application programming interface. Direct3D Interoperability. Memory Management. cudaGLSetGLDevice cudaGLRegisterBufferObject cudaGLMapBufferObject cudaGLUnmapBufferObject cudaGLUnregisterBufferObject SEE ALSO Device Management. Texture Reference Management. Execution Management. Error Handling 72 . Event Management. Thread Management. OpenGL Interoperability. Stream Management.

8.1 cudaGLSetGLDevice NAME cudaGLSetGLDevice . asynchronous launches. cudaGLUnmapBufferObject. Records the thread as using GL Interopability.1.sets the CUDA device for use with GL Interopability SYNOPSIS cudaError_t cudaGLSetGLDevice(int device). cudaGLUnregisterBufferObject 73 . RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidDevice Note that this function may also return error codes from previous. SEE ALSO cudaGLRegisterBufferObject. cudaGLMapBufferObject. DESCRIPTION Records dev as the device on which the active host thread executes the device code.

This function must be called before CUDA can map the buffer object. the buffer object cannot be used by any OpenGL commands except as a data source for OpenGL drawing commands.8.1.2 cudaGLRegisterBufferObject NAME cudaGLRegisterBufferObject . cudaGLMapBufferObject. cudaGLUnmapBufferObject. RETURN VALUE Relevant return values: cudaSuccess cudaErrorNotInitialized Note that this function may also return error codes from previous. While it is registered. cudaGLUnregisterBufferObject 74 . asynchronous launches. SEE ALSO cudaGLSetGLDevice.OpenGL interoperability SYNOPSIS cudaError_t cudaGLRegisterBufferObject(GLuint bufferObj) DESCRIPTION Registers the buffer object of ID bufferObj for access by CUDA.

8.3 cudaGLMapBufferObject NAME cudaGLMapBufferObject . GLuint bufferObj). SEE ALSO cudaGLSetGLDevice. RETURN VALUE Relevant return values: cudaSuccess cudaErrorMapBufferObjectFailed Note that this function may also return error codes from previous. cudaGLRegisterBufferObject. cudaGLUnregisterBufferObject 75 . asynchronous launches.OpenGL interoperability SYNOPSIS cudaError_t cudaGLMapBufferObject(void** devPtr. cudaGLUnmapBufferObject. DESCRIPTION Maps the buffer object of ID bufferObj into the address space of CUDA and returns in *devPtr the base pointer of the resulting mapping.1.

asynchronous launches. cudaGLUnregisterBufferObject 76 .OpenGL interoperability SYNOPSIS cudaError_t cudaGLUnmapBufferObject(GLuint bufferObj). SEE ALSO cudaGLSetGLDevice.4 cudaGLUnmapBufferObject NAME cudaGLUnmapBufferObject . cudaGLRegisterBufferObject.1. DESCRIPTION Unmaps the buffer object of ID bufferObj for access by CUDA. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidDevicePointer cudaErrorUnmapBufferObjectFailed Note that this function may also return error codes from previous. cudaGLMapBufferObject.8.

SEE ALSO cudaGLSetGLDevice. cudaGLRegisterBufferObject. cudaGLMapBufferObject.8. cudaGLUnmapBufferObject 77 .OpenGL interoperability SYNOPSIS cudaError_t cudaGLUnregisterBufferObject(GLuint bufferObj). DESCRIPTION Unregisters the buffer object of ID bufferObj for access by CUDA. asynchronous launches.5 cudaGLUnregisterBufferObject NAME cudaGLUnregisterBufferObject .1. RETURN VALUE Relevant return values: cudaSuccess Note that this function may also return error codes from previous.

1.9

Direct3dInteroperability RT

NAME
Direct3D Interoperability

DESCRIPTION
This section describes the CUDA runtime application programming interface. cudaD3D9GetDevice cudaD3D9SetDirect3DDevice cudaD3D9GetDirect3DDevice cudaD3D9RegisterResource cudaD3D9UnregisterResource cudaD3D9MapResources cudaD3D9UnmapResources cudaD3D9ResourceGetSurfaceDimensions cudaD3D9ResourceSetMapFlags cudaD3D9ResourceGetMappedPointer cudaD3D9ResourceGetMappedSize cudaD3D9ResourceGetMappedPitch As of CUDA 2.0 the following functions are deprecated. They should not be used in new development. cudaD3D9Begin cudaD3D9End cudaD3D9RegisterVertexBuffer cudaD3D9MapVertexBuffer cudaD3D9UnmapVertexBuffer cudaD3D9UnregisterVertexBuffer

SEE ALSO
Device Management, Thread Management, Stream Management, Event Management, Execution Management, Memory Management, Texture Reference Management, OpenGL Interoperability, Direct3D Interoperability, Error Handling

78

1.9.1

cudaD3D9GetDevice

NAME
cudaD3D9GetDevice - gets the device number for an adapter

SYNOPSIS
cudaError_t cudaD3D9GetDevice(int* dev, const char* adapterName);

DESCRIPTION
Returns in *dev the CUDA-compatible device corresponding to the adapter name adapterName obtained from EnumDisplayDevices or IDirect3D9::GetAdapterIdentifier(). If no device on the adapter with name adapterName is CUDA-compatible then the call will fail.

RETURN VALUE
Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorUnknown Note that this function may also return error codes from previous, asynchronous launches.

SEE ALSO

cudaD3D9SetDirect3DDevice, cudaD3D9GetDirect3DDevice, cudaD3D9RegisterResource, cudaD3D9UnregisterResource, cudaD3D9MapResources, cudaD3D9UnmapResources, cudaD3D9ResourceGetSurfaceDimensions, cudaD3D9ResourceSetMapF cudaD3D9ResourceGetMappedPointer, cudaD3D9ResourceGetMappedSize, cudaD3D9ResourceGetMappedPitch

79

1.9.2

cudaD3D9SetDirect3DDevice

NAME
cudaD3D9SetDirect3DDevice - sets the Direct3D device to use for interoperability in this thread

SYNOPSIS
cudaError_t cudaD3D9SetDirect3DDevice(IDirect3DDevice9* pDxDevice);

DESCRIPTION
Records pDxDevice as the Direct3D device to use for Direct3D interoperability on this host thread. In order to use Direct3D interoperability, this call must be made before any other CUDA runtime calls on this thread. Successful context creation on pDxDevice will increase the internal reference count on pDxDevice. This reference count will be decremented upon destruction of this context through cudaThreadExit.

RETURN VALUE
Relevant return values: cudaSuccess cudaErrorInitializationError cudaErrorInvalidValue Note that this function may also return error codes from previous, asynchronous launches.

SEE ALSO

cudaD3D9GetDevice, cudaD3D9GetDirect3DDevice, cudaD3D9RegisterResource, cudaD3D9UnregisterResource, cudaD3D9MapResources, cudaD3D9UnmapResources, cudaD3D9ResourceGetSurfaceDimensions, cudaD3D9ResourceSetMapF cudaD3D9ResourceGetMappedPointer, cudaD3D9ResourceGetMappedSize, cudaD3D9ResourceGetMappedPitch

80

1.9.3

cudaD3D9GetDirect3DDevice

NAME
cudaD3D9GetDirect3DDevice - get the Direct3D device against which the current CUDA context was created

SYNOPSIS
cudaError_t cudaD3D9GetDirect3DDevice(IDirect3DDevice9** ppDxDevice);

DESCRIPTION
Returns in *ppDxDevice the Direct3D device against which this CUDA context was created in cudaD3D9SetDirect3DDevice.

RETURN VALUE
Relevant return values: cudaSuccess cudaErrorUnknown Note that this function may also return error codes from previous, asynchronous launches.

SEE ALSO

cudaD3D9GetDevice, cudaD3D9SetDirect3DDevice, cudaD3D9RegisterResource, cudaD3D9UnregisterResource, cudaD3D9MapResources, cudaD3D9UnmapResources, cudaD3D9ResourceGetSurfaceDimensions, cudaD3D9ResourceSetMapF cudaD3D9ResourceGetMappedPointer, cudaD3D9ResourceGetMappedSize, cudaD3D9ResourceGetMappedPitch

81

this call will increase the internal reference count on pResource.register a Direct3D resource for access by CUDA SYNOPSIS cudaError_t cudaD3D9RegisterResource(IDirect3DResource9* pResource. This call is potentially high-overhead and should not be called every frame in interactive applications. • IDirect3DBaseTexture9: When a texture is registered all surfaces associated with the all mipmap levels of all faces of the texture will be accessible to CUDA. This reference count will be decremented when this resource is unregistered through cudaD3D9UnregisterResource. 16. 2. • Any resources allocated in D3DPOOL_SYSTEMMEM may not be registered with CUDA. • IDirect3DVertexBuffer9: No notes. • The primary rendertarget may not be registered with CUDA. The Flags argument specifies the mechanism through which CUDA will access the Direct3D resource. or 32-bit integer or floating-point data cannot be shared. and pitch for each subresource of this resource may be queried through cudaD3D9ResourceGetMappedPointe cudaD3D9ResourceGetMappedSize. The pointer. and cudaD3D9ResourceGetMappedPitch respectively.4 cudaD3D9RegisterResource NAME cudaD3D9RegisterResource . • Textures which are not of a format which is 1. DESCRIPTION Registers the Direct3D resource pResource for access by CUDA. unsigned int Flags). one must register the base texture object. If this call is successful then the application will be able to map and unmap this resource until it is unregistered through cudaD3D9UnregisterResource. • cudaD3D9RegisterFlagsNone: Specifies that CUDA will access this resource through a void*. • Resources allocated as shared may not be registered with CUDA. size. individual mipmap levels and faces of cube maps may not be registered directly. or 4 channels of 8. The following are some limitations. This option is valid for all resource types.1. • IDirect3DSurface9: Only stand-alone objects of type IDirect3DSurface9 may be explicitly shared. The following value is allowed. The type of pResource must be one of the following. Not all Direct3D resources of the above types may be used for interoperability with CUDA. In particular. 82 .9. Also on success. • IDirect3DIndexBuffer9: No notes. To access individual surfaces associated with a texture.

If pResource is of incorrect type (e. asynchronous launches. cudaD3D9UnregisterResource. cudaD3D9UnmapResources. cudaD3D9SetDirect3DDevice. If Direct3D interoperability is not initialized on this context then is returned. cudaD3D9ResourceGetMappedSize.g. cudaD3D9MapResources. cudaD3D9ResourceGetMappedPitch 83 .• Surfaces of depth or stencil formats cannot be shared. SEE ALSO cudaD3D9GetDevice. is a non-stand-alone IDirect3DSurface9) or is already registered then cudaErrorInvalidHandle is returned. cudaD3D9ResourceGetSurfaceDimensions. cudaD3D9ResourceSetMapF cudaD3D9ResourceGetMappedPointer. If pResource cannot be registered then cudaErrorUnknown is returned. cudaD3D9GetDirect3DDevice. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidHandle cudaErrorUnknown Note that this function may also return error codes from previous.

cudaD3D9ResourceGetMappedSize. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidHandle cudaErrorUnknown Note that this function may also return error codes from previous. cudaD3D9SetDirect3DDevice.9. asynchronous launches. cudaD3D9UnmapResources. cudaD3D9MapResources. cudaD3D9GetDirect3DDevice. cudaD3D9ResourceGetMappedPitch 84 .unregister a Direct3D resource SYNOPSIS cudaError_t cudaD3D9UnregisterResource(IDirect3DResource9* pResource).5 cudaD3D9UnregisterResource NAME cudaD3D9UnregisterResource .1. cudaD3D9ResourceGetSurfaceDimensions. DESCRIPTION Unregisters the Direct3D resource pResource so it is not accessable by CUDA unless registered again. If pResource is not registered then cudaErrorInvalidHandle is returned. cudaD3D9RegisterResource. cudaD3D9ResourceSetMapF cudaD3D9ResourceGetMappedPointer. SEE ALSO cudaD3D9GetDevice.

RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidHandle cudaErrorUnknown Note that this function may also return error codes from previous. If any of ppResources have not been registered for use with CUDA or if ppResources contains any duplicate entries then cudaErrorInvalidHandle is returned. cudaD3D9UnmapResources. cudaD3D9ResourceSetMapFlags. asynchronous launches. SEE ALSO cudaD3D9GetDevice. This function provides the synchronization guarantee that any Direct3D calls issued before cudaD3D9MapResources will complete before any CUDA kernels issued after cudaD3D9MapResources begin. DESCRIPTION Maps the count Direct3D resources in ppResources for access by CUDA. If an application does so the results are undefined.9. cudaD3D9ResourceGetMappedPitch 85 . cudaD3D9UnregisterResource.6 cudaD3D9MapResources NAME cudaD3D9MapResources . The resources in ppResources may be accessed in CUDA kernels until they are unmapped. cudaD3D9ResourceGetMappedPointer. cudaD3D9ResourceGetMappedSize. If any of ppResources are presently mapped for access by CUDA then cudaErrorUnknown is returned. cudaD3D9GetDirect3DDevice. IDirect3DResource9 **ppResources). cudaD3D9SetDirect3DDevice. Direct3D should not access any resources while they are mapped by CUDA.map Direct3D resources for access by CUDA SYNOPSIS cudaError_t cudaD3D9MapResources(unsigned int count.1. cudaD3D9ResourceGetSurfaceDimensions. cudaD3D9RegisterResource.

1. SEE ALSO cudaD3D9GetDevice. cudaD3D9ResourceGetSurfaceDimensions. cudaD3D9ResourceGetMappedPitch 86 . cudaD3D9ResourceSetMa cudaD3D9ResourceGetMappedPointer.7 cudaD3D9UnmapResources NAME cudaD3D9UnmapResources . DESCRIPTION Unmaps the count Direct3D resources in ppResources.9. cudaD3D9MapResources. cudaD3D9RegisterResource. This function provides the synchronization guarantee that any CUDA kernels issued before cudaD3D9UnmapResources will complete before any Direct3D calls issued after cudaD3D9UnmapResources begin. cudaD3D9SetDirect3DDevice. cudaD3D9ResourceGetMappedSize. cudaD3D9GetDirect3DDevice. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidHandle cudaErrorUnknown Note that this function may also return error codes from previous. asynchronous launches. If any of ppResources have not been registered for use with CUDA or if ppResources contains any duplicate entries then cudaErrorInvalidHandle is returned. cudaD3D9UnregisterResource.unmap Direct3D resources SYNOPSIS cudaError_t cudaD3D9UnmapResources(unsigned int count. IDirect3DResource9** ppResources). If any of ppResources are not presently mapped for access by CUDA then cudaErrorUnknown is returned.

RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidHandle cudaErrorUnknown Note that this function may also return error codes from previous. unsigned int Flags). DESCRIPTION Set flags for mapping the Direct3D resource pResource. • cudaD3D9MapFlagsReadOnly: Specifies that CUDA kernels which access this resource will not write to this resource. If pResource is presently mapped for access by CUDA then cudaErrorUnknown is returned. asynchronous launches.1.9. If pResource has not been registered for use with CUDA then cudaErrorInvalidHandle is returned. Changes to flags will take effect the next time pResource is mapped. • cudaD3D9MapFlagsWriteDiscard: Specifies that CUDA kernels which access this resource will not read from this resource and will write over the entire contents of the resource. It is therefore assumed that this resource will be read from and written to by CUDA kernels. The Flags argument may be any of the following. so none of the data previously stored in the resource will be preserved. • cudaD3D9MapFlagsNone: Specifies no hints about how this resource will be used. 87 .8 cudaD3D9ResourceSetMapFlags NAME cudaD3D9ResourceSetMapFlags .set usage flags for mapping a Direct3D resource SYNOPSIS cudaError_t cudaD3D9ResourceSetMapFlags(IDirect3DResource9 *pResource. This is the default value.

cudaD3D9SetDirect3DDevice. cudaD3D9ResourceGetMappedPitch 88 . cudaD3D9MapResources. cudaD3D9UnregisterResource. cudaD3D9UnmapResources. cudaD3D9ResourceGetSurfaceDimensio cudaD3D9ResourceGetMappedPointer. cudaD3D9RegisterResource. cudaD3D9ResourceGetMappedSize.SEE ALSO cudaD3D9GetDevice. cudaD3D9GetDirect3DDevice.

cudaD3D9ResourceGetMappedPitch 89 .get the dimensions of a registered surface SYNOPSIS cudaError_t cudaD3D9ResourceGetSurfaceDimensions(size_t* pWidth. size_t *pDepth. If pResource is not of type IDirect3DBaseTexture9 or IDirect3DSurface9 or if pResource has not been registered for use with CUDA then cudaErrorInvalidHandle is returned. cudaD3D9UnregisterResource. cudaD3D9ResourceGetMappedSize. unsigned int Level). For usage requirements of Face and Level parameters see cudaD3D9ResourceGetMappedPointer. For 2D surfaces. cudaD3D9ResourceSetMapFlags. cudaD3D9UnmapResources. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidHandle Note that this function may also return error codes from previous.9 cudaD3D9ResourceGetSurfaceDimensions NAME cudaD3D9ResourceGetSurfaceDimensions . the value returned in *pDepth will be 0. SEE ALSO cudaD3D9GetDevice.9. cudaD3D9MapResources. *pHeight. size_t* pHeight. unsigned int Face. pHeight. cudaD3D9ResourceGetMappedPointer. DESCRIPTION Returns in *pWidth. The parameters pWidth. cudaD3D9SetDirect3DDevice. Because anti-aliased surfaces may have multiple samples per pixel it is possible that the dimensions of a resource will be an integer factor larger than the dimensions reported by the Direct3D runtime. asynchronous launches. and pDepth are optional. IDirect3DResource9* pResource. cudaD3D9GetDirect3DDevice. cudaD3D9RegisterResource. and *pDepth the dimensions of the subresource of the mapped Direct3D resource pResource which corresponds to Face and Level.1.

cudaD3D9UnmapResources. DESCRIPTION Returns in *pPointer the base pointer of the subresource of the mapped Direct3D resource pResource which corresponds to Face and Level. cudaD3D9GetDirect3DDevice.1. The value set in pPointer may change every time that pResource is mapped. For all other types Face must be 0. If Face is invalid then cudaErrorInvalidValue is returned. unsigned int Face. cudaD3D9ResourceGetMappedSize. IDirect3DResource9* pResource.9. cudaD3D9MapResources. cudaD3D9RegisterResource. For all other types Level must be 0. If pResource is of type IDirect3DCubeTexture9 then Face must one of the values enumerated by type D3DCUBEMAP_FACES.get a pointer through which to access a subresource of a Direct3D resource which has been mapped for access by CUDA SYNOPSIS cudaError_t cudaD3D9ResourceGetMappedPointer(void** pPointer. unsigned int Level). If pResource was not registered with usage flags cudaD3D9RegisterFlagsNone then cudaErrorInvalidHandle is returned. cudaD3D9UnregisterResource. cudaD3D9ResourceGetSurfaceDimensio cudaD3D9ResourceSetMapFlags. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidHandle cudaErrorUnknown Note that this function may also return error codes from previous. If pResource is not registered then cudaErrorInvalidHandle is returned. SEE ALSO cudaD3D9GetDevice. If Level is invalid then cudaErrorInvalidValue is returned.10 cudaD3D9ResourceGetMappedPointer NAME cudaD3D9ResourceGetMappedPointer . asynchronous launches. If pResource is not mapped then cudaErrorUnknown is returned. Only mipmap level 0 is supported for now. If pResource is of type IDirect3DBaseTexture9 then Level must correspond to a valid mipmap level. cudaD3D9SetDirect3DDevice. cudaD3D9ResourceGetMappedPitch 90 .

If pResource was not registered with usage flags cudaD3D9RegisterFlagsNone then cudaErrorInvalidHandle is returned.11 cudaD3D9ResourceGetMappedSize NAME cudaD3D9ResourceGetMappedSize . unsigned int Level). IDirect3DResource9* pResource. cudaD3D9ResourceGetMappedPitch 91 . cudaD3D9ResourceGetSurfaceDimensio cudaD3D9ResourceSetMapFlags. cudaD3D9UnmapResources. If pResource has not been registered for use with CUDA then cudaErrorInvalidHandle is returned. cudaD3D9RegisterResource. cudaD3D9SetDirect3DDevice. unsigned int Face. cudaD3D9MapResources. cudaD3D9ResourceGetMappedPointer. SEE ALSO cudaD3D9GetDevice.get the size of a subresource of a Direct3D resource which has been mapped for access by CUDA SYNOPSIS cudaError_t cudaD3D9ResourceGetMappedSize(size_t* pSize. DESCRIPTION Returns in *pSize the size of the subresource of the mapped Direct3D resource pResource which corresponds to Face and Level. The value set in pSize may change every time that pResource is mapped. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidHandle cudaErrorUnknown Note that this function may also return error codes from previous.9.1. If pResource is not mapped for access by CUDA then cudaErrorUnknown is returned. cudaD3D9UnregisterResource. cudaD3D9GetDirect3DDevice. asynchronous launches. For usage requirements of Face and Level parameters see cudaD3D9ResourceGetMappedPointer.

get the pitch of a subresource of a Direct3D resource which has been mapped for access by CUDA SYNOPSIS cudaError_t cudaD3D9ResourceGetMappedPitch(size_t* pPitch. DESCRIPTION Returns in *pPitch and *pPitchSlice the pitch and Z-slice pitch of the subresource of the mapped Direct3D resource pResource which corresponds to Face and Level. The values set in pPitch and pPitchSlice may change every time that pResource is mapped. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInvalidValue cudaErrorInvalidHandle cudaErrorUnknown Note that this function may also return error codes from previous. y*pitch + (bytes per pixel)*x For a 3D surface the byte offset of the sample of at position x. The pitch and Z-slice pitch values may be used to compute the location of a sample on a surface as follows.y from the base pointer of the surface is If pResource is not of type IDirect3DBaseTexture9 or one of its sub-types or if pResource has not been registered for use with CUDA then cudaErrorInvalidHandle is returned. IDirect3DResource9* pResource.z from the base pointer of the surface is z*slicePitch + y*pitch + (bytes per pixel)*x Both parameters pPitch and pPitchSlice are optional and may be set to NULL. size_t* pPitchSlice. 92 .12 cudaD3D9ResourceGetMappedPitch NAME cudaD3D9ResourceGetMappedPitch .9. unsigned int Level). If pResource was not registered with usage flags cudaD3D9RegisterFlagsNone then cudaErrorInvalidHandle is returned. asynchronous launches. For a 2D surface the byte offset of the sample of at position x.y. If pResource is not mapped for access by CUDA then cudaErrorUnknown is returned. For usage requirements of Face and Level parameters see cudaD3D9ResourceGetMappedPointer.1. unsigned int Face.

cudaD3D9ResourceGetMappedSize 93 . cudaD3D9RegisterResource. cudaD3D9ResourceGetSurfaceDimensio cudaD3D9ResourceSetMapFlags.SEE ALSO cudaD3D9GetDevice. cudaD3D9UnregisterResource. cudaD3D9ResourceGetMappedPointer. cudaD3D9GetDirect3DDevice. cudaD3D9MapResources. cudaD3D9SetDirect3DDevice. cudaD3D9UnmapResources.

10 ErrorHandling RT NAME Error Handling DESCRIPTION This section describes the CUDA runtime application programming interface. Direct3D Interoperability. Texture Reference Management. Event Management. Memory Management. Error Handling 94 . Execution Management. Stream Management. cudaGetLastError cudaGetErrorString SEE ALSO Device Management. Thread Management. OpenGL Interoperability.1.

1. RETURN VALUE Relevant return values: cudaSuccess cudaErrorInitializationError cudaErrorLaunchFailure cudaErrorPriorLaunchFailure cudaErrorLaunchTimeout cudaErrorLaunchOutOfResources cudaErrorInvalidDeviceFunction cudaErrorInvalidConfiguration cudaErrorInvalidDevice cudaErrorInvalidValue cudaErrorInvalidDevicePointer cudaErrorInvalidTexture cudaErrorInvalidTextureBinding cudaErrorInvalidChannelDescriptor cudaErrorTextureFetchFailed cudaErrorTextureNotBound cudaErrorSynchronizationError cudaErrorUnknown cudaErrorInvalidResourceHandle cudaErrorNotReady Note that this function may also return error codes from previous asynchronous launches. 95 .10.returns the last error from a run-time call SYNOPSIS cudaError_t cudaGetLastError( void ) DESCRIPTION Returns the last error that was returned from any of the runtime calls in the same host thread and resets it to cudaSuccess.1 cudaGetLastError NAME cudaGetLastError .

cudaError 96 .SEE ALSO cudaGetErrorString.

returns the message string from an error SYNOPSIS const char* cudaGetErrorString(cudaError_t error).1.10. RETURN VALUE char* pointer to a NULL-terminated string SEE ALSO cudaGetLastError 97 . DESCRIPTION Returns a message string from an error code.2 cudaGetErrorString NAME cudaGetErrorString .

MemoryManagement. DeviceManagement. ModuleManagement.2 DriverApiReference NAME Driver API Reference DESCRIPTION This section describes the low-level CUDA driver application programming interface. EventManagement. TextureReferenceManagement. SEE ALSO Initialization. ContextManagement. OpenGlInteroperability. Direct3dInteroperability 98 . ExecutionControl. StreamManagement.

DeviceManagement. ContextManagement. Direct3dInteroperability 99 .2. MemoryManagement. cuInit SEE ALSO Initialization. OpenGlInteroperability. StreamManagement.1 Initialization NAME Driver Initialization DESCRIPTION This section describes the low-level CUDA driver application programming interface. ModuleManagement. TextureReferenceManagement. ExecutionControl. EventManagement.

1 cuInit NAME cuInit . asynchronous launches. any function from the driver API will return CUDA_ERROR_NOT_INITIALIZED. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_INVALID_VALUE CUDA_ERROR_NO_DEVICE Note that this function may also return error codes from previous. the Flags parameters must be 0. If cuInit() has not been called.initialize the CUDA driver API SYNOPSIS CUresult cuInit( unsigned int Flags ). DESCRIPTION Initializes the driver API and must be called before any other function from the driver API. Currently.2.1. SEE ALSO 100 .

StreamManagement. ExecutionControl. cuDeviceComputeCapability cuDeviceGet cuDeviceGetAttribute cuDeviceGetCount cuDeviceGetName cuDeviceGetProperties cuDeviceTotalMem SEE ALSO Initialization. ModuleManagement. TextureReferenceManagement. DeviceManagement. OpenGlInteroperability. ContextManagement.2 DeviceManagement NAME Device Management DESCRIPTION This section describes the low-level CUDA driver application programming interface. EventManagement. MemoryManagement. Direct3dInteroperability 101 .2.

returns the compute capability of the device SYNOPSIS CUresult cuDeviceComputeCapability(int* major.1 cuDeviceComputeCapability NAME cuDeviceComputeCapability . cuDeviceGetProperties. CUdevice dev). int* minor. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_INVALID_DEVICE Note that this function may also return error codes from previous. DESCRIPTION Returns in *major and *minor the major and minor revision numbers that define the compute capability of device dev.2. asynchronous launches. cuDeviceGetCount.2. cuDeviceTotalMem 102 . cuDeviceGetName. SEE ALSO cuDeviceGetAttribute. cuDeviceGet.

2 cuDeviceGet NAME cuDeviceGet .returns a device-handle SYNOPSIS CUresult cuDeviceGet(CUdevice* dev. cuDeviceTotalMem 103 . cuDeviceGetAttribute. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_INVALID_DEVICE Note that this function may also return error codes from previous. cuDeviceGetCount()-1]. cuDeviceGetName. SEE ALSO cuDeviceComputeCapability. asynchronous launches.2.2. int ordinal). DESCRIPTION Returns in *dev a device handle given an ordinal in the range [0. cuDeviceGetProperties. cuDeviceGetCount.

CUdevice dev). 104 . this amount is shared by all thread blocks simultaneously resident on a multiprocessor.returns information about the device SYNOPSIS CUresult cuDeviceGetAttribute(int* value. DESCRIPTION Returns in *value the integer value of the attribute attrib on device dev. • CU_DEVICE_ATTRIBUTE_WARP_SIZE: warp size in threads. • CU_DEVICE_ATTRIBUTE_TOTAL_CONSTANT_MEMORY: total amount of constant memory available on the device in bytes. texture base addresses aligned to textureAlign bytes do not need an offset applied to texture fetches. • CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Y: maximum y-dimension of a grid. • CU_DEVICE_ATTRIBUTE_GPU_OVERLAP: 1 if the device can concurrently copy memory between host and device while executing a kernel. this number is shared by all thread blocks simultaneously resident on a multiprocessor. or 0 if not. • CU_DEVICE_ATTRIBUTE_MAX_PITCH: maximum pitch in bytes allowed by the memory copy functions that involve memory regions allocated through cuMemAllocPitch(). • CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_Z: maximum z-dimension of a grid. • CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT: number of multiprocessors on the device. • CU_DEVICE_ATTRIBUTE_MAX_SHARED_MEMORY_PER_BLOCK: maximum amount of shared memory available to a thread block in bytes. • CU_DEVICE_ATTRIBUTE_TEXTURE_ALIGNMENT: alignment requirement. • CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_X: maximum x-dimension of a block.3 cuDeviceGetAttribute NAME cuDeviceGetAttribute . • CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Y: maximum y-dimension of a block. CUdevice_attribute attrib.2. • CU_DEVICE_ATTRIBUTE_MAX_BLOCK_DIM_Z: maximum z-dimension of a block. • CU_DEVICE_ATTRIBUTE_CLOCK_RATE: clock frequency in kilohertz. • CU_DEVICE_ATTRIBUTE_MAX_GRID_DIM_X: maximum x-dimension of a grid.2. The supported attributes are: • CU_DEVICE_ATTRIBUTE_MAX_THREADS_PER_BLOCK: maximum number of threads per block. • CU_DEVICE_ATTRIBUTE_MAX_REGISTERS_PER_BLOCK: maximum number of 32-bit registers available to a thread block.

cuDeviceGetName. asynchronous launches.RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_INVALID_DEVICE Note that this function may also return error codes from previous. cuDeviceGetProperties. cuDeviceGetCount. cuDeviceGet. SEE ALSO cuDeviceComputeCapability. cuDeviceTotalMem 105 .

SEE ALSO cuDeviceComputeCapability. cuDeviceGetName.returns the number of compute-capable devices SYNOPSIS CUresult cuDeviceGetCount(int* count).0 that are available for execution.2. asynchronous launches. If there is no such device. cuDeviceGetProperties. cuDeviceGetAttribute. cuDeviceGet. cuDeviceGetCount() returns 0. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous.2. cuDeviceTotalMem 106 .4 cuDeviceGetCount NAME cuDeviceGetCount . DESCRIPTION Returns in *count the number of devices with compute capability greater or equal to 1.

CUdevice dev). len specifies the maximum length of the string that may be returned. cuDeviceGetCount.2. SEE ALSO cuDeviceComputeCapability. cuDeviceTotalMem 107 . int len. cuDeviceGetAttribute. DESCRIPTION Returns an ASCII string identifying the device dev in the NULL-terminated string pointed to by name. asynchronous launches.returns an identifier string SYNOPSIS CUresult cuDeviceGetName(char* name.5 cuDeviceGetName NAME cuDeviceGetName . RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_INVALID_DEVICE Note that this function may also return error codes from previous.2. cuDeviceGetProperties. cuDeviceGet.

• textureAlign is the alignment requirement. int SIMDWidth.2. DESCRIPTION Returns in *prop the properties of device dev. • memPitch is the maximum pitch allowed by the memory copy functions that involve memory regions allocated through cuMemAllocPitch().6 cuDeviceGetProperties NAME cuDeviceGetProperties . • totalConstantMemory is the total amount of constant memory available on the device in bytes. int totalConstantMemory. int memPitch. CUdevice dev). int regsPerBlock. • regsPerBlock is the total number of registers available per block. int maxGridSize[3]. 108 . • maxThreadsDim[3] is the maximum sizes of each dimension of a block. int clockRate. where: • maxThreadsPerBlock is the maximum number of threads per block. • sharedMemPerBlock is the total amount of shared memory available per block in bytes. int textureAlign } CUdevprop. • clockRate is the clock frequency in kilohertz. texture base addresses that are aligned to textureAlign bytes do not need an offset applied to texture fetches. The CUdevprop structure is defined as: typedef struct CUdevprop_st { int maxThreadsPerBlock. • maxGridSize[3] is the maximum sizes of each dimension of a grid. int sharedMemPerBlock. • SIMDWidth is the warp size.2. int maxThreadsDim[3].get device properties SYNOPSIS CUresult cuDeviceGetProperties(CUdevprop* prop.

RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_INVALID_DEVICE Note that this function may also return error codes from previous. SEE ALSO cuDeviceComputeCapability. cuDeviceTotalMem 109 . cuDeviceGetName. cuDeviceGetAttribute. cuDeviceGetCount. cuDeviceGet. asynchronous launches.

cuDeviceGetAttribute. asynchronous launches. cuDeviceGetCount.2.2. CUdevice dev ). DESCRIPTION Returns in *bytes the total amount of memory available on the device dev in bytes. SEE ALSO cuDeviceComputeCapability. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_INVALID_DEVICE Note that this function may also return error codes from previous. cuDeviceGetName. cuDeviceGetProperties 110 . cuDeviceGet.returns the total amount of memory on the device SYNOPSIS CUresult cuDeviceTotalMem( unsigned int* bytes.7 cuDeviceTotalMem NAME cuDeviceTotalMem .

Direct3dInteroperability 111 . EventManagement. ContextManagement.2. TextureReferenceManagement. ModuleManagement. cuCtxAttach cuCtxCreate cuCtxDestroy cuCtxDetach cuCtxGetDevice cuCtxPopCurrent cuCtxPushCurrent cuCtxSynchronize SEE ALSO Initialization. ExecutionControl. MemoryManagement.3 ContextManagement NAME Context Management DESCRIPTION This section describes the low-level CUDA driver application programming interface. StreamManagement. OpenGlInteroperability. DeviceManagement.

1 cuCtxAttach NAME cuCtxAttach .2. cuCtxAttach() fails if there is no context current to the thread. cuCtxDetach. the Flags parameter must be 0.3. unsigned int Flags). asynchronous launches. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. Currently. SEE ALSO cuCtxCreate. cuCtxSynchronize 112 . DESCRIPTION Increments the usage count of the context and passes back a context handle in *pCtx that must be passed to cuCtxDetach() when the application is done with the context. cuCtxGetDevice.increment context usage-count SYNOPSIS CUresult cuCtxAttach(CUcontext* pCtx.

If C > P then CUDA will yield to other OS threads when waiting for the GPU. • CU_CTX_SCHED_AUTO: The default value if the Flags parameter is zero. DESCRIPTION Creates a new CUDA context and associates it with the calling thread. 113 . RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_DEVICE CUDA_ERROR_INVALID_VALUE CUDA_ERROR_OUT_OF_MEMORY CUDA_ERROR_UNKNOWN Note that this function may also return error codes from previous. If a context is already current to the thread. but may lower the performance of CPU threads if they are performing work in parallel with the CUDA thread. This can decrease latency when waiting for the GPU. • CU_CTX_SCHED_SPIN: Instruct CUDA to actively spin when waiting for results from the GPU.3.create a CUDA context SYNOPSIS CUresult cuCtxCreate(CUcontext* pCtx. The context is created with a usage count of 1 and the caller of cuCtxCreate() must call cuCtxDestroy() or cuCtxDetach() when done using the context. The two LSBs of the Flags parameter can be used to control how the OS thread which owns the CUDA context at the time of an API call interacts with the OS scheduler when waiting for results from the GPU.2 cuCtxCreate NAME cuCtxCreate .2. This can increase latency when waiting for the GPU. • CU_CTX_SCHED_YIELD: Instruct CUDA to yield its thread when waiting for results from the GPU. otherwise CUDA will not yield while waiting for results and actively spin on the processor. The Flags parameter is described below. unsigned int Flags. but can increase the performance of CPU threads performing work in parallel with the GPU. it is supplanted by the newly created context and may be restored by a subsequent call to cuCtxPopCurrent(). uses a heuristic based on the number of active CUDA contexts in the process C and the number of logical processors in the system P. CUdevice dev). asynchronous launches.

SEE ALSO cuCtxAttach. cuCtxDetach. cuCtxDestroy. cuCtxPushCurrent. cuCtxPopCurrent 114 .

asynchronous launches.destroy the current context context or a floating CuDA context SYNOPSIS CUresult cuCtxDestroy(CUcontext ctx). If the context usage count is not equal to 1.2. or the context is current to any CPU thread other than the current one. Floating contexts (detached from a CPU thread via cuCtxPopCurrent()) may be destroyed by this function. cuCtxAttach. SEE ALSO cuCtxCreate.3 cuCtxDestroy NAME cuCtxDestroy . RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. cuCtxDetach. cuCtxPopCurrent 115 . DESCRIPTION Destroys the given CUDA context. this function fails. cuCtxPushCurrent.3.

2. cuCtxPopCurrent 116 . The context must be a handle that was passed back by cuCtxCreate() or cuCtxAttach(). asynchronous launches. cuCtxPushCurrent.3. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT Note that this function may also return error codes from previous. cuCtxAttach. SEE ALSO cuCtxCreate. cuCtxDestroy. and must be current to the calling thread. DESCRIPTION Decrements the usage count of the context.decrement a context’s usage-count SYNOPSIS CUresult cuCtxDetach(CUcontext ctx).4 cuCtxDetach NAME cuCtxDetach . and destroys the context if the usage count goes to 0.

RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous.3. asynchronous launches.return device-ID for current context SYNOPSIS CUresult cuCtxGetDevice(CUdevice* device).2. cuCtxDetach. cuCtxSynchronize 117 . cuCtxAttach.5 cuCtxGetDevice NAME cuCtxGetDevice . SEE ALSO cuCtxCreate. DESCRIPTION Returns in *device the ordinal of the current context’s device.

If successful.6 cuCtxPopCurrent NAME cuCtxPopCurrent . asynchronous launches. cuCtxDestroy. CUDA contexts have a usage count of 1 upon creation. cuCtxPopCurrent() passes back the context handle in *pctx. Floating contexts may be destroyed by calling cuCtxDestroy(). cuCtxPushCurrent 118 . cuCtxDetach. The context may then be made current to a different CPU thread by calling cuCtxPushCurrent(). SEE ALSO cuCtxCreate.2. this function makes that context current to the CPU thread again. If a context was current to the CPU thread before cuCtxCreate or cuCtxPushCurrent was called. cuCtxAttach. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT Note that this function may also return error codes from previous. DESCRIPTION Pops the current CUDA context from the CPU thread. the usage count may be incremented with cuCtxAttach() and decremented with cuCtxDetach().3.pops the current CUDA context from the current CPU thread SYNOPSIS CUresult cuCtxPopCurrent(CUcontext *pctx). The CUDA context must have a usage count of 1.

The previous current context may be made current again by calling cuCtxDestroy() or cuCtxPopCurrent(). asynchronous launches." i. cuCtxAttach. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. SEE ALSO cuCtxCreate.7 cuCtxPushCurrent NAME cuCtxPushCurrent .2. The specified context becomes the CPU thread’s current context. so all CUDA functions that operate on the current context are affected.attach floating context to CPU thread SYNOPSIS CUresult cuCtxPushCurrent(CUcontext ctx). The context must be "floating. DESCRIPTION Pushes the given context onto the CPU thread’s stack of current contexts. not attached to any thread.e.3. Contexts are made to float by calling cuCtxPopCurrent(). cuCtxDetach. cuCtxDestroy. cuCtxPopCurrent 119 .

cuCtxSynchronize() returns an error if one of the preceding tasks failed.3. cuCtxDetach. cuCtxGetDevice 120 . SEE ALSO cuCtxCreate. DESCRIPTION Blocks until the device has completed all preceding requested tasks. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT Note that this function may also return error codes from previous.8 cuCtxSynchronize NAME cuCtxSynchronize .block for a context’s tasks to complete SYNOPSIS CUresult cuCtxSynchronize(void). cuCtxAttach. asynchronous launches.2.

Direct3dInteroperability 121 . ModuleManagement. TextureReferenceManagement. DeviceManagement. cuModuleGetFunction cuModuleGetGlobal cuModuleGetTexRef cuModuleLoad cuModuleLoadData cuModuleLoadFatBinary cuModuleUnload SEE ALSO Initialization. ExecutionControl.2. OpenGlInteroperability. MemoryManagement. ContextManagement. StreamManagement.4 ModuleManagement NAME Module Management DESCRIPTION This section describes the low-level CUDA driver application programming interface. EventManagement.

RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_NOT_FOUND Note that this function may also return error codes from previous. DESCRIPTION Returns in *func the handle of the function of name funcname located in module mod. cuModuleGetFunction() returns CUDA_ERROR_NOT_FOUND. SEE ALSO cuModuleLoad. const char* funcname). cuModuleGetTexRef 122 . cuModuleGetGlobal. cuModuleLoadFatBinary.4.2. cuModuleUnload.1 cuModuleGetFunction NAME cuModuleGetFunction . cuModuleLoadData. If no function of that name exists. CUmodule mod. asynchronous launches.returns a function handle SYNOPSIS CUresult cuModuleGetFunction(CUfunction* func.

it is ignored. cuModuleLoadData. CUmodule mod. cuModuleUnload. cuModuleGetFunction. SEE ALSO cuModuleLoad. Both parameters devPtr and bytes are optional. If no variable of that name exists. unsigned int* bytes. const char* globalname). cuModuleGetTexRef 123 .2. asynchronous launches.returns a global pointer from a module SYNOPSIS CUresult cuModuleGetGlobal(CUdeviceptr* devPtr. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_NOT_FOUND Note that this function may also return error codes from previous. DESCRIPTION Returns in *devPtr and *bytes the base pointer and size of the global of name globalname located in module mod. cuModuleLoadFatBinary. cuModuleGetGlobal() returns CUDA_ERROR_NOT_FOUND.4.2 cuModuleGetGlobal NAME cuModuleGetGlobal . If one of them is null.

2.4.3

cuModuleGetTexRef

NAME
cuModuleGetTexRef - gets a handle to a texture-reference

SYNOPSIS
CUresult cuModuleGetTexRef(CUtexref* texRef, CUmodule hmod, const char* texrefname);

DESCRIPTION
Returns in *texref the handle of the texture reference of name texrefname in the module mod. If no texture reference of that name exists, cuModuleGetTexRef() returns CUDA_ERROR_NOT_FOUND. This texture reference handle should not be destroyed, since it will be destroyed when the module is unloaded.

RETURN VALUE
Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_NOT_FOUND Note that this function may also return error codes from previous, asynchronous launches.

SEE ALSO
cuModuleLoad, cuModuleLoadData, cuModuleLoadFatBinary, cuModuleUnload, cuModuleGetFunction, cuModuleGetGlobal

124

2.4.4

cuModuleLoad

NAME
cuModuleLoad - loads a compute module

SYNOPSIS
CUresult cuModuleLoad(CUmodule* mod, const char* filename);

DESCRIPTION
Takes a file name filename and loads the corresponding module mod into the current context. The CUDA driver API does not attempt to lazily allocate the resources needed by a module; if the memory for functions and data (constant and global) needed by the module cannot be allocated, cuModuleLoad() fails. The file should be a cubin file as output by nvcc.

RETURN VALUE
Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_NOT_FOUND CUDA_ERROR_OUT_OF_MEMORY CUDA_ERROR_FILE_NOT_FOUND Note that this function may also return error codes from previous, asynchronous launches.

SEE ALSO
cuModuleLoadData, cuModuleLoadFatBinary, cuModuleUnload, cuModuleGetFunction, cuModuleGetGlobal, cuModuleGetTexRef

125

2.4.5

cuModuleLoadData

NAME
cuModuleLoadData - loads a module’s data

SYNOPSIS
CUresult cuModuleLoadData(CUmodule* mod, const void* image);

DESCRIPTION
Takes a pointer image and loads the corresponding module mod into the current context. The pointer may be obtained by mapping a cubin file, passing a cubin file as a text string, or incorporating a cubin object into the executable resources and using operation system calls such as WindowsâĂŹ FindResource() to obtain the pointer.

RETURN VALUE
Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_OUT_OF_MEMORY Note that this function may also return error codes from previous, asynchronous launches.

SEE ALSO
cuModuleLoad, cuModuleLoadFatBinary, cuModuleUnload, cuModuleGetFunction, cuModuleGetGlobal, cuModuleGetTexRef

126

2.4.6

cuModuleLoadFatBinary

NAME
cuModuleLoadFatBinary - loads a fat-binary object

SYNOPSIS
CUresult cuModuleLoadFatBinary(CUmodule* mod, const void* fatBin);

DESCRIPTION
Takes a pointer fatBin and loads the corresponding module mod into the current context. The pointer represents a fat binary object, which is a collection of different cubin files, all representing the same device code but compiled and optimized for different architectures. There is currently no documented API for constructing and using fat binary objects by programmers, and therefore this function is an internal function in this version of CUDA. More information can be found in the nvcc document.

RETURN VALUE
Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_NOT_FOUND CUDA_ERROR_OUT_OF_MEMORY CUDA_ERROR_NO_BINARY_FOR_GPU Note that this function may also return error codes from previous, asynchronous launches.

SEE ALSO
cuModuleLoad, cuModuleLoadData, cuModuleUnload, cuModuleGetFunction, cuModuleGetGlobal, cuModuleGetTexRef

127

RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous.7 cuModuleUnload NAME cuModuleUnload .unloads a module SYNOPSIS CUresult cuModuleUnload(CUmodule mod). cuModuleLoadFatBinary. cuModuleLoadData.4. SEE ALSO cuModuleLoad.2. DESCRIPTION Unloads a module mod from the current context. asynchronous launches. cuModuleGetGlobal. cuModuleGetTexRef 128 . cuModuleGetFunction.

ModuleManagement. ExecutionControl. OpenGlInteroperability. Direct3dInteroperability 129 . DeviceManagement. ContextManagement.2. cuStreamCreate cuStreamDestroy cuStreamQuery cuStreamSynchronize SEE ALSO Initialization.5 StreamManagement NAME Stream Management DESCRIPTION This section describes the low-level CUDA driver application programming interface. MemoryManagement. EventManagement. StreamManagement. TextureReferenceManagement.

cuStreamSynchronize.2. asynchronous launches. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_OUT_OF_MEMORY Note that this function may also return error codes from previous. cuStreamDestroy 130 .5. unsigned int flags).create a stream SYNOPSIS CUresult cuStreamCreate(CUstream* stream. At present. DESCRIPTION Creates a stream. flags is required to be 0. SEE ALSO cuStreamQuery.1 cuStreamCreate NAME cuStreamCreate .

RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_HANDLE Note that this function may also return error codes from previous. asynchronous launches.destroys a stream SYNOPSIS CUresult cuStreamDestroy(CUstream stream). cuStreamQuery.2. SEE ALSO cuStreamCreate. DESCRIPTION Destroys the stream.2 cuStreamDestroy NAME cuStreamDestroy . cuStreamSynchronize 131 .5.

DESCRIPTION Returns CUDA_SUCCESS if all operations in the stream have completed.3 cuStreamQuery NAME cuStreamQuery .determine status of a compute stream SYNOPSIS CUresult cuStreamQuery(CUstream stream). SEE ALSO cuStreamCreate. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_HANDLE CUDA_ERROR_NOT_READY Note that this function may also return error codes from previous. asynchronous launches. or CUDA_ERROR_NOT_READY if not.2. cuStreamSynchronize. cuStreamDestroy 132 .5.

5. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_HANDLE Note that this function may also return error codes from previous. SEE ALSO cuStreamCreate.4 cuStreamSynchronize NAME cuStreamSynchronize .2. DESCRIPTION Blocks until the device has completed all operations in the stream. cuStreamQuery. asynchronous launches.block until a stream’s tasks are completed SYNOPSIS CUresult cuStreamSynchronize(CUstream stream). cuStreamDestroy 133 .

MemoryManagement. ModuleManagement. Direct3dInteroperability 134 . StreamManagement.6 EventManagement NAME Event Management DESCRIPTION This section describes the low-level CUDA driver application programming interface. OpenGlInteroperability. EventManagement. ExecutionControl. TextureReferenceManagement.2. DeviceManagement. ContextManagement. cuEventCreate cuEventDestroy cuEventElapsedTime cuEventQuery cuEventRecord cuEventSynchronize SEE ALSO Initialization.

cuEventDestroy.2. At present.creates an event SYNOPSIS CUresult cuEventCreate(CUevent* event. flags is required to be 0. cuEventQuery. unsigned int flags). cuEventSynchronize. cuEventElapsedTime 135 . asynchronous launches.6. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_OUT_OF_MEMORY Note that this function may also return error codes from previous. SEE ALSO cuEventRecord.1 cuEventCreate NAME cuEventCreate . DESCRIPTION Creates an event.

6. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_HANDLE Note that this function may also return error codes from previous. cuEventQuery. cuEventRecord. cuEventSynchronize.destroys an event SYNOPSIS CUresult cuEventDestroy(CUevent event).2.2 cuEventDestroy NAME cuEventDestroy . DESCRIPTION Destroys the event. cuEventElapsedTime 136 . SEE ALSO cuEventCreate. asynchronous launches.

DESCRIPTION Computes the elapsed time between two events (in milliseconds with a resolution of around 0. CUevent end). cuEventSynchronize. this function returns CUDA_ERROR_INVALID_VALUE.2. If either event has been recorded with a non-zero stream. asynchronous launches. CUevent start. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_HANDLE CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. cuEventRecord.5 microseconds). SEE ALSO cuEventCreate.6. the result is undefined. cuEventDestroy 137 .computes the elapsed time between two events SYNOPSIS CUresult cuEventDestroy(float* time. If either event has not been recorded yet. cuEventQuery.3 cuEventElapsedTime NAME cuEventElapsedTime .

DESCRIPTION Returns CUDA_SUCCESS if the event has actually been recorded. cuEventDestroy. SEE ALSO cuEventCreate. If cuEventRecord() has not been called on this event. asynchronous launches.queries an event’s status SYNOPSIS CUresult cuEventQuery(CUevent event).4 cuEventQuery NAME cuEventQuery . cuEventSynchronize.2. the function returns CUDA_ERROR_INVALID_VALUE RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_HANDLE CUDA_ERROR_NOT_READY Note that this function may also return error codes from previous. or CUDA_ERROR_NOT_READY if not.6. cuEventElapsedTime 138 . cuEventRecord.

CUstream stream). If cuEventRecord() has previously been called and the event has not been recorded yet. cuEventElapsedTime 139 .records an event SYNOPSIS CUresult cuEventRecord(CUevent event. cuEventQuery. asynchronous launches. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_HANDLE CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous.6. the event is recorded after all preceding operations in the stream have been completed. cuEventQuery() and/or cuEventSynchronize() must be used to determine when the event has actually been recorded. SEE ALSO cuEventCreate. cuEventSynchronize.5 cuEventRecord NAME cuEventRecord . DESCRIPTION Records an event. cuEventDestroy. otherwise. this function returns CUDA_ERROR_INVALID_VALUE.2. Since this operation is asynchronous. If stream is non-zero. it is recorded after all preceding operations in the CUDA context have been completed.

the function returns CUDA_ERROR_INVALID_VALUE. DESCRIPTION Blocks until the event has actually been recorded. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_HANDLE Note that this function may also return error codes from previous.2. If cuEventRecord() has not been called on this event.waits for an event to complete SYNOPSIS CUresult cuEventSynchronize(CUevent event). SEE ALSO cuEventCreate.6 cuEventSynchronize NAME cuEventSynchronize . cuEventRecord. cuEventElapsedTime 140 . asynchronous launches. cuEventDestroy. cuEventQuery.6.

OpenGlInteroperability. ModuleManagement. TextureReferenceManagement. StreamManagement. Direct3dInteroperability 141 . ContextManagement. ExecutionControl. DeviceManagement.2. cuLaunch cuLaunchGrid cuParamSetSize cuParamSetTexRef cuParamSetf cuParamSeti cuParamSetv cuFuncSetBlockShape cuFuncSetSharedSize SEE ALSO Initialization. EventManagement.7 ExecutionControl NAME Execution Control DESCRIPTION This section describes the low-level CUDA driver application programming interface. MemoryManagement.

SEE ALSO cuFuncSetBlockShape. The block contains the number of threads specified by a previous call to cuFuncSetBlockShape().1 cuLaunch NAME cuLaunch . cuParamSetv. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING Note that this function may also return error codes from previous. asynchronous launches. cuParamSeti. DESCRIPTION Invokes the kernel func on a 1ÃŮ1 grid of blocks. cuParamSetSize.launches a CUDA function SYNOPSIS CUresult cuLaunch(CUfunction func).2. cuParamSetTexRef.7. cuFuncSetSharedSize. cuLaunchGrid 142 . cuParamSetf.

asynchronous launches. int grid_width. CUstream stream). int grid_width. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING Note that this function may also return error codes from previous. cuParamSetTexRef.7.launches a CUDA function SYNOPSIS CUresult cuLaunchGrid(CUfunction func. cuFuncSetSharedSize. Each block contains the number of threads specified by a previous call to cuFuncSetBlockShape(). DESCRIPTION Invokes the kernel on a grid_width x grid_height grid of blocks. cuParamSeti. CUresult cuLaunchGridAsync(CUfunction func. int grid_height). cuParamSetv. SEE ALSO cuFuncSetBlockShape. cuLaunch 143 . int grid_height. cuParamSetf.2 cuLaunchGrid NAME cuLaunchGrid . cuLaunchGridAsync() can optionally be associated to a stream by passing a non-zero stream argument. cuParamSetSize.2.

SEE ALSO cuFuncSetBlockShape.sets the parameter-size for the function SYNOPSIS CUresult cuParamSetSize(CUfunction func. asynchronous launches. cuParamSetf. cuParamSetv.2. cuLaunchGrid 144 .3 cuParamSetSize NAME cuParamSetSize . cuParamSetTexRef. cuLaunch. cuParamSeti. cuFuncSetSharedSize. DESCRIPTION Sets through numbytes the total size in bytes needed by the function parameters of function func. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. unsigned int numbytes).7.

cuLaunchGrid 145 . cuParamSeti. cuParamSetf. In this version of CUDA. cuFuncSetSharedSize. cuLaunch. asynchronous launches. int texunit. cuParamSetv.2. CUtexref texRef). SEE ALSO cuFuncSetBlockShape. the texture reference must be obtained via cuModuleGetTexRef() and the texunit parameter must be set to CU_PARAM_TR_DEFAULT. DESCRIPTION Makes the CUDA array or linear memory bound to the texture reference texRef available to a device program as a texture.4 cuParamSetTexRef NAME cuParamSetTexRef . cuParamSetSize.7.adds a texture-reference to the function’s argument list SYNOPSIS CUresult cuParamSetTexRef(CUfunction func. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous.

float value). SEE ALSO cuFuncSetBlockShape. cuFuncSetSharedSize. asynchronous launches.7. int offset. cuLaunch.5 cuParamSetf NAME cuParamSetf .adds a floating-point parameter to the function’s argument list SYNOPSIS CUresult cuParamSetf(CUfunction func. cuParamSeti. DESCRIPTION Sets a floating point parameter that will be specified the next time the kernel corresponding to func will be invoked. cuParamSetv. cuLaunchGrid 146 . cuParamSetSize. cuParamSetTexRef. offset is a byte offset.2. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous.

cuFuncSetSharedSize. offset is a byte offset.7. int offset. SEE ALSO cuFuncSetBlockShape. unsigned int value).6 cuParamSeti NAME cuParamSeti .adds an integer parameter to the function’s argument list SYNOPSIS CUresult cuParamSeti(CUfunction func. cuParamSetf. cuParamSetv. cuParamSetSize. cuLaunchGrid 147 . cuParamSetTexRef. asynchronous launches. cuLaunch. DESCRIPTION Sets an integer parameter that will be specified the next time the kernel corresponding to func will be invoked. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous.2.

cuFuncSetSharedSize. cuLaunch. DESCRIPTION Copies an arbitrary amount of data into the parameter space of the kernel corresponding to func. cuParamSetTexRef. cuParamSeti. cuLaunchGrid 148 . asynchronous launches. cuParamSetSize. SEE ALSO cuFuncSetBlockShape.2. void* ptr.adds arbitrary data to the function’s argument list SYNOPSIS CUresult cuParamSetv(CUfunction func.7. unsigned int numbytes). int offset. offset is a byte offset. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous.7 cuParamSetv NAME cuParamSetv . cuParamSetf.

RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_HANDLE CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous.8 cuFuncSetBlockShape NAME cuFuncSetBlockShape . int y.7.sets the block-dimensions for the function SYNOPSIS CUresult cuFuncSetBlockShape(CUfunction func. SEE ALSO cuFuncSetSharedSize. asynchronous launches. int x. cuParamSetf. DESCRIPTION Specifies the X.2. cuParamSetSize. Y and Z dimensions of the thread blocks that are created when the kernel given by func is launched. cuLaunch. cuLaunchGrid 149 . cuParamSeti. int z). cuParamSetv. cuParamSetTexRef.

9 cuFuncSetSharedSize NAME cuFuncSetSharedSize . unsigned int bytes). cuLaunchGrid 150 . cuParamSetSize.2. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_HANDLE CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. cuParamSetTexRef.7. SEE ALSO cuFuncSetBlockShape. cuParamSetf.sets the shared-memory size for the function SYNOPSIS CUresult cuFuncSetSharedSize(CUfunction func. cuParamSeti. asynchronous launches. cuParamSetv. cuLaunch. DESCRIPTION Sets through bytes the amount of shared memory that will be available to each thread block when the kernel given by func is launched.

EventManagement. ExecutionControl.2. TextureReferenceManagement. Direct3dInteroperability 151 .8 MemoryManagement NAME Memory Management DESCRIPTION This section describes the low-level CUDA driver application programming interface. ContextManagement. DeviceManagement. ModuleManagement. StreamManagement. OpenGlInteroperability. MemoryManagement. cuArrayCreate cuArray3DCreate cuArrayDestroy cuArrayGetDescriptor cuArray3DGetDescriptor cuMemAlloc cuMemAllocHost cuMemAllocPitch cuMemFree cuMemFreeHost cuMemGetAddressRange cuMemGetInfo cuMemcpy2D cuMemcpy3D cuMemcpyAtoA cuMemcpyAtoD cuMemcpyAtoH cuMemcpyDtoA cuMemcpyDtoD cuMemcpyDtoH cuMemcpyHtoA cuMemcpyHtoD cuMemset cuMemset2D SEE ALSO Initialization.

the CUDA array is one-dimensional if height is 0. 152 . The CUDA_ARRAY_DESCRIPTOR structure is defined as such: typedef struct { unsigned int Width.. desc.Format = CU_AD_FORMAT_FLOAT. 2 or 4. CUarray_format is defined as such: typedef enum CUarray_format_enum { CU_AD_FORMAT_UNSIGNED_INT8 = 0x01. Here are examples of CUDA array descriptions: • Description for a CUDA array of 2048 floats: CUDA_ARRAY_DESCRIPTOR desc.creates a 1D or 2D CUDA array SYNOPSIS CUresult cuArrayCreate(CUarray* array. CU_AD_FORMAT_SIGNED_INT8 = 0x08. } CUDA_ARRAY_DESCRIPTOR. two-dimensional. CU_AD_FORMAT_UNSIGNED_INT16 = 0x02. CU_AD_FORMAT_FLOAT = 0x20 } CUarray_format. unsigned int Height. unsigned int NumChannels. • NumChannels specifies the number of packed components per CUDA array element. const CUDA_ARRAY_DESCRIPTOR* desc). CU_AD_FORMAT_UNSIGNED_INT32 = 0x03.1 cuArrayCreate NAME cuArrayCreate . CU_AD_FORMAT_SIGNED_INT16 = 0x09. • Format specifies the format of the elements.8. DESCRIPTION Creates a CUDA array according to the CUDA_ARRAY_DESCRIPTOR structure desc and returns a handle to the new CUDA array in *array. CUarray_format Format. CU_AD_FORMAT_SIGNED_INT32 = 0x0a. where: • Width and Height are the width and height of the CUDA array (in elements). otherwise. CU_AD_FORMAT_HALF = 0x10. it may be 1.2.

Height = 1. cuMemset2D 153 . each of which is two 8-bit unsigned chars: CUDA_ARRAY_DESCRIPTOR arrayDesc. 4x16-bit float16’s: CUDA_ARRAY_DESCRIPTOR desc.Height = height. desc. cuMemGetAddressRange.desc.Width = 64.NumChannels = 2. desc. cuMemAllocPitch. cuArrayDestroy. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_OUT_OF_MEMORY CUDA_ERROR_UNKNOWN Note that this function may also return error codes from previous.Width = width. desc. • Description for a 64 x 64 CUDA array of floats: CUDA_ARRAY_DESCRIPTOR desc. cuMemFree. desc.NumChannels = 1.Height = 64. desc. • Description for a width x height CUDA array of 16-bit elements.Height = height. desc. desc.Format = CU_AD_FORMAT_FLOAT. desc. desc.FormatFlags = CU_AD_FORMAT_UNSIGNED_INTS. desc.Width = width. asynchronous launches. cuArrayGetDescriptor. SEE ALSO cuMemGetInfo. cuMemAllocHost.NumChannels = 4. desc. desc. desc. desc.Width = 2048. cuMemFreeHost.FormatFlags = CU_AD_FORMAT_HALF. • Description for a width x height CUDA array of 64-bit.NumChannels = 1. cuMemset. cuMemAlloc.

the CUDA array is one-dimensional if height and depth are 0. height and depth of the CUDA array (in elements). CU_AD_FORMAT_SIGNED_INT8 = 0x08. Height and Depth are the width. For now. it must be set to 0. CU_AD_FORMAT_SIGNED_INT16 = 0x09. Here are examples of CUDA array descriptions: 154 . CUarray_format is defined as such: typedef enum CUarray_format_enum { CU_AD_FORMAT_UNSIGNED_INT8 = 0x01. CUarray_format Format. unsigned int NumChannels.2. unsigned int Depth. } CUDA_ARRAY3D_DESCRIPTOR.creates a CUDA array SYNOPSIS CUresult cuArray3DCreate(CUarray* array. CU_AD_FORMAT_FLOAT = 0x20 } CUarray_format. two-dimensional if depth is 0. CU_AD_FORMAT_UNSIGNED_INT16 = 0x02. CU_AD_FORMAT_UNSIGNED_INT32 = 0x03. • Format specifies the format of the elements. unsigned int Flags. • NumChannels specifies the number of packed components per CUDA array element. and threedimensional otherwise. unsigned int Height.8. • Flags provides for future features.2 cuArray3DCreate NAME cuArray3DCreate . const CUDA_ARRAY3D_DESCRIPTOR* desc). The CUDA_ARRAY3D_DESCRIPTOR structure is defined as such: typedef struct { unsigned int Width. CU_AD_FORMAT_HALF = 0x10. DESCRIPTION Creates a CUDA array according to the CUDA_ARRAY3D_DESCRIPTOR structure desc and returns a handle to the new CUDA array in *array. it may be 1. where: • Width.. 2 or 4. CU_AD_FORMAT_SIGNED_INT32 = 0x0a.

Depth = 0.Format = CU_AD_FORMAT_FLOAT. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_OUT_OF_MEMORY CUDA_ERROR_UNKNOWN Note that this function may also return error codes from previous.Height = 0. cuMemFree. desc. desc.• Description for a CUDA array of 2048 floats: CUDA_ARRAY3D_DESCRIPTOR desc. desc. cuMemAllocHost. desc. desc. desc. cuMemAlloc.Depth = 0. • Description for a width x height x depth CUDA array of 64-bit.Width = width.Depth = depth.NumChannels = 1. 4x16-bit float16’s: CUDA_ARRAY_DESCRIPTOR desc.Width = 2048. cuArray3DGetDescriptor. desc. • Description for a 64 x 64 CUDA array of floats: CUDA_ARRAY3D_DESCRIPTOR desc. cuMemFreeHost.Height = height. desc.Height = 64. SEE ALSO cuMemGetInfo. asynchronous launches. cuMemGetAddressRange. desc. desc.FormatFlags = CU_AD_FORMAT_HALF.NumChannels = 4. cuArrayDestroy 155 . desc. cuMemAllocPitch.Format = CU_AD_FORMAT_FLOAT.Width = 64. desc. desc.NumChannels = 1. desc. desc.

destroys a CUDA array SYNOPSIS CUresult cuArrayDestroy(CUarray array). asynchronous launches.8. cuMemset2D 156 . cuMemFreeHost. cuArrayCreate. cuMemAllocPitch. DESCRIPTION Destroys the CUDA array array. SEE ALSO cuMemGetInfo. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_HANDLE CUDA_ERROR_ARRAY_IS_MAPPED Note that this function may also return error codes from previous. cuMemAlloc. cuMemFree. cuArrayGetDescriptor. cuMemAllocHost.3 cuArrayDestroy NAME cuArrayDestroy . cuMemset.2. cuMemGetAddressRange.

RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_INVALID_HANDLE Note that this function may also return error codes from previous.2. but need to know the CUDA array parameters for validation or other purposes. cuArrayDestroy 157 . cuArray3DGetDescriptor.8.4 cuArrayGetDescriptor NAME cuArrayGetDescriptor . SEE ALSO cuArrayCreate.get a 1D or 2D CUDA array descriptor SYNOPSIS CUresult cuArrayGetDescriptor(CUDA_ARRAY_DESCRIPTOR* arrayDesc. cuArray3DCreate. CUarray array) DESCRIPTION Returns in *arrayDesc a descriptor of the format and dimensions of the 1D or 2D CUDA array array. asynchronous launches. It is useful for subroutines that have been passed a CUDA array.

RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_INVALID_HANDLE Note that this function may also return error codes from previous. but need to know the CUDA array parameters for validation or other purposes. CUarray array). cuArray3DCreate. SEE ALSO cuArrayCreate.8.get a 3D CUDA array descriptor SYNOPSIS CUresult cuArray3DGetDescriptor(CUDA_ARRAY3D_DESC *arrayDesc. cuArrayDestroy 158 . It is useful for subroutines that have been passed a CUDA array. cuArrayGetDescriptor.5 cuArray3DGetDescriptor NAME cuArray3DGetDescriptor . asynchronous launches.2. DESCRIPTION Returns in *arrayDesc a descriptor containing information on the format and dimensions of the CUDA array array.

DESCRIPTION Allocates count bytes of linear memory on the device and returns in *devPtr a pointer to the allocated memory. cuMemset. If count is 0. cuMemFreeHost. cuMemGetAddressRange. cuMemFree. cuArrayCreate. SEE ALSO cuMemGetInfo.allocates device memory SYNOPSIS CUresult cuMemAlloc(CUdeviceptr* devPtr. cuArrayDestroy. cuMemset2D 159 . unsigned int count).2. cuMemAlloc() returns CUDA_ERROR_INVALID_VALUE. asynchronous launches. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_OUT_OF_MEMORY Note that this function may also return error codes from previous. The memory is not cleared.6 cuMemAlloc NAME cuMemAlloc . cuArrayGetDescriptor.8. cuMemAllocHost. The allocated memory is suitably aligned for any kind of variable. cuMemAllocPitch.

7 cuMemAllocHost NAME cuMemAllocHost . cuMemAlloc. since it reduces the amount of memory available to the system for paging. cuMemGetAddressRange. cuMemAllocPitch. cuArrayGetDescriptor.2. cuArrayCreate. cuMemset2D 160 . cuMemFree. DESCRIPTION Allocates count bytes of host memory that is page-locked and accessible to the device.8. SEE ALSO cuMemGetInfo. asynchronous launches. Since the memory can be accessed directly by the device. cuMemset. cuMemFreeHost. Allocating excessive amounts of memory with cuMemAllocHost() may degrade system performance. cuArrayDestroy.allocates page-locked host memory SYNOPSIS CUresult cuMemAllocHost(void** hostPtr. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_OUT_OF_MEMORY Note that this function may also return error codes from previous. this function is best used sparingly to allocate staging areas for data exchange between host and device. The driver tracks the virtual memory ranges allocated with this function and automatically accelerates calls to functions such as cuMemcpy(). As a result. it can be read or written with much higher bandwidth than pageable memory obtained with functions such as malloc(). unsigned int count).

but possibly at reduced speed. 8 or 16 (since coalesced memory transactions are not possible on other data sizes). used to compute addresses within the 2D array. it is recommended that programmers consider performing pitch allocations using cuMemAllocPitch(). unsigned int height.8 cuMemAllocPitch NAME cuMemAllocPitch . Given the row and column of an array element of type T. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_OUT_OF_MEMORY Note that this function may also return error codes from previous. unsigned int elementSizeBytes). elementSizeBytes may be 4. the address is computed as T* pElement = (T*)((char*)BaseAddress + Row * Pitch) + Column. The intended usage of pitch is as a separate parameter of the allocation. DESCRIPTION Allocates at least widthInBytes*height bytes of linear memory on the device and returns in *devPtr a pointer to the allocated memory. For allocations of 2D arrays. unsigned int widthInBytes.allocates device memory SYNOPSIS CUresult cuMemAllocPitch(CUdeviceptr* devPtr. unsigned int* pitch.8. this is especially true if the application will be performing 2D memory copies between different regions of device memory (whether linear memory or CUDA arrays). If elementSizeBytes is smaller than the actual read/write size of a kernel. The pitch returned in *pitch by cuMemAllocPitch() is the width in bytes of the allocation.2. The function may pad the allocation to ensure that corresponding pointers in any given row will continue to meet the alignment requirements for coalescing as the address is updated from row to row. elementSizeBytes specifies the size of the largest reads and writes that will be performed on the memory range. the kernel will run correctly. asynchronous launches. Due to alignment restrictions in the hardware. 161 . The pitch returned by cuMemAllocPitch() is guaranteed to work with cuMemcpy2D() under all circumstances.

cuMemFree. cuMemGetAddressRange.SEE ALSO cuMemGetInfo. cuMemset. cuMemAlloc. cuArrayDestroy. cuMemFreeHost. cuArrayCreate. cuMemAllocHost. cuMemset2D 162 . cuArrayGetDescriptor.

which must have been returned by a previous call to cuMemMalloc() or cuMemMallocPitch(). cuMemset2D 163 . cuMemAlloc. asynchronous launches. DESCRIPTION Frees the memory space pointed to by devPtr. cuMemset. cuArrayDestroy. cuMemGetAddressRange. cuMemFreeHost.frees device memory SYNOPSIS CUresult cuMemFree(CUdeviceptr devPtr). RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. cuArrayCreate. SEE ALSO cuMemGetInfo. cuMemAllocPitch.9 cuMemFree NAME cuMemFree .2. cuArrayGetDescriptor. cuMemAllocHost.8.

cuMemset2D 164 .8. cuMemAlloc. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. cuMemset. cuArrayCreate. cuArrayDestroy.frees page-locked host memory SYNOPSIS CUresult cuMemFreeHost(void* hostPtr). cuArrayGetDescriptor. cuMemAllocPitch. which must have been returned by a previous call to cuMemAllocHost(). asynchronous launches. cuMemGetAddressRange. DESCRIPTION Frees the memory space pointed to by hostPtr. cuMemFree. cuMemAllocHost. SEE ALSO cuMemGetInfo.10 cuMemFreeHost NAME cuMemFreeHost .2.

Both parameters basePtr and size are optional. cuArrayGetDescriptor. unsigned int* size. DESCRIPTION Returns the base address in *basePtr and size and *size of the allocation by cuMemAlloc() or cuMemAllocPitch() that contains the input pointer devPtr. cuMemset.get information on memory allocations SYNOPSIS CUresult cuMemGetAddressRange(CUdeviceptr* basePtr. cuMemFreeHost. CUdeviceptr devPtr). SEE ALSO cuMemGetInfo. cuMemset2D 165 .11 cuMemGetAddressRange NAME cuMemGetAddressRange . cuMemAllocHost. cuMemFree. cuMemAllocPitch. If one of them is null. asynchronous launches. it is ignored. cuArrayDestroy. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. cuArrayCreate.2. cuMemAlloc.8.

DESCRIPTION Returns in *free and *total respectively. cuMemset. cuMemAllocPitch. cuMemset2D 166 . asynchronous launches. the free and total amount of memory available for allocation by the CUDA context. cuMemFree.gets free and total memory SYNOPSIS CUresult cuMemGetInfo(unsigned int* free. cuArrayCreate.12 cuMemGetInfo NAME cuMemGetInfo . RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. cuMemAllocHost. cuArrayGetDescriptor.8. in bytes. cuMemGetAddressRange. SEE ALSO cuMemAlloc. cuMemFreeHost. cuArrayDestroy. unsigned int* total).2.

2. CUdeviceptr dstDevice. srcY.8. srcHost and srcPitch specify the (host) base address of the source data and the bytes per row to apply. where: • srcMemoryType and dstMemoryType specify the type of memory of the source and destination. respectively. } CUDA_MEMCPY2D. DESCRIPTION Perform a 2D memory copy according to the parameters specified in copyParam. CUdeviceptr srcDevice. CUarray srcArray. If srcMemoryType is CU_MEMORYTYPE_DEVICE. const void *srcHost. unsigned int srcPitch. CUmemorytype_enum is defined as such: typedef enum CUmemorytype_enum { CU_MEMORYTYPE_HOST = 0x01. unsigned int dstXInBytes. unsigned int dstPitch. CUresult cuMemcpy2DUnaligned(const CUDA_MEMCPY2D* copyParam). CUmemorytype srcMemoryType. unsigned int Height.copies memory for 2D arrays SYNOPSIS CUresult cuMemcpy2D(const CUDA_MEMCPY2D* copyParam). void *dstHost. srcArray is ignored. unsigned int WidthInBytes. CUstream stream).13 cuMemcpy2D NAME cuMemcpy2D . dstY. srcDevice and srcPitch specify the (device) base address of the source data and the bytes per row to apply. If srcMemoryType is CU_MEMORYTYPE_HOST. The CUDA_MEMCPY2D structure is defined as such: typedef struct CUDA_MEMCPY2D_st { unsigned int srcXInBytes. 167 . CUmemorytype dstMemoryType. srcArray is ignored. CU_MEMORYTYPE_ARRAY = 0x03 } CUmemorytype. CU_MEMORYTYPE_DEVICE = 0x02. CUarray dstArray. CUresult cuMemcpy2DAsync(const CUDA_MEMCPY2D* copyParam.

It only works on page-locked host memory and returns an error if a pointer to pageable memory is passed as input. dstDevice and dstPitch are ignored. cuMemcpy2D() may fail for pitches not computed by cuMemAllocPitch(). • srcXInBytes and srcY specify the base address of the source data for the copy. • dstXInBytes and dstY specify the base address of the destination data for the copy. cuMemcpy2DUnaligned() does not have this restriction. • WidthInBytes and Height specify the width (in bytes) and height of the 2D copy being performed. For CUDA arrays. srcXInBytes must be evenly divisible by the array element size. If dstMemoryType is CU_MEMORYTYPE_DEVICE. dstArray specifies the handle of the destination data. srcHost.If srcMemoryType is CU_MEMORYTYPE_ARRAY. srcDevice and srcPitch are ignored. dstXInBytes must be evenly divisible by the array element size. cuMemcpy2D() returns an error if any pitch is greater than the maximum allowed (CU_DEVICE_ATTRIBUTE_ cuMemAllocPitch() passes back pitches that always work with cuMemcpy2D(). dstArray is ignored. Any pitches must be greater than or equal to WidthInBytes. the starting address is CUdeviceptr Start = srcDevice+srcY*srcPitch+srcXInBytes. dstHost. the base address is void* dstStart = (void*)((char*)dstHost+dstY*dstPitch + dstXInBytes). CUDA array ? CUDA array). the starting address is CUdeviceptr dstStart = dstDevice+dstY*dstPitch+dstXInBytes. For device pointers. For CUDA arrays. but may run significantly slower in the cases where cuMemcpy2D() would have returned an error code. dstDevice and dstPitch specify the (device) base address of the destination data and the bytes per row to apply. dstHost and dstPitch specify the (host) base address of the destination data and the bytes per row to apply. If dstMemoryType is CU_MEMORYTYPE_HOST. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED 168 . CUDA array ? device. srcArray specifies the handle of the source data. For host pointers. For device pointers. cuMemcpy2DAsync() is asynchronous and can optionally be associated to a stream by passing a non-zero stream argument. If dstMemoryType is CU_MEMORYTYPE_ARRAY. For host pointers. dstArray is ignored. On intra-device memory copies (device ? device. the starting address is void* Start = (void*)((char*)srcHost+srcY*srcPitch + srcXInBytes).

SEE ALSO cuMemcpyHtoD. cuMemcpyDtoA. cuMemcpy3D 169 . asynchronous launches. cuMemcpyHtoA. cuMemcpyAtoH. cuMemcpyDtoH. cuMemcpyAtoD. cuMemcpyDtoD. cuMemcpyAtoA.CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous.

The CUDA_MEMCPY3D structure is defined as such: typedef struct CUDA_MEMCPY3D_st { unsigned int srcXInBytes. unsigned int srcPitch. may be 0 if Depth==1 unsigned int dstXInBytes. CUdeviceptr srcDevice. respectively. unsigned int srcLOD. CUmemorytype_enum is defined as such: typedef enum CUmemorytype_enum { 170 . CUresult cuMemcpy3DAsync(const CUDA_MEMCPY3D* copyParam.8. // ignored when dst is array unsigned int dstHeight. void *dstHost. // ignored when src is array. dstZ. where: • srcMemoryType and dstMemoryType specify the type of memory of the source and destination. // ignored when src is array unsigned int srcHeight. CUarray srcArray. may be 0 if Depth==1 unsigned int WidthInBytes.14 cuMemcpy3D NAME cuMemcpy3D . CUdeviceptr dstDevice. srcZ. unsigned int dstLOD. CUresult CUDAAPI cuMemcpy3D( const CUDA_MEMCPY3D *pCopy ). CUarray dstArray.2. unsigned int Height. srcY. DESCRIPTION Perform a 3D memory copy according to the parameters specified in copyParam.copies memory for 3D arrays SYNOPSIS CUresult cuMemcpy3D(const CUDA_MEMCPY3D* copyParam). unsigned int Depth. } CUDA_MEMCPY3D. CUstream stream). dstY. // ignored when dst is array. const void *srcHost. CUmemorytype dstMemoryType. unsigned int dstPitch. CUmemorytype srcMemoryType.

If srcMemoryType is CU_MEMORYTYPE_ARRAY. dstY and dstZ specify the base address of the destination data for the copy. Height and Depth specify the width (in bytes). For CUDA arrays. and the height of each 2D slice of the 3D array. the bytes per row. the starting address is CUdeviceptr Start = srcDevice+(srcZ*srcHeight+srcY)*srcPitch+srcXInBytes. Any pitches must be greater than or equal to WidthInBytes. dstHost. • WidthInBytes. dstDevice and dstPitch specify the (device) base address of the destination data. cuMemcpy3DAsync() is asynchronous and can optionally be associated to a stream by passing a non-zero stream argument. dstArray is ignored. the bytes per row. srcPitch and srcHeight are ignored. dstHost and dstPitch specify the (host) base address of the destination data. • srcXInBytes. height and depth of the 3D copy being performed. srcXInBytes must be evenly divisible by the array element size. srcDevice. and the height of each 2D slice of the 3D array. CU_MEMORYTYPE_ARRAY = 0x03 } CUmemorytype.CU_MEMORYTYPE_HOST = 0x01. For host pointers. CU_MEMORYTYPE_DEVICE = 0x02. srcPitch and srcHeight specify the (device) base address of the source data. srcPitch and srcHeight specify the (host) base address of the source data. dstPitch and dstHeight are ignored. If dstMemoryType is CU_MEMORYTYPE_DEVICE. If srcMemoryType is CU_MEMORYTYPE_HOST. the starting address is void* Start = (void*)((char*)srcHost+(srcZ*srcHeight+srcY)*srcPitch + srcXInBytes). the bytes per row. For device pointers. the bytes per row. srcHost. srcDevice. For host pointers. srcArray specifies the handle of the source data. and the height of each 2D slice of the 3D array. It only works on page-locked host memory and returns an error if a pointer to pageable memory is passed as input. srcY and srcZ specify the base address of the source data for the copy. 171 cuMemcpy3D() returns an error if any pitch is greater than the maximum allowed (CU_DEVICE_ATTRIBUTE_ . the starting address is CUdeviceptr dstStart = dstDevice+(dstZ*dstHeight+dstY)*dstPitch+dstXInBytes. srcArray is ignored. If srcMemoryType is CU_MEMORYTYPE_DEVICE. For device pointers. If dstMemoryType is CU_MEMORYTYPE_HOST. dstDevice. dstXInBytes must be evenly divisible by the array element size. The srcLOD and dstLOD members of the CUDA_MEMCPY3D structure must be set to 0. srcArray is ignored. and the height of each 2D slice of the 3D array. For CUDA arrays. • dstXInBytes. If dstMemoryType is CU_MEMORYTYPE_ARRAY. dstArray specifies the handle of the destination data. srcHost. dstArray is ignored. the base address is void* dstStart = (void*)((char*)dstHost+(dstZ*dstHeight+dstY)*dstPitch + dstXInBytes).

cuMemcpyAtoH. cuMemcpyDtoH. cuMemcpyDtoD. cuMemcpyAtoD. cuMemcpyHtoA. cuMemcpyAtoA.RETURN VALUE CUDA_SUCCESS SEE ALSO cuMemcpyHtoD. cuMemcpyDtoA. cuMemcpy2D. cuMemcpy2DAsync 172 .

cuMemcpyDtoD. they are not byte offsets. cuMemcpy2D 173 . These values are in the range [0. The size of the elements in the CUDA arrays need not be the same format. unsigned int srcIndex. DESCRIPTION Copies from one 1D CUDA array to another. CUarray srcArray. asynchronous launches. SEE ALSO cuMemcpyHtoD.2. cuMemcpyHtoA. count is the number of bytes to be copied. cuMemcpyAtoD. dstArray and srcArray specify the handles of the destination and source CUDA arrays for the copy. respectively. cuMemcpyAtoH. but the elements must be the same size. cuMemcpyDtoA. unsigned int count). dstIndex and srcIndex specify the destination and source indices into the CUDA array.8. and count must be evenly divisible by that size. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. unsigned int dstIndex. Width-1] for the CUDA array.copies memory from Array to Array SYNOPSIS CUresult cuMemcpyAtoA(CUarray dstArray.15 cuMemcpyAtoA NAME cuMemcpyAtoA . cuMemcpyDtoH.

SEE ALSO cuMemcpyHtoD. cuMemcpyAtoH.2. cuMemcpyDtoH. unsigned int count).16 cuMemcpyAtoD NAME cuMemcpyAtoD . srcArray and srcIndex specify the CUDA array handle and the index (in array elements) of the array element where the copy is to begin. unsigned int srcIndex. cuMemcpyDtoA.8. count specifies the number of bytes to copy and must be evenly divisible by the array element size. cuMemcpyDtoD. dstDevPtr specifies the base pointer of the destination and must be naturally aligned with the CUDA array elements. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. cuMemcpyAtoA. cuMemcpy2D 174 . cuMemcpyHtoA. asynchronous launches.copies memory from Array to Device SYNOPSIS CUresult cuMemcpyAtoD(CUdeviceptr dstDevPtr. DESCRIPTION Copies from a 1D CUDA array to device memory. CUarray srcArray.

unsigned int srcIndex. It only works on page-locked host memory and returns an error if a pointer to pageable memory is passed as input. cuMemcpyHtoA. asynchronous launches. unsigned int count). unsigned int srcIndex.8. DESCRIPTION Copies from a 1D CUDA array to host memory. CUresult cuMemcpyAtoHAsync(void* dstHostPtr. cuMemcpyDtoH. CUstream stream). dstHostPtr specifies the base pointer of the destination. SEE ALSO cuMemcpyHtoD.copies memory from Array to Host SYNOPSIS CUresult cuMemcpyAtoH(void* dstHostPtr. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous.2. cuMemcpyDtoD. unsigned int count. count specifies the number of bytes to copy. CUarray srcArray. cuMemcpyAtoA. srcArray and srcIndex specify the CUDA array handle and starting index of the source data. cuMemcpy2D 175 . cuMemcpyAtoD. CUarray srcArray. cuMemcpyDtoA.17 cuMemcpyAtoH NAME cuMempcyAtoH . cuMemcpyAtoHAsync() is asynchronous and can optionally be associated to a stream by passing a nonzero stream argument.

CUdeviceptr srcDevPtr.18 cuMemcpyDtoA NAME cuMemcpyDtoA . asynchronous launches. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. dstArray and dstIndex specify the CUDA array handle and starting index of the destination data. cuMemcpyHtoA. DESCRIPTION Copies from device memory to a 1D CUDA array. cuMemcpyAtoD.copies memory from Device to Array SYNOPSIS CUresult cuMemcpyDtoA(CUarray dstArray. SEE ALSO cuMemcpyHtoD.8. unsigned int count). cuMemcpyDtoD. unsigned int dstIndex. count specifies the number of bytes to copy. cuMemcpyAtoA. cuMemcpyDtoH.2. srcDevPtr specifies the base pointer of the source. cuMemcpyAtoH. cuMemcpy2D 176 .

cuMemcpyAtoD.8.copies memory from Device to Device SYNOPSIS CUresult cuMemcpyDtoD(CUdeviceptr dstDevPtr. SEE ALSO cuMemcpyHtoD. cuMemcpy2D 177 . respectively.2. count specifies the number of bytes to copy. cuMemcpyDtoH. cuMemcpyAtoA. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. cuMemcpyDtoA. asynchronous launches.19 cuMemcpyDtoD NAME cuMemcpyDtoD . dstDevice and srcDevPtr are the base pointers of the destination and source. cuMemcpyAtoH. cuMemcpyHtoA. CUdeviceptr srcDevPtr. DESCRIPTION Copies from device memory to device memory. unsigned int count).

20 cuMemcpyDtoH NAME cuMemcpyDtoH . cuMemcpyAtoA. CUdeviceptr srcDevPtr. DESCRIPTION Copies from device to host memory.copies memory from Device to Host SYNOPSIS CUresult cuMemcpyDtoH(void* dstHostPtr. cuMemcpyAtoH. cuMemcpyHtoA. asynchronous launches. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. dstHostPtr and srcDevPtrspecify the base addresses of the source and destination. SEE ALSO cuMemcpyHtoD. respectively. unsigned int count. It only works on page-locked host memory and returns an error if a pointer to pageable memory is passed as input.2. cuMemcpyAtoD. MemcpyDtoHAsync() is asynchronous and can optionally be associated to a stream by passing a non-zero stream argument. CUdeviceptr srcDevPtr. cuMemcpyDtoD. countspecifies the number of bytes to copy. unsigned int count).8. cuMemcpy2D 178 . CUstream stream). cuMemcpyDtoA. CUresult cuMemcpyDtoHAsync(void* dstHostPtr.

cuMemcpyDtoD. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. cuMemcpyAtoH.2. DESCRIPTION Copies from host memory to a 1D CUDA array. It only works on page-locked host memory and returns an error if a pointer to pageable memory is passed as input.8. cuMemcpyAtoA. CUresult cuMemcpyHtoAAsync(CUarray dstArray.copies memory from Host to Array SYNOPSIS CUresult cuMemcpyHtoA(CUarray dstArray. const void *srcHostPtr. cuMemcpyDtoA. cuMemcpyDtoH. unsigned int count. dstArray and dstIndex specify the CUDA array handle and starting index of the destination data. unsigned int dstIndex.21 cuMemcpyHtoA NAME cuMemcpyHtoA . const void *srcHostPtr. SEE ALSO cuMemcpyHtoD. srcHostPtr specify the base addresse of the source. cuMemcpyAtoD. unsigned int count). asynchronous launches. CUstream stream). unsigned int dstIndex. cuMemcpyHtoAAsync() is asynchronous and can optionally be associated to a stream by passing a nonzero stream argument. cuMemcpy2D 179 . count specifies the number of bytes to copy.

dstDevPtr and srcHostPtr specify the base addresses of the destination and source.copy memory from Host to Device SYNOPSIS CUresult cuMemcpyHtoD(CUdeviceptr dstDevPtr.2. cuMemcpy2D 180 . cuMemcpyDtoD. DESCRIPTION Copies from host memory to device memory. It only works on page-locked host memory and returns an error if a pointer to pageable memory is passed as input. unsigned int count).8. count specifies the number of bytes to copy. cuMemcpyAtoA. CUstream stream).22 cuMemcpyHtoD NAME cuMemcpyHtoD . const void *srcHostPtr. asynchronous launches. unsigned int count. cuMemcpyHtoDAsync() is asynchronous and can optionally be associated to a stream by passing a nonzero stream argument. CUresult cuMemcpyHtoDAsync(CUdeviceptr dstDevPtr. cuMemcpyHtoA. cuMemcpyAtoH. cuMemcpyAtoD. cuMemcpyDtoA. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. SEE ALSO cuMemcpyDtoH. const void *srcHostPtr. respectively.

cuArrayCreate. cuMemset2D 181 . SEE ALSO cuMemGetInfo. CUresult cuMemsetD16(CUdeviceptr dstDevPtr. unsigned int count ).8. CUresult cuMemsetD32(CUdeviceptr dstDevPtr. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. cuMemAllocHost. cuMemFree.23 cuMemset NAME cuMemset . unsigned int value. cuMemFreeHost. asynchronous launches. unsigned short value. DESCRIPTION Sets the memory range of count 8-. cuMemGetAddressRange. cuArrayGetDescriptor. unsigned int count ). cuArrayDestroy. unsigned int count ).2.initializes device memory SYNOPSIS CUresult cuMemsetD8(CUdeviceptr dstDevPtr. unsigned char value. or 32-bit values to the specified value value. cuMemAllocPitch. 16-. cuMemAlloc.

unsigned int width.initializes device memory SYNOPSIS CUresult cuMemsetD2D8(CUdeviceptr dstDevPtr. CUresult cuMemsetD2D32(CUdeviceptr dstDevPtr. SEE ALSO cuMemGetInfo. cuArrayGetDescriptor.24 cuMemset2D NAME cuMemset2D . cuMemFreeHost. unsigned int width. unsigned int height ). unsigned int dstPitch. unsigned char value. These functions perform fastest when the pitch is one that has been passed back by cuMemAllocPitch(). CUresult cuMemsetD2D16(CUdeviceptr dstDevPtr. unsigned int dstPitch. cuMemFree. unsigned short value. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous.2. unsigned int dstPitch. cuMemGetAddressRange. cuArrayCreate.8. unsigned int height ). unsigned int width. and dstPitch specifies the number of bytes between each row. unsigned int value. or 32-bit values to the specified value value. cuMemAllocPitch. cuMemAlloc. unsigned int height ). cuArrayDestroy. asynchronous launches. 16-. cuMemset 182 . cuMemAllocHost. DESCRIPTION Sets the 2D memory range of width 8-. height specifies the number of rows to set.

TextureReferenceManagement. EventManagement. DeviceManagement.2. Direct3dInteroperability 183 . cuTexRefCreate cuTexRefDestroy cuTexRefGetAddress cuTexRefGetAddressMode cuTexRefGetArray cuTexRefGetFilterMode cuTexRefGetFlags cuTexRefGetFormat cuTexRefSetAddress cuTexRefSetAddressMode cuTexRefSetArray cuTexRefSetFilterMode cuTexRefSetFlags cuTexRefSetFormat SEE ALSO Initialization. StreamManagement. ModuleManagement. OpenGlInteroperability. ContextManagement.9 TextureReferenceManagement NAME Texture Reference Management DESCRIPTION This section describes the low-level CUDA driver application programming interface. ExecutionControl. MemoryManagement.

cuTexRefGetFilterMode. cuTexRefSetAddressMode.) to be used when the memory is read through this texture reference.1 cuTexRefCreate NAME cuTexRefCreate . filtering. cuTexRefSetArray. Other texture reference functions are used to specify the format and interpretation (addressing. asynchronous launches. cuTexRefSetFilterMode. the application should call cuParamSetTexRef(). cuTexRefSetFlags. cuTexRefGetAddressMode. cuTexRefGetFlags 184 . cuTexRefGetFormat. cuTexRefSetFormat. DESCRIPTION Creates a texture reference and returns its handle in *texRef.2. the application must call cuTexRefSetArray() or cuTexRefSetAddress() to associate the reference with allocated memory. Once created. cuTexRefGetAddress. To associate the texture reference with a texture ordinal for a given function. cuTexRefGetArray.9.creates a texture-reference SYNOPSIS CUresult cuTexRefCreate(CUtexref* texRef). RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. cuTexRefSetAddress. SEE ALSO cuTexRefDestroy. etc.

RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. cuTexRefGetFlags 185 .2. SEE ALSO cuTexRefCreate. cuTexRefGetFormat.destroys a texture-reference SYNOPSIS CUresult cuTexRefDestroy(CUtexref texRef). cuTexRefSetAddressMode. cuTexRefGetArray. cuTexRefGetAddressMode.9. cuTexRefSetFormat. cuTexRefGetAddress. cuTexRefSetAddress. cuTexRefSetArray. asynchronous launches. cuTexRefGetFilterMode. cuTexRefSetFlags. DESCRIPTION Destroys the texture reference. cuTexRefSetFilterMode.2 cuTexRefDestroy NAME cuTexRefDestroy .

cuTexRefSetFilterMode. asynchronous launches. SEE ALSO cuTexRefCreate.9. cuTexRefSetFormat. cuTexRefSetArray. cuTexRefGetFlags 186 . cuTexRefGetFilterMode. or returns CUDA_ERROR_INVALID_VA if the texture reference is not bound to any device memory range. cuTexRefGetArray. cuTexRefDestroy. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous.2. cuTexRefGetFormat.3 cuTexRefGetAddress NAME cuTexRefGetAddress .gets the address associated with a texture-reference SYNOPSIS CUresult cuTexRefGetAddress(CUdeviceptr* devPtr. cuTexRefSetFlags. cuTexRefGetAddressMode. DESCRIPTION Returns in *devPtr the base address bound to the texture reference texRef. CUtexref texRef). cuTexRefSetAddressMode. cuTexRefSetAddress.

2. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. SEE ALSO cuTexRefCreate. cuTexRefDestroy. cuTexRefSetFormat. cuTexRefSetFlags.4 cuTexRefGetAddressMode NAME cuTexRefGetAddressMode . cuTexRefGetFlags 187 . Currently the only valid values for dim are 0 and 1. int dim). CUtexref texRef. cuTexRefGetFilterMode.9. cuTexRefGetArray. cuTexRefSetFilterMode. cuTexRefSetArray. DESCRIPTION Returns in *mode the addressing mode corresponding to the dimension dim of the texture reference texRef. asynchronous launches. cuTexRefSetAddressMode.gets the addressing mode used by a texture-reference SYNOPSIS CUresult cuTexRefGetAddressMode(CUaddress_mode* mode. cuTexRefGetFormat. cuTexRefSetAddress. cuTexRefGetAddress.

cuTexRefGetFormat. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. or returns CUDA_ERROR_INVALID_VAL if the texture reference is not bound to any CUDA array. cuTexRefSetFlags. cuTexRefDestroy.9.gets the array bound to a texture-reference SYNOPSIS CUresult cuTexRefGetArray(CUarray* array. cuTexRefSetArray. cuTexRefGetAddress.5 cuTexRefGetArray NAME cuTexRefGetArray . cuTexRefSetFilterMode. cuTexRefSetAddress. cuTexRefGetFlags 188 . asynchronous launches. cuTexRefGetFilterMode. CUtexref texRef). cuTexRefGetAddressMode. SEE ALSO cuTexRefCreate. DESCRIPTION Returns in *array the CUDA array bound by the texture reference texRef. cuTexRefSetAddressMode. cuTexRefSetFormat.2.

RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. cuTexRefSetFilterMode. asynchronous launches. cuTexRefGetArray. cuTexRefDestroy. cuTexRefGetFlags 189 . cuTexRefSetAddress.2. cuTexRefSetAddressMode. cuTexRefGetAddress.gets the filter-mode used by a texture-reference SYNOPSIS CUresult cuTexRefGetFilterMode(CUfilter_mode* mode. CUtexref texRef).6 cuTexRefGetFilterMode NAME cuTexRefGetFilterMode . cuTexRefSetFlags. cuTexRefGetAddressMode. cuTexRefSetFormat. SEE ALSO cuTexRefCreate.9. cuTexRefSetArray. DESCRIPTION Returns in *mode the filtering mode of the texture reference texRef. cuTexRefGetFormat.

9. cuTexRefGetAddress. cuTexRefSetFlags. cuTexRefSetArray. cuTexRefDestroy. cuTexRefSetAddressMode. cuTexRefGetAddressMode. cuTexRefSetFilterMode.gets the flags used by a texture-reference SYNOPSIS CUresult cuTexRefGetFlags(unsigned int* flags.2. asynchronous launches. DESCRIPTION Returns in *flags the flags of the texture reference texRef. cuTexRefGetArray. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous.7 cuTexRefGetFlags NAME cuTexRefGetFlags . cuTexRefGetFormat 190 . CUtexref texRef). SEE ALSO cuTexRefCreate. cuTexRefSetAddress. cuTexRefSetFormat. cuTexRefGetFilterMode.

RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. If format or numPackedComponents is null. cuTexRefGetAddress. SEE ALSO cuTexRefCreate.9.2. CUtexref texRef).8 cuTexRefGetFormat NAME cuTexRefGetFormat . cuTexRefGetArray. cuTexRefGetFlags 191 . cuTexRefSetAddress. cuTexRefSetArray. cuTexRefDestroy. asynchronous launches. cuTexRefGetAddressMode. cuTexRefGetFilterMode. cuTexRefSetFilterMode.gets the format used by a texture-reference SYNOPSIS CUresult cuTexRefGetFormat(CUarray_format* format. cuTexRefSetFormat. cuTexRefSetAddressMode. cuTexRefSetFlags. int* numPackedComponents. DESCRIPTION Returns in *format and *numPackedComponents the format and number of components of the CUDA array bound to the texture reference texRef. it will be ignored.

If the device memory pointer was returned from cuMemAlloc(). cuTexRefSetAddressMode. cuTexRefSetFlags.9. Any previous address or CUDA array state associated with the texture reference is superseded by this function. cuTexRefGetArray.2. int bytes). cuTexRefGetFilterMode. DESCRIPTION Binds a linear address range to the texture reference texRef. the offset is guaranteed to be 0 and NULL may be passed as the ByteOffset parameter. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. cuTexRefDestroy.binds an address as a texture-reference SYNOPSIS CUresult cuTexRefSetAddress(unsigned int* byteOffset. cuTexRefGetAddress.9 cuTexRefSetAddress NAME cuTexRefSetAddress . cuTexRefSetAddress() passes back a byte offset in *byteOffset that must be applied to texture fetches in order to read from the desired memory. CUdeviceptr devPtr. Any memory previously bound to texRef is unbound. asynchronous launches. Since the hardware enforces an alignment requirement on texture base addresses. This offset must be divided by the texel size and passed to kernels that read from the texture so they can be applied to the tex1Dfetch() function. cuTexRefSetFilterMode. SEE ALSO cuTexRefCreate. cuTexRefGetFormat. cuTexRefGetAddressMode. cuTexRefSetArray. CUtexref texRef. cuTexRefGetFlags 192 . cuTexRefSetFormat.

if dim is 1. cuTexRefSetAddress. the second. cuTexRefGetAddress. asynchronous launches. Note that this call has no effect if texRef is bound to linear memory. SEE ALSO cuTexRefCreate. cuTexRefSetArray.9. cuTexRefGetFilterMode. cuTexRefGetArray. cuTexRefSetFilterMode.set the addressing mode for a texture-reference SYNOPSIS CUresult cuTexRefSetAddressMode(CUtexref texRef. cuTexRefSetFormat. CUaddress_mode is defined as such: typedef enum CUaddress_mode_enum { CU_TR_ADDRESS_MODE_WRAP = 0. cuTexRefGetFlags 193 . cuTexRefSetFlags. the addressing mode is applied to the first parameter of the functions used to fetch from the texture. } CUaddress_mode. DESCRIPTION Specifies the addressing mode mode for the given dimension of the texture reference texRef. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. cuTexRefGetFormat. cuTexRefGetAddressMode. and so on. int dim. CU_TR_ADDRESS_MODE_CLAMP = 1. CU_TR_ADDRESS_MODE_MIRROR = 2. If dim is zero. CUaddress_mode mode).2. cuTexRefDestroy.10 cuTexRefSetAddressMode NAME cuTexRefSetAddressMode .

cuTexRefGetFlags 194 . cuTexRefGetFormat. SEE ALSO cuTexRefCreate.binds an array to a texture-reference SYNOPSIS CUresult cuTexRefSetArray(CUtexref texRef. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. cuTexRefGetArray. cuTexRefGetAddress.11 cuTexRefSetArray NAME cuTexRefSetArray . cuTexRefSetAddressMode. asynchronous launches. CUarray array. flags must be set to CU_TRSA_OVERRIDE_FORMAT. cuTexRefGetAddressMode. Any previous address or CUDA array state associated with the texture reference is superseded by this function.2. cuTexRefDestroy. cuTexRefSetAddress.9. cuTexRefGetFilterMode. DESCRIPTION Binds the CUDA array array to the texture reference texRef. cuTexRefSetFilterMode. cuTexRefSetFormat. cuTexRefSetFlags. Any CUDA array previously bound to texRef is unbound. unsigned int flags).

Note that this call has no effect if texRef is bound to linear memory.2. cuTexRefSetArray. cuTexRefGetAddressMode. cuTexRefSetAddress. CUfilter_mode_enum is defined as such: typedef enum CUfilter_mode_enum { CU_TR_FILTER_MODE_POINT = 0. cuTexRefGetArray. cuTexRefSetFlags. CU_TR_FILTER_MODE_LINEAR = 1 } CUfilter_mode. CUfilter_mode mode).sets the mode for a texture-reference SYNOPSIS CUresult cuTexRefSetFilterMode(CUtexref texRef. cuTexRefGetFilterMode.9. SEE ALSO cuTexRefCreate. cuTexRefSetFormat. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. cuTexRefGetFlags 195 .12 cuTexRefSetFilterMode NAME cuTexRefSetFilterMode . cuTexRefGetAddress. DESCRIPTION Specifies the filtering mode mode to be used when reading memory through the texture reference texRef. asynchronous launches. cuTexRefGetFormat. cuTexRefDestroy. cuTexRefSetAddressMode.

sets flags for a texture-reference SYNOPSIS CUresult cuTexRefSetFlags(CUtexref texRef. which suppresses the default behavior of having the texture promote integer data to floating point data in the range [0. • CU_TRSF_NORMALIZED_COORDINATES. asynchronous launches. SEE ALSO cuTexRefCreate. cuTexRefSetAddressMode. cuTexRefGetAddress.13 cuTexRefSetFlags NAME cuTexRefSetFlags . cuTexRefSetFilterMode. cuTexRefSetArray. the texture coordinates [0. cuTexRefGetArray. Instead. unsigned int Flags). The valid flags are: • CU_TRSF_READ_AS_INTEGER. Dim) where Dim is the width or height of the CUDA array. cuTexRefGetFilterMode. cuTexRefGetFormat.9. cuTexRefSetAddress. cuTexRefDestroy. cuTexRefGetAddressMode. 1. 1]. which suppresses the default behavior of having the texture coordinates range from [0. cuTexRefGetFlags 196 . DESCRIPTION Specifies optional flags to control the behavior of data returned through the texture reference. cuTexRefSetFormat.2.0) reference the entire breadth of the array dimension RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous.

9. cuTexRefSetAddress. CUarray_format format. asynchronous launches. format and numPackedComponents are exactly analogous to the Format and NumChannels members of the CUDA_ARRAY_DESCRIPTOR structure: They specify the format of each component and the number of components per array element. cuTexRefSetArray. SEE ALSO cuTexRefCreate. cuTexRefGetArray. cuTexRefSetFilterMode. cuTexRefGetAddress. cuTexRefGetAddressMode.14 cuTexRefSetFormat NAME cuTexRefSetFormat .sets the format for a texture-reference SYNOPSIS CUresult cuTexRefSetFormat(CUtexref texRef. cuTexRefGetFilterMode. int numPackedComponents) DESCRIPTION Specifies the format of the data to be read by the texture reference texRef. cuTexRefDestroy. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous.2. cuTexRefSetFlags. cuTexRefSetAddressMode. cuTexRefGetFlags 197 . cuTexRefGetFormat.

ModuleManagement. Direct3dInteroperability 198 .2. ExecutionControl. MemoryManagement. ContextManagement. cuGLCtxCreate cuGLInit cuGLMapBufferObject cuGLRegisterBufferObject cuGLUnmapBufferObject cuGLUnregisterBufferObject SEE ALSO Initialization. TextureReferenceManagement. DeviceManagement. StreamManagement. OpenGLInteroperability. EventManagement.10 OpenGlInteroperability NAME OpenGL Interoperability DESCRIPTION This section describes the low-level CUDA driver application programming interface.

cuGLUnmapBufferObject. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_OUT_OF_MEMORY Note that this function may also return error codes from previous. It may fail if the needed OpenGL driver facilities are not available. see cuCtxCreate. initializes OpenGL interoperability.10. CUdevice device). DESCRIPTION Creates a new CUDA context. and associates the CUDA context with the calling thread. unsigned int Flags. asynchronous launches. cuGLUnregisterBufferObject 199 . It must be called before performing any other OpenGL interoperability operations. cuGLInit cuGLRegisterBufferObject.create a CUDA context for interoperability with OpenGL SYNOPSIS CUresult cuGLCtxCreate(CUcontext *pCtx.2.1 cuGLCtxCreate NAME cuGLCtxCreate . cuGLMapBufferObject. SEE ALSO cuCtxCreate. For usage of the Flags parameter.

2 cuGLInit NAME cuGLInit . cuGLUnregisterBufferObject 200 . DESCRIPTION Initializes OpenGL interoperability. cuGLMapBufferObject. cuGLUnmapBufferObject. asynchronous launches. cuGLRegisterBufferObject.2. It must be called before performing any other OpenGL interoperability operations. SEE ALSO cuGLCtxCreate. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_UNKNOWN Note that this function may also return error codes from previous. It may fail if the needed OpenGL driver facilities are not available.10.initializes GL interoperability SYNOPSIS CUresult cuGLInit(void).

DESCRIPTION Maps the buffer object of ID bufferObj into the address space of the current CUDA context and returns in *devPtr and *size the base pointer and size of the resulting mapping. GLuint bufferObj). asynchronous launches.3 cuGLMapBufferObject NAME cuGLMapBufferObject . cuGLRegisterBufferObject.maps a GL buffer object SYNOPSIS CUresult cuGLMapBufferObject(CUdeviceptr* devPtr. cuGLUnmapBufferObject.2. SEE ALSO cuGLCtxCreate. unsigned int* size. cuGLInit. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_MAP_FAILED Note that this function may also return error codes from previous. cuGLUnregisterBufferObject 201 .10.

While it is registered. asynchronous launches.registers a GL buffer object SYNOPSIS CUresult cuGLRegisterBufferObject(GLuint bufferObj). cuGLUnmapBufferObject. cuGLMapBufferObject.10. cuGLInit.4 cuGLRegisterBufferObject NAME cuGLRegisterBufferObject . SEE ALSO cuGLCtxCreate. cuGLUnregisterBufferObject 202 . DESCRIPTION Registers the buffer object of ID bufferObj for access by CUDA.2. the buffer object cannot be used by any OpenGL commands except as a data source for OpenGL drawing commands. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_ALREADY_MAPPED Note that this function may also return error codes from previous. This function must be called before CUDA can map the buffer object.

cuGLRegisterBufferObject. cuGLInit.10. DESCRIPTION Unmaps the buffer object of ID bufferObj for access by CUDA.2.unmaps a GL buffer object SYNOPSIS CUresult cuGLUnmapBufferObject(GLuint bufferObj). asynchronous launches. SEE ALSO cuGLCtxCreate. cuGLMapBufferObject. cuGLUnregisterBufferObject 203 . RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous.5 cuGLUnmapBufferObject NAME cuGLUnmapBufferObject .

2. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE Note that this function may also return error codes from previous. cuGLRegisterBufferObject. cuGLInit. SEE ALSO cuGLCtxCreate. cuGLUnmapBufferObject 204 .unregister a GL buffer object SYNOPSIS CUresult cuGLUnregisterBufferObject(GLuint bufferObj). cuGLMapBufferObject. asynchronous launches.6 cuGLUnregisterBufferObject NAME cuGLUnregisterBufferObject .10. DESCRIPTION Unregisters the buffer object of ID bufferObj for access by CUDA.

2. MemoryManagement.11 Direct3dInteroperability NAME Direct3D Interoperability DESCRIPTION This section describes Direct3D interoperability in the the low-level CUDA driver application programming interface. ContextManagement. They should not be used in new development. Direct3dInteroperability 205 . DeviceManagement. ModuleManagement. cuD3D9GetDevice cuD3D9CtxCreate cuD3D9GetDirect3DDevice cuD3D9RegisterResource cuD3D9UnregisterResource cuD3D9MapResources cuD3D9UnmapResources cuD3D9ResourceGetSurfaceDimensions cuD3D9ResourceSetMapFlags cuD3D9ResourceGetMappedPointer cuD3D9ResourceGetMappedSize cuD3D9ResourceGetMappedPitch As of CUDA 2. EventManagement.0 the following functions are deprecated. StreamManagement. cuD3D9Begin cuD3D9End cuD3D9MapVertexBuffer cuD3D9RegisterVertexBuffer cuD3D9UnmapVertexBuffer cuD3D9UnregisterVertexBuffer SEE ALSO Initialization. ExecutionControl. TextureReferenceManagement. OpenGLInteroperability.

cuD3D9ResourceGetMappedPitch 206 . cuD3D9UnregisterResource.1 cuD3D9GetDevice NAME cuD3D9GetDevice . SEE ALSO cuD3D9CtxCreate.11. cuD3D9ResourceSetMapFlags. cuD3D9ResourceGetMappe cuD3D9ResourceGetMappedSize. asynchronous launches. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_VALUE CUDA_ERROR_UNKNOWN Note that this function may also return error codes from previous. DESCRIPTION Returns in *dev the CUDA-compatible device corresponding to the adapter name adapterName obtained from EnumDisplayDevices or IDirect3D9::GetAdapterIdentifier(). If no device on the adapter with name adapterName is CUDA-compatible then the call will fail.gets the device number for an adapter SYNOPSIS CUresult cuD3D9GetDevice(CUdevice* dev. cuD3D9RegisterResource. cuD3D9MapResources.2. cuD3D9GetDirect3DDevice. cuD3D9UnmapResources. const char* adapterName). cuD3D9ResourceGetSurfaceDimensions.

asynchronous launches. DESCRIPTION Creates a new CUDA context. cuD3D9ResourceGetMappedPitch 207 . On success. and associates the created CUDA context with the calling thread. cuD3D9RegisterResource. cuD3D9GetDirect3DDevice. see cuCtxCreate. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_VALUE CUDA_ERROR_OUT_OF_MEMORY CUDA_ERROR_UNKNOWN Note that this function may also return error codes from previous. The CUcontext created will be returned in *pCtx. unsigned int Flags. enables interoperability for that context with the Direct3D device pDxDevice. cuD3D9ResourceSetMapFlags. If pCuDevice is non-NULL then the CUdevice on which this CUDA context was created will be returned in *pCuDevice. this call will increase the internal reference count on pDxDevice. cuD3D9ResourceGetMappe cuD3D9ResourceGetMappedSize.2. CUdevice* pCuDevice. IDirect3DDevice9* pDxDevice). Direct3D resources from this device may be registered and mapped through the lifetime of this CUDA context. cuD3D9UnregisterResource. cuD3D9ResourceGetSurfaceDimensions. This reference count will be decremented upon destruction of this context through cuCtxDestroy. This context will function only until its Direct3D device is destroyed. cuD3D9MapResources cuD3D9UnmapResources. SEE ALSO cuD3D9GetDevice. For usage of the Flags parameter.create a CUDA context for interoperability with Direct3D SYNOPSIS CUresult cuD3D9CtxCreate(CUcontext* pCtx.2 cuD3D9CtxCreate NAME cuD3D9CtxCreate .11.

cuD3D9ResourceGetSurfaceDimensions.3 cuD3D9GetDirect3DDevice NAME cuD3D9GetDirect3DDevice . cuD3D9UnmapResources. cuD3D9CtxCreate.get the Direct3D device against which the current CUDA context was created SYNOPSIS CUresult cuD3D9GetDirect3DDevice(IDirect3DDevice9** ppDxDevice). cuD3D9MapResources. cuD3D9ResourceGetMappedPitch 208 . DESCRIPTION Returns in *ppDxDevice the Direct3D device against which this CUDA context was created in cuD3D9CtxCreate.2. cuD3D9UnregisterResource. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT Note that this function may also return error codes from previous. cuD3D9ResourceGetMappe cuD3D9ResourceGetMappedSize. cuD3D9RegisterResource. asynchronous launches.11. cuD3D9ResourceSetMapFlags. SEE ALSO cuD3D9GetDevice.

In particular. The following are some limitations. • Any resources allocated in D3DPOOL_SYSTEMMEM may not be registered with CUDA. this call will increase the internal reference count on pResource. 209 . cuD3D9ResourceGetMappedSize. • The primary rendertarget may not be registered with CUDA. • IDirect3DBaseTexture9: When a texture is registered all surfaces associated with the all mipmap levels of all faces of the texture will be accessible to CUDA. The Flags argument specifies the mechanism through which CUDA will access the Direct3D resource. DESCRIPTION Registers the Direct3D resource pResource for access by CUDA. or 32-bit integer or floating-point data cannot be shared. • Resources allocated as shared may not be registered with CUDA. The following value is allowed. and cuD3D9ResourceGetMappedPitch respectively. The pointer. This call is potentially high-overhead and should not be called every frame in interactive applications.4 cuD3D9RegisterResource NAME cuD3D9RegisterResource .register a Direct3D resource for access by CUDA SYNOPSIS CUresult cuD3D9RegisterResource(IDirect3DResource9* pResource. To access individual surfaces associated with a texture. • Textures which are not of a format which is 1. 2. or 4 channels of 8. size. This reference count will be decremented when this resource is unregistered through cuD3D9UnregisterResource. • IDirect3DIndexBuffer9: No notes. • IDirect3DSurface9: Only stand-alone objects of type IDirect3DSurface9 may be explicitly shared. This option is valid for all resource types.2. If this call is successful then the application will be able to map and unmap this resource until it is unregistered through cuD3D9UnregisterResource. one must register the base texture object. Not all Direct3D resources of the above types may be used for interoperability with CUDA. individual mipmap levels and faces of cube maps may not be registered directly. The type of pResource must be one of the following. • IDirect3DVertexBuffer9: No notes. • CU_D3D9_REGISTER_FLAGS_NONE: Specifies that CUDA will access this resource through a CUdeviceptr. Also on success. unsigned int Flags). 16. and pitch for each subresource of this resource may be queried through cuD3D9ResourceGetMappedPointer.11.

g. cuD3D9MapResources. SEE ALSO cuD3D9GetDevice. is a non-stand-alone IDirect3DSurface9) or is already registered then CUDA_ERROR_INVALID_HANDLE is returned. If pResource is of incorrect type (e. cuD3D9UnmapResources. cuD3D9ResourceGetMappedPitch 210 . If pResource cannot be registered then CUDA_ERROR_UNKNOWN is returned. asynchronous launches.• Surfaces of depth or stencil formats cannot be shared. cuD3D9CtxCreate. cuD3D9ResourceSetMapFlags. cuD3D9GetDirect3DDevice. cuD3D9ResourceGetMappe cuD3D9ResourceGetMappedSize. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_INVALID_HANDLE CUDA_ERROR_OUT_OF_MEMORY CUDA_ERROR_UNKNOWN Note that this function may also return error codes from previous. If Direct3D interoperability is not initialized on this context then CUDA_ERROR_INVALID_CONTEXT is returned. cuD3D9UnregisterResource. cuD3D9ResourceGetSurfaceDimensions.

cuD3D9ResourceGetMappedPitch 211 . cuD3D9CtxCreate.5 cuD3D9UnregisterResource NAME cuD3D9UnregisterResource .2. cuD3D9GetDirect3DDevice.unregister a Direct3D resource SYNOPSIS CUresult cuD3D9UnregisterResource(IDirect3DResource9* pResource). RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_HANDLE CUDA_ERROR_UNKNOWN Note that this function may also return error codes from previous. If pResource is not registered then CUDA_ERROR_INVALID_HANDLE is returned. DESCRIPTION Unregisters the Direct3D resource pResource so it is not accessable by CUDA unless registered again.11. cuD3D9ResourceGetSurfaceDimensions. cuD3D9RegisterResource. SEE ALSO cuD3D9GetDevice. cuD3D9ResourceSetMapFlags. cuD3D9ResourceGetMappe cuD3D9ResourceGetMappedSize. asynchronous launches. cuD3D9UnmapResources. cuD3D9MapResources.

11. cuD3D9CtxCreate. If an application does so the results are undefined. cuD3D9ResourceGetMappe cuD3D9ResourceGetMappedSize. Direct3D should not access any resources while they are mapped by CUDA. The resources in ppResources may be accessed in CUDA kernels until they are unmapped. SEE ALSO cuD3D9GetDevice. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_HANDLE CUDA_ERROR_ALREADY_MAPPED CUDA_ERROR_UNKNOWN Note that this function may also return error codes from previous. This function provides the synchronization guarantee that any Direct3D calls issued before cuD3D9MapResources will complete before any CUDA kernels issued after cuD3D9MapResources begin.map Direct3D resources for access by CUDA SYNOPSIS CUresult cuD3D9MapResources(unsigned int count.6 cuD3D9MapResources NAME cuD3D9MapResources . cuD3D9ResourceSetMapFlags. If any of ppResources are presently mapped for access by CUDA then CUDA_ERROR_ALREADY_MAPPED is returned. cuD3D9UnregisterResource. asynchronous launches. cuD3D9UnmapResources. If any of ppResources have not been registered for use with CUDA or if ppResources contains any duplicate entries then CUDA_ERROR_INVALID_HANDLE is returned. cuD3D9GetDirect3DDevice.2. DESCRIPTION Maps the count Direct3D resources in ppResources for access by CUDA. IDirect3DResource9 **ppResources). cuD3D9ResourceGetMappedPitch 212 . cuD3D9ResourceGetSurfaceDimensions. cuD3D9RegisterResource.

2.11.7

cuD3D9UnmapResources

NAME
cuD3D9UnmapResources - unmap Direct3D resources

SYNOPSIS
CUresult cuD3D9UnmapResources(unsigned int count, IDirect3DResource9** ppResources);

DESCRIPTION
Unmaps the count Direct3D resources in ppResources. This function provides the synchronization guarantee that any CUDA kernels issued before cuD3D9UnmapResources will complete before any Direct3D calls issued after cuD3D9UnmapResources begin. If any of ppResources have not been registered for use with CUDA or if ppResources contains any duplicate entries then CUDA_ERROR_INVALID_HANDLE is returned. If any of ppResources are not presently mapped for access by CUDA then CUDA_ERROR_NOT_MAPPED is returned.

RETURN VALUE
Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_HANDLE CUDA_ERROR_NOT_MAPPED CUDA_ERROR_UNKNOWN Note that this function may also return error codes from previous, asynchronous launches.

SEE ALSO

cuD3D9GetDevice, cuD3D9CtxCreate, cuD3D9GetDirect3DDevice, cuD3D9RegisterResource, cuD3D9UnregisterResource, cuD3D9MapResources, cuD3D9ResourceGetSurfaceDimensions, cuD3D9ResourceSetMapFlags, cuD3D9ResourceGetMappedP cuD3D9ResourceGetMappedSize, cuD3D9ResourceGetMappedPitch

213

2.11.8

cuD3D9ResourceSetMapFlags

NAME
cuD3D9ResourceSetMapFlags - set usage flags for mapping a Direct3D resource

SYNOPSIS
CUresult cuD3D9ResourceSetMapFlags(IDirect3DResource9 *pResource, unsigned int Flags);

DESCRIPTION
Set flags for mapping the Direct3D resource pResource. Changes to flags will take effect the next time pResource is mapped. The Flags argument may be any of the following. • CU_D3D9_MAPRESOURCE_FLAGS_NONE: Specifies no hints about how this resource will be used. It is therefore assumed that this resource will be read from and written to by CUDA kernels. This is the default value. • CU_D3D9_MAPRESOURCE_FLAGS_READONLY: Specifies that CUDA kernels which access this resource will not write to this resource. • CU_D3D9_MAPRESOURCE_FLAGS_WRITEDISCARD: Specifies that CUDA kernels which access this resource will not read from this resource and will write over the entire contents of the resource, so none of the data previously stored in the resource will be preserved. If pResource has not been registered for use with CUDA then CUDA_ERROR_INVALID_HANDLE is returned. If pResource is presently mapped for access by CUDA then CUDA_ERROR_ALREADY_MAPPED is returned.

RETURN VALUE
Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_INVALID_HANDLE CUDA_ERROR_ALREADY_MAPPED Note that this function may also return error codes from previous, asynchronous launches.

214

SEE ALSO

cuD3D9GetDevice, cuD3D9CtxCreate, cuD3D9GetDirect3DDevice, cuD3D9RegisterResource, cuD3D9UnregisterResource, cuD3D9MapResources, cuD3D9UnmapResources, cuD3D9ResourceGetSurfaceDimensions, cuD3D9ResourceGetMappedPointe cuD3D9ResourceGetMappedSize, cuD3D9ResourceGetMappedPitch

215

2.11.9

cuD3D9ResourceGetSurfaceDimensions

NAME
cuD3D9ResourceGetSurfaceDimensions - get the dimensions of a registered surface

SYNOPSIS
CUresult cuD3D9ResourceGetSurfaceDimensions(unsigned int* pWidth, unsigned int* pHeight, unsigned int *pDepth, IDirect3DResource9* pResource, unsigned int Face, unsigned int Level);

DESCRIPTION
Returns in *pWidth, *pHeight, and *pDepth the dimensions of the subresource of the mapped Direct3D resource pResource which corresponds to Face and Level. Because anti-aliased surfaces may have multiple samples per pixel it is possible that the dimensions of a resource will be an integer factor larger than the dimensions reported by the Direct3D runtime. The parameters pWidth, pHeight, and pDepth are optional. For 2D surfaces, the value returned in *pDepth will be 0. If pResource is not of type IDirect3DBaseTexture9 or IDirect3DSurface9 or if pResource has not been registered for use with CUDA then CUDA_ERROR_INVALID_HANDLE is returned. For usage requirements of Face and Level parameters see cuD3D9ResourceGetMappedPointer.

RETURN VALUE
Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_INVALID_HANDLE Note that this function may also return error codes from previous, asynchronous launches.

SEE ALSO
cuD3D9GetDevice, cuD3D9CtxCreate, cuD3D9GetDirect3DDevice, cuD3D9RegisterResource, cuD3D9UnregisterResource, cuD3D9MapResources, cuD3D9UnmapResources, cuD3D9ResourceSetMapFlags, cuD3D9ResourceGetMappedPointer, cuD3D9ResourceGetMappedSize, cuD3D9ResourceGetMappedPitch

216

For all other types Face must be 0. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_INVALID_HANDLE CUDA_ERROR_NOT_MAPPED Note that this function may also return error codes from previous. unsigned int Level). IDirect3DResource9* pResource.10 cuD3D9ResourceGetMappedPointer NAME cuD3D9ResourceGetMappedPointer . If Face is invalid then CUDA_ERROR_INVALID_V is returned. If pResource was not registered with usage flags CU_D3D9_REGISTER_FLAGS_NONE then CUDA_ERROR_INVA is returned. At present only mipmap level 0 is supported.2. If pResource is of type IDirect3DBaseTexture9 then Level must correspond to a valid mipmap level. If pResource is of type IDirect3DCubeTexture9 then Face must one of the values enumerated by type D3DCUBEMAP_FACES. For all other types Level must be 0. The value set in pDevPtr may change every time that pResource is mapped.11. 217 . asynchronous launches. DESCRIPTION Returns in *pDevPtr the base pointer of the subresource of the mapped Direct3D resource pResource which corresponds to Face and Level. If Level is invalid then CUDA_ERROR_INVALID_VALUE is returned. unsigned int Face. If pResource is not mapped then CUDA_ERROR_NOT_MAPPED is returned.get a pointer through which to access a subresource of a Direct3D resource which has been mapped for access by CUDA SYNOPSIS CUresult cuD3D9ResourceGetMappedPointer(CUdeviceptr* pDevPtr. If pResource is not registered then CUDA_ERROR_INVALID_HANDLE is returned.

cuD3D9UnregisterResource. cuD3D9ResourceGetMappedPitch 218 . cuD3D9RegisterResource. cuD3D9MapResources. cuD3D9ResourceGetMappedSize. cuD3D9UnmapResources. cuD3D9ResourceSetMapFlags.SEE ALSO cuD3D9GetDevice. cuD3D9GetDirect3DDevice. cuD3D9ResourceGetSurfaceDimensions. cuD3D9CtxCreate.

11 cuD3D9ResourceGetMappedSize NAME cuD3D9ResourceGetMappedSize .2. cuD3D9ResourceGetSurfaceDimensions. cuD3D9UnmapResources. SEE ALSO cuD3D9GetDevice. cuD3D9UnregisterResource. IDirect3DResource9* pResource. If pResource has not been registered for use with CUDA then CUDA_ERROR_INVALID_HANDLE is returned.11. cuD3D9CtxCreate. The value set in pSize may change every time that pResource is mapped. cuD3D9ResourceGetMappedPitch 219 . asynchronous launches. If pResource is not mapped for access by CUDA then CUDA_ERROR_NOT_MAPPED is returned. cuD3D9GetDirect3DDevice. cuD3D9ResourceGetMappedPointer. unsigned int Level).get the size of a subresource of a Direct3D resource which has been mapped for access by CUDA SYNOPSIS CUresult cuD3D9ResourceGetMappedSize(unsigned int* pSize. unsigned int Face. For usage requirements of Face and Level parameters see cuD3D9ResourceGetMappedPointer. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_INVALID_HANDLE CUDA_ERROR_NOT_MAPPED Note that this function may also return error codes from previous. cuD3D9ResourceSetMapFlags. cuD3D9RegisterResource. If pResource was not registered with usage flags CU_D3D9_REGISTER_FLAGS_NONE then CUDA_ERROR_INVALID_HANDLE is returned. cuD3D9MapResources. DESCRIPTION Returns in *pSize the size of the subresource of the mapped Direct3D resource pResource which corresponds to Face and Level.

z from the base pointer of the surface is z*slicePitch + y*pitch + (bytes per pixel)*x Both parameters pPitch and pPitchSlice are optional and may be set to NULL.12 cuD3D9ResourceGetMappedPitch NAME cuD3D9ResourceGetMappedPitch . DESCRIPTION Returns in *pPitch and *pPitchSlice the pitch and Z-slice pitch of the subresource of the mapped Direct3D resource pResource which corresponds to Face and Level.2. The pitch and Z-slice pitch values may be used to compute the location of a sample on a surface as follows.get the pitch of a subresource of a Direct3D resource which has been mapped for access by CUDA SYNOPSIS CUresult cuD3D9ResourceGetMappedPitch(unsigned int* pPitch. RETURN VALUE Relevant return values: CUDA_SUCCESS CUDA_ERROR_DEINITIALIZED CUDA_ERROR_NOT_INITIALIZED CUDA_ERROR_INVALID_CONTEXT CUDA_ERROR_INVALID_VALUE CUDA_ERROR_INVALID_HANDLE CUDA_ERROR_NOT_MAPPED Note that this function may also return error codes from previous. IDirect3DResource pResource. If pResource is not mapped for access by CUDA then CUDA_ERROR_NOT_MAPPED is returned.11. unsigned int* pPitchSlice. For usage requirements of Face and Level parameters see cuD3D9ResourceGetMappedPointer. If pResource was not registered with usage flags CU_D3D9_REGISTER_FLAGS_NONE then CUDA_ERROR_INVALID_HANDLE is returned.y. unsigned int Level). asynchronous launches. y*pitch + (bytes per pixel)*x For a 3D surface the byte offset of the sample of at position x. 220 .y from the base pointer of the surface is If pResource is not of type IDirect3DBaseTexture9 or one of its sub-types or if pResource has not been registered for use with CUDA then CUDA_ERROR_INVALID_HANDLE is returned. For a 2D surface the byte offset of the sample of at position x. The values set in pPitch and pPitchSlice may change every time that pResource is mapped. unsigned int Face.

cuD3D9ResourceGetSurfaceDimensions. cuD3D9UnregisterResource. cuD3D9UnmapResources. cuD3D9GetDirect3DDevice. cuD3D9ResourceGetMappedPointer. cuD3D9ResourceGetMappedSize 221 . cuD3D9MapResources. cuD3D9ResourceSetMapFlags. cuD3D9RegisterResource.SEE ALSO cuD3D9GetDevice. cuD3D9CtxCreate.

64-bit atomic operations are only supported on devices of compute capability 1.3 AtomicFunctions NAME Atomic Functions DESCRIPTION Atomic functions can only be used in device functions. SEE ALSO ArithmeticFunctions.2 and higher. NOTES 32-bit atomic operations are only supported on devices of compute capability 1.1 and higher. BitwiseFunctions 222 .

atomicAdd atomicSub atomicExch atomicMin atomicMax atomicInc atomicDec atomicCAS SEE ALSO BitwiseFunctions 223 .3.1 ArithmeticFunctions NAME Arithmetic Functions DESCRIPTION This section describes the atomic arithmetic functions.

computes (old + val). unsigned int atomicAdd(unsigned int* address. 64-bit atomic operations are only supported on devices of compute capability 1. unsigned int val). The function returns old. unsigned long long int atomicAdd(unsigned long long int* address. and stores the result back to global memory at the same address. atomicMax.1 and higher. int val). atomicExch. atomicInc. atomicCAS 224 .3. SEE ALSO atomicSub. atomicDec.atomic addition SYNOPSIS int atomicAdd(int* address. atomicMin. DESCRIPTION Reads the 32. unsigned long long int val).1.or 64-bit word old located at the address address in global memory.2 and higher. These three operations are performed in one atomic transaction.1 atomicAdd NAME atomicAdd . NOTES 32-bit atomic operations are only supported on devices of compute capability 1.

unsigned int atomicSub(unsigned int* address. unsigned int val). SEE ALSO atomicAdd.atomic subtraction SYNOPSIS int atomicSub(int* address. atomicMin. atomicCAS 225 .3.2 atomicSub NAME atomicSub . atomicInc. int val). computes (old . These three operations are performed in one atomic transaction.1 and higher. NOTES Atomic operations are only supported on devices of compute capability 1.val). DESCRIPTION Reads the 32-bit word old located at the address address in global memory. atomicExch. The function returns old. atomicMax.1. atomicDec. and stores the result back to global memory at the same address.

unsigned int val).2 and higher. 64-bit atomic operations are only supported on devices of compute capability 1. These two operations are performed in one atomic transaction. atomicInc. DESCRIPTION Reads the 32.3 atomicExch NAME atomicExch . atomicMax. unsigned long long int atomicExch(unsigned long long int* address. atomicDec. atomicMin. int val). atomicCAS 226 . NOTES 32-bit atomic operations are only supported on devices of compute capability 1. unsigned long long int val).or 64-bit word old located at the address address in global memory and stores val back to global memory at the same address. SEE ALSO atomicAdd.3. The function returns old. unsigned int atomicExch(unsigned int* address.1. atomicSub.1 and higher.atomic exchange SYNOPSIS int atomicExch(int* address.

atomicDec. These three operations are performed in one atomic transaction. unsigned int atomicMin(unsigned int* address. atomicExch. DESCRIPTION Reads the 32-bit word old located at the address address in global memory. The function returns b<old>. and stores the result back to global memory at the same address.1 and higher. computes the minimum of old and val.atomic minimum SYNOPSIS int atomicMin(int* address.4 atomicMin NAME atomicMin . atomicSub.3. NOTES Atomic operations are only supported on devices of compute capability 1.1. SEE ALSO atomicAdd. int val). unsigned int val). atomicMax. atomicInc. atomicCAS 227 .

The function returns old. atomicSub.3. int val). atomicDec. computes the maximum of old and val.1 and higher. NOTES Atomic operations are only supported on devices of compute capability 1. atomicCAS 228 .5 atomicMax NAME atomicMax .1. DESCRIPTION Reads the 32-bit word old located at the address address in global memory. atomicMin. atomicExch. atomicInc.atomic maximum SYNOPSIS int atomicMax(int* address. and stores the result back to global memory at the same address. unsigned int val). SEE ALSO atomicAdd. These three operations are performed in one atomic transaction. unsigned int atomicMax(unsigned int* address.

1. atomicCAS 229 . The function returns old. atomicSub. DESCRIPTION Reads the 32-bit word old located at the address address in global memory. SEE ALSO atomicAdd. NOTES Atomic operations are only supported on devices of compute capability 1. atomicDec.atomic increment SYNOPSIS unsigned int atomicInc(unsigned int* address.6 atomicInc NAME atomicInc . and stores the result back to global memory at the same address.1 and higher.3. atomicExch. unsigned int val). atomicMax. computes ((old >= val) ? 0 : (old+1)). These three operations are performed in one atomic transaction. atomicMin.

NOTES Atomic operations are only supported on devices of compute capability 1.7 atomicDec NAME atomicDec . The function returns old.3. atomicMin.1 and higher.1. unsigned int val). and stores the result back to global memory at the same address.atomic decrement SYNOPSIS unsigned int atomicDec(unsigned int* address. atomicSub. computes (((old == 0) . SEE ALSO atomicAdd. atomicInc. atomicMax. atomicCAS 230 . atomicExch. These three operations are performed in one atomic transaction. DESCRIPTION Reads the 32-bit word old located at the address address in global memory.

atomicSub. SEE ALSO atomicAdd. int val).atomic compare-and-swap SYNOPSIS int atomicCAS(int* address. unsigned int compare. atomicExch. unsigned int val). atomicDec 231 . DESCRIPTION Reads the 32.or 64-bit word old located at the address address in global memory.2 and higher. atomicInc. NOTES 32-bit atomic operations are only supported on devices of compute capability 1. atomicMax. int compare.3. The function returns old (Compare And Swap). unsigned int atomicCAS(unsigned int* address. These three operations are performed in one atomic transaction.1. atomicMin. unsigned long long int atomicCAS(unsigned long long int* address. unsigned long long int compare. 64-bit atomic operations are only supported on devices of compute capability 1. unsigned long long int val).8 atomicCAS NAME atomicCAS .1 and higher. computes (old == compare ? val : old). and stores the result back to global memory at the same address.

3.2

BitwiseFunctions

NAME
Bitwise Functions

DESCRIPTION
This section describes the atomic bitwise functions. atomicAnd atomicOr atomicXor

SEE ALSO
ArithmeticFunctions

232

3.2.1

atomicAnd

NAME
atomicAnd - atomic bitwise-and

SYNOPSIS
int atomicAnd(int* address, int val); unsigned int atomicAnd(unsigned int* address, unsigned int val);

DESCRIPTION
Reads the 32-bit word old located at the address address in global memory, computes (old & val), and stores the result back to global memory at the same address. These three operations are performed in one atomic transaction. The function returns old.

NOTES
Atomic operations are only supported on devices of compute capability 1.1 and higher.

SEE ALSO
atomicOr, atomicXor

233

3.2.2

atomicOr

NAME
atomicOr - atomic bitwise-or

SYNOPSIS
int atomicOr(int* address, int val); unsigned int atomicOr(unsigned int* address, unsigned int val);

DESCRIPTION
Reads the 32-bit word old located at the address address in global memory, computes (old , and stores the result back to global memory at the same address. These three operations are performed in one atomic transaction. The function returns old.

NOTES
Atomic operations are only supported on devices of compute capability 1.1 and higher.

SEE ALSO
atomicAnd, atomicXor

234

3.2.3

atomicXor

NAME
atomicXor - atomic bitwise-xor

SYNOPSIS
int atomicXor(int* address, int val); unsigned int atomicXor(unsigned int* address, unsigned int val);

DESCRIPTION
Reads the 32-bit word old located at the address address in global memory, computes (old ˆ val), and stores the result back to global memory at the same address. These three operations are performed in one atomic transaction. The function returns old.

NOTES
Atomic operations are only supported on devices of compute capability 1.1 and higher.

SEE ALSO
atomicAnd, atomicOr

235

209 cuD3D9ResourceGetMappedPitch. 207 cuD3D9GetDevice. 8 cudaConfigureCall. 58 cudaGLMapBufferObject. 230 atomicExch. 220 cuD3D9ResourceGetMappedPointer. 97 cudaGetLastError. 115 cuCtxDetach. 95 cudaGetSymbolAddress. 89 cudaD3D9ResourceSetMapFlags. 85 cudaD3D9RegisterResource. 158 cuArrayCreate. 59 cudaBindTexture HL. 228 atomicMin. 119 cuCtxSynchronize. 116 cuCtxGetDevice. 86 cudaD3D9UnregisterResource. 43 236 . 216 cuD3D9ResourceSetMapFlags.Index ArithmeticFunctions. 233 atomicCAS. 40 cudaMemcpyFromArray. 64 cudaD3D9GetDevice. 22 cudaEventElapsedTime. 81 cudaD3D9MapResources. 91 cudaD3D9ResourceGetSurfaceDimensions. 26 cudaMemcpy. 29 cudaFreeHost. 117 cuCtxPopCurrent. 82 cudaD3D9ResourceGetMappedPitch. 34 cudaMemcpy2D. 224 atomicAnd. 27 cudaFreeArray. 39 cudaMemcpy2DToArray. 41 cudaMemcpy2DFromArray. 223 atomicAdd. 222 atomicInc. 70 cudaMalloc. 62 cudaGetTextureReference. 226 AtomicFunctions. 225 atomicXor. 23 cudaEventQuery. 20 cudaEventRecord. 3 cudaGetDeviceProperties. 73 cudaGLUnmapBufferObject. 206 cuD3D9GetDirect3DDevice. 74 cudaGLSetGLDevice. 87 cudaD3D9SetDirect3DDevice. 38 cudaMemcpyFromSymbol. 229 atomicMax. 214 cuD3D9UnmapResources. 19 cudaEventSynchronize. 66 cudaChooseDevice. 157 cuCtxAttach. 92 cudaD3D9ResourceGetMappedPointer. 52 cudaMemcpyArrayToArray. 76 cudaGLUnregisterBufferObject. 65 cudaBindTextureToArray. 118 cuCtxPushCurrent. 6 cudaGetErrorString. 213 cuD3D9UnregisterResource. 37 cudaMemcpy3D. 56 cudaCreateChannelDesc HL. 208 cuD3D9MapResources. 154 cuArray3DGetDescriptor. 21 cudaFree. 112 cuCtxCreate. 75 cudaGLRegisterBufferObject. 35 cudaMemcpy2DArrayToArray. 156 cuArrayGetDescriptor. 69 cudaCreateChannelDesc. 30 cudaMallocPitch. 227 atomicOr. 28 cudaMallocHost. 84 cudaEventCreate. 152 cuArrayDestroy. 57 cudaGetDevice. 90 cudaD3D9ResourceGetMappedSize. 219 cuD3D9ResourceGetSurfaceDimensions. 120 cuD3D9CtxCreate. 25 cudaMalloc3D. 77 cudaLaunch. 5 cudaGetDeviceCount. 80 cudaD3D9UnmapResources. 45 cudaGetTextureAlignmentOffset. 79 cudaD3D9GetDirect3DDevice. 113 cuCtxDestroy. 234 atomicSub. 231 atomicDec. 111 cuArray3DCreate. 60 cudaBindTextureToArray HL. 48 cudaMallocArray. 217 cuD3D9ResourceGetMappedSize. 46 cudaMalloc3DArray. 232 ContextManagement. 44 cudaGetSymbolSize. 235 BitwiseFunctions. 18 cudaEventDestroy. 31 cudaGetChannelDesc. 211 cudaBindTexture. 212 cuD3D9RegisterResource.

149 cuFuncSetSharedSize. 122 cuModuleGetGlobal. 176 cuMemcpyDtoD. 182 cuModuleGetFunction. 199 cuGLInit. 180 cuMemFree. 125 cuModuleLoadData. 148 cuStreamCreate. 144 cuParamSetTexRef. 190 cuTexRefGetFormat. 2 Direct3dInteroperability. 130 cuStreamDestroy. 108 cuDeviceTotalMem. 189 cuTexRefGetFlags. 24 237 . 16 cudaStreamQuery. 195 cuTexRefSetFlags. 68 HighLevelApi. 50 cudaSetDevice. 186 cuTexRefGetAddressMode. 145 cuParamSetv. 99 LowLevelApi. 142 cuLaunchGrid. 135 cuEventDestroy. 102 cuDeviceGet. 42 cudaMemset. 14 cudaStreamSynchronize. 173 cuMemcpyAtoD. 146 cuParamSeti. 11 cudaThreadSynchronize. 161 cuMemcpy2D. 110 cuEventCreate. 193 cuTexRefSetArray. 78 DriverApiReference. 203 cuGLUnregisterBufferObject. 103 cuDeviceGetAttribute. 136 cuEventElapsedTime. 200 cuGLMapBufferObject. 4 cudaSetupArgument. 150 cuGLCtxCreate. 137 cuEventQuery. 143 cuMemAlloc. 10 cudaUnbindTexture. 160 cuMemAllocPitch. 177 cuMemcpyDtoH. 205 Direct3dInteroperability RT.cudaMemcpyToArray. 15 cudaThreadExit. 139 cuEventSynchronize. 104 cuDeviceGetCount. 164 cuMemGetAddressRange. 165 cuMemGetInfo. 128 cuParamSetf. 123 cuModuleGetTexRef. 71 cudaStreamCreate. 55 MemoryManagement. 166 cuMemset. 201 cuGLRegisterBufferObject. 187 cuTexRefGetArray. 140 cuFuncSetBlockShape. 126 cuModuleLoadFatBinary. 170 cuMemcpyAtoA. 133 cuTexRefCreate. 13 cudaStreamDestroy. 185 cuTexRefGetAddress. 67 cuDeviceComputeCapability. 141 ExecutionControl RT. 174 cuMemcpyAtoH. 107 cuDeviceGetProperties. 63 Initialization. 132 cuStreamSynchronize. 147 cuParamSetSize. 192 cuTexRefSetAddressMode. 151 MemoryManagement RT. 124 cuModuleLoad. 179 cuMemcpyHtoD. 196 cuTexRefSetFormat. 134 EventManagement RT. 184 cuTexRefDestroy. 204 cuInit. 127 cuModuleUnload. 94 EventManagement. 106 cuDeviceGetName. 100 cuLaunch. 98 ErrorHandling RT. 101 DeviceManagement RT. 197 DeviceManagement. 61 cudaUnbindTexture HL. 33 cudaMemset3D. 163 cuMemFreeHost. 175 cuMemcpyDtoA. 36 cudaMemcpyToSymbol. 178 cuMemcpyHtoA. 202 cuGLUnmapBufferObject. 32 cudaMemset2D. 138 cuEventRecord. 191 cuTexRefSetAddress. 17 ExecutionControl. 131 cuStreamQuery. 167 cuMemcpy3D. 159 cuMemAllocHost. 181 cuMemset2D. 188 cuTexRefGetFilterMode. 194 cuTexRefSetFilterMode.

121 OpenGlInteroperability.ModuleManagement. 54 ThreadManagement RT. 1 StreamManagement. 72 RuntimeApiReference. 183 TextureReferenceManagement RT. 9 238 . 12 TextureReferenceManagement. 198 OpenGlInteroperability RT. 129 StreamManagement RT.