-
Notifications
You must be signed in to change notification settings - Fork 877
/
Copy pathcuda_test.go
120 lines (91 loc) · 2.32 KB
/
cuda_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package cuda
import (
"testing"
"gocv.io/x/gocv"
)
func TestNewGpuMat(t *testing.T) {
mat := NewGpuMat()
defer mat.Close()
if !mat.Empty() {
t.Error("New GpuMat should be empty")
}
}
func TestGpuMatClosed(t *testing.T) {
mat := NewGpuMat()
mat.Close()
if !mat.Closed() {
t.Error("Closed GpuMat should be closed")
}
}
func TestNewGpuMatFromMat(t *testing.T) {
mat := gocv.NewMat()
defer mat.Close()
gpumat := NewGpuMatFromMat(mat)
defer gpumat.Close()
if !gpumat.Empty() {
t.Error("New GpuMat should be empty")
}
}
func TestNewGpuMatFromMatWithSize(t *testing.T) {
mat := gocv.NewMatWithSize(100, 200, gocv.MatTypeCV32FC4)
defer mat.Close()
gpumat := NewGpuMatFromMat(mat)
defer gpumat.Close()
if gpumat.Empty() {
t.Error("New GpuMat should be not empty")
}
if gpumat.Rows() != 100 {
t.Error("incorrect number of rows for GpuMat")
}
if gpumat.Cols() != 200 {
t.Error("incorrect number of cols for GpuMat")
}
if gpumat.Type() != gocv.MatTypeCV32FC4 {
t.Error("incorrect type for GpuMat")
}
}
func TestNewGpuMatWithSize(t *testing.T) {
gpumat := NewGpuMatWithSize(100, 200, gocv.MatTypeCV32FC4)
defer gpumat.Close()
if gpumat.Empty() {
t.Error("New GpuMat should be not empty")
}
if gpumat.Rows() != 100 {
t.Error("incorrect number of rows for GpuMat")
}
if gpumat.Cols() != 200 {
t.Error("incorrect number of cols for GpuMat")
}
if gpumat.Type() != gocv.MatTypeCV32FC4 {
t.Error("incorrect type for GpuMat")
}
}
func TestGetCudaEnabledDeviceCount(t *testing.T) {
if GetCudaEnabledDeviceCount() < 1 {
t.Fatal("expected atleast one cuda enabled device")
}
}
func TestConvertFp16(t *testing.T) {
gpumat := NewGpuMatWithSize(100, 200, gocv.MatTypeCV32FC4)
defer gpumat.Close()
fp16mat := NewGpuMatWithSize(100, 200, gocv.MatTypeCV32FC4)
defer fp16mat.Close()
gpumat.ConvertFp16(&fp16mat)
if fp16mat.Empty() {
t.Error("New fp16mat should be not empty")
}
if fp16mat.Rows() != 100 {
t.Error("incorrect number of rows for fp16mat")
}
if fp16mat.Cols() != 200 {
t.Error("incorrect number of cols for fp16mat")
}
if fp16mat.Type() != gocv.MatTypeCV16SC4 {
t.Error("incorrect type for fp16mat", fp16mat.Type())
}
}
func TestCudaDeviceSupports(t *testing.T) {
if !DeviceSupports(FeatureSetCompute10) {
t.Fatal("expected FeatureSetCompute10 on cuda enabled device")
}
}