Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompatHelper: bump compat for GPUCompiler to 0.23-0.26 #43

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "IPUToolkit"
uuid = "92e0b95a-4011-435a-96f4-10064551ddbe"
authors = ["Emily Dietrich <[email protected]>", "Luk Burchard <[email protected]>", "Mosè Giordano <[email protected]>"]
version = "1.5.0"
version = "1.6.0"

[deps]
Clang = "40e3b903-d033-50b4-a0cc-940c62c95e31"
Expand All @@ -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"
Expand All @@ -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"
10 changes: 1 addition & 9 deletions src/compiler/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
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
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
24 changes: 9 additions & 15 deletions test/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down
Loading