コード例 #1
0
ファイル: ckernel_interp.py プロジェクト: AbhiAgarwal/blaze
def interpret(func, env, args, storage=None, **kwds):
    assert len(args) == len(func.args)

    # Make a copy, since we're going to mutate our IR!
    func, _ = copy_function(func)

    # If it's a BLZ output, we want an interpreter that streams
    # the processing through in chunks
    if storage is not None:
        if len(func.type.restype.shape) == 0:
            raise TypeError('Require an array, not a scalar, for outputting to BLZ')
        env['stream-outer'] = True
        result_ndim = env['result-ndim'] = len(func.type.restype.shape)
    else:
        # Convert any persistent inputs to memory
        # TODO: should stream the computation in this case
        for i, arg in enumerate(args):
            if isinstance(arg._data, BLZDataDescriptor):
                args[i] = arg[:]

    # Update environment with dynd type information
    dynd_types = dict((arg, get_dynd_type(array))
                          for arg, array in zip(func.args, args)
                              if isinstance(array._data, DyNDDataDescriptor))
    env['dynd-types'] = dynd_types

    # Lift ckernels
    func, env = run_pipeline(func, env, run_time_passes)

    if storage is None:
        # Evaluate once
        values = dict(zip(func.args, args))
        interp = CKernelInterp(values)
        visit(interp, func)
        return interp.result
    else:
        res_shape, res_dt = datashape.to_numpy(func.type.restype)
        dim_size = operator.index(res_shape[0])
        row_size = ndt.type(str(func.type.restype.subarray(1))).data_size
        chunk_size = min(max(1, (1024*1024) // row_size), dim_size)
        # Evaluate by streaming the outermost dimension,
        # and using the BLZ data descriptor's append
        dst_dd = BLZDataDescriptor(blz.zeros((0,)+res_shape[1:], res_dt,
                                             rootdir=storage.path))
        # Loop through all the chunks
        for chunk_start in range(0, dim_size, chunk_size):
            # Tell the interpreter which chunk size to use (last
            # chunk might be smaller)
            chunk_size = min(chunk_size, dim_size - chunk_start)
            # Evaluate the chunk
            args_chunk = [arg[chunk_start:chunk_start+chunk_size]
                            if len(arg.dshape.shape) == result_ndim
                            else arg for arg in args]
            values = dict(zip(func.args, args_chunk))
            interp = CKernelChunkInterp(values, chunk_size, result_ndim)
            visit(interp, func)
            chunk = interp.result._data.dynd_arr()
            dst_dd.append(chunk)
        return blaze.Array(dst_dd)
コード例 #2
0
ファイル: jit.py プロジェクト: AbhiAgarwal/blaze
def build_kerneltrees(func, jitted):
    """
    Builds the kernel trees for all the nodes that are to be jitted,
    also populating lists of arguments.
    """
    fuser = BuildKernelTrees(func, jitted)
    visit(fuser, func)
    return fuser.trees, fuser.arguments
コード例 #3
0
def build_kerneltrees(func, jitted):
    """
    Builds the kernel trees for all the nodes that are to be jitted,
    also populating lists of arguments.
    """
    fuser = BuildKernelTrees(func, jitted)
    visit(fuser, func)
    return fuser.trees, fuser.arguments
コード例 #4
0
    def test_combinator(self):
        visitor = SampleVisitor()
        def op_blah(op):
            visitor.recorded.append(op.opcode)

        comb = combine(visitor, {'op_blah': op_blah})
        with self.b.at_front(self.entry):
            self.b.emit(Op('blah', None, []))
        visit(comb, self.f)
        self.eq(visitor.recorded, ['blah', 'mul'])
コード例 #5
0
ファイル: jit.py プロジェクト: AbhiAgarwal/blaze
def identify_jitnodes(func, env):
    """
    Identifies which nodes (kernels and converters) should be jitted,
    and creates a dictionary mapping them to corresponding
    BlazeElementKernels.
    """
    v = IdentifyJitKernels(func, env)
    visit(v, func)
    v = IdentifyJitConvertors(func, v.jitted)
    visit(v, func)
    return v.jitted
コード例 #6
0
def identify_jitnodes(func, env):
    """
    Identifies which nodes (kernels and converters) should be jitted,
    and creates a dictionary mapping them to corresponding
    BlazeElementKernels.
    """
    v = IdentifyJitKernels(func, env)
    visit(v, func)
    v = IdentifyJitConvertors(func, v.jitted)
    visit(v, func)
    return v.jitted
コード例 #7
0
ファイル: test_traversal.py プロジェクト: Inaimathi/pykit
    def test_combinator(self):
        visitor = SampleVisitor()

        def op_blah(op):
            visitor.recorded.append(op.opcode)

        comb = combine(visitor, {"op_blah": op_blah})
        with self.b.at_front(self.entry):
            self.b.emit(Op("blah", None, []))
        visit(comb, self.f)
        self.eq(visitor.recorded, ["blah", "mul"])
コード例 #8
0
ファイル: ckernel_interp.py プロジェクト: pepmadon/blaze
def interpret(func, env, args, **kwds):
    assert len(args) == len(func.args)

    # Make a copy, since we're going to mutate our IR!
    func = copy_function(func)

    # Update environment with dynd type information
    dynd_types = dict((arg, get_dynd_type(array))
                          for arg, array in zip(func.args, args)
                              if isinstance(array._data, DyNDDataDescriptor))
    env['dynd-types'] = dynd_types

    # Lift ckernels
    func, env = run_pipeline(func, env, run_time_passes)

    print(func)

    # Evaluate
    values = dict(zip(func.args, args))
    interp = CKernelInterp(values)
    visit(interp, func)
    return interp.result
コード例 #9
0
ファイル: interp.py プロジェクト: xsixing/blaze
def interpret(func, env, storage=None, **kwds):
    args = env['runtime.arglist']

    if storage is None:
        # Evaluate once
        values = dict(zip(func.args, args))
        interp = CKernelInterp(values)
        visit(interp, func)
        return interp.result
    else:
        result_ndim = env['result-ndim']

        res_shape, res_dt = datashape.to_numpy(func.type.restype)
        dim_size = operator.index(res_shape[0])
        row_size = ndt.type(str(func.type.restype.subarray(1))).data_size
        chunk_size = min(max(1, (1024 * 1024) // row_size), dim_size)
        # Evaluate by streaming the outermost dimension,
        # and using the BLZ data descriptor's append
        dst_dd = BLZDataDescriptor(
            blz.zeros((0, ) + res_shape[1:], res_dt, rootdir=storage.path))
        # Loop through all the chunks
        for chunk_start in range(0, dim_size, chunk_size):
            # Tell the interpreter which chunk size to use (last
            # chunk might be smaller)
            chunk_size = min(chunk_size, dim_size - chunk_start)
            # Evaluate the chunk
            args_chunk = [
                arg[chunk_start:chunk_start + chunk_size]
                if len(arg.dshape.shape) == result_ndim else arg
                for arg in args
            ]
            values = dict(zip(func.args, args_chunk))
            interp = CKernelChunkInterp(values, chunk_size, result_ndim)
            visit(interp, func)
            chunk = interp.result._data.dynd_arr()
            dst_dd.append(chunk)

        return blaze.Array(dst_dd)
コード例 #10
0
ファイル: interp.py プロジェクト: aaronmartin0303/blaze
def interpret(func, env, storage=None, **kwds):
    args = env['runtime.arglist']

    if storage is None:
        # Evaluate once
        values = dict(zip(func.args, args))
        interp = CKernelInterp(values)
        visit(interp, func)
        return interp.result
    else:
        result_ndim = env['result-ndim']

        res_shape, res_dt = datashape.to_numpy(func.type.restype)
        dim_size = operator.index(res_shape[0])
        row_size = ndt.type(str(func.type.restype.subarray(1))).data_size
        chunk_size = min(max(1, (1024*1024) // row_size), dim_size)
        # Evaluate by streaming the outermost dimension,
        # and using the BLZ data descriptor's append
        dst_dd = BLZDataDescriptor(blz.zeros((0,)+res_shape[1:], res_dt,
                                             rootdir=storage.path))
        # Loop through all the chunks
        for chunk_start in range(0, dim_size, chunk_size):
            # Tell the interpreter which chunk size to use (last
            # chunk might be smaller)
            chunk_size = min(chunk_size, dim_size - chunk_start)
            # Evaluate the chunk
            args_chunk = [arg[chunk_start:chunk_start+chunk_size]
                            if len(arg.dshape.shape) == result_ndim
                            else arg for arg in args]
            values = dict(zip(func.args, args_chunk))
            interp = CKernelChunkInterp(values, chunk_size, result_ndim)
            visit(interp, func)
            chunk = interp.result._data.dynd_arr()
            dst_dd.append(chunk)

        return blaze.Array(dst_dd)
コード例 #11
0
ファイル: verification.py プロジェクト: B-Rich/pykit
def verify_semantics(func, env=None):
    verifier = combine(Verifier(), env and env.get("verify.handlers"))
    visit(verifier, func)
コード例 #12
0
ファイル: inference.py プロジェクト: liuzhenhai/numba-lang
def generate_constraints(func, G):
    gen = ConstraintGenerator(func, G)
    ir.visit(gen, func, errmissing=True)
    return gen.constraints, gen.metadata
コード例 #13
0
def run(func, env):
    visit(CKernelLifter(env), func)
コード例 #14
0
ファイル: typecheck.py プロジェクト: pausz/flypy
def typecheck(func, env):
    context = env["flypy.typing.context"]
    visit(TypeChecker(context), func)

    check_scoping(func, env)
コード例 #15
0
ファイル: inference.py プロジェクト: pombreda/flypy
def generate_constraints(func, G):
    gen = ConstraintGenerator(func, G)
    ir.visit(gen, func, errmissing=True)
    return gen.constraints, gen.metadata
コード例 #16
0
ファイル: lower_calls.py プロジェクト: inaimathi/pykit
def run(func, env):
    """Generate runtime calls into thread library"""
    if env.get("verify"):
        visit(Verify(), func)
    visit(ExceptionChecking(func), func)
コード例 #17
0
ファイル: verification.py プロジェクト: inaimathi/pykit
def verify_semantics(func, env=None):
    verifier = combine(Verifier(), env and env.get("verify.handlers"))
    visit(verifier, func)
コード例 #18
0
ファイル: jit.py プロジェクト: zeeshanali/blaze
def jitter(func, jit_env):
    v = KernelJitter(func)
    visit(v, func)
    v = ConvertJitter(func, v.jitted)
    visit(v, func)
    jit_env['jitted'] = v.jitted
コード例 #19
0
ファイル: lower_calls.py プロジェクト: B-Rich/pykit
def run(func, env):
    """Generate runtime calls into thread library"""
    if env.get("verify"):
        visit(Verify(), func)
    visit(ExceptionChecking(func), func)
コード例 #20
0
ファイル: typecheck.py プロジェクト: liuzhenhai/numba-lang
def typecheck(func, env):
    context = env['numba.typing.context']
    visit(TypeChecker(context), func)
コード例 #21
0
ファイル: ckernel_lift.py プロジェクト: imclab/blaze
def run(func, env):
    visit(CKernelLifter(env), func)
コード例 #22
0
ファイル: lower_errcheck.py プロジェクト: inaimathi/pykit
def lower_costful(func, env=None):
    visit(LowerExceptionChecksCostful(func), func)
コード例 #23
0
ファイル: jit.py プロジェクト: zeeshanali/blaze
def treebuilder(func, jit_env):
    fuser = JitFuser(func, jit_env['jitted'])
    visit(fuser, func)
    jit_env['trees'] = fuser.trees
    jit_env['arguments'] = fuser.arguments
コード例 #24
0
ファイル: typecheck.py プロジェクト: pombreda/flypy
def typecheck(func, env):
    context = env['flypy.typing.context']
    visit(TypeChecker(context), func)

    check_scoping(func, env)
コード例 #25
0
ファイル: lower_errcheck.py プロジェクト: aterrel/pykit
def lower_costful(func, env=None):
    visit(LowerExceptionChecksCostful(func), func)
コード例 #26
0
ファイル: jit.py プロジェクト: pepmadon/blaze
def jitter(func, jit_env):
    v = Jitter(func)
    visit(v, func)
    jit_env['jitted'] = v.jitted