Beispiel #1
0
    def __init__(self, with_cilk=False, inject_failure=None):
        self.inject_failure = inject_failure

        # we want to raise an exception if there is no kernel()
        # method defined.
        try:
            dir(self).index("kernel")
        except ValueError:
            raise Exception("No kernel method defined.")

        # get text of kernel() method and parse into a StencilModel
        self.kernel_src = inspect.getsource(self.kernel)
        # print(self.kernel_src)
        self.kernel_ast = ast.parse(self.remove_indentation(self.kernel_src))
        # print(ast.dump(self.kernel_ast, include_attributes=True))
        self.model = StencilPythonFrontEnd().parse(self.kernel_ast)
        # print(ast.dump(self.model, include_attributes=True))

        self.pure_python = False
        self.pure_python_kernel = self.kernel
        self.should_unroll = True
        self.should_cacheblock = False
        self.block_size = 1
        
        # replace kernel with shadow version
        self.kernel = self.shadow_kernel

        self.specialized_sizes = None
        self.with_cilk = with_cilk
    def __init__(self, with_cilk=False):
        # we want to raise an exception if there is no kernel()
        # method defined.
        try:
            dir(self).index("kernel")
        except ValueError:
            raise Exception("No kernel method defined.")

        # get text of kernel() method and parse into a StencilModel
        self.kernel_src = inspect.getsource(self.kernel)
        # print(self.kernel_src)
        self.kernel_ast = ast.parse(self.remove_indentation(self.kernel_src))
        # print(ast.dump(self.kernel_ast, include_attributes=True))
        self.model = StencilPythonFrontEnd().parse(self.kernel_ast)
        # print(ast.dump(self.model, include_attributes=True))

        self.pure_python = False
        self.pure_python_kernel = self.kernel
        self.should_unroll = True
        self.should_cacheblock = False
        self.block_size = 1

        # replace kernel with shadow version
        self.kernel = self.shadow_kernel

        self.specialized_sizes = None
        self.with_cilk = with_cilk
    def __init__(self, with_cilk=False):
        # we want to raise an exception if there is no kernel()
        # method defined.
        try:
            dir(self).index("kernel")
        except ValueError:
            raise Exception("No kernel method defined.")

        # get text of kernel() method and parse into a StencilModel
        self.kernel_src = inspect.getsource(self.kernel)
        self.kernel_ast = ast.parse(self.remove_indentation(self.kernel_src))
        self.model = StencilPythonFrontEnd().parse(self.kernel_ast)

        self.pure_python = False
        self.pure_python_kernel = self.kernel
        self.should_unroll = True
        self.should_cacheblock = False
        self.block_size = 1
        self.should_trace = False
        self.verify_log = False
        
        # replace kernel with shadow version
        self.kernel = self.shadow_kernel

        self.specialized_sizes = None
        self.with_cilk = with_cilk
Beispiel #4
0
 def __init__(self):
   # check for hello method
   try:
     dir(self).index('hello')
   except ValueError:
     raise Exception('No hello method defined.')
   self.hello_src = inspect.getsource(self.hello)
   self.hello_ast = ast.parse(self.hello_src.lstrip())  
   self.hello = self.shadow_hello
Beispiel #5
0
    def __init__(self):
        # get text of kernel() method and parse into a Python AST
        self.kernel_src = inspect.getsource(self.kernel)
        self.kernel_ast = ast.parse(self.remove_indentation(self.kernel_src))

        self.pure_python = False
        self.pure_python_kernel = self.kernel
        
        # replace kernel with shadow version
        self.kernel = self.shadow_kernel
Beispiel #6
0
 def test_visit_StencilNeighborIter(self):
     import asp.codegen.python_ast as ast, re
     n = StencilKernel.StencilNeighborIter("in_grid",
                           [ast.parse("in_grid[x] = in_grid[x] + out_grid[y]").body[0]],
                           ast.Name("y", None),
                           1)
     converter = StencilKernel.StencilConvertAST(self.argdict)
     # visit_StencilNeighborIter expects to have dim vars defined already
     converter.gen_dim_var()
     converter.gen_dim_var()
     result = converter.visit(n)
     self.assertTrue(re.search("array_macro", str(result)))
Beispiel #7
0
    def processFunctions(self, mod):
        index = 0
        math_funcs = []
        while hasattr(self, "func"+str(index)):
            math_funcs.append("func"+str(index))

            func_src = inspect.getsource(getattr(self, "func"+str(index)))
            func_ast = ast.parse(self.remove_indentation(func_src))

            phase2 = NewtonKernel.NewtonProcessAST({}).visit(func_ast)
            phase3 = NewtonKernel.NewtonConvertAST({}).visit(phase2)
        
            mod.add_function(phase3, fname="func"+str(index))#rendered)
            index+=1
        return index
	def __init__(self):
		# we want to raise an exception if there is no kernel()
		# method defined.
		try:
			dir(self).index("kernel")
		except ValueError:
			raise Exception("No kernel method defined.")

		# if the method is defined, let us introspect and find
		# its AST
		self.kernel_src = inspect.getsource(self.kernel)
		self.kernel_ast = ast.parse(self.remove_indentation(self.kernel_src))

		self.pure_python = False
		self.pure_python_kernel = self.kernel

		# replace kernel with shadow version
		self.kernel = self.shadow_kernel
    def __init__(self, operators):
        # check for 'op' method
        self.operators = operators
        #temp_path = "/tmp/" #"/home/harper/Documents/Work/SEJITS/temp/"
        #makefile_path = "/vagrant/KDTSpecializer/kdt/pyCombBLAS"
        include_files = ["pyOperations.h"] #, "swigpyrun.h"]
        self.mod = mod = asp_module.ASPModule(specializer="kdt")

        # add some include directories
        for x in include_files:
            self.mod.add_header(x)
        self.mod.backends["c++"].toolchain.cc = "mpicxx"
        self.mod.backends["c++"].module.add_to_preamble([cpp_ast.Line("#include <tr1/memory>")])
        self.mod.backends["c++"].toolchain.cflags = ["-g", "-fPIC", "-shared", "-DCOMBBLAS_TR1"]
        self.mod.add_library("pycombblas",
                             ["/vagrant/trunk/kdt/pyCombBLAS"],
                             library_dirs=["/vagrant/trunk/build/lib.linux-i686-2.6"],
                             libraries=["mpi_cxx"])
                               

        # the pyCombBLAS library must be imported in order for the SWIG typelookup to work
        import kdt.pyCombBLAS
        
        for operator in self.operators:
            try:
                dir(self).index(operator.name)
            except ValueError:
                raise Exception('No %s method defined.' % operator.name)

            operator.src = inspect.getsource(getattr(self, operator.name))
            operator.ast = ast.parse(operator.src.lstrip())
            phase2 = PcbOperator.ProcessAST(operator).visit(operator.ast)
            converted = PcbOperator.ConvertAST().visit(phase2)

            print "==="
            print converted
            
            print "==="

            self.mod.backends["c++"].module.add_to_module(converted.contents[0:-1])
            self.mod.add_function(operator.name, converted.contents[2].text)

            # now delete the method so the lookup goes through the Asp module
            delattr(self.__class__, operator.name)
Beispiel #10
0
    def map_using_trees(self, arr):
        import asp.codegen.templating.template as template
        import inspect
        import asp.codegen.python_ast as ast
        import asp.codegen.ast_tools as ast_tools

        src = inspect.getsource(self.operation)
        operation_ast = ast.parse(src.lstrip())
        return_ast = operation_ast.body[0]
        expr_ast = return_ast.body[0].value
        expr_cpp = ast_tools.ConvertAST().visit(expr_ast)

        mytemplate = template.Template(filename="templates/map_template.mako", disable_unicode=True)
        rendered = mytemplate.render(num_items=len(arr), expr=expr_cpp)

        import asp.jit.asp_module as asp_module
        mod = asp_module.ASPModule()
        mod.add_function("map_in_c", rendered)
        return mod.map_in_c(arr)
Beispiel #11
0
    def __init__(self, asp_module_factory=None):
        # we want to raise an exception if there is no kernel()
        # method defined.
        try:
            dir(self).index("kernel")
        except ValueError:
            raise Exception("No kernel method defined.")

        # if the method is defined, let us introspect and find
        # its AST
        self.kernel_src = inspect.getsource(self.kernel)
        self.kernel_ast = ast.parse(self.remove_indentation(self.kernel_src))

        self.pure_python = False
        self.pure_python_kernel = self.kernel

        # replace kernel with shadow version
        self.kernel = self.shadow_kernel
        if asp_module_factory is None:
            from asp.jit import asp_module
            self.asp_module_factory = asp_module.ASPModule
        else:
            self.asp_module_factory = asp_module_factory