@@ -435,8 +435,15 @@ nb = sizeof(data)
435435typed_pointer (buf:: Union{CUDA.DeviceMemory, CUDA.UnifiedMemory} , T) = convert (CuPtr{T}, buf)
436436typed_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)
496504end
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)
505512end
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 )
515521 CUDA. free (src)
516522end
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 )]
550563end
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)
571583 CUDA. free (src)
572584end
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