diff --git a/include/npcomp/JITRuntime/JITModule.h b/include/npcomp/JITRuntime/JITModule.h index 2b35fe6c2..f6cbc371c 100644 --- a/include/npcomp/JITRuntime/JITModule.h +++ b/include/npcomp/JITRuntime/JITModule.h @@ -39,13 +39,6 @@ public: fromCompiledModule(mlir::ModuleOp module, llvm::ArrayRef sharedLibs); - /// All in one factory function for compiling from an input module. - /// This method will construct a PassManager, perform backend compilation - /// and construct a JITModule all in one. - // static llvm::Expected> - // fromMLIR(mlir::ModuleOp module, llvm::ArrayRef - // sharedLibs); - llvm::Expected, 6>> invoke(llvm::StringRef functionName, llvm::ArrayRef> inputs); diff --git a/pytest/Backend/RefJIT/simple_invoke.py b/pytest/Backend/RefJIT/simple_invoke.py index 49139c5a3..a41704470 100644 --- a/pytest/Backend/RefJIT/simple_invoke.py +++ b/pytest/Backend/RefJIT/simple_invoke.py @@ -19,8 +19,8 @@ def compile_function(f): target_factory=GenericTarget32)) fe.import_global_function(f) compiler = refjit.CompilerBackend() - vm_blob = compiler.compile(fe.ir_module) - loaded_m = compiler.load(vm_blob) + blob = compiler.compile(fe.ir_module) + loaded_m = compiler.load(blob) return loaded_m[f.__name__] diff --git a/python/samples/compiled_add.py b/python/samples/compiled_add.py index 1b19a92f2..37ed54042 100644 --- a/python/samples/compiled_add.py +++ b/python/samples/compiled_add.py @@ -1,10 +1,20 @@ -# Run full pipeline with: -# -npcomp-cpa-type-inference -numpy-public-functions-to-tensor -convert-numpy-to-tcf -canonicalize - import numpy as np -from npcomp.compiler import test_config -import_global = test_config.create_import_dump_decorator() +from npcomp.compiler import test_config +from npcomp.compiler.backend import refjit +from npcomp.compiler.frontend import * +from npcomp.compiler.target import * + + +def compile_function(f): + fe = ImportFrontend(config=test_config.create_test_config( + target_factory=GenericTarget32)) + fe.import_global_function(f) + compiler = refjit.CompilerBackend() + vm_blob = compiler.compile(fe.ir_module) + loaded_m = compiler.load(vm_blob) + return loaded_m[f.__name__] + global_data = (np.zeros((2, 3)) + [1.0, 2.0, 3.0] * np.reshape([1.0, 2.0], (2, 1))) @@ -13,6 +23,13 @@ a = np.asarray([1.0, 2.0], dtype=np.float32) b = np.asarray([3.0, 4.0], dtype=np.float32) -@import_global +@compile_function def global_add(): return np.add(a, np.add(b, a)) + + +assert global_add.__isnpcomp__ + +# CHECK: GLOBAL_ADD: [5. 8.] +result = global_add() +print("GLOBAL_ADD:", result)