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

Run Runic after explicit return rule addition #516

Merged
merged 2 commits into from
Jan 21, 2025
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
22 changes: 22 additions & 0 deletions .github/workflows/Check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Check
on:
push:
branches:
- 'master'
- 'release-'
tags:
- '*'
pull_request:
jobs:
runic:
name: Runic formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: "1"
- uses: julia-actions/cache@v2
- uses: fredrikekre/runic-action@v1
with:
version: "1"
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function main()
push_preview = true,
)
end
return
end

isinteractive() || main()
2 changes: 2 additions & 0 deletions examples/histogram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ function histogram!(histogram_output, input)
# Need static block size
kernel! = histogram_kernel!(backend, (256,))
kernel!(histogram_output, input, ndrange = size(input))
return
end

function move(backend, input)
# TODO replace with adapt(backend, input)
out = KernelAbstractions.allocate(backend, eltype(input), size(input))
KernelAbstractions.copyto!(backend, out, input)
return out
end

@testset "histogram tests" begin
Expand Down
1 change: 1 addition & 0 deletions examples/matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function matmul!(output, a, b)
backend = KernelAbstractions.get_backend(a)
kernel! = matmul_kernel!(backend)
kernel!(output, a, b, ndrange = size(output))
return
end

a = rand!(allocate(backend, Float32, 256, 123))
Expand Down
1 change: 1 addition & 0 deletions examples/memcopy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function mycopy!(A, B)

kernel = copy_kernel!(backend)
kernel(A, B, ndrange = length(A))
return
end

A = KernelAbstractions.zeros(backend, Float64, 128, 128)
Expand Down
1 change: 1 addition & 0 deletions examples/memcopy_static.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function mycopy_static!(A, B)

kernel = copy_kernel!(backend, 32, size(A)) # if size(A) varies this will cause recompilation
kernel(A, B, ndrange = size(A))
return
end

A = KernelAbstractions.zeros(backend, Float64, 128, 128)
Expand Down
3 changes: 3 additions & 0 deletions examples/mpi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function cooperative_test!(req)
done, _ = MPI.Test(req, MPI.Status)
yield()
end
return
end

function cooperative_wait(task::Task)
Expand All @@ -17,6 +18,7 @@ function cooperative_wait(task::Task)
yield()
end
wait(task)
return
end

function exchange!(h_send_buf, d_recv_buf, h_recv_buf, src_rank, dst_rank, comm)
Expand Down Expand Up @@ -68,6 +70,7 @@ function main(backend)
cooperative_wait(send_task)

@test all(d_recv_buf .== src_rank)
return
end

main(backend)
1 change: 1 addition & 0 deletions examples/naive_transpose.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function naive_transpose!(a, b)
groupsize = KernelAbstractions.isgpu(backend) ? 256 : 1024
kernel! = naive_transpose_kernel!(backend, groupsize)
kernel!(a, b, ndrange = size(a))
return
end

# resolution of grid will be res*res
Expand Down
4 changes: 2 additions & 2 deletions ext/EnzymeCore07Ext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function EnzymeRules.forward(
f = kernel.f
fwd_kernel = similar(kernel, cpu_fwd)

fwd_kernel(f, args...; ndrange, workgroupsize)
return fwd_kernel(f, args...; ndrange, workgroupsize)
end

function EnzymeRules.forward(
Expand All @@ -36,7 +36,7 @@ function EnzymeRules.forward(
f = kernel.f
fwd_kernel = similar(kernel, gpu_fwd)

fwd_kernel(f, args...; ndrange, workgroupsize)
return fwd_kernel(f, args...; ndrange, workgroupsize)
end

_enzyme_mkcontext(kernel::Kernel{CPU}, ndrange, iterspace, dynamic) =
Expand Down
4 changes: 2 additions & 2 deletions ext/EnzymeCore08Ext.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function EnzymeRules.forward(
f = kernel.f
fwd_kernel = similar(kernel, cpu_fwd)

fwd_kernel(config, f, args...; ndrange, workgroupsize)
return fwd_kernel(config, f, args...; ndrange, workgroupsize)
end

function EnzymeRules.forward(
Expand All @@ -38,7 +38,7 @@ function EnzymeRules.forward(
f = kernel.f
fwd_kernel = similar(kernel, gpu_fwd)

fwd_kernel(config, f, args...; ndrange, workgroupsize)
return fwd_kernel(config, f, args...; ndrange, workgroupsize)
end

_enzyme_mkcontext(kernel::Kernel{CPU}, ndrange, iterspace, dynamic) =
Expand Down
4 changes: 2 additions & 2 deletions src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function transform_gpu!(def, constargs, force_inbounds)
Expr(:block, let_constargs...),
body,
)
return nothing
return
end

# The hard case, transform the function for CPU execution
Expand Down Expand Up @@ -138,7 +138,7 @@ function transform_cpu!(def, constargs, force_inbounds)
Expr(:block, let_constargs...),
Expr(:block, new_stmts...),
)
return nothing
return
end

struct WorkgroupLoop
Expand Down
3 changes: 2 additions & 1 deletion test/compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ end

function compiler_testsuite(backend, ArrayT)
kernel = index(CPU(), DynamicSize(), DynamicSize())
iterspace = NDRange{1, StaticSize{(128,)}, StaticSize{(8,)}}();
iterspace = NDRange{1, StaticSize{(128,)}, StaticSize{(8,)}}()
ctx = KernelAbstractions.mkcontext(kernel, 1, nothing, iterspace, Val(KernelAbstractions.NoDynamicCheck()))
@test ndims(ctx) == 1
@test KernelAbstractions.__index_Global_NTuple(ctx, CartesianIndex(1)) == (1,)
Expand Down Expand Up @@ -75,4 +75,5 @@ function compiler_testsuite(backend, ArrayT)
# test that there is no invoke of overdub
@test !any(check_for_overdub, CI.code)
end
return
end
1 change: 1 addition & 0 deletions test/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ function convert_testsuite(backend, ArrayT)
@test d_B[:, i + 20] == round.(d_A)
end
end
return
end
1 change: 1 addition & 0 deletions test/copyto.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ function copyto_testsuite(Backend, ArrayT)

@test isapprox(a, Array(A))
@test isapprox(a, Array(B))
return
end
3 changes: 2 additions & 1 deletion test/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function find_sources(path::String, sources = String[])
elseif endswith(path, ".jl")
push!(sources, path)
end
sources
return sources
end

function examples_testsuite(backend_str)
Expand All @@ -27,4 +27,5 @@ function examples_testsuite(backend_str)
end

end
return
end
3 changes: 3 additions & 0 deletions test/extensions/enzyme.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function square_caller(A, backend)
kernel = square!(backend)
kernel(A, ndrange = size(A))
KernelAbstractions.synchronize(backend)
return
end


Expand All @@ -23,6 +24,7 @@ function mul_caller(A, B, backend)
kernel = mul!(backend)
kernel(A, B, ndrange = size(A))
KernelAbstractions.synchronize(backend)
return
end

function enzyme_testsuite(backend, ArrayT, supports_reverse = true)
Expand Down Expand Up @@ -58,4 +60,5 @@ function enzyme_testsuite(backend, ArrayT, supports_reverse = true)
@test all(dA .≈ 2:2:128)

end
return
end
5 changes: 3 additions & 2 deletions test/localmem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using Test
end
I = @index(Global, Linear)
i = @index(Local, Linear)
lmem = @localmem Int (N,) # Ok iff groupsize is static
lmem = @localmem Int (N,) # Ok iff groupsize is static
@inbounds begin
lmem[i] = i
@synchronize
Expand All @@ -23,7 +23,7 @@ end
end
I = @index(Global, Linear)
i = @index(Local, Linear)
lmem = @localmem Int (N,) # Ok iff groupsize is static
lmem = @localmem Int (N,) # Ok iff groupsize is static
@inbounds begin
lmem[i] = i + 3
for j in 1:2
Expand All @@ -47,4 +47,5 @@ function localmem_testsuite(backend, ArrayT)
@test all(B[49:64] .== 16:-1:1)
end
end
return
end
3 changes: 2 additions & 1 deletion test/nditeration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function nditeration_testsuite()

function check(idx, offset, offset_x, offset_y, Dim_x, Dim_y)
N = Dim_x * Dim_y
all(p -> p[1] == p[2], zip(idx[(offset * N .+ 1):N], CartesianIndices(((offset_x * Dim_x .+ 1):Dim_x, (offset_y * Dim_y .+ 1):Dim_y))))
return all(p -> p[1] == p[2], zip(idx[(offset * N .+ 1):N], CartesianIndices(((offset_x * Dim_x .+ 1):Dim_x, (offset_y * Dim_y .+ 1):Dim_y))))
end

@testset "linear_iteration" begin
Expand Down Expand Up @@ -93,4 +93,5 @@ function nditeration_testsuite()
@test ndims(ndrange) == 2
end
end
return
end
1 change: 1 addition & 0 deletions test/print_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ function printing_testsuite(backend)
end
@test true
end
return
end
1 change: 1 addition & 0 deletions test/private.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,5 @@ function private_testsuite(backend, ArrayT)
end
end
end
return
end
6 changes: 6 additions & 0 deletions test/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function test_typed_kernel_dynamic(backend, backend_str, ArrayT)
@test isa(res, Pair{Core.CodeInfo, DataType})
end
@test isa(res[1].code, Array{Any, 1})
return
end

function test_typed_kernel_dynamic_no_info(backend, backend_str, ArrayT)
Expand All @@ -43,6 +44,7 @@ function test_typed_kernel_dynamic_no_info(backend, backend_str, ArrayT)
@test isa(res, Pair{Core.CodeInfo, DataType})
end
@test isa(res[1].code, Array{Any, 1})
return
end

function test_typed_kernel_static(backend, backend_str, ArrayT)
Expand All @@ -59,6 +61,7 @@ function test_typed_kernel_static(backend, backend_str, ArrayT)
@test isa(res, Pair{Core.CodeInfo, DataType})
end
@test isa(res[1].code, Array{Any, 1})
return
end

function test_typed_kernel_no_optimize(backend, backend_str, ArrayT)
Expand All @@ -72,6 +75,7 @@ function test_typed_kernel_no_optimize(backend, backend_str, ArrayT)
res_opt = @ka_code_typed kernel(A, ndrange = size(A))
# FIXME: Need a better test
# @test size(res[1].code) < size(res_opt[1].code)
return
end

function test_expr_kernel(backend, backend_str, ArrayT)
Expand All @@ -89,6 +93,7 @@ function test_expr_kernel(backend, backend_str, ArrayT)
@test isa(res, Pair{Core.CodeInfo, DataType})
end
@test isa(res[1].code, Array{Any, 1})
return
end

function reflection_testsuite(backend, backend_str, ArrayT)
Expand All @@ -97,4 +102,5 @@ function reflection_testsuite(backend, backend_str, ArrayT)
test_typed_kernel_static(backend, backend_str, ArrayT)
test_typed_kernel_no_optimize(backend, backend_str, ArrayT)
test_expr_kernel(backend, backend_str, ArrayT)
return
end
1 change: 1 addition & 0 deletions test/specialfunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ function specialfunctions_testsuite(Backend)
synchronize(backend)
@test Array(cy) ≈ SpecialFunctions.erfc.(x)
end
return
end
4 changes: 3 additions & 1 deletion test/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function unittest_testsuite(Backend, backend_str, backend_mod, BackendArrayT; sk
@conditional_testset "Const" skip_tests begin
let kernel = constarg(Backend(), 8, (1024,))
# this is poking at internals
iterspace = NDRange{1, StaticSize{(128,)}, StaticSize{(8,)}}();
iterspace = NDRange{1, StaticSize{(128,)}, StaticSize{(8,)}}()
ctx = if Backend == CPU
KernelAbstractions.mkcontext(kernel, 1, nothing, iterspace, Val(NoDynamicCheck()))
else
Expand Down Expand Up @@ -266,6 +266,7 @@ function unittest_testsuite(Backend, backend_str, backend_mod, BackendArrayT; sk
function f(KernelAbstractions.@context, a)
I = @index(Global, Linear)
a[I] = 1
return
end
@kernel cpu = false function context_kernel(a)
f(KernelAbstractions.@context, a)
Expand Down Expand Up @@ -324,4 +325,5 @@ function unittest_testsuite(Backend, backend_str, backend_mod, BackendArrayT; sk
end
end

return
end
4 changes: 3 additions & 1 deletion test/testsuite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const Pkg = Base.require(
)

macro conditional_testset(name, skip_tests, expr)
esc(
return esc(
quote
@testset $name begin
if $name ∉ $skip_tests
Expand Down Expand Up @@ -91,6 +91,8 @@ function testsuite(backend, backend_str, backend_mod, AT, DAT; skip_tests = Set{
@conditional_testset "Examples" skip_tests begin
examples_testsuite(backend_str)
end

return
end

end
1 change: 1 addition & 0 deletions test/unroll.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ function unroll_testsuite(backend, ArrayT)
kernel2! = kernel_unroll2!(backend(), 1, 1)
kernel2!(a)
synchronize(backend())
return
end
Loading