From 19792647310852ab18d00b25569517444f549078 Mon Sep 17 00:00:00 2001 From: john <58146965+ArbitRandomUser@users.noreply.github.com> Date: Mon, 9 Oct 2023 12:43:54 +0530 Subject: [PATCH] Contextfix (#143) * tweaked native_llvm_module for multiple functions to use the same context * added dispose * added kwarg before name while calling native_job * removed comments * wrapped multi function compilation in GPUCompiler.JuliaContext --- src/StaticCompiler.jl | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/StaticCompiler.jl b/src/StaticCompiler.jl index 820c630..cc9ecf6 100644 --- a/src/StaticCompiler.jl +++ b/src/StaticCompiler.jl @@ -595,13 +595,26 @@ end #Return an LLVM module for multiple functions function native_llvm_module(funcs::Union{Array,Tuple}; demangle=true, kwargs...) f,tt = funcs[1] - mod = native_llvm_module(f,tt; demangle, kwargs...) - if length(funcs) > 1 - for func in funcs[2:end] - f,tt = func - tmod = native_llvm_module(f,tt; demangle, kwargs...) - link!(mod,tmod) - end + mod = GPUCompiler.JuliaContext() do context + name_f = fix_name(f) + if !demangle + name_f = "julia_"*name_f + end + job, kwargs = native_job(f, tt, true; name = name_f, kwargs...) + mod,_ = GPUCompiler.codegen(:llvm, job; strip=true, only_entry=false, validate=false) + if length(funcs) > 1 + for func in funcs[2:end] + f,tt = func + name_f = fix_name(f) + if !demangle + name_f = "julia_"*name_f + end + job, kwargs = native_job(f, tt, true; name = name_f, kwargs...) + tmod,_ = GPUCompiler.codegen(:llvm, job; strip=true, only_entry=false, validate=false) + link!(mod,tmod) + end + end + mod end # Just to be sure for (modfunc, func) in zip(functions(mod), funcs)