From 276ff2b3b70669d3148f7ea1c2632307e7a869e4 Mon Sep 17 00:00:00 2001 From: Billy Moses Date: Sun, 22 Dec 2024 15:20:41 -0500 Subject: [PATCH 1/5] Improve reactant error messages --- Project.toml | 2 +- src/XLA.jl | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index f15d06e759..721d9bcff2 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/XLA.jl b/src/XLA.jl index 5dbbad038b..fc2e813d4a 100644 --- a/src/XLA.jl +++ b/src/XLA.jl @@ -91,6 +91,20 @@ 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) + 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, ()) @@ -136,6 +150,14 @@ function __init__() cglobal((:EnzymeGPUCustomCall, MLIR.API.mlir_c))::Ptr{Cvoid}, "CUDA"::Cstring, )::Cvoid + + errptr = cglobal((:ReactantThrowError, MLIR.API.mlir_c), Ptr{Ptr{Cvoid}}) + + unsafe_store!(errptr, @cfunction( + reactant_err, + Cvoid, + (Cstring,) + )) return nothing end From 1e6d2cb4ac0f366fdc33335f2a33a12e59cd71eb Mon Sep 17 00:00:00 2001 From: Billy Moses Date: Sun, 22 Dec 2024 15:30:56 -0500 Subject: [PATCH 2/5] More exported symbols --- deps/ReactantExtra/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/deps/ReactantExtra/BUILD b/deps/ReactantExtra/BUILD index 10da834e94..0a512067a9 100644 --- a/deps/ReactantExtra/BUILD +++ b/deps/ReactantExtra/BUILD @@ -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", From 417c35b4857ef5c76ec48b5ffc3a71c688279829 Mon Sep 17 00:00:00 2001 From: William Moses Date: Sun, 22 Dec 2024 19:32:15 -0500 Subject: [PATCH 3/5] Update XLA.jl --- src/XLA.jl | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/XLA.jl b/src/XLA.jl index fc2e813d4a..54f9fb970f 100644 --- a/src/XLA.jl +++ b/src/XLA.jl @@ -151,13 +151,18 @@ function __init__() "CUDA"::Cstring, )::Cvoid - errptr = cglobal((:ReactantThrowError, MLIR.API.mlir_c), Ptr{Ptr{Cvoid}}) - - unsafe_store!(errptr, @cfunction( - reactant_err, - Cvoid, - (Cstring,) - )) + # 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 From ae2edd32e5d29fc2ad3d03eedd5a28a35a98f99f Mon Sep 17 00:00:00 2001 From: William Moses Date: Sun, 22 Dec 2024 19:32:36 -0500 Subject: [PATCH 4/5] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/XLA.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/XLA.jl b/src/XLA.jl index 54f9fb970f..8cff01d6a4 100644 --- a/src/XLA.jl +++ b/src/XLA.jl @@ -92,13 +92,12 @@ using Reactant_jll using Libdl using Scratch, Downloads - struct ReactantInternalError <: Base.Exception msg::String end function Base.showerror(io::IO, ece::ReactantInternalError) - print(io, ece.msg, '\n') + return print(io, ece.msg, '\n') end function reactant_err(msg::Cstring)::Cvoid From 02ce45a43ba8155cbcccb9ef54832afe63967c80 Mon Sep 17 00:00:00 2001 From: William Moses Date: Sun, 22 Dec 2024 19:36:00 -0500 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/XLA.jl | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/XLA.jl b/src/XLA.jl index 8cff01d6a4..bdeb4aa8e5 100644 --- a/src/XLA.jl +++ b/src/XLA.jl @@ -154,14 +154,9 @@ function __init__() # has the fix. try errptr = cglobal((:ReactantThrowError, MLIR.API.mlir_c), Ptr{Ptr{Cvoid}}) - unsafe_store!(errptr, @cfunction( - reactant_err, - Cvoid, - (Cstring,) - )) + unsafe_store!(errptr, @cfunction(reactant_err, Cvoid, (Cstring,))) finally end - return nothing end