Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve error messages by including symbol index in trampolines
We smuggle symbol indices in a scratch register through our trampolines, allowing our default error printing function to rescue out the appropriate symbol index, and turn that into a symbol name. While this is fancy, reduces code size, and makes me feel clever, it's also not very reproducible for other projects that wish to replicate this technique without requiring that the scratch register be preserved long enough for their handling code to get at it. In such a case, the fallback implementation would be to generate function stubs for every symbol individually. A Julia implementation of this follows: First, a module is defined with error stubs for every symbol: ```julia module LBTDebuggingFuncs import LinearAlgebra.BLAS: lbt_get_config for func_name in lbt_get_config().exported_symbols @eval $(Symbol(func_name))() = println("Error: no BLAS/LAPACK library loaded for ", $(func_name), "()!") end end # module LBTDebuggingFuncs ``` Next, these functions are inserted as the base layer of forwards for LBT: ```julia symbol_list = lbt_get_config().exported_symbols for (symbol_idx, symbol) in enumerate(symbol_list) func = getproperty(LBTDebuggingFuncs, Symbol(symbol)) debug_fptr = @cfunction($func, Cvoid, ()) lbt_set_forward_by_index(symbol_idx-1, debug_fptr, :ilp64) lbt_set_forward_by_index(symbol_idx-1, debug_fptr, :lp64) end ``` After that, subsequent `lbt_forward()` calls (without `clear` set, of course) will fill in forwards to the actual backing BLAS calls, but those left behind will have customized error messages, denoting which BLAS call was unsupported.
- Loading branch information