Skip to content

[release-0.9] Test correct backend with examples tests #593

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

Open
wants to merge 13 commits into
base: release-0.9
Choose a base branch
from
2 changes: 2 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ steps:
- JuliaCI/julia-coverage#v1:
codecov: true
command: |
echo -e "[CUDA_Runtime_jll]\nlocal = \"true\"" >LocalPreferences.toml
julia -e 'println("--- :julia: Instantiating project")
using Pkg
Pkg.develop(; path=pwd())
Expand Down Expand Up @@ -38,6 +39,7 @@ steps:
- JuliaCI/julia-coverage#v1:
codecov: true
command: |
echo -e "[CUDA_Runtime_jll]\nlocal = \"true\"" >LocalPreferences.toml
julia -e 'println("--- :julia: Instantiating project")
using Pkg
try
Expand Down
17 changes: 9 additions & 8 deletions examples/histogram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include(joinpath(dirname(pathof(KernelAbstractions)), "../examples/utils.jl")) #

# Function to use as a baseline for CPU metrics
function create_histogram(input)
histogram_output = zeros(Int, maximum(input))
histogram_output = zeros(eltype(input), maximum(input))
for i in input
histogram_output[i] += 1
end
Expand All @@ -22,7 +22,7 @@ end
@uniform gs = @groupsize()[1]
@uniform N = length(histogram_output)

shared_histogram = @localmem Int (gs)
shared_histogram = @localmem eltype(input) (gs)

# This will go through all input elements and assign them to a location in
# shmem. Note that if there is not enough shem, we create different shmem
Expand Down Expand Up @@ -77,9 +77,10 @@ end
if Base.VERSION < v"1.7.0" && !KernelAbstractions.isgpu(backend)
@test_skip false
else
rand_input = [rand(1:128) for i in 1:1000]
linear_input = [i for i in 1:1024]
all_two = [2 for i in 1:512]
# Use Int32 as some backends don't support 64-bit atomics
rand_input = Int32[rand(1:128) for i in 1:1000]
linear_input = Int32[i for i in 1:1024]
all_two = Int32[2 for i in 1:512]

histogram_rand_baseline = create_histogram(rand_input)
histogram_linear_baseline = create_histogram(linear_input)
Expand All @@ -89,9 +90,9 @@ end
linear_input = move(backend, linear_input)
all_two = move(backend, all_two)

rand_histogram = KernelAbstractions.zeros(backend, Int, 128)
linear_histogram = KernelAbstractions.zeros(backend, Int, 1024)
two_histogram = KernelAbstractions.zeros(backend, Int, 2)
rand_histogram = KernelAbstractions.zeros(backend, Int32, 128)
linear_histogram = KernelAbstractions.zeros(backend, Int32, 1024)
two_histogram = KernelAbstractions.zeros(backend, Int32, 2)

histogram!(rand_histogram, rand_input)
histogram!(linear_histogram, linear_input)
Expand Down
4 changes: 2 additions & 2 deletions examples/memcopy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function mycopy!(A, B)
return
end

A = KernelAbstractions.zeros(backend, Float64, 128, 128)
B = KernelAbstractions.ones(backend, Float64, 128, 128)
A = KernelAbstractions.zeros(backend, f_type, 128, 128)
B = KernelAbstractions.ones(backend, f_type, 128, 128)
mycopy!(A, B)
KernelAbstractions.synchronize(backend)
@test A == B
4 changes: 2 additions & 2 deletions examples/memcopy_static.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function mycopy_static!(A, B)
return
end

A = KernelAbstractions.zeros(backend, Float64, 128, 128)
B = KernelAbstractions.ones(backend, Float64, 128, 128)
A = KernelAbstractions.zeros(backend, f_type, 128, 128)
B = KernelAbstractions.ones(backend, f_type, 128, 128)
mycopy_static!(A, B)
KernelAbstractions.synchronize(backend)
@test A == B
2 changes: 1 addition & 1 deletion examples/performant_matmul.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using Test
using Random
include(joinpath(dirname(pathof(KernelAbstractions)), "../examples/utils.jl")) # Load backend

const TILE_DIM = 32
const TILE_DIM = 16

@kernel function coalesced_matmul_kernel!(
output, @Const(input1), @Const(input2), N, R, M,
Expand Down
4 changes: 4 additions & 0 deletions examples/utils.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# EXCLUDE FROM TESTING
if !(@isdefined backend)
if Base.find_package("CUDA") !== nothing
using CUDA
using CUDA.CUDAKernels
Expand All @@ -7,3 +8,6 @@ if Base.find_package("CUDA") !== nothing
else
const backend = CPU()
end
end

const f_type = KernelAbstractions.supports_float64(backend) ? Float64 : Float32
3 changes: 2 additions & 1 deletion test/examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function find_sources(path::String, sources = String[])
return sources
end

function examples_testsuite(backend_str)
function examples_testsuite(backend, backend_str)
@testset "examples" begin
examples_dir = joinpath(@__DIR__, "..", "examples")
examples = find_sources(examples_dir)
Expand All @@ -21,6 +21,7 @@ function examples_testsuite(backend_str)
@testset "$(basename(example))" for example in examples
@eval module $(gensym())
backend_str = $backend_str
const backend = ($backend)()
include($example)
end
@test true
Expand Down
12 changes: 6 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ struct NewBackend <: KernelAbstractions.GPU end
end


include("extensions/enzyme.jl")
@static if VERSION >= v"1.7.0"
@testset "Enzyme" begin
enzyme_testsuite(CPU, Array)
end
end
# include("extensions/enzyme.jl")
# @static if VERSION >= v"1.7.0"
# @testset "Enzyme" begin
# enzyme_testsuite(CPU, Array)
# end
# end
74 changes: 37 additions & 37 deletions test/testsuite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,56 +40,56 @@ include("convert.jl")
include("specialfunctions.jl")

function testsuite(backend, backend_str, backend_mod, AT, DAT; skip_tests = Set{String}())
@conditional_testset "Unittests" skip_tests begin
unittest_testsuite(backend, backend_str, backend_mod, DAT; skip_tests)
end
# @conditional_testset "Unittests" skip_tests begin
# unittest_testsuite(backend, backend_str, backend_mod, DAT; skip_tests)
# end

@conditional_testset "SpecialFunctions" skip_tests begin
specialfunctions_testsuite(backend)
end
# @conditional_testset "SpecialFunctions" skip_tests begin
# specialfunctions_testsuite(backend)
# end

@conditional_testset "Localmem" skip_tests begin
localmem_testsuite(backend, AT)
end
# @conditional_testset "Localmem" skip_tests begin
# localmem_testsuite(backend, AT)
# end

@conditional_testset "Private" skip_tests begin
private_testsuite(backend, AT)
end
# @conditional_testset "Private" skip_tests begin
# private_testsuite(backend, AT)
# end

@conditional_testset "Unroll" skip_tests begin
unroll_testsuite(backend, AT)
end
# @conditional_testset "Unroll" skip_tests begin
# unroll_testsuite(backend, AT)
# end

@testset "NDIteration" begin
nditeration_testsuite()
end
# @testset "NDIteration" begin
# nditeration_testsuite()
# end

@conditional_testset "copyto!" skip_tests begin
copyto_testsuite(backend, AT)
end
# @conditional_testset "copyto!" skip_tests begin
# copyto_testsuite(backend, AT)
# end

@conditional_testset "Devices" skip_tests begin
devices_testsuite(backend)
end
# @conditional_testset "Devices" skip_tests begin
# devices_testsuite(backend)
# end

@conditional_testset "Printing" skip_tests begin
printing_testsuite(backend)
end
# @conditional_testset "Printing" skip_tests begin
# printing_testsuite(backend)
# end

@conditional_testset "Compiler" skip_tests begin
compiler_testsuite(backend, AT)
end
# @conditional_testset "Compiler" skip_tests begin
# compiler_testsuite(backend, AT)
# end

@conditional_testset "Reflection" skip_tests begin
reflection_testsuite(backend, backend_str, AT)
end
# @conditional_testset "Reflection" skip_tests begin
# reflection_testsuite(backend, backend_str, AT)
# end

@conditional_testset "Convert" skip_tests begin
convert_testsuite(backend, AT)
end
# @conditional_testset "Convert" skip_tests begin
# convert_testsuite(backend, AT)
# end

@conditional_testset "Examples" skip_tests begin
examples_testsuite(backend_str)
examples_testsuite(backend, backend_str)
end

return
Expand Down
Loading