Skip to content

Commit

Permalink
Store more debug files when encountering compilation errors. (#482)
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt authored Nov 27, 2024
1 parent 240c4b0 commit 3ec440f
Showing 1 changed file with 37 additions and 23 deletions.
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

0 comments on commit 3ec440f

Please sign in to comment.