Skip to content

Commit

Permalink
Remove code no longer relevant in Julia v1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
giordano committed Apr 5, 2024
1 parent db3d378 commit 7551807
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 59 deletions.
62 changes: 18 additions & 44 deletions src/compiler/runtime.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,58 +156,32 @@ end
@print_and_throw "asin(x) not defined for |x| > 1, x = " x

# range.jl
@static if VERSION >= v"1.7-"
@eval begin
@device_override function Base.StepRangeLen{T,R,S,L}(ref::R, step::S, len::Integer,
offset::Integer=1) where {T,R,S,L}
if T <: Integer && !isinteger(ref + step)
@print_and_throw("StepRangeLen{<:Integer} cannot have non-integer step")
end
len = convert(L, len)
len >= zero(len) || @print_and_throw("StepRangeLen length cannot be negative")
offset = convert(L, offset)
L1 = oneunit(typeof(len))
L1 <= offset <= max(L1, len) || @print_and_throw("StepRangeLen: offset must be in [1,...]")
$(
Expr(:new, :(StepRangeLen{T,R,S,L}), :ref, :step, :len, :offset)
)
end
end
else
@device_override function Base.StepRangeLen{T,R,S}(ref::R, step::S, len::Integer,
offset::Integer=1) where {T,R,S}
@eval begin
@device_override function Base.StepRangeLen{T,R,S,L}(ref::R, step::S, len::Integer,
offset::Integer=1) where {T,R,S,L}
if T <: Integer && !isinteger(ref + step)
@print_and_throw("StepRangeLen{<:Integer} cannot have non-integer step")
end
len >= 0 || @print_and_throw("StepRangeLen length cannot be negative")
1 <= offset <= max(1,len) || @print_and_throw("StepRangeLen: offset must be in [1,...]")
new(ref, step, len, offset)
len = convert(L, len)
len >= zero(len) || @print_and_throw("StepRangeLen length cannot be negative")
offset = convert(L, offset)
L1 = oneunit(typeof(len))
L1 <= offset <= max(L1, len) || @print_and_throw("StepRangeLen: offset must be in [1,...]")
$(
Expr(:new, :(StepRangeLen{T,R,S,L}), :ref, :step, :len, :offset)
)
end
end

# LinearAlgebra
@static if VERSION >= v"1.8-"
@device_override function Base.setindex!(D::LinearAlgebra.Diagonal, v, i::Int, j::Int)
@boundscheck checkbounds(D, i, j)
if i == j
@inbounds D.diag[i] = v
elseif !iszero(v)
@print_and_throw("cannot set off-diagonal entry to a nonzero value")
end
return v
@device_override function Base.setindex!(D::LinearAlgebra.Diagonal, v, i::Int, j::Int)
@boundscheck checkbounds(D, i, j)
if i == j
@inbounds D.diag[i] = v
elseif !iszero(v)
@print_and_throw("cannot set off-diagonal entry to a nonzero value")
end
end

# fastmath.jl
@static if VERSION <= v"1.7-"
## prevent fallbacks to libm
for f in (:acosh, :asinh, :atanh, :cbrt, :cosh, :exp2, :expm1, :log1p, :sinh, :tanh)
f_fast = Base.FastMath.fast_op[f]
@eval begin
@device_override Base.FastMath.$f_fast(x::Float32) = $f(x)
@device_override Base.FastMath.$f_fast(x::Float64) = $f(x)
end
end
return v
end

end # module IPURuntime
4 changes: 1 addition & 3 deletions src/compiler/vertices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ end
# In Julia v1.9 the default algorithm for sorting arrays requires a scratch area, but we
# can't use it on an IPU because it'd need to allocate an extra array, so let's default to
# the simple fully in-place `QuickSort`.
if VERSION v"1.9.0-"
Base.Sort.defalg(::VertexVector) = QuickSort
end
Base.Sort.defalg(::VertexVector) = QuickSort

# Simple methods, don't access the elements
Base.show(io::IO, x::VertexVector) = Base.show_default(io, x)
Expand Down
17 changes: 5 additions & 12 deletions test/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ function test_compiler_program(device)

add_vertex(graph, prog, TimesTwo, inconst, outvec1)
add_vertex(graph, prog, Sort, outvec1, outvec2)
if VERSION v"1.7"
# The `@device_override` business works well only on Julia v1.7+
add_vertex(graph, prog, Sin, outvec2, outvec3)
end
add_vertex(graph, prog, Sin, outvec2, outvec3)
add_vertex(graph, prog, Print, 3.14f0)
# Pass as codelet a function with more than one method
@test_throws ArgumentError add_vertex(graph, prog, +, outvec3)
Expand All @@ -92,10 +89,8 @@ function test_compiler_program(device)
Poplar.GraphCreateHostRead(graph, "timestwo-read", outvec1)
output_sort = similar(input)
Poplar.GraphCreateHostRead(graph, "sort-read", outvec2)
if VERSION v"1.7"
output_sin = similar(input)
Poplar.GraphCreateHostRead(graph, "sin-read", outvec3)
end
output_sin = similar(input)
Poplar.GraphCreateHostRead(graph, "sin-read", outvec3)

flags = @cxxtest Poplar.OptionFlags()
Poplar.OptionFlagsSet(flags, "debug.instrument", "true")
Expand Down Expand Up @@ -128,10 +123,8 @@ function test_compiler_program(device)
@test output_timestwo == 2 .* input
Poplar.EngineReadTensor(engine, "sort-read", output_sort)
@test output_sort == sort(output_timestwo)
if VERSION v"1.7"
Poplar.EngineReadTensor(engine, "sin-read", output_sin)
@test output_sin == sin.(output_sort)
end
Poplar.EngineReadTensor(engine, "sin-read", output_sin)
@test output_sin == sin.(output_sort)

Poplar.detach_devices()
end
Expand Down

0 comments on commit 7551807

Please sign in to comment.