Skip to content

Commit ba186da

Browse files
committed
add quirks
1 parent e6545f3 commit ba186da

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

src/pocl/device/quirks.jl

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
macro print_and_throw(args...)
2+
quote
3+
@println "ERROR: " $(args...) "."
4+
throw(nothing)
5+
end
6+
end
7+
8+
# math.jl
9+
@device_override @noinline Base.Math.throw_complex_domainerror(f::Symbol, x) =
10+
@print_and_throw "This operation requires a complex input to return a complex result"
11+
@device_override @noinline Base.Math.throw_exp_domainerror(x) =
12+
@print_and_throw "Exponentiation yielding a complex result requires a complex argument"
13+
14+
# intfuncs.jl
15+
@device_override @noinline Base.throw_domerr_powbysq(::Any, p) =
16+
@print_and_throw "Cannot raise an integer to a negative power"
17+
@device_override @noinline Base.throw_domerr_powbysq(::Integer, p) =
18+
@print_and_throw "Cannot raise an integer to a negative power"
19+
@device_override @noinline Base.throw_domerr_powbysq(::AbstractMatrix, p) =
20+
@print_and_throw "Cannot raise an integer to a negative power"
21+
22+
# checked.jl
23+
@device_override @noinline Base.Checked.throw_overflowerr_binaryop(op, x, y) =
24+
@print_and_throw "Binary operation overflowed"
25+
@device_override @noinline Base.Checked.throw_overflowerr_negation(op, x, y) =
26+
@print_and_throw "Negation overflowed"
27+
28+
# boot.jl
29+
@device_override @noinline Core.throw_inexacterror(f::Symbol, ::Type{T}, val) where {T} =
30+
@print_and_throw "Inexact conversion"
31+
32+
# abstractarray.jl
33+
@device_override @noinline Base.throw_boundserror(A, I) =
34+
@print_and_throw "Out-of-bounds array access"
35+
36+
# trig.jl
37+
@device_override @noinline Base.Math.sincos_domain_error(x) =
38+
@print_and_throw "sincos(x) is only defined for finite x."
39+
40+
# diagonal.jl
41+
# XXX: remove when we have malloc
42+
import LinearAlgebra
43+
@device_override function Base.setindex!(D::LinearAlgebra.Diagonal, v, i::Int, j::Int)
44+
@boundscheck checkbounds(D, i, j)
45+
if i == j
46+
@inbounds D.diag[i] = v
47+
elseif !iszero(v)
48+
@print_and_throw "cannot set off-diagonal entry to a nonzero value"
49+
end
50+
return v
51+
end
52+
53+
# number.jl
54+
# XXX: remove when we have malloc
55+
@device_override @inline function Base.getindex(x::Number, I::Integer...)
56+
@boundscheck all(isone, I) ||
57+
@print_and_throw "Out-of-bounds access of scalar value"
58+
x
59+
end

src/pocl/device/runtime.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
signal_exception() = return
2+
3+
malloc(sz) = C_NULL
4+
5+
report_oom(sz) = return
6+
7+
report_exception(ex) = return
8+
9+
report_exception_name(ex) = return
10+
11+
report_exception_frame(idx, func, file, line) = return

src/pocl/pocl.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ include("compiler/reflection.jl")
5555
import Core: LLVMPtr
5656

5757
include("device/array.jl")
58+
include("device/quirks.jl")
59+
include("device/runtime.jl")
5860

5961
function Adapt.adapt_storage(to::KernelAdaptor, xs::Array{T,N}) where {T,N}
6062
CLDeviceArray{T,N,AS.Global}(size(xs), reinterpret(LLVMPtr{T,AS.Global}, pointer(xs)))

0 commit comments

Comments
 (0)