@@ -435,8 +435,15 @@ nb = sizeof(data)
435
435
typed_pointer (buf:: Union{CUDA.DeviceMemory, CUDA.UnifiedMemory} , T) = convert (CuPtr{T}, buf)
436
436
typed_pointer (buf:: CUDA.HostMemory , T) = convert (Ptr{T}, buf)
437
437
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],
440
447
dstTy in [CUDA. DeviceMemory, CUDA. HostMemory, CUDA. UnifiedMemory]
441
448
442
449
dummy = CUDA. alloc (srcTy, 0 )
@@ -472,6 +479,7 @@ for srcTy in [CUDA.DeviceMemory, CUDA.HostMemory, CUDA.UnifiedMemory],
472
479
473
480
# test device with context in which pointer was allocated.
474
481
@test device (typed_pointer (src, T)) == device ()
482
+ @test context (typed_pointer (src, T)) == context ()
475
483
if ! memory_pools_supported (device ())
476
484
# NVIDIA bug #3319609
477
485
@test context (typed_pointer (src, T)) == context ()
@@ -495,17 +503,15 @@ for srcTy in [CUDA.DeviceMemory, CUDA.HostMemory, CUDA.UnifiedMemory],
495
503
CUDA. free (dst)
496
504
end
497
505
498
- # pointer attributes
499
- let
506
+ @testset " pointer attributes" begin
500
507
src = CUDA. alloc (CUDA. DeviceMemory, nb)
501
508
502
509
attribute! (typed_pointer (src, T), CUDA. POINTER_ATTRIBUTE_SYNC_MEMOPS, 0 )
503
510
504
511
CUDA. free (src)
505
512
end
506
513
507
- # asynchronous operations
508
- let
514
+ @testset " asynchronous operations" begin
509
515
src = CUDA. alloc (CUDA. DeviceMemory, nb)
510
516
511
517
unsafe_copyto! (typed_pointer (src, T), pointer (data), N; async= true )
515
521
CUDA. free (src)
516
522
end
517
523
518
- # pinned memory
519
- let
524
+ @testset " pinned memory" begin
520
525
# create a pinned and mapped buffer
521
526
src = CUDA. alloc (CUDA. HostMemory, nb, CUDA. MEMHOSTALLOC_DEVICEMAP)
522
527
@@ -547,10 +552,17 @@ if attribute(device(), CUDA.DEVICE_ATTRIBUTE_HOST_REGISTER_SUPPORTED) != 0
547
552
@test ref == data
548
553
549
554
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 )]
550
563
end
551
564
552
- # unified memory
553
- let
565
+ @testset " unified memory" begin
554
566
src = CUDA. alloc (CUDA. UnifiedMemory, nb)
555
567
556
568
@test_throws BoundsError CUDA. prefetch (src, 2 * nb; device= CUDA. DEVICE_CPU)
571
583
CUDA. free (src)
572
584
end
573
585
574
- # 3d memcpy
575
- let
586
+ @testset " 3d memcpy" begin
576
587
# TODO : use cuMemAllocPitch (and put pitch in buffer?) to actually get benefit from this
577
588
578
589
data = collect (reshape (1 : 27 , 3 , 3 , 3 ))
0 commit comments