Skip to content

Commit 9455b65

Browse files
authored
Some cudadrv tests (#2684)
1 parent 6bf72dd commit 9455b65

File tree

3 files changed

+41
-12
lines changed

3 files changed

+41
-12
lines changed

src/texture.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ end
9797

9898
# idempotency
9999
CuTextureArray{T,N}(xs::CuTextureArray{T,N}) where {T,N} = xs
100+
CuTextureArray(xs::CuTextureArray{T,N}) where {T,N} = xs
100101

101102
CuTextureArray(A::AbstractArray{T,N}) where {T,N} = CuTextureArray{T,N}(A)
102103

test/base/texture.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ end
5151
texarr1D = CuTextureArray(d_a1D)
5252
tex1D = CuTexture(texarr1D)
5353
@test fetch_all(tex1D) == d_a1D
54+
array_mem = texarr1D.mem
55+
@test startswith(sprint(show, array_mem), "$testheight-element ArrayMemory")
5456

5557
texarr2D = CuTextureArray(d_a2D)
5658
tex2D = CuTexture(texarr2D)
@@ -59,6 +61,14 @@ end
5961
texarr3D = CuTextureArray(d_a3D)
6062
tex3D = CuTexture(texarr3D)
6163
@test fetch_all(tex3D) == d_a3D
64+
65+
# test the underlying ArrayMemory too
66+
array_mem = texarr3D.mem
67+
@test_throws ErrorException("Opaque array memory does not have a definite size") sizeof(array_mem)
68+
@test size(array_mem) == size(d_a3D)
69+
@test length(array_mem) == length(d_a3D)
70+
@test ndims(array_mem) == ndims(d_a3D)
71+
6272
end
6373

6474
@testset "CuTextureArray(::Array)" begin
@@ -76,13 +86,20 @@ end
7686
texarr2D = CuTextureArray(a2D)
7787
tex2D = CuTexture(texarr2D)
7888
@test Array(fetch_all(tex2D)) == a2D
89+
texarr2D_2 = CuTextureArray(texarr2D)
90+
tex2D_2 = CuTexture(texarr2D_2)
91+
@test Array(fetch_all(tex2D_2)) == a2D
92+
7993

8094
tex2D_dir = CuTexture(CuTextureArray(a2D))
8195
@test Array(fetch_all(tex2D_dir)) == a2D
8296

8397
texarr3D = CuTextureArray(a3D)
8498
tex3D = CuTexture(texarr3D)
8599
@test Array(fetch_all(tex3D)) == a3D
100+
texarr3D_2 = CuTextureArray(texarr3D)
101+
tex3D_2 = CuTexture(texarr3D_2)
102+
@test Array(fetch_all(tex3D_2)) == a3D
86103
end
87104

88105
@testset "CuTexture(::CuArray)" begin

test/core/cudadrv.jl

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,15 @@ nb = sizeof(data)
435435
typed_pointer(buf::Union{CUDA.DeviceMemory, CUDA.UnifiedMemory}, T) = convert(CuPtr{T}, buf)
436436
typed_pointer(buf::CUDA.HostMemory, T) = convert(Ptr{T}, buf)
437437

438-
# allocations and copies
439-
for srcTy in [CUDA.DeviceMemory, CUDA.HostMemory, CUDA.UnifiedMemory],
438+
@testset "showing" begin
439+
for (Ty, str) in zip([CUDA.DeviceMemory, CUDA.HostMemory, CUDA.UnifiedMemory], ("DeviceMemory", "HostMemory", "UnifiedMemory"))
440+
dummy = CUDA.alloc(Ty, 0)
441+
@test startswith(sprint(show, dummy), str)
442+
CUDA.free(dummy)
443+
end
444+
end
445+
446+
@testset "allocations and copies, src $srcTy dst $dstTy" for srcTy in [CUDA.DeviceMemory, CUDA.HostMemory, CUDA.UnifiedMemory],
440447
dstTy in [CUDA.DeviceMemory, CUDA.HostMemory, CUDA.UnifiedMemory]
441448

442449
dummy = CUDA.alloc(srcTy, 0)
@@ -472,6 +479,7 @@ for srcTy in [CUDA.DeviceMemory, CUDA.HostMemory, CUDA.UnifiedMemory],
472479

473480
# test device with context in which pointer was allocated.
474481
@test device(typed_pointer(src, T)) == device()
482+
@test context(typed_pointer(src, T)) == context()
475483
if !memory_pools_supported(device())
476484
# NVIDIA bug #3319609
477485
@test context(typed_pointer(src, T)) == context()
@@ -495,17 +503,15 @@ for srcTy in [CUDA.DeviceMemory, CUDA.HostMemory, CUDA.UnifiedMemory],
495503
CUDA.free(dst)
496504
end
497505

498-
# pointer attributes
499-
let
506+
@testset "pointer attributes" begin
500507
src = CUDA.alloc(CUDA.DeviceMemory, nb)
501508

502509
attribute!(typed_pointer(src, T), CUDA.POINTER_ATTRIBUTE_SYNC_MEMOPS, 0)
503510

504511
CUDA.free(src)
505512
end
506513

507-
# asynchronous operations
508-
let
514+
@testset "asynchronous operations" begin
509515
src = CUDA.alloc(CUDA.DeviceMemory, nb)
510516

511517
unsafe_copyto!(typed_pointer(src, T), pointer(data), N; async=true)
@@ -515,8 +521,7 @@ let
515521
CUDA.free(src)
516522
end
517523

518-
# pinned memory
519-
let
524+
@testset "pinned memory" begin
520525
# create a pinned and mapped buffer
521526
src = CUDA.alloc(CUDA.HostMemory, nb, CUDA.MEMHOSTALLOC_DEVICEMAP)
522527

@@ -547,10 +552,17 @@ if attribute(device(), CUDA.DEVICE_ATTRIBUTE_HOST_REGISTER_SUPPORTED) != 0
547552
@test ref == data
548553

549554
CUDA.unregister(src)
555+
556+
# with a RefValue
557+
src = Ref{T}(T(42))
558+
CUDA.pin(src)
559+
cpu_ptr = Base.unsafe_convert(Ptr{T}, src)
560+
ref = Array{T}(undef, 1)
561+
unsafe_copyto!(pointer(ref), cpu_ptr, 1)
562+
@test ref == [T(42)]
550563
end
551564

552-
# unified memory
553-
let
565+
@testset "unified memory" begin
554566
src = CUDA.alloc(CUDA.UnifiedMemory, nb)
555567

556568
@test_throws BoundsError CUDA.prefetch(src, 2*nb; device=CUDA.DEVICE_CPU)
@@ -571,8 +583,7 @@ let
571583
CUDA.free(src)
572584
end
573585

574-
# 3d memcpy
575-
let
586+
@testset "3d memcpy" begin
576587
# TODO: use cuMemAllocPitch (and put pitch in buffer?) to actually get benefit from this
577588

578589
data = collect(reshape(1:27, 3, 3, 3))

0 commit comments

Comments
 (0)