1 /*
2  * Copyright (c) 2011-2021, The OSKAR Developers.
3  * See the LICENSE file at the top-level directory of this distribution.
4  */
5 
6 #include <gtest/gtest.h>
7 
8 #include "interferometer/oskar_jones.h"
9 #include "mem/oskar_mem.h"
10 #include "utility/oskar_get_error_string.h"
11 #include "utility/oskar_timer.h"
12 #include "utility/oskar_vector_types.h"
13 
14 #include <cstdio>
15 #include <cstdlib>
16 #include <cmath>
17 
18 #define CPU  OSKAR_CPU
19 #define GPU  OSKAR_GPU
20 #define CL   OSKAR_CL
21 #define SC   OSKAR_SINGLE_COMPLEX
22 #define SCM  OSKAR_SINGLE_COMPLEX_MATRIX
23 #define DC   OSKAR_DOUBLE_COMPLEX
24 #define DCM  OSKAR_DOUBLE_COMPLEX_MATRIX
25 
check_values(const oskar_Mem * approx,const oskar_Mem * accurate)26 static void check_values(const oskar_Mem* approx, const oskar_Mem* accurate)
27 {
28     int status = 0;
29     double min_rel_error = 0.0, max_rel_error = 0.0;
30     double avg_rel_error = 0.0, std_rel_error = 0.0, tol = 0.0;
31     oskar_mem_evaluate_relative_error(approx, accurate, &min_rel_error,
32             &max_rel_error, &avg_rel_error, &std_rel_error, &status);
33     ASSERT_EQ(0, status) << oskar_get_error_string(status);
34     tol = oskar_mem_is_double(approx) &&
35             oskar_mem_is_double(accurate) ? 1e-10 : 1e-4;
36     EXPECT_LT(max_rel_error, tol) << std::setprecision(5) <<
37             "RELATIVE ERROR" <<
38             " MIN: " << min_rel_error << " MAX: " << max_rel_error <<
39             " AVG: " << avg_rel_error << " STD: " << std_rel_error;
40     tol = oskar_mem_is_double(approx) &&
41             oskar_mem_is_double(accurate) ? 1e-12 : 1e-6;
42     EXPECT_LT(avg_rel_error, tol) << std::setprecision(5) <<
43             "RELATIVE ERROR" <<
44             " MIN: " << min_rel_error << " MAX: " << max_rel_error <<
45             " AVG: " << avg_rel_error << " STD: " << std_rel_error;
46 }
47 
48 static const int sources = 277;
49 static const int stations = 19;
50 
t_join(int out_typeA,int in_type1A,int in_type2A,int out_locA,int in_loc1A,int in_loc2A,int out_typeB,int in_type1B,int in_type2B,int out_locB,int in_loc1B,int in_loc2B,int expectedA,int expectedB)51 static void t_join(int out_typeA, int in_type1A, int in_type2A,
52         int out_locA, int in_loc1A, int in_loc2A,
53         int out_typeB, int in_type1B, int in_type2B,
54         int out_locB, int in_loc1B, int in_loc2B,
55         int expectedA, int expectedB)
56 {
57     int status = 0;
58     oskar_Timer *timerA = 0, *timerB = 0;
59 //    double timeA, timeB;
60     oskar_Jones *in1 = 0, *in2 = 0, *outA = 0, *outB = 0;
61 
62     // Create the timers.
63     timerA = oskar_timer_create(out_locA == OSKAR_GPU ?
64             OSKAR_TIMER_CUDA : OSKAR_TIMER_NATIVE);
65     timerB = oskar_timer_create(out_locB == OSKAR_GPU ?
66             OSKAR_TIMER_CUDA : OSKAR_TIMER_NATIVE);
67 
68     // Create output blocks.
69     outA = oskar_jones_create(out_typeA, out_locA, stations, sources, &status);
70     outB = oskar_jones_create(out_typeB, out_locB, stations, sources, &status);
71 
72     // Run test A.
73     in1 = oskar_jones_create(in_type1A, in_loc1A, stations, sources, &status);
74     in2 = oskar_jones_create(in_type2A, in_loc2A, stations, sources, &status);
75     srand(2);
76     oskar_mem_random_range(oskar_jones_mem(in1), 1.0, 2.0, &status);
77     oskar_mem_random_range(oskar_jones_mem(in2), 1.0, 2.0, &status);
78     ASSERT_EQ(0, status) << oskar_get_error_string(status);
79     oskar_timer_start(timerA);
80     oskar_jones_join(outA, in1, in2, &status);
81 //    timeA = oskar_timer_elapsed(timerA);
82     EXPECT_EQ(expectedA, status);
83     status = 0;
84     oskar_jones_free(in1, &status);
85     oskar_jones_free(in2, &status);
86     ASSERT_EQ(0, status) << oskar_get_error_string(status);
87 
88     // Run test B.
89     in1 = oskar_jones_create(in_type1B, in_loc1B, stations, sources, &status);
90     in2 = oskar_jones_create(in_type2B, in_loc2B, stations, sources, &status);
91     srand(2);
92     oskar_mem_random_range(oskar_jones_mem(in1), 1.0, 2.0, &status);
93     oskar_mem_random_range(oskar_jones_mem(in2), 1.0, 2.0, &status);
94     ASSERT_EQ(0, status) << oskar_get_error_string(status);
95     oskar_timer_start(timerB);
96     oskar_jones_join(outB, in1, in2, &status);
97 //    timeB = oskar_timer_elapsed(timerB);
98     EXPECT_EQ(expectedB, status);
99     status = 0;
100     oskar_jones_free(in1, &status);
101     oskar_jones_free(in2, &status);
102     ASSERT_EQ(0, status) << oskar_get_error_string(status);
103 
104     // Destroy the timers.
105     oskar_timer_free(timerA);
106     oskar_timer_free(timerB);
107 
108     // Compare results.
109     check_values(oskar_jones_mem(outA), oskar_jones_mem(outB));
110 
111     // Free memory.
112     oskar_jones_free(outA, &status);
113     oskar_jones_free(outB, &status);
114     ASSERT_EQ(0, status) << oskar_get_error_string(status);
115 }
116 
117 static
t_join_in_place(int in_type1A,int in_type2A,int in_loc1A,int in_loc2A,int in_type1B,int in_type2B,int in_loc1B,int in_loc2B,int expectedA,int expectedB)118 void t_join_in_place(int in_type1A, int in_type2A, int in_loc1A, int in_loc2A,
119         int in_type1B, int in_type2B, int in_loc1B, int in_loc2B,
120         int expectedA, int expectedB)
121 {
122     int status = 0;
123     oskar_Timer *timerA = 0, *timerB = 0;
124 //    double timeA, timeB;
125     oskar_Jones *in1A = 0, *in2A = 0, *in1B = 0, *in2B = 0;
126 
127     // Create the timers.
128     timerA = oskar_timer_create(in_loc1A == OSKAR_GPU ?
129             OSKAR_TIMER_CUDA : OSKAR_TIMER_NATIVE);
130     timerB = oskar_timer_create(in_loc1B == OSKAR_GPU ?
131             OSKAR_TIMER_CUDA : OSKAR_TIMER_NATIVE);
132 
133     // Run test A.
134     in1A = oskar_jones_create(in_type1A, in_loc1A, stations, sources, &status);
135     in2A = oskar_jones_create(in_type2A, in_loc2A, stations, sources, &status);
136     srand(2);
137     oskar_mem_random_range(oskar_jones_mem(in1A), 1.0, 2.0, &status);
138     oskar_mem_random_range(oskar_jones_mem(in2A), 1.0, 2.0, &status);
139     ASSERT_EQ(0, status) << oskar_get_error_string(status);
140     oskar_timer_start(timerA);
141     oskar_jones_join(in1A, in1A, in2A, &status);
142 //    timeA = oskar_timer_elapsed(timerA);
143     EXPECT_EQ(expectedA, status);
144     status = 0;
145     oskar_jones_free(in2A, &status);
146     ASSERT_EQ(0, status) << oskar_get_error_string(status);
147 
148     // Run test B.
149     in1B = oskar_jones_create(in_type1B, in_loc1B, stations, sources, &status);
150     in2B = oskar_jones_create(in_type2B, in_loc2B, stations, sources, &status);
151     srand(2);
152     oskar_mem_random_range(oskar_jones_mem(in1B), 1.0, 2.0, &status);
153     oskar_mem_random_range(oskar_jones_mem(in2B), 1.0, 2.0, &status);
154     ASSERT_EQ(0, status) << oskar_get_error_string(status);
155     oskar_timer_start(timerB);
156     oskar_jones_join(in1B, in1B, in2B, &status);
157 //    timeB = oskar_timer_elapsed(timerB);
158     EXPECT_EQ(expectedB, status);
159     status = 0;
160     oskar_jones_free(in2B, &status);
161     ASSERT_EQ(0, status) << oskar_get_error_string(status);
162 
163     // Destroy the timers.
164     oskar_timer_free(timerA);
165     oskar_timer_free(timerB);
166 
167     // Compare results.
168     check_values(oskar_jones_mem(in1A), oskar_jones_mem(in1B));
169 
170     // Free memory.
171     oskar_jones_free(in1A, &status);
172     oskar_jones_free(in1B, &status);
173     ASSERT_EQ(0, status) << oskar_get_error_string(status);
174 }
175 
test_ones(int precision,int location)176 static void test_ones(int precision, int location)
177 {
178     oskar_Jones *jones = 0, *temp = 0, *j_ptr = 0;
179     int status = 0, num_stations = 0, num_sources = 0;
180 
181     // Test scalar complex type.
182     jones = oskar_jones_create(precision | OSKAR_COMPLEX, location,
183             stations, sources, &status);
184     ASSERT_EQ(0, status);
185     oskar_mem_set_value_real(oskar_jones_mem(jones), 1.0,
186             0, stations * sources, &status);
187     EXPECT_EQ(0, status);
188     j_ptr = jones;
189 
190     // Copy back to CPU memory if required.
191     if (location != OSKAR_CPU)
192     {
193         temp = oskar_jones_create_copy(jones, OSKAR_CPU, &status);
194         ASSERT_EQ(0, status);
195         j_ptr = temp;
196     }
197 
198     // Check data.
199     num_stations = oskar_jones_num_stations(j_ptr);
200     num_sources  = oskar_jones_num_sources(j_ptr);
201     if (precision == OSKAR_SINGLE)
202     {
203         float2* p = oskar_mem_float2(oskar_jones_mem(j_ptr), &status);
204         for (int st = 0; st < num_stations; ++st)
205         {
206             for (int src = 0, i = 0; src < num_sources; ++src, ++i)
207             {
208                 EXPECT_FLOAT_EQ(p[i].x, 1.0f);
209                 EXPECT_FLOAT_EQ(p[i].y, 0.0f);
210             }
211         }
212     }
213     else
214     {
215         double2* p = oskar_mem_double2(oskar_jones_mem(j_ptr), &status);
216         for (int st = 0; st < num_stations; ++st)
217         {
218             for (int src = 0, i = 0; src < num_sources; ++src, ++i)
219             {
220                 EXPECT_DOUBLE_EQ(p[i].x, 1.0);
221                 EXPECT_DOUBLE_EQ(p[i].y, 0.0);
222             }
223         }
224     }
225 
226     // Free memory.
227     if (location != OSKAR_CPU)
228     {
229         oskar_jones_free(temp, &status);
230     }
231     oskar_jones_free(jones, &status);
232     ASSERT_EQ(0, status);
233 
234     // Test matrix complex type.
235     jones = oskar_jones_create(precision | OSKAR_COMPLEX | OSKAR_MATRIX,
236             location, stations, sources, &status);
237     ASSERT_EQ(0, status);
238     oskar_mem_set_value_real(oskar_jones_mem(jones), 1.0,
239             0, stations * sources, &status);
240     EXPECT_EQ(0, status);
241     j_ptr = jones;
242 
243     // Copy back to CPU memory if required.
244     if (location != OSKAR_CPU)
245     {
246         temp = oskar_jones_create_copy(jones, OSKAR_CPU, &status);
247         ASSERT_EQ(0, status);
248         j_ptr = temp;
249     }
250 
251     // Check data.
252     num_stations = oskar_jones_num_stations(j_ptr);
253     num_sources  = oskar_jones_num_sources(j_ptr);
254     if (precision == OSKAR_SINGLE)
255     {
256         float4c* p = oskar_mem_float4c(oskar_jones_mem(j_ptr), &status);
257         for (int st = 0; st < num_stations; ++st)
258         {
259             for (int src = 0, i = 0; src < num_sources; ++src, ++i)
260             {
261                 EXPECT_FLOAT_EQ(p[i].a.x, 1.0f);
262                 EXPECT_FLOAT_EQ(p[i].a.y, 0.0f);
263                 EXPECT_FLOAT_EQ(p[i].b.x, 0.0f);
264                 EXPECT_FLOAT_EQ(p[i].b.y, 0.0f);
265                 EXPECT_FLOAT_EQ(p[i].c.x, 0.0f);
266                 EXPECT_FLOAT_EQ(p[i].c.y, 0.0f);
267                 EXPECT_FLOAT_EQ(p[i].d.x, 1.0f);
268                 EXPECT_FLOAT_EQ(p[i].d.y, 0.0f);
269             }
270         }
271     }
272     else
273     {
274         double4c* p = oskar_mem_double4c(oskar_jones_mem(j_ptr), &status);
275         for (int st = 0; st < num_stations; ++st)
276         {
277             for (int src = 0, i = 0; src < num_sources; ++src, ++i)
278             {
279                 EXPECT_DOUBLE_EQ(p[i].a.x, 1.0);
280                 EXPECT_DOUBLE_EQ(p[i].a.y, 0.0);
281                 EXPECT_DOUBLE_EQ(p[i].b.x, 0.0);
282                 EXPECT_DOUBLE_EQ(p[i].b.y, 0.0);
283                 EXPECT_DOUBLE_EQ(p[i].c.x, 0.0);
284                 EXPECT_DOUBLE_EQ(p[i].c.y, 0.0);
285                 EXPECT_DOUBLE_EQ(p[i].d.x, 1.0);
286                 EXPECT_DOUBLE_EQ(p[i].d.y, 0.0);
287             }
288         }
289     }
290 
291     // Free memory.
292     if (location != OSKAR_CPU)
293     {
294         oskar_jones_free(temp, &status);
295     }
296     oskar_jones_free(jones, &status);
297     ASSERT_EQ(0, status);
298 }
299 
300 // CPU only. //////////////////////////////////////////////////////////////////
301 
TEST(Jones,join_scal_scal_scal_singleCPU_doubleCPU)302 TEST(Jones, join_scal_scal_scal_singleCPU_doubleCPU)
303 {
304     t_join(SC, SC, SC, CPU, CPU, CPU,
305             DC, DC, DC, CPU, CPU, CPU, 0, 0);
306 }
307 
TEST(Jones,join_matx_scal_scal_singleCPU_doubleCPU)308 TEST(Jones, join_matx_scal_scal_singleCPU_doubleCPU)
309 {
310     t_join(SCM, SC, SC, CPU, CPU, CPU,
311             DCM, DC, DC, CPU, CPU, CPU, 0, 0);
312 }
313 
TEST(Jones,join_matx_scal_matx_singleCPU_doubleCPU)314 TEST(Jones, join_matx_scal_matx_singleCPU_doubleCPU)
315 {
316     t_join(SCM, SC, SCM, CPU, CPU, CPU,
317             DCM, DC, DCM, CPU, CPU, CPU, 0, 0);
318 }
319 
TEST(Jones,join_matx_matx_matx_singleCPU_doubleCPU)320 TEST(Jones, join_matx_matx_matx_singleCPU_doubleCPU)
321 {
322     t_join(SCM, SCM, SCM, CPU, CPU, CPU,
323             DCM, DCM, DCM, CPU, CPU, CPU, 0, 0);
324 }
325 
TEST(Jones,join_in_place_scal_scal_scal_singleCPU_doubleCPU)326 TEST(Jones, join_in_place_scal_scal_scal_singleCPU_doubleCPU)
327 {
328     t_join_in_place(SC, SC, CPU, CPU,
329             DC, DC, CPU, CPU, 0, 0);
330 }
331 
TEST(Jones,join_in_place_matx_matx_scal_singleCPU_doubleCPU)332 TEST(Jones, join_in_place_matx_matx_scal_singleCPU_doubleCPU)
333 {
334     t_join_in_place(SCM, SC, CPU, CPU,
335             DCM, DC, CPU, CPU, 0, 0);
336 }
337 
TEST(Jones,join_in_place_matx_matx_matx_singleCPU_doubleCPU)338 TEST(Jones, join_in_place_matx_matx_matx_singleCPU_doubleCPU)
339 {
340     t_join_in_place(SCM, SCM, CPU, CPU,
341             DCM, DCM, CPU, CPU, 0, 0);
342 }
343 
344 #ifdef OSKAR_HAVE_OPENCL
345 
346 // OpenCL only. ///////////////////////////////////////////////////////////////
347 
TEST(Jones,join_scal_scal_scal_singleCL_doubleCL)348 TEST(Jones, join_scal_scal_scal_singleCL_doubleCL)
349 {
350     t_join(SC, SC, SC, CL, CL, CL,
351             DC, DC, DC, CL, CL, CL, 0, 0);
352 }
353 
TEST(Jones,join_matx_scal_scal_singleCL_doubleCL)354 TEST(Jones, join_matx_scal_scal_singleCL_doubleCL)
355 {
356     t_join(SCM, SC, SC, CL, CL, CL,
357             DCM, DC, DC, CL, CL, CL, 0, 0);
358 }
359 
TEST(Jones,join_matx_scal_matx_singleCL_doubleCL)360 TEST(Jones, join_matx_scal_matx_singleCL_doubleCL)
361 {
362     t_join(SCM, SC, SCM, CL, CL, CL,
363             DCM, DC, DCM, CL, CL, CL, 0, 0);
364 }
365 
TEST(Jones,join_matx_matx_matx_singleCL_doubleCL)366 TEST(Jones, join_matx_matx_matx_singleCL_doubleCL)
367 {
368     t_join(SCM, SCM, SCM, CL, CL, CL,
369             DCM, DCM, DCM, CL, CL, CL, 0, 0);
370 }
371 
TEST(Jones,join_in_place_scal_scal_scal_singleCL_doubleCL)372 TEST(Jones, join_in_place_scal_scal_scal_singleCL_doubleCL)
373 {
374     t_join_in_place(SC, SC, CL, CL,
375             DC, DC, CL, CL, 0, 0);
376 }
377 
TEST(Jones,join_in_place_matx_matx_scal_singleCL_doubleCL)378 TEST(Jones, join_in_place_matx_matx_scal_singleCL_doubleCL)
379 {
380     t_join_in_place(SCM, SC, CL, CL,
381             DCM, DC, CL, CL, 0, 0);
382 }
383 
TEST(Jones,join_in_place_matx_matx_matx_singleCL_doubleCL)384 TEST(Jones, join_in_place_matx_matx_matx_singleCL_doubleCL)
385 {
386     t_join_in_place(SCM, SCM, CL, CL,
387             DCM, DCM, CL, CL, 0, 0);
388 }
389 
390 
391 // Compare CPU and OpenCL. ////////////////////////////////////////////////////
392 
393 // Single CL, single CPU.
TEST(Jones,join_scal_scal_scal_singleCL_singleCPU)394 TEST(Jones, join_scal_scal_scal_singleCL_singleCPU)
395 {
396     t_join(SC, SC, SC, CL, CL, CL,
397             SC, SC, SC, CPU, CPU, CPU, 0, 0);
398 }
399 
TEST(Jones,join_matx_scal_scal_singleCL_singleCPU)400 TEST(Jones, join_matx_scal_scal_singleCL_singleCPU)
401 {
402     t_join(SCM, SC, SC, CL, CL, CL,
403             SCM, SC, SC, CPU, CPU, CPU, 0, 0);
404 }
405 
TEST(Jones,join_matx_scal_matx_singleCL_singleCPU)406 TEST(Jones, join_matx_scal_matx_singleCL_singleCPU)
407 {
408     t_join(SCM, SC, SCM, CL, CL, CL,
409             SCM, SC, SCM, CPU, CPU, CPU, 0, 0);
410 }
411 
TEST(Jones,join_matx_matx_matx_singleCL_singleCPU)412 TEST(Jones, join_matx_matx_matx_singleCL_singleCPU)
413 {
414     t_join(SCM, SCM, SCM, CL, CL, CL,
415             SCM, SCM, SCM, CPU, CPU, CPU, 0, 0);
416 }
417 
TEST(Jones,join_in_place_scal_scal_scal_singleCL_singleCPU)418 TEST(Jones, join_in_place_scal_scal_scal_singleCL_singleCPU)
419 {
420     t_join_in_place(SC, SC, CL, CL,
421             SC, SC, CPU, CPU, 0, 0);
422 }
423 
TEST(Jones,join_in_place_matx_matx_scal_singleCL_singleCPU)424 TEST(Jones, join_in_place_matx_matx_scal_singleCL_singleCPU)
425 {
426     t_join_in_place(SCM, SC, CL, CL,
427             SCM, SC, CPU, CPU, 0, 0);
428 }
429 
TEST(Jones,join_in_place_matx_matx_matx_singleCL_singleCPU)430 TEST(Jones, join_in_place_matx_matx_matx_singleCL_singleCPU)
431 {
432     t_join_in_place(SCM, SCM, CL, CL,
433             SCM, SCM, CPU, CPU, 0, 0);
434 }
435 
436 // Double CL, double CPU.
TEST(Jones,join_scal_scal_scal_doubleCL_doubleCPU)437 TEST(Jones, join_scal_scal_scal_doubleCL_doubleCPU)
438 {
439     t_join(DC, DC, DC, CL, CL, CL,
440             DC, DC, DC, CPU, CPU, CPU, 0, 0);
441 }
442 
TEST(Jones,join_matx_scal_scal_doubleCL_doubleCPU)443 TEST(Jones, join_matx_scal_scal_doubleCL_doubleCPU)
444 {
445     t_join(DCM, DC, DC, CL, CL, CL,
446             DCM, DC, DC, CPU, CPU, CPU, 0, 0);
447 }
448 
TEST(Jones,join_matx_scal_matx_doubleCL_doubleCPU)449 TEST(Jones, join_matx_scal_matx_doubleCL_doubleCPU)
450 {
451     t_join(DCM, DC, DCM, CL, CL, CL,
452             DCM, DC, DCM, CPU, CPU, CPU, 0, 0);
453 }
454 
TEST(Jones,join_matx_matx_matx_doubleCL_doubleCPU)455 TEST(Jones, join_matx_matx_matx_doubleCL_doubleCPU)
456 {
457     t_join(DCM, DCM, DCM, CL, CL, CL,
458             DCM, DCM, DCM, CPU, CPU, CPU, 0, 0);
459 }
460 
TEST(Jones,join_in_place_scal_scal_scal_doubleCL_doubleCPU)461 TEST(Jones, join_in_place_scal_scal_scal_doubleCL_doubleCPU)
462 {
463     t_join_in_place(DC, DC, CL, CL,
464             DC, DC, CPU, CPU, 0, 0);
465 }
466 
TEST(Jones,join_in_place_matx_matx_scal_doubleCL_doubleCPU)467 TEST(Jones, join_in_place_matx_matx_scal_doubleCL_doubleCPU)
468 {
469     t_join_in_place(DCM, DC, CL, CL,
470             DCM, DC, CPU, CPU, 0, 0);
471 }
472 
TEST(Jones,join_in_place_matx_matx_matx_doubleCL_doubleCPU)473 TEST(Jones, join_in_place_matx_matx_matx_doubleCL_doubleCPU)
474 {
475     t_join_in_place(DCM, DCM, CL, CL,
476             DCM, DCM, CPU, CPU, 0, 0);
477 }
478 
479 // Single CL, double CPU.
TEST(Jones,join_scal_scal_scal_singleCL_doubleCPU)480 TEST(Jones, join_scal_scal_scal_singleCL_doubleCPU)
481 {
482     t_join(SC, SC, SC, CL, CL, CL,
483             DC, DC, DC, CPU, CPU, CPU, 0, 0);
484 }
485 
TEST(Jones,join_matx_scal_scal_singleCL_doubleCPU)486 TEST(Jones, join_matx_scal_scal_singleCL_doubleCPU)
487 {
488     t_join(SCM, SC, SC, CL, CL, CL,
489             DCM, DC, DC, CPU, CPU, CPU, 0, 0);
490 }
491 
TEST(Jones,join_matx_scal_matx_singleCL_doubleCPU)492 TEST(Jones, join_matx_scal_matx_singleCL_doubleCPU)
493 {
494     t_join(SCM, SC, SCM, CL, CL, CL,
495             DCM, DC, DCM, CPU, CPU, CPU, 0, 0);
496 }
497 
TEST(Jones,join_matx_matx_matx_singleCL_doubleCPU)498 TEST(Jones, join_matx_matx_matx_singleCL_doubleCPU)
499 {
500     t_join(SCM, SCM, SCM, CL, CL, CL,
501             DCM, DCM, DCM, CPU, CPU, CPU, 0, 0);
502 }
503 
TEST(Jones,join_in_place_scal_scal_scal_singleCL_doubleCPU)504 TEST(Jones, join_in_place_scal_scal_scal_singleCL_doubleCPU)
505 {
506     t_join_in_place(SC, SC, CL, CL,
507             DC, DC, CPU, CPU, 0, 0);
508 }
509 
TEST(Jones,join_in_place_matx_matx_scal_singleCL_doubleCPU)510 TEST(Jones, join_in_place_matx_matx_scal_singleCL_doubleCPU)
511 {
512     t_join_in_place(SCM, SC, CL, CL,
513             DCM, DC, CPU, CPU, 0, 0);
514 }
515 
TEST(Jones,join_in_place_matx_matx_matx_singleCL_doubleCPU)516 TEST(Jones, join_in_place_matx_matx_matx_singleCL_doubleCPU)
517 {
518     t_join_in_place(SCM, SCM, CL, CL,
519             DCM, DCM, CPU, CPU, 0, 0);
520 }
521 
522 // Single CPU, double CL.
TEST(Jones,join_scal_scal_scal_singleCPU_doubleCL)523 TEST(Jones, join_scal_scal_scal_singleCPU_doubleCL)
524 {
525     t_join(SC, SC, SC, CPU, CPU, CPU,
526             DC, DC, DC, CL, CL, CL, 0, 0);
527 }
528 
TEST(Jones,join_matx_scal_scal_singleCPU_doubleCL)529 TEST(Jones, join_matx_scal_scal_singleCPU_doubleCL)
530 {
531     t_join(SCM, SC, SC, CPU, CPU, CPU,
532             DCM, DC, DC, CL, CL, CL, 0, 0);
533 }
534 
TEST(Jones,join_matx_scal_matx_singleCPU_doubleCL)535 TEST(Jones, join_matx_scal_matx_singleCPU_doubleCL)
536 {
537     t_join(SCM, SC, SCM, CPU, CPU, CPU,
538             DCM, DC, DCM, CL, CL, CL, 0, 0);
539 }
540 
TEST(Jones,join_matx_matx_matx_singleCPU_doubleCL)541 TEST(Jones, join_matx_matx_matx_singleCPU_doubleCL)
542 {
543     t_join(SCM, SCM, SCM, CPU, CPU, CPU,
544             DCM, DCM, DCM, CL, CL, CL, 0, 0);
545 }
546 
TEST(Jones,join_in_place_scal_scal_scal_singleCPU_doubleCL)547 TEST(Jones, join_in_place_scal_scal_scal_singleCPU_doubleCL)
548 {
549     t_join_in_place(SC, SC, CPU, CPU,
550             DC, DC, CL, CL, 0, 0);
551 }
552 
TEST(Jones,join_in_place_matx_matx_scal_singleCPU_doubleCL)553 TEST(Jones, join_in_place_matx_matx_scal_singleCPU_doubleCL)
554 {
555     t_join_in_place(SCM, SC, CPU, CPU,
556             DCM, DC, CL, CL, 0, 0);
557 }
558 
TEST(Jones,join_in_place_matx_matx_matx_singleCPU_doubleCL)559 TEST(Jones, join_in_place_matx_matx_matx_singleCPU_doubleCL)
560 {
561     t_join_in_place(SCM, SCM, CPU, CPU,
562             DCM, DCM, CL, CL, 0, 0);
563 }
564 
565 #endif
566 
567 #ifdef OSKAR_HAVE_CUDA
568 
569 // GPU only. //////////////////////////////////////////////////////////////////
570 
TEST(Jones,join_scal_scal_scal_singleGPU_doubleGPU)571 TEST(Jones, join_scal_scal_scal_singleGPU_doubleGPU)
572 {
573     t_join(SC, SC, SC, GPU, GPU, GPU,
574             DC, DC, DC, GPU, GPU, GPU, 0, 0);
575 }
576 
TEST(Jones,join_matx_scal_scal_singleGPU_doubleGPU)577 TEST(Jones, join_matx_scal_scal_singleGPU_doubleGPU)
578 {
579     t_join(SCM, SC, SC, GPU, GPU, GPU,
580             DCM, DC, DC, GPU, GPU, GPU, 0, 0);
581 }
582 
TEST(Jones,join_matx_scal_matx_singleGPU_doubleGPU)583 TEST(Jones, join_matx_scal_matx_singleGPU_doubleGPU)
584 {
585     t_join(SCM, SC, SCM, GPU, GPU, GPU,
586             DCM, DC, DCM, GPU, GPU, GPU, 0, 0);
587 }
588 
TEST(Jones,join_matx_matx_matx_singleGPU_doubleGPU)589 TEST(Jones, join_matx_matx_matx_singleGPU_doubleGPU)
590 {
591     t_join(SCM, SCM, SCM, GPU, GPU, GPU,
592             DCM, DCM, DCM, GPU, GPU, GPU, 0, 0);
593 }
594 
TEST(Jones,join_in_place_scal_scal_scal_singleGPU_doubleGPU)595 TEST(Jones, join_in_place_scal_scal_scal_singleGPU_doubleGPU)
596 {
597     t_join_in_place(SC, SC, GPU, GPU,
598             DC, DC, GPU, GPU, 0, 0);
599 }
600 
TEST(Jones,join_in_place_matx_matx_scal_singleGPU_doubleGPU)601 TEST(Jones, join_in_place_matx_matx_scal_singleGPU_doubleGPU)
602 {
603     t_join_in_place(SCM, SC, GPU, GPU,
604             DCM, DC, GPU, GPU, 0, 0);
605 }
606 
TEST(Jones,join_in_place_matx_matx_matx_singleGPU_doubleGPU)607 TEST(Jones, join_in_place_matx_matx_matx_singleGPU_doubleGPU)
608 {
609     t_join_in_place(SCM, SCM, GPU, GPU,
610             DCM, DCM, GPU, GPU, 0, 0);
611 }
612 
613 
614 // Compare CPU and GPU. ///////////////////////////////////////////////////////
615 
616 // Single GPU, single CPU.
TEST(Jones,join_scal_scal_scal_singleGPU_singleCPU)617 TEST(Jones, join_scal_scal_scal_singleGPU_singleCPU)
618 {
619     t_join(SC, SC, SC, GPU, GPU, GPU,
620             SC, SC, SC, CPU, CPU, CPU, 0, 0);
621 }
622 
TEST(Jones,join_matx_scal_scal_singleGPU_singleCPU)623 TEST(Jones, join_matx_scal_scal_singleGPU_singleCPU)
624 {
625     t_join(SCM, SC, SC, GPU, GPU, GPU,
626             SCM, SC, SC, CPU, CPU, CPU, 0, 0);
627 }
628 
TEST(Jones,join_matx_scal_matx_singleGPU_singleCPU)629 TEST(Jones, join_matx_scal_matx_singleGPU_singleCPU)
630 {
631     t_join(SCM, SC, SCM, GPU, GPU, GPU,
632             SCM, SC, SCM, CPU, CPU, CPU, 0, 0);
633 }
634 
TEST(Jones,join_matx_matx_matx_singleGPU_singleCPU)635 TEST(Jones, join_matx_matx_matx_singleGPU_singleCPU)
636 {
637     t_join(SCM, SCM, SCM, GPU, GPU, GPU,
638             SCM, SCM, SCM, CPU, CPU, CPU, 0, 0);
639 }
640 
TEST(Jones,join_in_place_scal_scal_scal_singleGPU_singleCPU)641 TEST(Jones, join_in_place_scal_scal_scal_singleGPU_singleCPU)
642 {
643     t_join_in_place(SC, SC, GPU, GPU,
644             SC, SC, CPU, CPU, 0, 0);
645 }
646 
TEST(Jones,join_in_place_matx_matx_scal_singleGPU_singleCPU)647 TEST(Jones, join_in_place_matx_matx_scal_singleGPU_singleCPU)
648 {
649     t_join_in_place(SCM, SC, GPU, GPU,
650             SCM, SC, CPU, CPU, 0, 0);
651 }
652 
TEST(Jones,join_in_place_matx_matx_matx_singleGPU_singleCPU)653 TEST(Jones, join_in_place_matx_matx_matx_singleGPU_singleCPU)
654 {
655     t_join_in_place(SCM, SCM, GPU, GPU,
656             SCM, SCM, CPU, CPU, 0, 0);
657 }
658 
659 // Double GPU, double CPU.
TEST(Jones,join_scal_scal_scal_doubleGPU_doubleCPU)660 TEST(Jones, join_scal_scal_scal_doubleGPU_doubleCPU)
661 {
662     t_join(DC, DC, DC, GPU, GPU, GPU,
663             DC, DC, DC, CPU, CPU, CPU, 0, 0);
664 }
665 
TEST(Jones,join_matx_scal_scal_doubleGPU_doubleCPU)666 TEST(Jones, join_matx_scal_scal_doubleGPU_doubleCPU)
667 {
668     t_join(DCM, DC, DC, GPU, GPU, GPU,
669             DCM, DC, DC, CPU, CPU, CPU, 0, 0);
670 }
671 
TEST(Jones,join_matx_scal_matx_doubleGPU_doubleCPU)672 TEST(Jones, join_matx_scal_matx_doubleGPU_doubleCPU)
673 {
674     t_join(DCM, DC, DCM, GPU, GPU, GPU,
675             DCM, DC, DCM, CPU, CPU, CPU, 0, 0);
676 }
677 
TEST(Jones,join_matx_matx_matx_doubleGPU_doubleCPU)678 TEST(Jones, join_matx_matx_matx_doubleGPU_doubleCPU)
679 {
680     t_join(DCM, DCM, DCM, GPU, GPU, GPU,
681             DCM, DCM, DCM, CPU, CPU, CPU, 0, 0);
682 }
683 
TEST(Jones,join_in_place_scal_scal_scal_doubleGPU_doubleCPU)684 TEST(Jones, join_in_place_scal_scal_scal_doubleGPU_doubleCPU)
685 {
686     t_join_in_place(DC, DC, GPU, GPU,
687             DC, DC, CPU, CPU, 0, 0);
688 }
689 
TEST(Jones,join_in_place_matx_matx_scal_doubleGPU_doubleCPU)690 TEST(Jones, join_in_place_matx_matx_scal_doubleGPU_doubleCPU)
691 {
692     t_join_in_place(DCM, DC, GPU, GPU,
693             DCM, DC, CPU, CPU, 0, 0);
694 }
695 
TEST(Jones,join_in_place_matx_matx_matx_doubleGPU_doubleCPU)696 TEST(Jones, join_in_place_matx_matx_matx_doubleGPU_doubleCPU)
697 {
698     t_join_in_place(DCM, DCM, GPU, GPU,
699             DCM, DCM, CPU, CPU, 0, 0);
700 }
701 
702 // Single GPU, double CPU.
TEST(Jones,join_scal_scal_scal_singleGPU_doubleCPU)703 TEST(Jones, join_scal_scal_scal_singleGPU_doubleCPU)
704 {
705     t_join(SC, SC, SC, GPU, GPU, GPU,
706             DC, DC, DC, CPU, CPU, CPU, 0, 0);
707 }
708 
TEST(Jones,join_matx_scal_scal_singleGPU_doubleCPU)709 TEST(Jones, join_matx_scal_scal_singleGPU_doubleCPU)
710 {
711     t_join(SCM, SC, SC, GPU, GPU, GPU,
712             DCM, DC, DC, CPU, CPU, CPU, 0, 0);
713 }
714 
TEST(Jones,join_matx_scal_matx_singleGPU_doubleCPU)715 TEST(Jones, join_matx_scal_matx_singleGPU_doubleCPU)
716 {
717     t_join(SCM, SC, SCM, GPU, GPU, GPU,
718             DCM, DC, DCM, CPU, CPU, CPU, 0, 0);
719 }
720 
TEST(Jones,join_matx_matx_matx_singleGPU_doubleCPU)721 TEST(Jones, join_matx_matx_matx_singleGPU_doubleCPU)
722 {
723     t_join(SCM, SCM, SCM, GPU, GPU, GPU,
724             DCM, DCM, DCM, CPU, CPU, CPU, 0, 0);
725 }
726 
TEST(Jones,join_in_place_scal_scal_scal_singleGPU_doubleCPU)727 TEST(Jones, join_in_place_scal_scal_scal_singleGPU_doubleCPU)
728 {
729     t_join_in_place(SC, SC, GPU, GPU,
730             DC, DC, CPU, CPU, 0, 0);
731 }
732 
TEST(Jones,join_in_place_matx_matx_scal_singleGPU_doubleCPU)733 TEST(Jones, join_in_place_matx_matx_scal_singleGPU_doubleCPU)
734 {
735     t_join_in_place(SCM, SC, GPU, GPU,
736             DCM, DC, CPU, CPU, 0, 0);
737 }
738 
TEST(Jones,join_in_place_matx_matx_matx_singleGPU_doubleCPU)739 TEST(Jones, join_in_place_matx_matx_matx_singleGPU_doubleCPU)
740 {
741     t_join_in_place(SCM, SCM, GPU, GPU,
742             DCM, DCM, CPU, CPU, 0, 0);
743 }
744 
745 // Single CPU, double GPU.
TEST(Jones,join_scal_scal_scal_singleCPU_doubleGPU)746 TEST(Jones, join_scal_scal_scal_singleCPU_doubleGPU)
747 {
748     t_join(SC, SC, SC, CPU, CPU, CPU,
749             DC, DC, DC, GPU, GPU, GPU, 0, 0);
750 }
751 
TEST(Jones,join_matx_scal_scal_singleCPU_doubleGPU)752 TEST(Jones, join_matx_scal_scal_singleCPU_doubleGPU)
753 {
754     t_join(SCM, SC, SC, CPU, CPU, CPU,
755             DCM, DC, DC, GPU, GPU, GPU, 0, 0);
756 }
757 
TEST(Jones,join_matx_scal_matx_singleCPU_doubleGPU)758 TEST(Jones, join_matx_scal_matx_singleCPU_doubleGPU)
759 {
760     t_join(SCM, SC, SCM, CPU, CPU, CPU,
761             DCM, DC, DCM, GPU, GPU, GPU, 0, 0);
762 }
763 
TEST(Jones,join_matx_matx_matx_singleCPU_doubleGPU)764 TEST(Jones, join_matx_matx_matx_singleCPU_doubleGPU)
765 {
766     t_join(SCM, SCM, SCM, CPU, CPU, CPU,
767             DCM, DCM, DCM, GPU, GPU, GPU, 0, 0);
768 }
769 
TEST(Jones,join_in_place_scal_scal_scal_singleCPU_doubleGPU)770 TEST(Jones, join_in_place_scal_scal_scal_singleCPU_doubleGPU)
771 {
772     t_join_in_place(SC, SC, CPU, CPU,
773             DC, DC, GPU, GPU, 0, 0);
774 }
775 
TEST(Jones,join_in_place_matx_matx_scal_singleCPU_doubleGPU)776 TEST(Jones, join_in_place_matx_matx_scal_singleCPU_doubleGPU)
777 {
778     t_join_in_place(SCM, SC, CPU, CPU,
779             DCM, DC, GPU, GPU, 0, 0);
780 }
781 
TEST(Jones,join_in_place_matx_matx_matx_singleCPU_doubleGPU)782 TEST(Jones, join_in_place_matx_matx_matx_singleCPU_doubleGPU)
783 {
784     t_join_in_place(SCM, SCM, CPU, CPU,
785             DCM, DCM, GPU, GPU, 0, 0);
786 }
787 
788 
789 // Mixed CPU and GPU. /////////////////////////////////////////////////////////
790 
791 // Single mixed GPU/CPU, single CPU.
TEST(Jones,join_scal_scal_scal_singleMix_singleCPU)792 TEST(Jones, join_scal_scal_scal_singleMix_singleCPU)
793 {
794     t_join(SC, SC, SC, GPU, CPU, GPU,
795             SC, SC, SC, CPU, CPU, CPU, 0, 0);
796 }
797 
TEST(Jones,join_matx_scal_scal_singleMix_singleCPU)798 TEST(Jones, join_matx_scal_scal_singleMix_singleCPU)
799 {
800     t_join(SCM, SC, SC, GPU, CPU, GPU,
801             SCM, SC, SC, CPU, CPU, CPU, 0, 0);
802 }
803 
TEST(Jones,join_matx_scal_matx_singleMix_singleCPU)804 TEST(Jones, join_matx_scal_matx_singleMix_singleCPU)
805 {
806     t_join(SCM, SC, SCM, GPU, CPU, GPU,
807             SCM, SC, SCM, CPU, CPU, CPU, 0, 0);
808 }
809 
TEST(Jones,join_matx_matx_matx_singleMix_singleCPU)810 TEST(Jones, join_matx_matx_matx_singleMix_singleCPU)
811 {
812     t_join(SCM, SCM, SCM, GPU, CPU, GPU,
813             SCM, SCM, SCM, CPU, CPU, CPU, 0, 0);
814 }
815 
TEST(Jones,join_in_place_scal_scal_scal_singleMix_singleCPU)816 TEST(Jones, join_in_place_scal_scal_scal_singleMix_singleCPU)
817 {
818     t_join_in_place(SC, SC, GPU, CPU,
819             SC, SC, CPU, CPU, 0, 0);
820 }
821 
TEST(Jones,join_in_place_matx_matx_scal_singleMix_singleCPU)822 TEST(Jones, join_in_place_matx_matx_scal_singleMix_singleCPU)
823 {
824     t_join_in_place(SCM, SC, GPU, CPU,
825             SCM, SC, CPU, CPU, 0, 0);
826 }
827 
TEST(Jones,join_in_place_matx_matx_matx_singleMix_singleCPU)828 TEST(Jones, join_in_place_matx_matx_matx_singleMix_singleCPU)
829 {
830     t_join_in_place(SCM, SCM, GPU, CPU,
831             SCM, SCM, CPU, CPU, 0, 0);
832 }
833 
834 // Double mixed GPU/CPU, double CPU.
TEST(Jones,join_scal_scal_scal_doubleMix_doubleCPU)835 TEST(Jones, join_scal_scal_scal_doubleMix_doubleCPU)
836 {
837     t_join(DC, DC, DC, GPU, CPU, GPU,
838             DC, DC, DC, CPU, CPU, CPU, 0, 0);
839 }
840 
TEST(Jones,join_matx_scal_scal_doubleMix_doubleCPU)841 TEST(Jones, join_matx_scal_scal_doubleMix_doubleCPU)
842 {
843     t_join(DCM, DC, DC, GPU, CPU, GPU,
844             DCM, DC, DC, CPU, CPU, CPU, 0, 0);
845 }
846 
TEST(Jones,join_matx_scal_matx_doubleMix_doubleCPU)847 TEST(Jones, join_matx_scal_matx_doubleMix_doubleCPU)
848 {
849     t_join(DCM, DC, DCM, GPU, CPU, GPU,
850             DCM, DC, DCM, CPU, CPU, CPU, 0, 0);
851 }
852 
TEST(Jones,join_matx_matx_matx_doubleMix_doubleCPU)853 TEST(Jones, join_matx_matx_matx_doubleMix_doubleCPU)
854 {
855     t_join(DCM, DCM, DCM, GPU, CPU, GPU,
856             DCM, DCM, DCM, CPU, CPU, CPU, 0, 0);
857 }
858 
TEST(Jones,join_in_place_scal_scal_scal_doubleMix_doubleCPU)859 TEST(Jones, join_in_place_scal_scal_scal_doubleMix_doubleCPU)
860 {
861     t_join_in_place(DC, DC, GPU, CPU,
862             DC, DC, CPU, CPU, 0, 0);
863 }
864 
TEST(Jones,join_in_place_matx_matx_scal_doubleMix_doubleCPU)865 TEST(Jones, join_in_place_matx_matx_scal_doubleMix_doubleCPU)
866 {
867     t_join_in_place(DCM, DC, GPU, CPU,
868             DCM, DC, CPU, CPU, 0, 0);
869 }
870 
TEST(Jones,join_in_place_matx_matx_matx_doubleMix_doubleCPU)871 TEST(Jones, join_in_place_matx_matx_matx_doubleMix_doubleCPU)
872 {
873     t_join_in_place(DCM, DCM, GPU, CPU,
874             DCM, DCM, CPU, CPU, 0, 0);
875 }
876 
TEST(Jones,set_ones_singleGPU)877 TEST(Jones, set_ones_singleGPU)
878 {
879     test_ones(OSKAR_SINGLE, OSKAR_GPU);
880 }
881 
TEST(Jones,set_ones_doubleGPU)882 TEST(Jones, set_ones_doubleGPU)
883 {
884     test_ones(OSKAR_DOUBLE, OSKAR_GPU);
885 }
886 
887 #endif /* OSKAR_HAVE_CUDA */
888 
TEST(Jones,set_ones_singleCPU)889 TEST(Jones, set_ones_singleCPU)
890 {
891     test_ones(OSKAR_SINGLE, OSKAR_CPU);
892 }
893 
TEST(Jones,set_ones_doubleCPU)894 TEST(Jones, set_ones_doubleCPU)
895 {
896     test_ones(OSKAR_DOUBLE, OSKAR_CPU);
897 }
898