#NEWLINE# def grid_expand( ndim ) : #NEWLINE# #INDENT# 'grid(ndim)\n\n    Return the absolute position of the current thread in the entire\n    grid of blocks.  *ndim* should correspond to the number of dimensions\n    declared when instantiating the kernel.  If *ndim* is 1, a single integer\n    is returned.  If *ndim* is 2 or 3, a tuple of the given number of\n    integers is returned.\n\n    Computation of the first integer is as follows::\n\n        cuda.threadIdx.x + cuda.blockIdx.x * cuda.blockDim.x\n\n    and is similar for the other two indices, but using the ``y`` and ``z``\n    attributes.\n    ' #NEWLINE# if ( ndim == 1 ) : #NEWLINE# #INDENT# fname = 'ptx.grid.1d' #NEWLINE# restype = types . int32 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ndim == 2 ) : #NEWLINE# #INDENT# fname = 'ptx.grid.2d' #NEWLINE# restype = types . UniTuple ( types . int32 , 2 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ndim == 3 ) : #NEWLINE# #INDENT# fname = 'ptx.grid.3d' #NEWLINE# restype = types . UniTuple ( types . int32 , 3 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( 'argument can only be 1, 2, 3' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return ir . Intrinsic ( fname , typing . signature ( restype , types . intp ) , args = [ ndim ] )