Skip to content

Commit

Permalink
Improve reactant error messages (EnzymeAD#418)
Browse files Browse the repository at this point in the history
* Improve reactant error messages

* More exported symbols

* Update XLA.jl

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
wsmoses and github-actions[bot] authored Dec 23, 2024
1 parent 2759c3c commit 4cc000c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ PythonCall = "0.9"
Random = "1.10"
Random123 = "1.7"
ReactantCore = "0.1.3"
Reactant_jll = "0.0.27"
Reactant_jll = "0.0.29"
Scratch = "1.2"
Statistics = "1.10"
YaoBlocks = "0.13"
Expand Down
1 change: 1 addition & 0 deletions deps/ReactantExtra/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ cc_library(
"-Wl,-exported_symbol,_RegisterCustomCallTarget",
"-Wl,-exported_symbol,_ConvertLLVMToMLIR",
"-Wl,-exported_symbol,_EnzymeGPUCustomCall",
"-Wl,-exported_symbol,_ReactantThrowError",
]}),
deps = [
"@enzyme//:EnzymeMLIR",
Expand Down
21 changes: 21 additions & 0 deletions src/XLA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ const default_device_idx = Ref{Int}(0)
using Reactant_jll
using Libdl
using Scratch, Downloads

struct ReactantInternalError <: Base.Exception
msg::String
end

function Base.showerror(io::IO, ece::ReactantInternalError)
return print(io, ece.msg, '\n')
end

function reactant_err(msg::Cstring)::Cvoid
throw(ReactantInternalError(Base.unsafe_string(msg)))
end

function __init__()
initLogs = Libdl.dlsym(Reactant_jll.libReactantExtra_handle, "InitializeLogs")
ccall(initLogs, Cvoid, ())
Expand Down Expand Up @@ -136,6 +149,14 @@ function __init__()
cglobal((:EnzymeGPUCustomCall, MLIR.API.mlir_c))::Ptr{Cvoid},
"CUDA"::Cstring,
)::Cvoid

# This wasn't properly exported on macos, we'll remove the try once macOS JLL
# has the fix.
try
errptr = cglobal((:ReactantThrowError, MLIR.API.mlir_c), Ptr{Ptr{Cvoid}})
unsafe_store!(errptr, @cfunction(reactant_err, Cvoid, (Cstring,)))
finally
end
return nothing
end

Expand Down

0 comments on commit 4cc000c

Please sign in to comment.