Esempio n. 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"),
            ]))
Esempio n. 2
0
    def emit_sequential_loop(self, codegen_state, iname, iname_dtype, lbound,
                             ubound, inner):
        ecm = codegen_state.expression_to_code_mapper

        from pymbolic.mapper.stringifier import PREC_NONE
        from genpy import For

        return For((iname, ), "range(%s, %s + 1)" % (
            ecm(lbound, PREC_NONE, "i"),
            ecm(ubound, PREC_NONE, "i"),
        ), inner)
Esempio n. 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"),
            ]))