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

Store more debug files when encountering compilation errors. #482

Merged
merged 1 commit into from
Nov 27, 2024
Merged
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
60 changes: 37 additions & 23 deletions src/compiler/compilation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,41 +133,46 @@ function compile(@nospecialize(job::CompilerJob))
wait(proc)
success(proc) || error(fetch(logger))
catch err
file = tempname(cleanup=false) * ".ll"
write(file, ir)
ir_file = tempname(cleanup=false) * ".ll"
write(ir_file, ir)
if parse(Bool, get(ENV, "BUILDKITE", "false"))
run(`buildkite-agent artifact upload $(file)`)
run(`buildkite-agent artifact upload $(ir_file)`)
end
error("""Compilation to AIR failed; see above for details.
If you think this is a bug, please file an issue and attach $(file)""")
If you think this is a bug, please file an issue and attach $(ir_file)""")
end

fetch(reader)
end
end

@signpost_interval log=log_compiler() "Create Metal library" begin
image = try
metallib_fun = MetalLibFunction(; name=entry, air_module=air,
air_version=job.config.target.air,
metal_version=job.config.target.metal)
metallib = MetalLib(; functions = [metallib_fun])

image_stream = IOBuffer()
write(image_stream, metallib)
take!(image_stream)
metallib = try
fun = MetalLibFunction(; name=entry, air_module=air,
air_version=job.config.target.air,
metal_version=job.config.target.metal)
lib = MetalLib(; functions = [fun])

io = IOBuffer()
write(io, lib)
take!(io)
catch err
file = tempname(cleanup=false) * ".air"
write(file, air)
ir_file = tempname(cleanup=false) * ".ll"
write(ir_file, ir)
air_file = tempname(cleanup=false) * ".air"
write(air_file, air)
if parse(Bool, get(ENV, "BUILDKITE", "false"))
run(`buildkite-agent artifact upload $(file)`)
run(`buildkite-agent artifact upload $(ir_file)`)
run(`buildkite-agent artifact upload $(air_file)`)
end
error("""Compilation to Metal library failed; see below for details.
If you think this is a bug, please file an issue and attach $(file)""")
If you think this is a bug, please file an issue and attach the following files:
- $(ir_file)
- $(air_file)""")
end
end

return (; image, entry)
return (; ir, air, metallib, entry)
end

# link into an executable kernel
Expand All @@ -177,7 +182,7 @@ end

@signpost_interval log=log_compiler() "Instantiate compute pipeline" begin
dev = device()
lib = MTLLibraryFromData(dev, compiled.image)
lib = MTLLibraryFromData(dev, compiled.metallib)
fun = MTLFunction(lib, compiled.entry)
pipeline_state = try
MTLComputePipelineState(dev, fun)
Expand All @@ -187,13 +192,22 @@ end

# the back-end compiler likely failed
# XXX: check more accurately? the error domain doesn't help much here
file = tempname(cleanup=false) * ".metallib"
write(file, compiled.image)
ir_file = tempname(cleanup=false) * ".ll"
write(ir_file, compiled.ir)
air_file = tempname(cleanup=false) * ".air"
write(air_file, compiled.air)
metallib_file = tempname(cleanup=false) * ".metallib"
write(metallib_file, compiled.metallib)
if parse(Bool, get(ENV, "BUILDKITE", "false"))
run(`buildkite-agent artifact upload $(file)`)
run(`buildkite-agent artifact upload $(ir_file)`)
run(`buildkite-agent artifact upload $(air_file)`)
run(`buildkite-agent artifact upload $(metallib_file)`)
end
error("""Compilation to native code failed; see below for details.
If you think this is a bug, please file an issue and attach $(file)""")
If you think this is a bug, please file an issue and attach the following files:
- $(ir_file)
- $(air_file)
- $(metallib_file)""")
end
end

Expand Down