COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
test_cublas1 Namespace Reference

Functions

def test_float_aimax ()
 
def test_float_aimin ()
 
def test_float_asum ()
 
def test_float_nrm2 ()
 
def test_float_scale ()
 
def test_float_swap ()
 
def test_float_copy ()
 
def test_float_axpy ()
 
def test_float_dot ()
 
def test_double_aimax ()
 
def test_double_aimin ()
 
def test_double_asum ()
 
def test_double_nrm2 ()
 
def test_double_scale ()
 
def test_double_swap ()
 
def test_double_copy ()
 
def test_double_axpy ()
 
def test_double_dot ()
 

Variables

int size = 1024
 
int dec = 4
 
int prec = 10**-dec
 
 seed = np.int32(time.perf_counter() * 1e3)
 
 c = ch.context.get_instance()
 

Function Documentation

◆ test_double_aimax()

def test_cublas1.test_double_aimax ( )

Definition at line 164 of file test_cublas1.py.

164 def test_double_aimax():
165  Vect = ch.obj_double(c, np.random.randn(size))
166  # Vect = ch.obj_double(c, np.empty((size), dtype=np.float32))
167  # Vect.random_host(seed, 'U')
168  v = np.array(Vect)
169 
170  #imax return the index in column major of the maximum absolute value element
171  imaxC = np.abs(v).argmax()
172  imaxG = Vect.aimax()
173 
174  print(v[imaxC], v[imaxG])
175  npt.assert_equal(imaxC, imaxG)
176 
177 

◆ test_double_aimin()

def test_cublas1.test_double_aimin ( )

Definition at line 178 of file test_cublas1.py.

178 def test_double_aimin():
179  Vect = ch.obj_double(c, np.random.randn(size))
180  # Vect = ch.obj_double(c, np.empty((size), dtype=np.float32))
181  # Vect.random_host(seed*2, 'U')
182  v = np.array(Vect)
183 
184  #imax return the index in column major of the minimum obsolute value element
185  iminC = np.abs(v).argmin()
186  iminG = Vect.aimin()
187 
188  print(v[iminC], v[iminG])
189  npt.assert_equal(iminC, iminG)
190 
191 

◆ test_double_asum()

def test_cublas1.test_double_asum ( )

Definition at line 192 of file test_cublas1.py.

192 def test_double_asum():
193  Vect = ch.obj_double(c, np.random.randn(size))
194  # Vect = ch.obj_double(c, np.empty((size), dtype=np.float32))
195  # Vect.random_host(seed*3, 'U')
196  v = np.array(Vect)
197 
198  sumC = np.sum(np.abs(v))
199  sumG = Vect.asum()
200  print(sumC, sumG)
201  npt.assert_almost_equal(sumC, sumG, decimal=2 * dec)
202 
203  # M = np.max(np.abs(sumC))
204  # d = 1
205  # if (M > 0):
206  # d = 10**np.ceil(np.log10(M))
207  # npt.assert_almost_equal(sumC / d, sumG / d, decimal=2*dec)
208 
209 

◆ test_double_axpy()

def test_cublas1.test_double_axpy ( )

Definition at line 268 of file test_cublas1.py.

268 def test_double_axpy():
269  Vect = ch.obj_double(c, np.random.randn(size))
270  # Vect = ch.obj_double(c, np.empty((size), dtype=np.float32))
271  # Vect.random_host(seed*9, 'U')
272  h_Vect = np.array(Vect)
273 
274  alpha = 1.4
275 
276  Vect2 = ch.obj_double(c, np.random.randn(size))
277  # Vect2 = ch.obj_double(c, np.empty((size), dtype=np.float32))
278  # Vect2.random_host(seed*10, 'U')
279  h_Vect2 = np.array(Vect2)
280 
281  Vect.axpy(alpha, Vect2, 1, 1)
282 
283  h_Vect = h_Vect + alpha * h_Vect2
284 
285  npt.assert_almost_equal(h_Vect, np.array(Vect), decimal=2 * dec)
286 
287 

◆ test_double_copy()

def test_cublas1.test_double_copy ( )

Definition at line 257 of file test_cublas1.py.

257 def test_double_copy():
258  Vect = ch.obj_double(c, np.random.randn(size))
259  # Vect = ch.obj_double(c, np.empty((size)))
260  # Vect.random_host(seed*8, 'U')
261 
262  Vect2 = ch.obj_double(c, np.random.randn(size))
263  # Vect2 = ch.obj_double(c, np.empty((size), dtype=np.float32))
264  Vect2.copy(Vect, 1, 1)
265  npt.assert_array_equal(np.array(Vect), np.array(Vect2))
266 
267 

◆ test_double_dot()

def test_cublas1.test_double_dot ( )

Definition at line 288 of file test_cublas1.py.

288 def test_double_dot():
289  Vect = ch.obj_double(c, np.random.randn(size))
290  # Vect = ch.obj_double(c, np.empty((size), dtype=np.float32))
291  # Vect.random_host(seed*11, 'U')
292  h_Vect = np.array(Vect)
293 
294  dotC = np.dot(h_Vect, h_Vect)
295  dotG = Vect.dot(Vect, 1, 1)
296 
297  M = np.max(np.abs(dotC))
298  d = 1
299  if (M > 0):
300  d = 10**np.ceil(np.log10(M))
301  npt.assert_almost_equal(dotC / d, dotG / d, decimal=2 * dec)

◆ test_double_nrm2()

def test_cublas1.test_double_nrm2 ( )

Definition at line 210 of file test_cublas1.py.

210 def test_double_nrm2():
211  Vect = ch.obj_double(c, np.random.randn(size))
212  # Vect = ch.obj_double(c, np.empty((size), dtype=np.float32))
213  # Vect.random_host(seed*4, 'U')
214  v = np.array(Vect)
215 
216  nC = np.linalg.norm(v)
217  nG = Vect.nrm2(1)
218 
219  npt.assert_almost_equal(nC, nG, decimal=2 * dec)
220 
221  # M = np.max(np.abs(nC))
222  # d = 1
223  # if (M > 0):
224  # d = 10**np.ceil(np.log10(M))
225  # npt.assert_almost_equal(nC / d, nG / d, decimal=2*dec)
226 
227 

◆ test_double_scale()

def test_cublas1.test_double_scale ( )

Definition at line 228 of file test_cublas1.py.

228 def test_double_scale():
229  Vect = ch.obj_double(c, np.random.randn(size))
230  # Vect = ch.obj_double(c, np.empty((size), dtype=np.float32))
231  # Vect.random_host(seed*5, 'U')
232  v = np.array(Vect)
233 
234  scale = 1.67
235  sC = v * scale
236  Vect.scale(scale, 1)
237  sG = np.array(Vect)
238  npt.assert_array_almost_equal(sC, sG, decimal=2 * dec)
239 
240 

◆ test_double_swap()

def test_cublas1.test_double_swap ( )

Definition at line 241 of file test_cublas1.py.

241 def test_double_swap():
242  Vect = ch.obj_double(c, np.random.randn(size))
243  # Vect = ch.obj_double(c, np.empty((size), dtype=np.float32))
244  # Vect.random_host(seed*6, 'U')
245  h_Vect = np.array(Vect)
246 
247  Vect2 = ch.obj_double(c, np.random.randn(size))
248  # Vect2 = ch.obj_double(c, np.empty((size), dtype=np.float32))
249  # Vect2.random_host(seed*7, 'U')
250  h_Vect2 = np.array(Vect2)
251 
252  Vect.swap(Vect2, 1, 1)
253  npt.assert_equal(h_Vect2, np.array(Vect))
254  npt.assert_equal(h_Vect, np.array(Vect2))
255 
256 

◆ test_float_aimax()

def test_cublas1.test_float_aimax ( )

Definition at line 24 of file test_cublas1.py.

24 def test_float_aimax():
25  Vect = ch.obj_float(c, np.random.randn(size))
26  # Vect = ch.obj_float(c, np.empty((size), dtype=np.float32))
27  # Vect.random_host(seed, 'U')
28  v = np.array(Vect)
29 
30  #imax return the index in column major of the maximum absolute value element
31  imaxC = np.abs(v).argmax()
32  imaxG = Vect.aimax()
33 
34  print(v[imaxC], v[imaxG])
35  npt.assert_equal(imaxC, imaxG)
36 
37 

◆ test_float_aimin()

def test_cublas1.test_float_aimin ( )

Definition at line 38 of file test_cublas1.py.

38 def test_float_aimin():
39  Vect = ch.obj_float(c, np.random.randn(size))
40  # Vect = ch.obj_float(c, np.empty((size), dtype=np.float32))
41  # Vect.random_host(seed*2, 'U')
42  v = np.array(Vect)
43 
44  #imax return the index in column major of the minimum obsolute value element
45  iminC = np.abs(v).argmin()
46  iminG = Vect.aimin()
47 
48  print(v[iminC], v[iminG])
49  npt.assert_equal(iminC, iminG)
50 
51 

◆ test_float_asum()

def test_cublas1.test_float_asum ( )

Definition at line 52 of file test_cublas1.py.

52 def test_float_asum():
53  Vect = ch.obj_float(c, np.random.randn(size))
54  # Vect = ch.obj_float(c, np.empty((size), dtype=np.float32))
55  # Vect.random_host(seed*3, 'U')
56  v = np.array(Vect)
57 
58  sumC = np.sum(np.abs(v))
59  sumG = Vect.asum()
60  print(sumC, sumG)
61  npt.assert_almost_equal(sumC, sumG, decimal=dec)
62 
63  # M = np.max(np.abs(sumC))
64  # d = 1
65  # if (M > 0):
66  # d = 10**np.ceil(np.log10(M))
67  # npt.assert_almost_equal(sumC / d, sumG / d, decimal=dec)
68 
69 

◆ test_float_axpy()

def test_cublas1.test_float_axpy ( )

Definition at line 128 of file test_cublas1.py.

128 def test_float_axpy():
129  Vect = ch.obj_float(c, np.random.randn(size))
130  # Vect = ch.obj_float(c, np.empty((size), dtype=np.float32))
131  # Vect.random_host(seed*9, 'U')
132  h_Vect = np.array(Vect)
133 
134  alpha = 1.4
135 
136  Vect2 = ch.obj_float(c, np.random.randn(size))
137  # Vect2 = ch.obj_float(c, np.empty((size), dtype=np.float32))
138  # Vect2.random_host(seed*10, 'U')
139  h_Vect2 = np.array(Vect2)
140 
141  Vect.axpy(alpha, Vect2, 1, 1)
142 
143  h_Vect = h_Vect + alpha * h_Vect2
144 
145  npt.assert_almost_equal(h_Vect, np.array(Vect), decimal=dec)
146 
147 

◆ test_float_copy()

def test_cublas1.test_float_copy ( )

Definition at line 117 of file test_cublas1.py.

117 def test_float_copy():
118  Vect = ch.obj_float(c, np.random.randn(size))
119  # Vect = ch.obj_float(c, np.empty((size)))
120  # Vect.random_host(seed*8, 'U')
121 
122  Vect2 = ch.obj_float(c, np.random.randn(size))
123  # Vect2 = ch.obj_float(c, np.empty((size), dtype=np.float32))
124  Vect2.copy(Vect, 1, 1)
125  npt.assert_array_equal(np.array(Vect), np.array(Vect2))
126 
127 

◆ test_float_dot()

def test_cublas1.test_float_dot ( )

Definition at line 148 of file test_cublas1.py.

148 def test_float_dot():
149  Vect = ch.obj_float(c, np.random.randn(size))
150  # Vect = ch.obj_float(c, np.empty((size), dtype=np.float32))
151  # Vect.random_host(seed*11, 'U')
152  h_Vect = np.array(Vect)
153 
154  dotC = np.dot(h_Vect, h_Vect)
155  dotG = Vect.dot(Vect, 1, 1)
156 
157  M = np.max(np.abs(dotC))
158  d = 1
159  if (M > 0):
160  d = 10**np.ceil(np.log10(M))
161  npt.assert_almost_equal(dotC / d, dotG / d, decimal=dec)
162 
163 

◆ test_float_nrm2()

def test_cublas1.test_float_nrm2 ( )

Definition at line 70 of file test_cublas1.py.

70 def test_float_nrm2():
71  Vect = ch.obj_float(c, np.random.randn(size))
72  # Vect = ch.obj_float(c, np.empty((size), dtype=np.float32))
73  # Vect.random_host(seed*4, 'U')
74  v = np.array(Vect)
75 
76  nC = np.linalg.norm(v)
77  nG = Vect.nrm2(1)
78 
79  npt.assert_almost_equal(nC, nG, decimal=dec)
80 
81  # M = np.max(np.abs(nC))
82  # d = 1
83  # if (M > 0):
84  # d = 10**np.ceil(np.log10(M))
85  # npt.assert_almost_equal(nC / d, nG / d, decimal=dec)
86 
87 

◆ test_float_scale()

def test_cublas1.test_float_scale ( )

Definition at line 88 of file test_cublas1.py.

88 def test_float_scale():
89  Vect = ch.obj_float(c, np.random.randn(size))
90  # Vect = ch.obj_float(c, np.empty((size), dtype=np.float32))
91  # Vect.random_host(seed*5, 'U')
92  v = np.array(Vect)
93 
94  scale = 1.67
95  sC = v * scale
96  Vect.scale(scale, 1)
97  sG = np.array(Vect)
98  npt.assert_array_almost_equal(sC, sG, decimal=dec)
99 
100 

◆ test_float_swap()

def test_cublas1.test_float_swap ( )

Definition at line 101 of file test_cublas1.py.

101 def test_float_swap():
102  Vect = ch.obj_float(c, np.random.randn(size))
103  # Vect = ch.obj_float(c, np.empty((size), dtype=np.float32))
104  # Vect.random_host(seed*6, 'U')
105  h_Vect = np.array(Vect)
106 
107  Vect2 = ch.obj_float(c, np.random.randn(size))
108  # Vect2 = ch.obj_float(c, np.empty((size), dtype=np.float32))
109  # Vect2.random_host(seed*7, 'U')
110  h_Vect2 = np.array(Vect2)
111 
112  Vect.swap(Vect2, 1, 1)
113  npt.assert_equal(h_Vect2, np.array(Vect))
114  npt.assert_equal(h_Vect, np.array(Vect2))
115 
116 

Variable Documentation

◆ c

test_cublas1.c = ch.context.get_instance()

Definition at line 14 of file test_cublas1.py.

◆ dec

int test_cublas1.dec = 4

Definition at line 7 of file test_cublas1.py.

◆ prec

int test_cublas1.prec = 10**-dec

Definition at line 8 of file test_cublas1.py.

◆ seed

test_cublas1.seed = np.int32(time.perf_counter() * 1e3)

Definition at line 13 of file test_cublas1.py.

◆ size

int test_cublas1.size = 1024

Definition at line 6 of file test_cublas1.py.