diff --git a/src/pocl/device/quirks.jl b/src/pocl/device/quirks.jl index 9ed006e19..035bcffb0 100644 --- a/src/pocl/device/quirks.jl +++ b/src/pocl/device/quirks.jl @@ -1,39 +1,40 @@ -macro print_and_throw(args...) +# throw a device-side exception of type `name`, printing the type and `reason` +macro gputhrow(name::String, reason::String) return quote - @println "ERROR: " $(args...) "." + @println "ERROR: " $name ": " $reason "." throw(nothing) end end # math.jl @device_override @noinline Base.Math.throw_complex_domainerror(f::Symbol, x) = - @print_and_throw "This operation requires a complex input to return a complex result" + @gputhrow "DomainError" "This operation requires a complex input to return a complex result" @device_override @noinline Base.Math.throw_exp_domainerror(x) = - @print_and_throw "Exponentiation yielding a complex result requires a complex argument" + @gputhrow "DomainError" "Exponentiation yielding a complex result requires a complex argument" # intfuncs.jl @device_override @noinline Base.throw_domerr_powbysq(::Any, p) = - @print_and_throw "Cannot raise an integer to a negative power" + @gputhrow "DomainError" "Cannot raise an integer to a negative power" @device_override @noinline Base.throw_domerr_powbysq(::Integer, p) = - @print_and_throw "Cannot raise an integer to a negative power" + @gputhrow "DomainError" "Cannot raise an integer to a negative power" @device_override @noinline Base.throw_domerr_powbysq(::AbstractMatrix, p) = - @print_and_throw "Cannot raise an integer to a negative power" + @gputhrow "DomainError" "Cannot raise an integer to a negative power" # checked.jl @device_override @noinline Base.Checked.throw_overflowerr_binaryop(op, x, y) = - @print_and_throw "Binary operation overflowed" + @gputhrow "OverflowError" "Binary operation overflowed" # boot.jl @device_override @noinline Core.throw_inexacterror(f::Symbol, ::Type{T}, val) where {T} = - @print_and_throw "Inexact conversion" + @gputhrow "InexactError" "Inexact conversion" # abstractarray.jl @device_override @noinline Base.throw_boundserror(A, I) = - @print_and_throw "Out-of-bounds array access" + @gputhrow "BoundsError" "Out-of-bounds array access" # trig.jl @device_override @noinline Base.Math.sincos_domain_error(x) = - @print_and_throw "sincos(x) is only defined for finite x." + @gputhrow "DomainError" "sincos(x) is only defined for finite x" # diagonal.jl # XXX: remove when we have malloc @@ -43,7 +44,7 @@ end # if i == j # @inbounds D.diag[i] = v # elseif !iszero(v) -# @print_and_throw "cannot set off-diagonal entry to a nonzero value" +# @gputhrow "ArgumentError" "cannot set off-diagonal entry to a nonzero value" # end # return v # end @@ -52,6 +53,6 @@ end # XXX: remove when we have malloc @device_override @inline function Base.getindex(x::Number, I::Integer...) @boundscheck all(isone, I) || - @print_and_throw "Out-of-bounds access of scalar value" + @gputhrow "BoundsError" "Out-of-bounds access of scalar value" x end