Skip to content
This repository was archived by the owner on Nov 18, 2020. It is now read-only.

Commit 8070d83

Browse files
authored
Merge pull request #18 from JuliaGPU/wsp/updates
Manual compiler rebase (was #17)
2 parents 2a59134 + a94781a commit 8070d83

28 files changed

+1007
-548
lines changed

.gitlab-ci.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,6 @@ test:source:llvm7:
5353
variables:
5454
CI_BUILD_ARGS: 'LLVM_VER=7.0.0 USE_BINARYBUILDER_LLVM=0'
5555

56-
test:source:llvm8:
57-
extends:
58-
- .julia:source
59-
- .test
60-
tags:
61-
- rocm
62-
variables:
63-
CI_BUILD_ARGS: 'LLVM_VER=8.0.0 USE_BINARYBUILDER_LLVM=0'
6456

6557
test:source:llvm9:
6658
extends:
@@ -70,4 +62,3 @@ test:source:llvm9:
7062
- rocm
7163
variables:
7264
CI_BUILD_ARGS: 'LLVM_VER=9.0.0rc6 USE_BINARYBUILDER_LLVM=0'
73-

Project.toml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
name = "AMDGPUnative"
22
uuid = "12f4821f-d7ee-5ba6-b76b-566925c5fcc5"
3-
version = "0.1.0"
4-
5-
[compat]
6-
julia = "1"
7-
HSARuntime = "0.2.5"
3+
version = "0.1.1"
84

95
[deps]
106
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
117
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
8+
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
129
HSARuntime = "2c364e2c-59fb-59c3-96f3-194112e690e0"
1310
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
1411
LLVM = "929cbde3-209d-540e-8aea-75f648917ca0"
1512
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
13+
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
14+
15+
[compat]
16+
Adapt = "0.4, 1.0"
17+
BinaryProvider = "0.5"
18+
DataStructures = "0.15, 0.16, 0.17"
19+
HSARuntime = "0.2.6"
20+
LLVM = "1.3"
21+
TimerOutputs = "0.5"
22+
julia = "1"
1623

1724
[extras]
1825
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Acknowledgment
2121
AMDGPUnative would not have been possible without the work by Tim Besard on [CUDAnative.jl](https://github.com/JuliaGPU/CUDAnative.jl)
2222
and [LLVM.jl](https://github.com/maleadt/LLVM.jl).
2323

24-
24+
In revision to: commit 53966d812d63c7cbea0de114ebee4033c7ddad0d of CUDAnative.jl
2525
License
2626
-------
2727

src/AMDGPUnative.jl

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,32 @@ using LLVM, LLVM.Interop
44
using InteractiveUtils
55
using HSARuntime
66
using Adapt
7+
using TimerOutputs
8+
using DataStructures
79
using Libdl
810

911
const configured = HSARuntime.configured
1012

11-
# where the ROCm-Device-Libs bitcode goes
13+
# ROCm-Device-Libs bitcode path
1214
include(joinpath(@__DIR__, "..", "deps", "deps.jl"))
1315
const device_libs_path = joinpath(@__DIR__, "..", "deps", "usr", "lib")
1416

15-
# needs to be loaded _before_ the compiler infrastructure, because of generated functions
17+
# Device sources must load _before_ the compiler infrastructure
18+
# because of generated functions.
1619
include(joinpath("device", "tools.jl"))
1720
include(joinpath("device", "pointer.jl"))
1821
include(joinpath("device", "array.jl"))
19-
include(joinpath("device", "gcn_intrinsics.jl"))
20-
include(joinpath("device", "runtime_intrinsics.jl"))
22+
include(joinpath("device", "gcn.jl"))
23+
include(joinpath("device", "runtime.jl"))
2124

2225
include("execution_utils.jl")
2326
include("compiler.jl")
2427
include("execution.jl")
25-
2628
include("reflection.jl")
2729

2830
function __init__()
2931
check_deps()
32+
__init_compiler__()
3033
end
3134

3235
end # module

src/compiler.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# JIT compilation of Julia code to GCN
22

3+
const to = Ref{TimerOutput}()
4+
5+
function timings!(new=TimerOutput())
6+
global to
7+
to[] = new
8+
return
9+
end
10+
311
include(joinpath("compiler", "common.jl"))
412
include(joinpath("compiler", "irgen.jl"))
513
include(joinpath("compiler", "optim.jl"))
@@ -10,6 +18,5 @@ include(joinpath("compiler", "debug.jl"))
1018
include(joinpath("compiler", "driver.jl"))
1119

1220
function __init_compiler__()
13-
# enable generation of FMA instructions to mimic behavior of nvcc
14-
#LLVM.clopts("--nvptx-fma-level=1")
21+
timings!()
1522
end

src/compiler/common.jl

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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)
2022
end
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, ", ")))"
3233
end
3334

34-
3535
struct 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)
4444
end
4545

4646
function 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)
5252
end
5353

54-
5554
struct 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)
6059
end
6160

6261
function 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, "\nInternalCompilerError: $(err.message)")
6866

6967
println(io, "\nCompiler 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, "\nInstalled 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, "\nInstalled 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)
8888
end
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
)
9696
end
9797

98-
9998
# maintain our own "global unique" suffix for disambiguating kernels
10099
globalUnique = 0
100+

src/compiler/debug.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# tools for dealing with compiler debug information
22

3-
# generate a pseudo-backtrace from LLVM IR instruction debug information
4-
#
5-
# this works by looking up the debug information of the instruction, and inspecting the call
6-
# sites of the containing function. if there's only one, repeat the process from that call.
7-
# finally, the debug information is converted to a Julia stack trace.
3+
# `backtrace()` generates a pseudo-backtrace from LLVM IR instruction debug
4+
# information. This works by looking up the debug information of the
5+
# instruction, and inspecting the call sites of the containing function.
6+
# If there's only one, repeat the process from that call. Finally, the debug
7+
# information is converted to a Julia stack trace.
88
function backtrace(inst::LLVM.Instruction, bt = StackTraces.StackFrame[])
99
name = Ref{Cstring}()
1010
filename = Ref{Cstring}()
@@ -13,7 +13,8 @@ function backtrace(inst::LLVM.Instruction, bt = StackTraces.StackFrame[])
1313

1414
# look up the debug information from the current instruction
1515
depth = 0
16-
while LLVM.API.LLVMGetSourceLocation(LLVM.ref(inst), depth, name, filename, line, col) == 1
16+
while LLVM.API.LLVMGetSourceLocation(LLVM.ref(inst), depth, name, filename,
17+
line, col) == 1
1718
frame = StackTraces.StackFrame(replace(unsafe_string(name[]), r";$"=>""),
1819
unsafe_string(filename[]), line[])
1920
push!(bt, frame)
@@ -46,3 +47,4 @@ function backtrace(inst::LLVM.Instruction, bt = StackTraces.StackFrame[])
4647

4748
return bt
4849
end
50+

0 commit comments

Comments
 (0)