@@ -3,44 +3,62 @@ Base.@kwdef struct NativeCompilerTarget <: GPUCompiler.AbstractCompilerTarget
33 features:: String = (LLVM. version () < v " 8" ) ? " " : unsafe_string (LLVM. API. LLVMGetHostCPUFeatures ())
44end
55
6- GPUCompiler. llvm_triple (:: NativeCompilerTarget ) = Sys. MACHINE
6+ Base. @kwdef struct ExternalNativeCompilerTarget <: GPUCompiler.AbstractCompilerTarget
7+ cpu:: String = (LLVM. version () < v " 8" ) ? " " : unsafe_string (LLVM. API. LLVMGetHostCPUName ())
8+ features:: String = (LLVM. version () < v " 8" ) ? " " : unsafe_string (LLVM. API. LLVMGetHostCPUFeatures ())
9+ end
710
8- function GPUCompiler. llvm_machine (target:: NativeCompilerTarget )
9- triple = GPUCompiler. llvm_triple (target)
11+ module StaticRuntime
12+ # the runtime library
13+ signal_exception () = return
14+ malloc (sz) = ccall (" extern malloc" , llvmcall, Csize_t, (Csize_t,), sz)
15+ report_oom (sz) = return
16+ report_exception (ex) = return
17+ report_exception_name (ex) = return
18+ report_exception_frame (idx, func, file, line) = return
19+ end
1020
11- t = LLVM . Target (triple = triple)
21+ struct StaticCompilerParams <: GPUCompiler.AbstractCompilerParams end
1222
13- tm = LLVM. TargetMachine (t, triple, target. cpu, target. features, reloc= LLVM. API. LLVMRelocPIC)
14- GPUCompiler. asm_verbosity! (tm, true )
23+ for target in (:NativeCompilerTarget , :ExternalNativeCompilerTarget )
24+ @eval begin
25+ GPUCompiler. llvm_triple (:: $target ) = Sys. MACHINE
1526
16- return tm
17- end
27+ function GPUCompiler . llvm_machine (target :: $target )
28+ triple = GPUCompiler . llvm_triple (target)
1829
19- GPUCompiler . runtime_slug (job :: GPUCompiler.CompilerJob{NativeCompilerTarget} ) = " native_ $(job . target . cpu) - $( hash (job . target . features)) "
30+ t = LLVM . Target (triple = triple)
2031
21- module StaticRuntime
22- # the runtime library
23- signal_exception () = return
24- malloc (sz) = ccall (" extern malloc" , llvmcall, Csize_t, (Csize_t,), sz)
25- report_oom (sz) = return
26- report_exception (ex) = return
27- report_exception_name (ex) = return
28- report_exception_frame (idx, func, file, line) = return
29- end
32+ tm = LLVM. TargetMachine (t, triple, target. cpu, target. features, reloc= LLVM. API. LLVMRelocPIC)
33+ GPUCompiler. asm_verbosity! (tm, true )
3034
31- struct StaticCompilerParams <: GPUCompiler.AbstractCompilerParams end
35+ return tm
36+ end
3237
33- GPUCompiler. runtime_module (:: GPUCompiler.CompilerJob{<:Any,StaticCompilerParams} ) = StaticRuntime
34- GPUCompiler. runtime_module (:: GPUCompiler.CompilerJob{NativeCompilerTarget} ) = StaticRuntime
35- GPUCompiler. runtime_module (:: GPUCompiler.CompilerJob{NativeCompilerTarget, StaticCompilerParams} ) = StaticRuntime
38+ GPUCompiler. runtime_slug (job:: GPUCompiler.CompilerJob{$target} ) = " native_$(job. target. cpu) -$(hash (job. target. features)) "
39+
40+ GPUCompiler. runtime_module (:: GPUCompiler.CompilerJob{$target} ) = StaticRuntime
41+ GPUCompiler. runtime_module (:: GPUCompiler.CompilerJob{$target, StaticCompilerParams} ) = StaticRuntime
3642
43+
44+ GPUCompiler. can_throw (job:: GPUCompiler.CompilerJob{$target, StaticCompilerParams} ) = true
45+ GPUCompiler. can_throw (job:: GPUCompiler.CompilerJob{$target} ) = true
46+ end
47+ end
48+
49+ GPUCompiler. runtime_module (:: GPUCompiler.CompilerJob{<:Any,StaticCompilerParams} ) = StaticRuntime
3750GPUCompiler. can_throw (job:: GPUCompiler.CompilerJob{<:Any,StaticCompilerParams} ) = true
38- GPUCompiler. can_throw (job:: GPUCompiler.CompilerJob{NativeCompilerTarget, StaticCompilerParams} ) = true
39- GPUCompiler. can_throw (job:: GPUCompiler.CompilerJob{NativeCompilerTarget} ) = true
4051
41- function native_job (@nospecialize (func), @nospecialize (types); kernel:: Bool = false , name= GPUCompiler. safe_name (repr (func)), kwargs... )
52+ # GPUCompiler.method_table(@nospecialize(job::GPUCompiler.CompilerJob{<:Any,StaticCompilerParams})) = nothing
53+ # GPUCompiler.method_table(@nospecialize(job::GPUCompiler.CompilerJob{NativeCompilerTarget})) = nothing
54+ # GPUCompiler.method_table(@nospecialize(job::GPUCompiler.CompilerJob{NativeCompilerTarget, StaticCompilerParams})) = nothing
55+
56+ GPUCompiler. method_table (@nospecialize (job:: GPUCompiler.CompilerJob{ExternalNativeCompilerTarget} )) = method_table
57+ GPUCompiler. method_table (@nospecialize (job:: GPUCompiler.CompilerJob{ExternalNativeCompilerTarget, StaticCompilerParams} )) = method_table
58+
59+ function native_job (@nospecialize (func), @nospecialize (types); kernel:: Bool = false , name= GPUCompiler. safe_name (repr (func)), ext = true , kwargs... )
4260 source = GPUCompiler. FunctionSpec (func, Base. to_tuple_type (types), kernel, name)
43- target = NativeCompilerTarget ()
61+ target = ext ? ExternalNativeCompilerTarget () : NativeCompilerTarget ()
4462 params = StaticCompilerParams ()
4563 GPUCompiler. CompilerJob (target, source, params), kwargs
4664end
0 commit comments