def run_test(): size = 10 weight_array = WeightArray( np.ones((3, 3), dtype=np.float) / 9 ) component = StencilComponent( "input", weight_array ) red = DomainUnion([ RectangularDomain(( (1, -1, 2), (1, -1, 2) )), RectangularDomain(( (2, 0, 2), (2, 0, 2) )) ]) stencil = Stencil( component, "output", red ) ccompiler = CCompiler() kern = ccompiler.compile(stencil) arr = np.arange(size**2, dtype=np.float).reshape((size, size)) out = np.zeros_like(arr) kern(out, arr) print(out)
def test(tile_size, n): opt_args = [test_in] + [test_in]*NDIM + [test_opt_out] compiler = CCompiler() compiler.tile_size = tile_size optimized = analyzer.repackage(sten, NDIM, n) kern = compiler.compile(optimized) kern(*opt_args) t = -time.time() kern(*opt_args) t += time.time() print(tile_size, n, t/ITER)
def run_test(): weight_array = WeightArray( np.ones((3, 3, 3), dtype=np.float) / 27 ) component = StencilComponent( "input", weight_array ) stencil = Stencil( component, "output", [(1, -1, 1)]*3 ) ccompiler = CCompiler() kern = ccompiler.compile(stencil) arr = np.arange(66**3, dtype=np.float).reshape((66, 66, 66)) out = np.zeros_like(arr) kern(out, arr)
upper_diff *= StencilComponent("beta_{}".format(dim), SparseWeightArray({Vector.unit_vector(dim, ndim): 1})) return lower_diff + upper_diff def create_stencil(ndim): components = [create_component(ndim, dim) for dim in range(ndim)] ## creates components for beta_1 to beta_n total = sum(components) return Stencil(total, "out", [(1, -1, 1)]*ndim, "mesh") sten = create_stencil(NDIM) optimized = analyzer.repackage(sten, NDIM, DECOMP) naive_compiler = CCompiler() optimized_compiler = CCompiler() naive_kernel = naive_compiler.compile(StencilGroup([sten]*ITER)) optimized_kernel = optimized_compiler.compile(StencilGroup(optimized.body*ITER)) test_in = np.arange((SIZE + 2)**NDIM, dtype=np.float).reshape((SIZE+2,)*NDIM) test_out = np.zeros_like(test_in) test_opt_out = np.zeros_like(test_in) naive_args = [test_in] + [test_in]*NDIM + [test_out] naive_kernel(*naive_args) t = -time.time()