1 #ifdef COMPILATION// -*-indent-tabs-mode:t;c-basic-offset:4;tab-width:4;-*-
2 $CXX $0 -o $0x -lcudart -lcublas -lboost_unit_test_framework `pkg-config --libs blas`&&$0x&&rm $0x;exit
3 #endif
4 // © Alfredo A. Correa 2019-2020
5
6 #define BOOST_TEST_MODULE "C++ Unit Tests for Multi BLAS herk"
7 #define BOOST_TEST_DYN_LINK
8 #include<boost/test/unit_test.hpp>
9
10 //#include "../../../adaptors/cuda.hpp" // multi::cuda ns
11
12 //#include "../../../adaptors/blas/cuda.hpp"
13 #include "../../../adaptors/blas/gemm.hpp"
14 #include "../../../adaptors/blas/herk.hpp"
15
16 #include "../../../array.hpp"
17
18 namespace multi = boost::multi;
19 //namespace cuda = multi::cuda;
20
21
BOOST_AUTO_TEST_CASE(multi_blas_herk)22 BOOST_AUTO_TEST_CASE(multi_blas_herk){
23 namespace blas = multi::blas;
24 using complex = std::complex<double>; constexpr complex I{0, 1};
25
26 multi::array<complex, 2> const a = {
27 { 1. + 3.*I, 3.- 2.*I, 4.+ 1.*I},
28 { 9. + 1.*I, 7.- 8.*I, 1.- 3.*I}
29 };
30 {
31 multi::array<complex, 2> c({2, 2}, 9999.);
32 blas::herk(a, c);
33 BOOST_REQUIRE( c[1][0] == complex(50., -49.) );
34 BOOST_REQUIRE( c[0][1] == complex(50., +49.) );
35
36 multi::array<complex, 2> const c_copy = blas::herk(1., a);
37 BOOST_REQUIRE( c == c_copy );
38
39 BOOST_REQUIRE( +blas::gemm(1., a, blas::H(a)) == blas::herk(a) );
40 }
41 }
42
43 //BOOST_AUTO_TEST_CASE(multi_blas_cuda_herk_complex){
44 // namespace blas = multi::blas;
45 // multi::array<complex, 2> const a = {
46 // { 1. + 3.*I, 3.- 2.*I, 4.+ 1.*I},
47 // { 9. + 1.*I, 7.- 8.*I, 1.- 3.*I}
48 // };
49 // {
50 // cuda::array<complex, 2> const acu = a;
51 // BOOST_REQUIRE(a == acu);
52
53 // cuda::array<complex, 2> ccu({2, 2}, 9999.);
54 // blas::herk(acu, ccu);
55 // BOOST_REQUIRE( ccu[1][0] == complex(50., -49.) );
56 // BOOST_REQUIRE( ccu[0][1] == complex(50., +49.) );
57
58 // cuda::array<complex, 2> const ccu_copy = blas::herk(1., acu);
59 // BOOST_REQUIRE( blas::herk(1., acu) == ccu );
60 // }
61 // {
62 // cuda::managed::array<complex, 2> const amcu = a; BOOST_REQUIRE(a == amcu);
63 // cuda::managed::array<complex, 2> cmcu({2, 2}, 9999.);
64
65 // blas::herk(1., amcu, cmcu);
66 // BOOST_REQUIRE( cmcu[1][0] == complex(50., -49.) );
67 // BOOST_REQUIRE( cmcu[0][1] == complex(50., +49.) );
68
69 // cuda::managed::array<complex, 2> const cmcu_copy = blas::herk(1., amcu);
70 // BOOST_REQUIRE( cmcu_copy == cmcu );
71 // }
72 // {
73 // multi::array<complex, 2> c({3, 3}, 9999.);
74 // blas::herk(1., blas::H(a), c);
75 // BOOST_REQUIRE( c[2][1] == complex(41, +2) );
76 // BOOST_REQUIRE( c[1][2] == complex(41, -2) );
77
78 // multi::array<complex, 2> const c_copy = blas::herk(1., blas::H(a));
79 // BOOST_REQUIRE( c_copy == c );
80 // }
81 // {
82 // cuda::array<complex, 2> const acu = a;
83 // BOOST_REQUIRE(a == acu);
84
85 // cuda::array<complex, 2> ccu({3, 3}, 9999.);
86
87 // blas::herk(1., blas::H(acu), ccu);
88 // BOOST_REQUIRE( ccu[2][1] == complex(41, +2) );
89 // BOOST_REQUIRE( ccu[1][2] == complex(41, -2) );
90
91 // cuda::array<complex, 2> const ccu_copy = blas::herk(1., blas::H(acu));
92 // BOOST_REQUIRE( ccu_copy == ccu );
93 // }
94 // {
95 // cuda::managed::array<complex, 2> const acu = a; BOOST_REQUIRE(a == acu);
96 // cuda::managed::array<complex, 2> ccu({3, 3}, 9999.);
97
98 // blas::herk(1., blas::H(acu), ccu);
99 // BOOST_REQUIRE( ccu[2][1] == complex(41, +2) );
100 // BOOST_REQUIRE( ccu[1][2] == complex(41, -2) );
101
102 // cuda::managed::array<complex, 2> const ccu_copy = blas::herk(1., blas::H(acu));
103 // BOOST_REQUIRE( ccu_copy == ccu );
104 // }
105 //}
106
107 //BOOST_AUTO_TEST_CASE(multi_blas_cuda_herk_n_complex){
108 // namespace blas = multi::blas;
109 // multi::array<complex, 2> const a = {
110 // { 1. + 3.*I, 3.- 2.*I, 4.+ 1.*I},
111 // { 9. + 1.*I, 7.- 8.*I, 1.- 3.*I}
112 // };
113 // blas::context ctxt;
114 // {
115 // multi::array<complex, 2> c({2, 2}, 9999.);
116 // blas::herk_n(ctxt, blas::filling::upper, 1., a.begin(), a.size(), 0., c.begin());
117 // BOOST_TEST_REQUIRE( c[0][1] == complex(50., +49.) );
118 // BOOST_TEST_REQUIRE( c[1][0] == 9999. );
119 // }
120 // {
121 // multi::array<complex, 2> c({2, 2}, 9999.);
122 // blas::herk_n(ctxt, blas::filling::lower, 1., a.begin(), a.size(), 0., c.begin());
123 // BOOST_TEST_REQUIRE( c[0][1] == 9999. );
124 // BOOST_TEST_REQUIRE( c[1][0] == complex(50., -49.) );
125 // }
126 // {
127 // multi::array<complex, 2> c({2, 2}, 9999.);
128 // blas::herk_n(ctxt, blas::filling::lower, 1., a.begin(), a.size(), 0., c.begin());
129 // blas::herk_n(ctxt, blas::filling::upper, 1., a.begin(), a.size(), 0., c.begin());
130 // BOOST_TEST_REQUIRE( c[0][1] == complex(50., +49.) );
131 // BOOST_TEST_REQUIRE( c[1][0] == complex(50., -49.) );
132 // }
133 // {
134 // multi::array<complex, 2> c({3, 3}, 9999.);
135 // blas::herk_n(ctxt, blas::filling::lower, 1., blas::H(a).begin(), blas::H(a).size(), 0., c.begin());
136 // BOOST_TEST_REQUIRE( c[1][2] == 9999. );
137 // BOOST_TEST_REQUIRE( c[2][1] == complex(41., +2.) );
138 // }
139 // {
140 // multi::array<complex, 2> c({3, 3}, 9999.);
141 // blas::herk_n(ctxt, blas::filling::upper, 1., blas::H(a).begin(), blas::H(a).size(), 0., c.begin());
142 // BOOST_TEST_REQUIRE( c[1][2] == complex(41., -2.) );
143 // BOOST_TEST_REQUIRE( c[2][1] == 9999. );
144 // }
145 // {
146 // multi::array<complex, 2> c({3, 3}, 9999.);
147 // blas::herk_n(ctxt, blas::filling::lower, 1., blas::H(a).begin(), blas::H(a).size(), 0., c.begin());
148 // blas::herk_n(ctxt, blas::filling::upper, 1., blas::H(a).begin(), blas::H(a).size(), 0., c.begin());
149 // BOOST_TEST_REQUIRE( c[1][2] == complex(41., -2.) );
150 // BOOST_TEST_REQUIRE( c[2][1] == complex(41., +2.) );
151 // }
152 // {
153 // multi::array<complex, 2> c({3, 3}, 9999.);
154 // blas::herk_n(ctxt, 1., blas::H(a).begin(), blas::H(a).size(), c.begin());
155 // BOOST_TEST_REQUIRE( c[1][2] == complex(41., -2.) );
156 // BOOST_TEST_REQUIRE( c[2][1] == complex(41., +2.) );
157 // }
158 //}
159
160 //BOOST_AUTO_TEST_CASE(multi_blas_cuda_herk_row){
161 // namespace blas = multi::blas;
162 // auto const a = []{
163 // multi::array<complex, 2> ret({1, 100});
164 // std::generate(begin(ret[0]), end(ret[0]), [c=complex{1, 2}]()mutable{return c+=2.;});
165 // return ret;
166 // }();
167 // BOOST_REQUIRE( size(a) == 1 );
168 // {
169 // BOOST_REQUIRE( +blas::gemm(1., a, blas::H(a)) == blas::herk(a) );
170
171 // cuda::array<complex, 2> const agpu = a;
172 // BOOST_REQUIRE( blas::gemm(agpu, blas::H(agpu)) == blas::herk(agpu) );
173
174 // cuda::managed::array<complex, 2> const amng = a;
175 // BOOST_REQUIRE( blas::gemm(amng, blas::H(amng)) == blas::herk(amng) );
176 // }
177 //}
178
179 //#if 1
180 //BOOST_AUTO_TEST_CASE(multi_blas_cuda_herk_real){
181 // namespace blas = multi::blas;
182 // multi::array<double, 2> const a = {
183 // { 1., 3., 4.},
184 // { 9., 7., 1.}
185 // };
186 // {
187 // multi::array<double, 2> c({2, 2}, 9999);
188 // blas::herk(1., a, c);
189 // BOOST_REQUIRE( c[1][0] == 34 );
190 // BOOST_REQUIRE( c[0][1] == 34 );
191
192 // // multi::array<double, 2> const c_copy = blas::herk(1., a);
193 // // BOOST_REQUIRE( c == c_copy );
194 // }
195 // {
196 // cuda::array<double, 2> acu = a;
197 // BOOST_REQUIRE(a == acu);
198
199 // cuda::array<double, 2> ccu({2, 2}, 9999.);
200
201 // // blas::herk(acu, ccu);
202 // // BOOST_REQUIRE( ccu[1][0] == 34 );
203 // // BOOST_REQUIRE( ccu[0][1] == 34 );
204
205 // // cuda::array<double, 2> const ccu_copy = blas::herk(1., acu);
206 // // BOOST_REQUIRE( herk(1., acu) == ccu );
207 // }
208
209 //}
210 //#endif
211
212 #if 0
213 {
214 cuda::array<double, 2> const acu = a; BOOST_REQUIRE(a == acu);
215 // cuda::array<double, 2> ccu({2, 2}, 9999.);
216 using multi::blas::herk;
217 cuda::array<double, 2> ccu = herk(acu);
218 BOOST_REQUIRE( ccu[1][0] == 34 );
219 BOOST_REQUIRE( ccu[0][1] == 34 );
220
221 cuda::array<double, 2> const ccu_copy = herk(1., acu);
222 BOOST_REQUIRE( herk(1., acu) == ccu );
223 }
224 {
225 cuda::managed::array<double, 2> const amcu = a; BOOST_REQUIRE(a == amcu);
226 cuda::managed::array<double, 2> cmcu({2, 2}, 9999.);
227 using multi::blas::herk;
228 herk(1., amcu, cmcu);
229 BOOST_REQUIRE( cmcu[1][0] == 34 );
230 BOOST_REQUIRE( cmcu[0][1] == 34 );
231
232 cuda::managed::array<double, 2> const cmcu_copy = herk(1., amcu);
233 BOOST_REQUIRE( cmcu_copy == cmcu );
234 }
235 if(0){
236 multi::array<double, 2> c({3, 3}, 9999.);
237 using multi::blas::herk;
238 using multi::blas::hermitized;
239 herk(1., hermitized(a), c);
240 BOOST_REQUIRE( c[2][1] == 19 );
241 BOOST_REQUIRE( c[1][2] == 19 );
242
243 multi::array<double, 2> const c_copy = herk(1., hermitized(a));
244 BOOST_REQUIRE( c_copy == c );
245 }
246 if(0){
247 cuda::array<double, 2> const acu = a; BOOST_REQUIRE(acu == a);
248 cuda::array<double, 2> ccu({3, 3}, 9999.);
249 using multi::blas::herk;
250 using multi::blas::hermitized;
251 herk(1., hermitized(acu), ccu);
252 BOOST_REQUIRE( ccu[2][1] == 19 );
253 BOOST_REQUIRE( ccu[1][2] == 19 );
254
255 cuda::array<double, 2> const c_copy = herk(1., hermitized(a));
256 BOOST_REQUIRE( c_copy == ccu );
257 }
258 if(0){
259 cuda::managed::array<double, 2> const amcu = a; BOOST_REQUIRE(amcu == a);
260 cuda::managed::array<double, 2> cmcu({3, 3}, 9999.);
261 using multi::blas::herk;
262 using multi::blas::hermitized;
263 herk(1., hermitized(amcu), cmcu);
264 BOOST_REQUIRE( cmcu[2][1] == 19 );
265 BOOST_REQUIRE( cmcu[1][2] == 19 );
266
267 cuda::managed::array<double, 2> const c_copy = herk(1., hermitized(a));
268 BOOST_REQUIRE( c_copy == cmcu );
269 }
270 }
271 #endif
272
273