コード例 #1
0
ファイル: Compiler.py プロジェクト: mpc-msri/EzPC
    def run(self):
        with open(Util.Config.astFile, "rb") as ff:
            ast = pickle.load(ff)

        if not (Util.Config.disableAllOpti):
            if not (Util.Config.disableRMO):
                print("Performing Relu-maxpool optimization...")
                ReluMaxpoolOpti.ReluMaxpoolOpti().visit(ast)
                print("Relu-maxpool optimization done.")

            if not (Util.Config.disableLivenessOpti):
                print("Performing Garbage collection...")
                mtdAST = MtdAST()
                GC = GarbageCollector.GarbageCollector(ast)
                GC.run([mtdAST])
                print("Garbage collection done.")

        # Perform type inference and annotate nodes with type information
        InferType().visit(ast)

        # if Util.Config.printASTBool :
        if False:
            PrintAST().visit(ast)
            print("\n")
            sys.stdout.flush()

        IRUtil.init()
        compiler = IRBuilderCSF()
        res = compiler.visit(ast)
        res = self.fixOuputScale(res, compiler)
        res = self.fixNames(res, compiler)

        Util.write_debug_info(compiler.name_mapping)

        # Insert a generic start_computation and end_computation function call after all input IR statements.
        res = self.insertStartEndFunctionCalls(res)
        writer = Writer(Util.Config.outputFileName)
        debugVarEzPCName = (compiler.name_mapping[Util.Config.debugVar] if
                            (Util.Config.debugVar
                             in compiler.name_mapping) else None)

        if Util.forEzPC():
            codegen = EzPCCodegen(writer, compiler.globalDecls,
                                  debugVarEzPCName)
        else:
            assert False

        codegen.printAll(*res)
        writer.close()
コード例 #2
0
    def run(self):
        with open(Util.Config.astFile, 'rb') as ff:
            ast = pickle.load(ff)

        if not (Util.Config.disableAllOpti):
            if not (Util.Config.disableRMO):
                print("Performing Relu-maxpool optimization...")
                # Perform optimizations on the AST
                ReluMaxpoolOpti.ReluMaxpoolOpti().visit(ast)

            if not (Util.Config.disableLivenessOpti):
                print("Performing Liveness Optimization...")
                # Perform liveness analysis optimization on the AST
                mtdAST = MtdAST()
                LivenessOpti.LivenessAnalysis().visit(ast)
                LivenessOpti.LivenessOpti().visit(ast, [mtdAST, 0, {}])

        if Util.Config.printASTBool:
            PrintAST().visit(ast)
            sys.stdout.flush()

# Perform type inference
        InferType().visit(ast)

        IRUtil.init()
        compiler = IRBuilderCSF()
        res = compiler.visit(ast)

        Util.write_debug_info(compiler.name_mapping)

        # Insert a generic start_computation and end_computation function call after all input IR statements.
        res = self.insertStartEndFunctionCalls(res)

        writer = Writer(Util.Config.outputFileName)

        debugVarEzPCName = compiler.name_mapping[Util.Config.debugVar] if (
            Util.Config.debugVar in compiler.name_mapping) else None

        if Util.forEzPC():
            codegen = EzPCCodegen(writer, compiler.decls, debugVarEzPCName)
        else:
            assert False

        codegen.printAll(*res)
        writer.close()