diff --git a/src/GPUCompiler.jl b/src/GPUCompiler.jl index e945862c..26492f11 100644 --- a/src/GPUCompiler.jl +++ b/src/GPUCompiler.jl @@ -24,6 +24,7 @@ include("native.jl") include("ptx.jl") include("gcn.jl") include("spirv.jl") +include("ve.jl") include("runtime.jl") diff --git a/src/ve.jl b/src/ve.jl new file mode 100644 index 00000000..6ae73dbd --- /dev/null +++ b/src/ve.jl @@ -0,0 +1,31 @@ +# implementation of the GPUCompiler interfaces for generating Aurora-SX VE code + +## target + +export VECompilerTarget + +Base.@kwdef struct VECompilerTarget <: AbstractCompilerTarget +end + +llvm_triple(::VECompilerTarget) = "ve-unkown-unkown" + +function llvm_machine(target::VECompilerTarget) + triple = llvm_triple(target) + t = Target(triple=triple) + + cpu = "ve" + feat = "" + optlevel = LLVM.API.LLVMCodeGenLevelDefault + reloc = LLVM.API.LLVMRelocPIC + tm = TargetMachine(t, triple, cpu, feat, optlevel, reloc) + asm_verbosity!(tm, true) + + return tm +end + +# TODO: encode debug build or not in the compiler job +# https://github.com/JuliaGPU/CUDAnative.jl/issues/368 +runtime_slug(job::CompilerJob{VECompilerTarget}) = "ve" + +const ve_intrinsics = () # TODO: ("vprintf", "__assertfail", "malloc", "free") +isintrinsic(::CompilerJob{VECompilerTarget}, fn::String) = in(fn, gcn_intrinsics) diff --git a/test/definitions/ve.jl b/test/definitions/ve.jl new file mode 100644 index 00000000..6166c45d --- /dev/null +++ b/test/definitions/ve.jl @@ -0,0 +1,50 @@ +using GPUCompiler + +if !@isdefined(TestRuntime) + include("../util.jl") +end + + +# create a VE-based test compiler, and generate reflection methods for it + +function ve_job(@nospecialize(func), @nospecialize(types); kernel::Bool=false, kwargs...) + source = FunctionSpec(func, Base.to_tuple_type(types), kernel) + target = VECompilerTarget() + params = TestCompilerParams() + CompilerJob(target, source, params), kwargs +end + +function ve_code_typed(@nospecialize(func), @nospecialize(types); kwargs...) + job, kwargs = ve_job(func, types; kwargs...) + GPUCompiler.code_typed(job; kwargs...) +end + +function ve_code_warntype(io::IO, @nospecialize(func), @nospecialize(types); kwargs...) + job, kwargs = ve_job(func, types; kwargs...) + GPUCompiler.code_warntype(io, job; kwargs...) +end + +function ve_code_llvm(io::IO, @nospecialize(func), @nospecialize(types); kwargs...) + job, kwargs = ve_job(func, types; kwargs...) + GPUCompiler.code_llvm(io, job; kwargs...) +end + +function ve_code_native(io::IO, @nospecialize(func), @nospecialize(types); kwargs...) + job, kwargs = ve_job(func, types; kwargs...) + GPUCompiler.code_native(io, job; kwargs...) +end + +# aliases without ::IO argument +for method in (:code_warntype, :code_llvm, :code_native) + ve_method = Symbol("ve_$(method)") + @eval begin + $ve_method(@nospecialize(func), @nospecialize(types); kwargs...) = + $ve_method(stdout, func, types; kwargs...) + end +end + +# simulates codegen for a kernel function: validates by default +function ve_code_execution(@nospecialize(func), @nospecialize(types); kwargs...) + job, kwargs = ve_job(func, types; kernel=true, kwargs...) + GPUCompiler.compile(:asm, job; kwargs...) +end