Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial VE support #86

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/GPUCompiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ include("native.jl")
include("ptx.jl")
include("gcn.jl")
include("spirv.jl")
include("ve.jl")

include("runtime.jl")

Expand Down
31 changes: 31 additions & 0 deletions src/ve.jl
Original file line number Diff line number Diff line change
@@ -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)
50 changes: 50 additions & 0 deletions test/definitions/ve.jl
Original file line number Diff line number Diff line change
@@ -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