11# common functionality
22
3- struct CompilerContext
3+ struct CompilerJob
44 # core invocation
5- f:: Core.Function
5+ f:: Base.Callable
66 tt:: DataType
77 agent:: HSAAgent
88 kernel:: Bool
@@ -12,63 +12,61 @@ struct CompilerContext
1212 maxthreads:: Union{Nothing,ROCDim}
1313 blocks_per_sm:: Union{Nothing,Integer}
1414 maxregs:: Union{Nothing,Integer}
15+ name:: Union{Nothing,String}
1516
16- CompilerContext (f, tt, agent, kernel;
17- minthreads= nothing , maxthreads= nothing ,
18- blocks_per_sm= nothing , maxregs= nothing ) =
19- new (f, tt, agent, kernel, minthreads, maxthreads, blocks_per_sm, maxregs)
17+ CompilerJob (f, tt, agent, kernel; name= nothing ,
18+ minthreads= nothing , maxthreads= nothing ,
19+ blocks_per_sm= nothing , maxregs= nothing ) =
20+ new (f, tt, agent, kernel, minthreads, maxthreads, blocks_per_sm,
21+ maxregs, name)
2022end
2123
2224# global context reference
23- # FIXME : thread through `ctx ` everywhere (deadlocks the Julia compiler when doing so with
25+ # FIXME : thread through `job ` everywhere (deadlocks the Julia compiler when doing so with
2426# the LLVM passes in AMDGPUnative)
25- global_ctx = nothing
27+ current_job = nothing
2628
27-
28- function signature (ctx:: CompilerContext )
29- fn = typeof (ctx. f). name. mt. name
30- args = join (ctx. tt. parameters, " , " )
31- return " $fn ($(join (ctx. tt. parameters, " , " )) )"
29+ function signature (job:: CompilerJob )
30+ fn = something (job. name, nameof (job. f))
31+ args = join (job. tt. parameters, " , " )
32+ return " $fn ($(join (job. tt. parameters, " , " )) )"
3233end
3334
34-
3535struct KernelError <: Exception
36- ctx :: CompilerContext
36+ job :: CompilerJob
3737 message:: String
3838 help:: Union{Nothing,String}
3939 bt:: StackTraces.StackTrace
4040
41- KernelError (ctx :: CompilerContext , message:: String , help= nothing ;
41+ KernelError (job :: CompilerJob , message:: String , help= nothing ;
4242 bt= StackTraces. StackTrace ()) =
43- new (ctx , message, help, bt)
43+ new (job , message, help, bt)
4444end
4545
4646function Base. showerror (io:: IO , err:: KernelError )
47- println (io, " GPU compilation of $(signature (err. ctx )) failed" )
47+ println (io, " GPU compilation of $(signature (err. job )) failed" )
4848 println (io, " KernelError: $(err. message) " )
4949 println (io)
5050 println (io, something (err. help, " Try inspecting the generated code with any of the @device_code_... macros." ))
5151 Base. show_backtrace (io, err. bt)
5252end
5353
54-
5554struct InternalCompilerError <: Exception
56- ctx :: CompilerContext
55+ job :: CompilerJob
5756 message:: String
5857 meta:: Dict
59- InternalCompilerError (ctx , message; kwargs... ) = new (ctx , message, kwargs)
58+ InternalCompilerError (job , message; kwargs... ) = new (job , message, kwargs)
6059end
6160
6261function Base. showerror (io:: IO , err:: InternalCompilerError )
6362 println (io, """ AMDGPUnative.jl encountered an unexpected internal compiler error.
6463 Please file an issue attaching the following information, including the backtrace,
6564 as well as a reproducible example (if possible).""" )
66-
6765 println (io, " \n InternalCompilerError: $(err. message) " )
6866
6967 println (io, " \n Compiler invocation:" )
70- for field in fieldnames (CompilerContext )
71- println (io, " - $field = $(repr (getfield (err. ctx , field))) " )
68+ for field in fieldnames (CompilerJob )
69+ println (io, " - $field = $(repr (getfield (err. job , field))) " )
7270 end
7371
7472 if ! isempty (err. meta)
@@ -78,23 +76,25 @@ function Base.showerror(io::IO, err::InternalCompilerError)
7876 end
7977 end
8078
81- println (io, " \n Installed packages:" )
82- for (pkg,ver) in Pkg. installed ()
83- println (io, " - $pkg = $ver " )
79+ let Pkg = Base. require (Base. PkgId (Base. UUID ((0x44cfe95a1eb252ea , 0xb672e2afdf69b78f )), " Pkg" ))
80+ println (io, " \n Installed packages:" )
81+ for (pkg,ver) in Pkg. installed ()
82+ println (io, " - $pkg = $(repr (ver)) " )
83+ end
8484 end
8585
8686 println (io)
8787 versioninfo (io)
8888end
8989
90- macro compiler_assert (ex, ctx , kwargs... )
90+ macro compiler_assert (ex, job , kwargs... )
9191 msg = " $ex , at $(__source__. file) :$(__source__. line) "
9292 return :($ (esc (ex)) ? $ (nothing )
93- : throw (InternalCompilerError ($ (esc (ctx )), $ msg;
93+ : throw (InternalCompilerError ($ (esc (job )), $ msg;
9494 $ (map (esc, kwargs)... )))
9595 )
9696end
9797
98-
9998# maintain our own "global unique" suffix for disambiguating kernels
10099globalUnique = 0
100+
0 commit comments