Skip to content

Commit bf1c589

Browse files
authored
More array tests (#2758)
1 parent a3d6aa4 commit bf1c589

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/base/array.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ using ChainRulesCore: add!!, is_inplaceable_destination
3636
@test collect(CUDA.fill(0, 2, 2)) == zeros(Float32, 2, 2)
3737
@test collect(CUDA.fill(1, 2, 2)) == ones(Float32, 2, 2)
3838

39+
# undef with various forms of dims
40+
let xs = CuArray{Int, 1, CUDA.DeviceMemory}(undef, (64,))
41+
@test size(xs) == (64,)
42+
end
43+
let xs = CuArray{Int, 1, CUDA.DeviceMemory}()
44+
@test size(xs) == (0,)
45+
end
46+
# cu with too many memory types
47+
@test_throws ArgumentError("Can only specify one of `device`, `unified`, or `host`") cu([1]; device=true, host=true)
3948
let
4049
@gensym typnam
4150
typ = @eval begin
@@ -62,6 +71,7 @@ end
6271
@test_throws ErrorException CuArray{MyBadType, 1}(undef, 64)
6372
@test_throws ErrorException CuArray{MyBadType2, 1}(undef, 64)
6473
@test_throws ErrorException CuArray{MyBadType3, 1}(undef, 64)
74+
@test_throws ErrorException CuArray{BigFloat, 1}(undef, 64)
6575
end
6676

6777
@testset "synchronization" begin
@@ -93,6 +103,10 @@ end
93103
@test size(b) == (1,)
94104
end
95105
end
106+
let a = cu([1]; device=true)
107+
p = pointer(a)
108+
@test_throws ArgumentError("Can only create a CPU array object from a unified or host CUDA array") unsafe_wrap(Array, p, 1)
109+
end
96110

97111
# unmanaged memory -> CuArray
98112
# note that the device-side pointer may differ from the host one (i.e., on Tegra)
@@ -747,13 +761,17 @@ end
747761

748762
let
749763
a = CuVector{Int,CUDA.DeviceMemory}(undef, 1)
764+
@test is_device(a)
765+
@test !is_host(a)
750766
@test !is_unified(a)
751767
@test !is_managed(pointer(a))
752768
end
753769

754770
let
755771
a = CuVector{Int,CUDA.UnifiedMemory}(undef, 1)
772+
@test !is_device(a)
756773
@test is_unified(a)
774+
@test !is_host(a)
757775
@test is_managed(pointer(a))
758776
a .= 0
759777
@test Array(a) == [0]

0 commit comments

Comments
 (0)