Skip to content

Commit fa5c389

Browse files
authored
Merge pull request #2079 from JuliaGPU/tb/tests
Test improvements
2 parents 9f43ac0 + 0d68345 commit fa5c389

File tree

13 files changed

+52
-105
lines changed

13 files changed

+52
-105
lines changed

Manifest.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
julia_version = "1.8.5"
44
manifest_format = "2.0"
5-
project_hash = "668ed29932abfaac250cb6c23a1bfa769a4b4fcf"
5+
project_hash = "bd7ca8996e1ea58c0718ac9f8390b825e95848f9"
66

77
[[deps.AbstractFFTs]]
88
deps = ["ChainRulesCore", "LinearAlgebra", "Test"]
@@ -158,9 +158,9 @@ version = "0.1.5"
158158

159159
[[deps.GPUCompiler]]
160160
deps = ["ExprTools", "InteractiveUtils", "LLVM", "Libdl", "Logging", "Scratch", "TimerOutputs", "UUIDs"]
161-
git-tree-sha1 = "8573c39f9c4e99720ab5ea44104efb3ed07a58b0"
161+
git-tree-sha1 = "e5e0f07db5c325860b21cadeb6e4271b0ff364c5"
162162
uuid = "61eb1bfa-7361-4325-ad38-22787b887f55"
163-
version = "0.23.0"
163+
version = "0.24.1"
164164

165165
[[deps.InlineStrings]]
166166
deps = ["Parsers"]

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Crayons = "4"
5252
DataFrames = "1"
5353
ExprTools = "0.1"
5454
GPUArrays = "9"
55-
GPUCompiler = "0.23"
55+
GPUCompiler = "0.24"
5656
KernelAbstractions = "0.9.2"
5757
LLVM = "6"
5858
NVTX = "0.3.2"

lib/cudadrv/error.jl

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,38 @@
33
export CuError
44

55

6+
# an optional struct, used to represent e.g. optional error logs.
7+
# this is to make CuErrors with/without additional logs compare equal
8+
# (so that we can simply reuse `@test_throws CuError(code)`).
9+
struct Optional{T}
10+
data::Union{Nothing,T}
11+
Optional{T}(data::Union{Nothing,T}=nothing) where {T} = new{T}(data)
12+
end
13+
Base.getindex(s::Optional) = s.data
14+
function Base.isequal(a::Optional, b::Optional)
15+
if a.data === nothing || b.data === nothing
16+
return true
17+
else
18+
return isequal(a.data, b.data)
19+
end
20+
end
21+
Base.convert(::Type{Optional{T}}, ::Nothing) where T = Optional{T}()
22+
Base.convert(::Type{Optional{T}}, x) where T = Optional{T}(convert(T, x))
23+
Base.convert(::Type{Optional{T}}, x::Optional) where T = convert(Optional{T}, x[])
24+
25+
626
"""
727
CuError(code)
8-
CuError(code, meta)
28+
CuError(code, details)
929
10-
Create a CUDA error object with error code `code`. The optional `meta` parameter indicates
11-
whether extra information, such as error logs, is known.
30+
Create a CUDA error object with error code `code`. The optional `details` parameter
31+
indicates whether extra information, such as error logs, is known.
1232
"""
1333
struct CuError <: Exception
1434
code::CUresult
15-
meta::Any
35+
details::Optional{String}
1636

17-
CuError(code, meta=nothing) = new(code, meta)
37+
CuError(code, details=nothing) = new(code, details)
1838
end
1939

2040
Base.convert(::Type{CUresult}, err::CuError) = err.code
@@ -63,9 +83,9 @@ function Base.showerror(io::IO, err::CuError)
6383
print(io, "CUDA error: $(description(err)) (code $(reinterpret(Int32, err.code)), $(name(err)))")
6484
end
6585

66-
if err.meta !== nothing
86+
if err.details[] !== nothing
6787
print(io, "\n")
68-
print(io, err.meta)
88+
print(io, err.details[])
6989
end
7090
end
7191

lib/cudadrv/state.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ function Base.get(x::PerDevice, dev::CuDevice, val)
470470
end
471471
end
472472

473-
function Base.get!(constructor::F, x::PerDevice{T}, dev::CuDevice) where {F, T}
473+
function Base.get!(constructor::F, x::PerDevice{T}, dev::CuDevice) where {F <: Base.Callable, T}
474474
y = get_values(x)
475475
id = deviceid(dev)+1
476476
ctx = device_context(id) # may be nothing

lib/cudadrv/synchronization.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function Base.put!(c::BidirectionalChannel{T}, v::T) where T
4343
end
4444
end
4545

46-
function Base.take!(f, c::BidirectionalChannel{T}) where T
46+
function Base.take!(f::Base.Callable, c::BidirectionalChannel{T}) where T
4747
lock(c)
4848
try
4949
# notify the producer that we're ready to accept a value

lib/utils/threading.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ end
2323
LazyInitialized{T}(validator=nothing) where {T} =
2424
LazyInitialized{T,typeof(validator)}(Threads.Atomic{Int}(0), Ref{T}(), validator)
2525

26-
@inline function Base.get!(constructor, x::LazyInitialized)
26+
@inline function Base.get!(constructor::Base.Callable, x::LazyInitialized)
2727
while x.guard[] != 2
2828
initialize!(x, constructor)
2929
end

src/device/texture.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,15 @@ end
5656
Base.Tuple(x::Vec4) = tuple(x.a, x.b, x.c, x.d)
5757

5858
for (dispatch_rettyp, julia_rettyp, llvm_rettyp) in
59-
((:Signed, :(Vec4{UInt32}), :v4u32),
60-
(:Unsigned, :(Vec4{Int32}), :v4s32),
59+
((:Signed, :(Vec4{Int32}), :v4u32),
60+
(:Unsigned, :(Vec4{UInt32}), :v4s32),
6161
(:AbstractFloat, :(Vec4{Float32}), :v4f32))
6262

63-
eltyp = :(Union{$dispatch_rettyp, NTuple{<:Any,$dispatch_rettyp}})
63+
eltyp = :(Union{$dispatch_rettyp,
64+
NTuple{1,$dispatch_rettyp},
65+
NTuple{2,$dispatch_rettyp},
66+
NTuple{3,$dispatch_rettyp},
67+
NTuple{4,$dispatch_rettyp}})
6468

6569
# tex1D only supports array memory
6670
@eval tex(texObject::CuDeviceTexture{<:$eltyp,1,ArrayMemory}, x::Number) =
@@ -74,7 +78,7 @@ for (dispatch_rettyp, julia_rettyp, llvm_rettyp) in
7478
julia_sig = ntuple(_->Float32, dims)
7579
julia_params = ntuple(i->:($(julia_args[i])::Number), dims)
7680

77-
@eval tex(texObject::CuDeviceTexture{<:$eltyp,$dims,}, $(julia_params...)) =
81+
@eval tex(texObject::CuDeviceTexture{<:$eltyp,$dims}, $(julia_params...)) =
7882
Tuple(ccall($("llvm.nvvm.tex.unified.$llvm_dim.$llvm_rettyp.f32"), llvmcall,
7983
$julia_rettyp, (CUtexObject, $(julia_sig...)), texObject, $(julia_args...)))
8084
end

test/base/aqua.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let ambs = Aqua.detect_ambiguities(CUDA; recursive=true)
99
pkg_match(pkgname, pkgdir::Nothing) = false
1010
pkg_match(pkgname, pkgdir::AbstractString) = occursin(pkgname, pkgdir)
1111
filter!(x -> pkg_match("CUDA", pkgdir(last(x).module)), ambs)
12-
@test length(ambs) 51
12+
@test length(ambs) 18
1313
end
1414

1515
Aqua.test_undefined_exports(CUDA)

test/core/cudadrv.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ let
705705
@test md != md2
706706
end
707707

708-
@test_throws_cuerror CUDA.ERROR_INVALID_IMAGE CuModule("foobar")
708+
@test_throws CuError(CUDA.ERROR_INVALID_IMAGE) CuModule("foobar")
709709

710710
@testset "globals" begin
711711
md = CuModuleFile(joinpath(@__DIR__, "ptx/global.ptx"))
@@ -735,7 +735,7 @@ end
735735
# TODO: test with valid object code
736736
# NOTE: apparently, on Windows cuLinkAddData! _does_ accept object data containing \0
737737
if !Sys.iswindows()
738-
@test_throws_cuerror CUDA.ERROR_UNKNOWN add_data!(link, "vadd_parent", UInt8[0])
738+
@test_throws CuError(CUDA.ERROR_UNKNOWN) add_data!(link, "vadd_parent", UInt8[0])
739739
end
740740
end
741741

@@ -744,10 +744,12 @@ end
744744
.version 3.1
745745
.target sm_999
746746
.address_size 64"""
747-
@test_throws_message contains("ptxas fatal") CuError CuModule(invalid_code)
747+
@test_throws CuError(CUDA.ERROR_INVALID_PTX) CuModule(invalid_code)
748+
@test_throws "ptxas fatal" CuModule(invalid_code)
748749

749750
link = CuLink()
750-
@test_throws_message contains("ptxas fatal") CuError add_data!(link, "dummy", invalid_code)
751+
@test_throws CuError(CUDA.ERROR_INVALID_PTX) add_data!(link, "dummy", invalid_code)
752+
@test_throws "ptxas fatal" add_data!(link, "dummy", invalid_code)
751753
end
752754

753755
let

test/core/execution.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ end
8888
# make sure invalid kernels can be partially reflected upon
8989
let
9090
invalid_kernel() = throw()
91-
@test_throws CUDA.KernelError @cuda invalid_kernel()
92-
@test_throws CUDA.KernelError @grab_output @device_code_warntype @cuda invalid_kernel()
91+
@test_throws CUDA.InvalidIRError @cuda invalid_kernel()
92+
@test_throws CUDA.InvalidIRError @grab_output @device_code_warntype @cuda invalid_kernel()
9393
out, err = @grab_output begin
9494
try
9595
@device_code_warntype @cuda invalid_kernel()

0 commit comments

Comments
 (0)