Exemplo n.º 1
0
def native_lowering_stage(targetctx, library, interp, typemap, restype,
                          calltypes, flags):
    # Lowering
    fndesc = funcdesc.PythonFunctionDescriptor.from_specialized_function(
        interp, typemap, restype, calltypes, mangler=targetctx.mangler,
        inline=flags.forceinline, noalias=flags.noalias)

    lower = lowering.Lower(targetctx, library, fndesc, interp)
    lower.lower()
    if not flags.no_cpython_wrapper:
        lower.create_cpython_wrapper(flags.release_gil)
    env = lower.env
    call_helper = lower.call_helper
    has_dynamic_globals = lower.has_dynamic_globals
    del lower

    if flags.no_compile:
        return _LowerResult(fndesc, call_helper, cfunc=None, env=env,
                            has_dynamic_globals=has_dynamic_globals)
    else:
        # Prepare for execution
        cfunc = targetctx.get_executable(library, fndesc, env)
        # Insert native function for use by other jitted-functions.
        # We also register its library to allow for inlining.
        targetctx.insert_user_function(cfunc, fndesc, [library])
        return _LowerResult(fndesc, call_helper, cfunc=cfunc, env=env,
                            has_dynamic_globals=has_dynamic_globals)
Exemplo n.º 2
0
def native_lowering_stage(targetctx, library, interp, typemap, restype,
                          calltypes, flags):
    # Lowering
    fndesc = lowering.PythonFunctionDescriptor.from_specialized_function(
        interp,
        typemap,
        restype,
        calltypes,
        mangler=targetctx.mangler,
        inline=flags.forceinline)

    lower = lowering.Lower(targetctx, library, fndesc, interp)
    lower.lower(create_wrapper=not flags.no_cpython_wrapper)
    env = lower.env
    exception_map = lower.exceptions
    del lower

    if flags.no_compile:
        return fndesc, exception_map, None
    else:
        # Prepare for execution
        cfunc = targetctx.get_executable(library, fndesc, env)
        # Insert native function for use by other jitted-functions.
        # We also register its library to allow for inlining.
        targetctx.insert_user_function(cfunc, fndesc, [library])
        return fndesc, exception_map, cfunc
Exemplo n.º 3
0
def native_lowering_stage(targetctx, interp, typemap, restype, calltypes,
                          nocompile):
    # Lowering
    fndesc = lowering.describe_function(interp, typemap, restype, calltypes)

    lower = lowering.Lower(targetctx, fndesc)
    lower.lower()

    if nocompile:
        return None, 0, lower.module, lower.function
    else:
        # Prepare for execution
        cfunc, fnptr = targetctx.get_executable(lower.function, fndesc)

        targetctx.insert_user_function(cfunc, fndesc)

        return cfunc, fnptr, lower.module, lower.function
Exemplo n.º 4
0
def native_lowering_stage(targetctx, interp, typemap, restype, calltypes,
                          nocompile):
    # Lowering
    fndesc = lowering.PythonFunctionDescriptor.from_specialized_function(
        interp, typemap, restype, calltypes, mangler=targetctx.mangler)

    lower = lowering.Lower(targetctx, fndesc)
    lower.lower()

    if nocompile:
        return None, 0, lower.module, lower.function, fndesc
    else:
        # Prepare for execution
        cfunc, fnptr = targetctx.get_executable(lower.function, fndesc)

        targetctx.insert_user_function(cfunc, fndesc)

        return cfunc, fnptr, lower.module, lower.function, fndesc
Exemplo n.º 5
0
def native_lowering_stage(targetctx, interp, typemap, restype, calltypes,
                          nocompile):
    # Lowering
    fndesc = lowering.PythonFunctionDescriptor.from_specialized_function(
        interp, typemap, restype, calltypes, mangler=targetctx.mangler)

    lower = lowering.Lower(targetctx, fndesc, interp)
    lower.lower()

    # Linking depending libraries
    targetctx.link_dependencies(lower.module, targetctx.linking)

    if nocompile:
        return None, lower.module, lower.function, fndesc
    else:
        # Prepare for execution
        cfunc = targetctx.get_executable(lower.function, fndesc, lower.env)
        targetctx.insert_user_function(cfunc, fndesc)
        return cfunc, lower.module, lower.function, fndesc
def native_lowering_stage(targetctx, library, interp, typemap, restype,
                          calltypes, flags, metadata):

    global LLVM_FILES
    global FIRST_DEC_RUN
    global func_cache
    
    # Lowering
    fndesc = funcdesc.PythonFunctionDescriptor.from_specialized_function(
        interp, typemap, restype, calltypes, mangler=targetctx.mangler,
        inline=flags.forceinline, noalias=flags.noalias)


    with targetctx.push_code_library(library):
        lower = lowering.Lower(targetctx, library, fndesc, interp,
                               metadata=metadata)
        lower.lower()

        if not flags.no_cpython_wrapper:
            lower.create_cpython_wrapper(flags.release_gil)
        env = lower.env
        call_helper = lower.call_helper
        del lower

    if flags.no_compile:
        return _LowerResult(fndesc, call_helper, cfunc=None, env=env)
    else:
        # Prepare for execution


        functions = [x.name for x in library.get_defined_functions()]
        is_kernel_compute = "_kernel_compute" in functions[0]
        is_kernel_supply = "_kernel_supply" in functions[0]
        is_tile_launcher = "tile_launcher" in functions[0]
        call_decpp = None
        if (DEC_Options.is_base_mode()):
            call_decpp = is_kernel_compute or is_tile_launcher
        if (DEC_Options.is_decoupled_mode()):
            call_decpp = is_kernel_compute or is_kernel_supply or is_tile_launcher

        assert(call_decpp is not None)


        if not call_decpp:
            pipe_line_print("")
            pipe_line_print("-----")
            pipe_line_print("DEC++ Pipeline compilation output")
            pipe_line_print("")

            pipe_line_print(functions)

            for l in library._linking_libraries:
                LINKING_LIBS_CACHES.append(l)


            LIBS_TO_SRC[library] = library.get_llvm_str()
            pipe_line_print("-----")
            pipe_line_print("")


        

        if call_decpp:
            #create_fresh_dir(DECADES_OUTDIR)
            if FIRST_DEC_RUN:
                ll.load_library_permanently(os.path.join(DEC_options["pythia_home"],"tools", "tracer.so"))
                ll.load_library_permanently(DEC_options["openmp_lib"])
                ll.load_library_permanently(os.path.join(BUILD_ROOT, "./utils/DecoupleServer/libproduce_consume-shared.so"))
                #pdb.set_trace()
                ll.load_library_permanently(os.path.join(BUILD_ROOT, "./utils/DECLib/libDECADES-numba.so"))

            pipe_line_print("")
            pipe_line_print("-----")
            pipe_line_print("DEC++ Pipeline compilation output")
            pipe_line_print("")

            functions = [x for x in library.get_defined_functions()]
            pipe_line_print("identified kernel:")
            pipe_line_print(functions[0].name)
            pipe_line_print("")


            def rec_mk_llvm_from_libs(lib):
                global LLVM_FILES
                if lib in func_cache:
                    return
                else:
                    if lib in LIBS_TO_SRC:
                        to_print = LIBS_TO_SRC[lib]
                    else:
                        to_print = lib.get_llvm_str()
                    llvm_output_file = str(LLVM_FILES) + "_" + DEC_options["llvm_outfile"]
                    fh = open(os.path.join(DECADES_OUTDIR,llvm_output_file), 'w')
                    fh.write(to_print)
                    fh.close()
                    LLVM_FILES += 1
                    func_cache.append(lib)
                    for l in lib._linking_libraries:
                        rec_mk_llvm_from_libs(l)
                
            rec_mk_llvm_from_libs(library)
            for kernel in TO_COMPILE:
                rec_mk_llvm_from_libs(kernel)
            TO_COMPILE.append(library)

            for l in library._linking_libraries:
                LINKING_LIBS_CACHES.append(l)



            cmd = DEC_Options.get_decpp_line()
            #cmd = "DEC++ -fn 1 --target simulator -spp ~/pythia_git/pythia/pass/preproc.sh " + DECADES_OUTDIR
            print("\nexecuting DEC++:")
            print(cmd + "\n")
            ret = os.system(cmd)
            if ret != 0:
                print("")
                print("Error executing DEC++")
                exit(0)

            assert(os.path.exists(os.path.join(DECADES_BASE, DECpp_output)))
            cmd = "sed -e s/immarg//g -i " + os.path.join(DECADES_BASE, DECpp_output)
            pipe_line_print(cmd)
            os.system(cmd)

            fh = open(os.path.join(DECADES_BASE, DECpp_output))
            llvm_src = fh.read()
            fh.close()

            reg_labels = re.findall(r"^\d+:\s*; preds =.*$", llvm_src, re.MULTILINE)
            for rl in reg_labels:
                new_line = "; <label>:" + rl
                llvm_src = llvm_src.replace(rl, new_line)

            
            codegen = library.codegen
            library2 = codegen.create_library('DEC++')
            #from pathlib import Path
            #contents = Path(os.path.join(DECADES_BASE, DECpp_output)).read_text()
            new_module = ll.parse_assembly(llvm_src)
            library2.add_llvm_module(new_module)
            library = library2
            #pdb.set_trace()
            #library._linking_libraries = linking_libs_cache
            LLVM_FILES += 1
            FIRST_DEC_RUN = False

        
        cfunc = targetctx.get_executable(library, fndesc, env)
        
        # Insert native function for use by other jitted-functions.
        # We also register its library to allow for inlining.
        targetctx.insert_user_function(cfunc, fndesc, [library])
        return _LowerResult(fndesc, call_helper, cfunc=cfunc, env=env)