Exemplo n.º 1
0
def countParfors(test_func, args, **kws):
    typingctx = typing.Context()
    targetctx = cpu.CPUContext(typingctx)
    test_ir = compiler.run_frontend(test_func)
    if kws:
        options = cpu.ParallelOptions(kws)
    else:
        options = cpu.ParallelOptions(True)

    with cpu_target.nested_context(typingctx, targetctx):
        tp = TestPipeline(typingctx, targetctx, args, test_ir)

        inline_pass = inline_closurecall.InlineClosureCallPass(
            tp.func_ir, options)
        inline_pass.run()

        numba.rewrites.rewrite_registry.apply('before-inference', tp,
                                              tp.func_ir)

        tp.typemap, tp.return_type, tp.calltypes = compiler.type_inference_stage(
            tp.typingctx, tp.func_ir, tp.args, None)

        type_annotations.TypeAnnotation(func_ir=tp.func_ir,
                                        typemap=tp.typemap,
                                        calltypes=tp.calltypes,
                                        lifted=(),
                                        lifted_from=None,
                                        args=tp.args,
                                        return_type=tp.return_type,
                                        html_output=config.HTML)

        preparfor_pass = numba.parfor.PreParforPass(tp.func_ir, tp.typemap,
                                                    tp.calltypes, tp.typingctx,
                                                    options)
        preparfor_pass.run()

        numba.rewrites.rewrite_registry.apply('after-inference', tp,
                                              tp.func_ir)

        parfor_pass = numba.parfor.ParforPass(tp.func_ir, tp.typemap,
                                              tp.calltypes, tp.return_type,
                                              tp.typingctx, options)
        parfor_pass.run()
    ret_count = 0

    for label, block in test_ir.blocks.items():
        for i, inst in enumerate(block.body):
            if isinstance(inst, numba.parfor.Parfor):
                ret_count += 1

    return ret_count
Exemplo n.º 2
0
class Flags(utils.ConfigOptions):
    # These options are all false by default, but the defaults are
    # different with the @jit decorator (see targets.options.TargetOptions).

    OPTIONS = {
        # Enable loop-lifting
        'enable_looplift': False,
        # Enable pyobject mode (in general)
        'enable_pyobject': False,
        # Enable pyobject mode inside lifted loops
        'enable_pyobject_looplift': False,
        # Force pyobject mode inside the whole function
        'force_pyobject': False,
        # Release GIL inside the native function
        'release_gil': False,
        'no_compile': False,
        'debuginfo': False,
        'boundcheck': False,
        'forceinline': False,
        'no_cpython_wrapper': False,
        # Enable automatic parallel optimization, can be fine-tuned by taking
        # a dictionary of sub-options instead of a boolean, see parfor.py for
        # detail.
        'auto_parallel': cpu.ParallelOptions(False),
        'nrt': False,
        'no_rewrites': False,
        'error_model': 'python',
        'fastmath': False,
        'noalias': False,
    }
Exemplo n.º 3
0
    def __init__(self, *args):
        # flags for njit()
        self.cflags = Flags()
        self.cflags.set('nrt')

        # flags for njit(parallel=True)
        self.pflags = Flags()
        self.pflags.set('auto_parallel', cpu.ParallelOptions(True))
        self.pflags.set('nrt')
        super(TestParforsBase, self).__init__(*args)
Exemplo n.º 4
0
def run_frontend(func, inline_closures=False):
    """
    Run the compiler frontend over the given Python function, and return
    the function's canonical Numba IR.

    If inline_closures is Truthy then closure inlining will be run
    """
    # XXX make this a dedicated Pipeline?
    func_id = bytecode.FunctionIdentity.from_function(func)
    interp = interpreter.Interpreter(func_id)
    bc = bytecode.ByteCode(func_id=func_id)
    func_ir = interp.interpret(bc)
    if inline_closures:
        inline_pass = InlineClosureCallPass(func_ir, cpu.ParallelOptions(False),
                                            {}, False)
        inline_pass.run()
    post_proc = postproc.PostProcessor(func_ir)
    post_proc.run()
    return func_ir
Exemplo n.º 5
0
 def compile_parallel(self, func, arg_types):
     fast_pflags = Flags()
     fast_pflags.set('auto_parallel', cpu.ParallelOptions(True))
     fast_pflags.set('nrt')
     fast_pflags.set('fastmath')
     return compile_isolated(func, arg_types, flags=fast_pflags).entry_point