예제 #1
0
    def get_function_definition(self, codegen_state, codegen_result,
                                schedule_index, function_decl, function_body):
        from loopy.kernel.data import TemporaryVariable
        args = (["_lpy_cl_kernels", "queue"] + [
            idi.name for idi in codegen_state.implemented_data_info
            if not issubclass(idi.arg_class, TemporaryVariable)
        ] + ["wait_for=None", "allocator=None"])

        from genpy import (For, Function, Suite, Return, Line, Statement as S)
        return Function(
            codegen_result.current_program(codegen_state).name,
            args,
            Suite([
                Line(),
            ] + [
                Line(),
                function_body,
                Line(),
            ] + ([
                For(
                    "_tv",
                    "_global_temporaries",
                    # free global temporaries
                    S("_tv.release()"))
            ] if self._get_global_temporaries(codegen_state) else []) + [
                Line(),
                Return("_lpy_evt"),
            ]))
예제 #2
0
파일: python.py 프로젝트: spillai/loopy
    def get_function_definition(self, codegen_state, codegen_result,
                                schedule_index, function_decl, function_body):

        assert function_decl is None

        from genpy import Function
        return Function(
            codegen_result.current_program(codegen_state).name,
            [idi.name for idi in codegen_state.implemented_data_info],
            function_body)
예제 #3
0
    def get_function_definition(self, codegen_state, codegen_result,
                                schedule_index, function_decl, function_body):
        from loopy.kernel.data import TemporaryVariable
        args = (["_lpy_cl_kernels", "queue"] + [
            idi.name for idi in codegen_state.implemented_data_info
            if not issubclass(idi.arg_class, TemporaryVariable)
        ] + ["wait_for=None", "allocator=None"])

        from genpy import (For, Function, Suite, Import, ImportAs, Return,
                           FromImport, If, Assign, Line, Statement as S)
        return Function(
            codegen_result.current_program(codegen_state).name,
            args,
            Suite([
                FromImport("struct", ["pack as _lpy_pack"]),
                ImportAs("pyopencl", "_lpy_cl"),
                Import("pyopencl.tools"),
                Line(),
                If(
                    "allocator is None",
                    Assign("allocator",
                           "_lpy_cl_tools.DeferredAllocator(queue.context)")),
                Line(),
            ] + [
                Line(),
                function_body,
                Line(),
            ] + [
                For(
                    "_tv",
                    "_global_temporaries",
                    # free global temporaries
                    S("_tv.release()"))
            ] + [
                Line(),
                Return("_lpy_evt"),
            ]))