add llvm 11.0, llvmlite and numba
Test script:
from ctypes import CFUNCTYPE, c_double
import llvmlite.binding as llvm
# All these initializations are required for code generation!
llvm.initialize()
llvm.initialize_all_targets()
llvm.initialize_all_asmprinters() # yes, even this one
llvm_ir = """
; ModuleID = "examples/ir_fpadd.py"
target triple = "wasm32"
target datalayout = ""
define double @"fpadd"(double %".1", double %".2")
{
entry:
%"res" = fadd double %".1", %".2"
ret double %"res"
}
"""
def create_execution_engine():
"""
Create an ExecutionEngine suitable for JIT code generation on
the host CPU. The engine is reusable for an arbitrary number of
modules.
"""
# Create a target machine representing the host
target = llvm.Target.from_triple("wasm32")
target_machine = target.create_target_machine()
# And an execution engine with an empty backing module
backing_mod = llvm.parse_assembly("")
engine = llvm.create_mcjit_compiler(backing_mod, target_machine)
return engine
def compile_ir(engine, llvm_ir):
"""
Compile the LLVM IR string with the given engine.
The compiled module object is returned.
"""
# Create a LLVM module object from the IR
mod = llvm.parse_assembly(llvm_ir)
mod.verify()
# Now add the module and make sure it is ready for execution
# engine.add_module(mod)
# engine.finalize_object()
# engine.run_static_constructors()
return mod
engine = create_execution_engine()
mod = compile_ir(engine, llvm_ir)
# Look up the function pointer (a Python int)
# func_ptr = engine.get_function_address("fpadd")
# # Run the function via ctypes
# cfunc = CFUNCTYPE(c_double, c_double, c_double)(func_ptr)
# res = cfunc(1.0, 3.5)
# print("fpadd(...) =", res)
target = llvm.Target.from_triple("wasm32")
target_machine = target.create_target_machine()
asm = str(target_machine.emit_assembly(mod))
print(asm)
Test script:
from ctypes import CFUNCTYPE, c_double import llvmlite.binding as llvm # All these initializations are required for code generation! llvm.initialize() llvm.initialize_all_targets() llvm.initialize_all_asmprinters() # yes, even this one llvm_ir = """ ; ModuleID = "examples/ir_fpadd.py" target triple = "wasm32" target datalayout = "" define double @"fpadd"(double %".1", double %".2") { entry: %"res" = fadd double %".1", %".2" ret double %"res" } """ def create_execution_engine(): """ Create an ExecutionEngine suitable for JIT code generation on the host CPU. The engine is reusable for an arbitrary number of modules. """ # Create a target machine representing the host target = llvm.Target.from_triple("wasm32") target_machine = target.create_target_machine() # And an execution engine with an empty backing module backing_mod = llvm.parse_assembly("") engine = llvm.create_mcjit_compiler(backing_mod, target_machine) return engine def compile_ir(engine, llvm_ir): """ Compile the LLVM IR string with the given engine. The compiled module object is returned. """ # Create a LLVM module object from the IR mod = llvm.parse_assembly(llvm_ir) mod.verify() # Now add the module and make sure it is ready for execution # engine.add_module(mod) # engine.finalize_object() # engine.run_static_constructors() return mod engine = create_execution_engine() mod = compile_ir(engine, llvm_ir) # Look up the function pointer (a Python int) # func_ptr = engine.get_function_address("fpadd") # # Run the function via ctypes # cfunc = CFUNCTYPE(c_double, c_double, c_double)(func_ptr) # res = cfunc(1.0, 3.5) # print("fpadd(...) =", res) target = llvm.Target.from_triple("wasm32") target_machine = target.create_target_machine() asm = str(target_machine.emit_assembly(mod)) print(asm)
@wolfv can we make this an actual pytest test?
@wolfv good pkg to check if the numba stuff works: https://pypi.org/project/umap-learn/ =)
of course, but I just wanted to keep it there to not loose this valuable content :)
Datashader is also a great test case for these packages when they are available. We are eagerly awaiting trying out Datashader standalone in the browser!
Is this blocked by anything? Would be awesome to get numba support into pyodide.
@DerThorsten , can you provide some context here? Is this being closed for lack of progress, or for some other reason?
@DerThorsten , can you provide some context here? Is this being closed for lack of progress, or for some other reason?
Lack of progress, but I'll reopen it in the hope someone wants to continue
this needs to be converted to the new rattler-recipe format