<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> from string import Template <EOL> import pycuda . autoinit <EOL> import pycuda . gpuarray as gpuarray <EOL> from pycuda . compiler import SourceModule <EOL> import numpy as np <EOL> import skcuda . misc as misc <EOL> A = <NUM_LIT:3> <EOL> B = <NUM_LIT:4> <EOL> C = <NUM_LIT:5> <EOL> N = A * B * C <EOL> x_orig = np . asarray ( np . random . rand ( N ) , np . float64 ) <EOL> x = x_orig . reshape ( ( A , B , C ) ) <EOL> a = lambda i : i / ( B * C ) <EOL> b = lambda i : np . mod ( i , B * C ) / C <EOL> c = lambda i : np . mod ( np . mod ( i , B * C ) , C ) <EOL> subscript = lambda i : ( a ( i ) , b ( i ) , c ( i ) ) <EOL> for i in range ( x . size ) : <EOL> assert x . flat [ i ] == x [ subscript ( i ) ] <EOL> index = lambda i , j , k : i * B * C + j * C + k <EOL> for i in range ( A ) : <EOL> for j in range ( B ) : <EOL> for k in range ( C ) : <EOL> assert x [ i , j , k ] == x . flat [ index ( i , j , k ) ] <EOL> func_mod_template = Template ( """<STR_LIT>""" ) <EOL> max_threads_per_block , max_block_dim , max_grid_dim = misc . get_dev_attrs ( pycuda . autoinit . device ) <EOL> block_dim , grid_dim = misc . select_block_grid_sizes ( pycuda . autoinit . device , x . shape ) <EOL> max_blocks_per_grid = max ( max_grid_dim ) <EOL> func_mod = SourceModule ( func_mod_template . substitute ( max_threads_per_block = max_threads_per_block , <EOL> max_blocks_per_grid = max_blocks_per_grid , <EOL> A = A , B = B , C = C ) ) <EOL> func = func_mod . get_function ( '<STR_LIT>' ) <EOL> x_gpu = gpuarray . to_gpu ( x ) <EOL> func ( x_gpu . gpudata , np . uint32 ( x_gpu . size ) , <EOL> block = block_dim , <EOL> grid = grid_dim ) <EOL> x_np = x . copy ( ) <EOL> x_np [ : , <NUM_LIT:0> , : ] = <NUM_LIT:100> <EOL> print ( '<STR_LIT>' , np . allclose ( x_np , x_gpu . get ( ) ) ) </s>
