diff --git a/Project.toml b/Project.toml index 8d3ca38..9e1e73e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "IPUToolkit" uuid = "92e0b95a-4011-435a-96f4-10064551ddbe" authors = ["Emily Dietrich ", "Luk Burchard ", "Mosè Giordano "] -version = "1.5.0" +version = "1.6.0" [deps] Clang = "40e3b903-d033-50b4-a0cc-940c62c95e31" @@ -20,7 +20,7 @@ libcxxwrap_julia_jll = "3eaa8342-bff7-56a5-9981-c04077f7cee7" [compat] Clang = "0.14, 0.17.4" CxxWrap = "0.14" -GPUCompiler = "0.21.4" +GPUCompiler = "0.23, 0.24, 0.25, 0.26" JSON = "0.21.4" LLVM = "6" LinearAlgebra = "1" @@ -29,5 +29,5 @@ ProgressMeter = "1.7" Scratch = "1.1" TOML = "1" UUIDs = "1" -julia = "1.6" +julia = "1.9" libcxxwrap_julia_jll = "0.11" diff --git a/src/compiler/compiler.jl b/src/compiler/compiler.jl index 2d92875..60a88d5 100644 --- a/src/compiler/compiler.jl +++ b/src/compiler/compiler.jl @@ -36,15 +36,7 @@ macro device_override(ex) ex = eval(ex) error() end - code = quote - $GPUCompiler.@override($method_table, $ex) - end - if isdefined(Base.Experimental, Symbol("@overlay")) - return esc(code) - else - push!(overrides, code) - return - end + return esc(:( Base.Experimental.@overlay($method_table, $ex) )) end macro device_function(ex) diff --git a/src/compiler/runtime.jl b/src/compiler/runtime.jl index 98fd798..24e3783 100644 --- a/src/compiler/runtime.jl +++ b/src/compiler/runtime.jl @@ -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 diff --git a/src/compiler/vertices.jl b/src/compiler/vertices.jl index b045973..bc04124 100644 --- a/src/compiler/vertices.jl +++ b/src/compiler/vertices.jl @@ -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) diff --git a/test/Project.toml b/test/Project.toml index b5eb88f..8e15617 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -8,5 +8,5 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] -Enzyme = "0.11" +Enzyme = "0.11, 0.12" StaticArrays = "1" diff --git a/test/compiler.jl b/test/compiler.jl index e9de74b..d66e513 100644 --- a/test/compiler.jl +++ b/test/compiler.jl @@ -5,7 +5,7 @@ const check_bounds = Base.JLOptions().check_bounds == 1 using Test using IPUToolkit.IPUCompiler -using GPUCompiler: KernelError +using GPUCompiler: GPUCompiler using IPUToolkit.Poplar if Poplar.SDK_VERSION ≥ v"2.2.0" || !check_bounds using Enzyme @@ -58,8 +58,9 @@ function test_compiler_program(device) end # Test some invalid kernels - @test_throws KernelError @codelet graph f_access_out_scalar(x::VertexScalar{Float32, Out}) = @ipushow x[] - @test_throws KernelError @codelet graph f_set_in_scalar(x::VertexScalar{Float32, In}) = x[] = 3.14f0 + invalid_error = pkgversion(GPUCompiler) <= v"0.23" ? GPUCompiler.KernelError : GPUCompiler.InvalidIRError + @test_throws invalid_error @codelet graph f_access_out_scalar(x::VertexScalar{Float32, Out}) = @ipushow x[] + @test_throws invalid_error @codelet graph f_set_in_scalar(x::VertexScalar{Float32, In}) = x[] = 3.14f0 # This function would contain a reference to a literal pointer, likely an # invalid memory address on the IPU. @@ -76,10 +77,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) @@ -92,10 +90,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") @@ -128,10 +124,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