예제 #1
0
파일: AstToDot.py 프로젝트: leonardt/ctree
def main():
    stmt0 = Assign(SymbolRef('foo'), Constant(123.4))
    stmt1 = FunctionDecl(Float(), SymbolRef("bar"), [
        SymbolRef("spam", Int()), SymbolRef("eggs", Long())], [String("baz")])
    stmt3 = [[SymbolRef("AAAAA")]]
    tree = CFile("myfile", [stmt0, stmt1, stmt3])
    print (to_dot(tree))
예제 #2
0
파일: AstToDot.py 프로젝트: lowks/ctree
def main():
    stmt0 = Assign(SymbolRef('foo'), Constant(123.4))
    stmt1 = FunctionDecl(Float(), SymbolRef("bar"),
                         [SymbolRef("spam", Int()),
                          SymbolRef("eggs", Long())], [String("baz")])
    stmt3 = [[SymbolRef("AAAAA")]]
    tree = CFile("myfile", [stmt0, stmt1, stmt3])
    print(to_dot(tree))
예제 #3
0
    def dot_ast_to_browser(ast_node, file_name):
        from  ctree.dotgen import to_dot

        dot_text = to_dot(ast_node)
        dot_output = DotManager.run_dot(dot_text)

        with open(file_name, "wb") as f:
            f.write(dot_output)

        import subprocess
        subprocess.check_output(["open", file_name])
예제 #4
0
파일: dot_manager.py 프로젝트: lowks/ctree
    def dot_ast_to_browser(ast_node, file_name):
        from ctree.dotgen import to_dot

        dot_text = to_dot(ast_node)
        dot_output = DotManager.run_dot(dot_text)

        with open(file_name, "wb") as f:
            f.write(dot_output)

        import subprocess
        subprocess.check_output(["open", file_name])
예제 #5
0
파일: OclDoubler.py 프로젝트: lowks/ctree
    def transform(self, py_ast, program_config):
        """
        Convert the Python AST to a C AST according to the directions
        given in program_config.
        """
        len_A, A_dtype, A_ndim, A_shape = program_config[0]
        A_type = NdPointer(A_dtype, A_ndim, A_shape)

        apply_one = PyBasicConversions().visit(py_ast.body[0])
        apply_one_typesig = FuncType(A_type.get_base_type(), [A_type.get_base_type()])
        apply_one.set_typesig(apply_one_typesig)

        apply_kernel = FunctionDecl(Void(), "apply_kernel",
                                    params=[SymbolRef("A", A_type)],
                                    defn=[
                                        Assign(SymbolRef("i", Int()),
                                               FunctionCall(SymbolRef("get_global_id"), [Constant(0)])),
                                        If(Lt(SymbolRef("i"), Constant(len_A)), [
                                            Assign(ArrayRef(SymbolRef("A"), SymbolRef("i")),
                                                   FunctionCall(SymbolRef("apply"),
                                                                [ArrayRef(SymbolRef("A"), SymbolRef("i"))]))
                                        ])
                                    ])

        # add opencl type qualifiers
        apply_kernel.set_kernel()
        apply_kernel.params[0].set_global()

        kernel = OclFile("kernel", [apply_one, apply_kernel])

        template_args = {
            'array_decl': SymbolRef("data", A_type),
            'array_ref':  SymbolRef("data"),
            'count':      Constant(len_A),
            'kernel_path': kernel.get_generated_path_ref(),
            'kernel_name': String(apply_kernel.name),
        }
        template_path = os.path.join(os.getcwd(), "templates", "OclDoubler.tmpl.c")

        control = CFile("control", [
            FileTemplate(template_path, template_args),
        ])
        tree = Project([kernel, control])

        with open("graph.dot", 'w') as f:
          f.write( to_dot(tree) )

        entry_point_typesig = FuncType(Int(), [A_type]).as_ctype()
        return tree, entry_point_typesig
예제 #6
0
    def transform(self, py_ast, program_config):
        """
        Convert the Python AST to a C AST according to the directions
        given in program_config.
        """
        arg_config, tuner_config = program_config
        len_A   = arg_config['A_len']
        A_dtype = arg_config['A_dtype']
        A_ndim  = arg_config['A_ndim']
        A_shape = arg_config['A_shape']

        inner_type = get_ctree_type(A_dtype)
        array_type = NdPointer(A_dtype, A_ndim, A_shape)
        apply_one_typesig = FuncType(inner_type, [inner_type])

        template_entries = {
            'array_decl': SymbolRef("A", array_type),
            'array_ref' : SymbolRef("A"),
            'num_items' : Constant(len_A),
        }

        tree = CFile("generated", [
            py_ast.body[0],
            StringTemplate("""\
            void apply_all($array_decl) {
                for (int i = 0; i < $num_items; i++) {
                    $array_ref[i] = apply( $array_ref[i] );
                }
            }
            """, template_entries)
        ])

        tree = PyBasicConversions().visit(tree)

        apply_one = tree.find(FunctionDecl, name="apply")
        apply_one.set_static().set_inline()
        apply_one.set_typesig(apply_one_typesig)

        with open("graph.dot", 'w') as f:
            f.write( to_dot(tree) )

        entry_point_typesig = FuncType(Void(), [array_type]).as_ctype()
        return Project([tree]), entry_point_typesig
예제 #7
0
파일: test_dot.py 프로젝트: lowks/ctree
 def test_c_identity(self):
     self.assertNotEqual(to_dot(identity_ast), "")
예제 #8
0
파일: test_dot.py 프로젝트: lowks/ctree
 def test_c_gcd(self):
     self.assertNotEqual(to_dot(gcd_ast), "")
예제 #9
0
파일: test_dot.py 프로젝트: leonardt/ctree
 def test_py_fib(self):
     self.assertNotEqual(to_dot(get_ast(fib)), "")
예제 #10
0
    def test_cl_mem_dot(self):
        from ctree.dotgen import to_dot

        to_dot(SymbolRef("foo", cl_mem()))
예제 #11
0
파일: test_dot.py 프로젝트: leonardt/ctree
 def test_py_identity(self):
     self.assertNotEqual(to_dot(get_ast(identity)), "")
예제 #12
0
파일: test_dot.py 프로젝트: leonardt/ctree
 def test_py_gcd(self):
     self.assertNotEqual(to_dot(get_ast(gcd)), "")
예제 #13
0
파일: dot_manager.py 프로젝트: lowks/ctree
    def dot_ast_to_image(ast_node):
        from ctree.dotgen import to_dot

        dot_text = to_dot(ast_node)

        return DotManager.dot_text_to_image(dot_text)
예제 #14
0
파일: test_dot.py 프로젝트: leonardt/ctree
 def test_c_l2norm(self):
     self.assertNotEqual(to_dot(l2norm_ast), "")
예제 #15
0
파일: test_dot.py 프로젝트: lowks/ctree
 def test_py_identity(self):
     self.assertNotEqual(to_dot(get_ast(identity)), "")
예제 #16
0
파일: test_dot.py 프로젝트: lowks/ctree
 def test_py_fib(self):
     self.assertNotEqual(to_dot(get_ast(fib)), "")
예제 #17
0
파일: test_dot.py 프로젝트: lowks/ctree
 def test_c_fib(self):
     self.assertNotEqual(to_dot(fib_ast), "")
예제 #18
0
 def test_file_template_dotgen(self):
     from ctree.c.nodes import String
     path = os.path.join(*(fixtures.__path__ + ["templates", "printf.tmpl.c"]))
     tree = FileTemplate(path, {'fmt': String('Hello, world!')})
     to_dot(tree)
예제 #19
0
    def dot_ast_to_image(ast_node):
        from  ctree.dotgen import to_dot

        dot_text = to_dot(ast_node)

        return DotManager.dot_text_to_image(dot_text)
예제 #20
0
 def test_dotgen(self):
     tree = StringTemplate("return $one $two", {
         'one': Constant(1),
         'two': Constant(2),
     })
     dot = to_dot(tree)
예제 #21
0
    def test_cl_mem_dot(self):
        from ctree.dotgen import to_dot

        to_dot(SymbolRef("foo", cl_mem()))
예제 #22
0
파일: test_dot.py 프로젝트: lowks/ctree
 def test_c_l2norm(self):
     self.assertNotEqual(to_dot(l2norm_ast), "")
예제 #23
0
파일: test_dot.py 프로젝트: leonardt/ctree
 def test_c_identity(self):
     self.assertNotEqual(to_dot(identity_ast), "")
예제 #24
0
파일: test_dot.py 프로젝트: lowks/ctree
 def test_py_gcd(self):
     self.assertNotEqual(to_dot(get_ast(gcd)), "")
예제 #25
0
파일: test_dot.py 프로젝트: leonardt/ctree
 def test_c_gcd(self):
     self.assertNotEqual(to_dot(gcd_ast), "")
예제 #26
0
파일: test_dot.py 프로젝트: leonardt/ctree
 def test_c_fib(self):
     self.assertNotEqual(to_dot(fib_ast), "")
예제 #27
0
 def test_lol_1(self):
     tree = Block([[a, b]])
     to_dot(tree)