forked from opencv/opencv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharithm.cpp
More file actions
1760 lines (1456 loc) · 71.9 KB
/
arithm.cpp
File metadata and controls
1760 lines (1456 loc) · 71.9 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
// Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
// Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// @Authors
// Niko Li, newlife20080214@gmail.com
// Jia Haipeng, jiahaipeng95@gmail.com
// Shengen Yan, yanshengen@gmail.com
// Jiang Liyuan, jlyuan001.good@163.com
// Rock Li, Rock.Li@amd.com
// Zailong Wu, bullet@yeah.net
// Peng Xiao, pengxiao@outlook.com
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "precomp.hpp"
#include "opencl_kernels.hpp"
using namespace cv;
using namespace cv::ocl;
static std::vector<uchar> scalarToVector(const cv::Scalar & sc, int depth, int ocn, int cn)
{
CV_Assert(ocn == cn || (ocn == 4 && cn == 3));
static const int sizeMap[] = { sizeof(uchar), sizeof(char), sizeof(ushort),
sizeof(short), sizeof(int), sizeof(float), sizeof(double) };
int elemSize1 = sizeMap[depth];
int bufSize = elemSize1 * ocn;
std::vector<uchar> _buf(bufSize);
uchar * buf = &_buf[0];
scalarToRawData(sc, buf, CV_MAKE_TYPE(depth, cn));
memset(buf + elemSize1 * cn, 0, (ocn - cn) * elemSize1);
return _buf;
}
//////////////////////////////////////////////////////////////////////////////
/////////////// add subtract multiply divide min max /////////////////////////
//////////////////////////////////////////////////////////////////////////////
enum { ADD = 0, SUB, MUL, DIV, ABS, ABS_DIFF, MIN, MAX };
static void arithmetic_run_generic(const oclMat &src1, const oclMat &src2, const Scalar & scalar, const oclMat & mask,
oclMat &dst, int op_type, bool use_scalar = false)
{
Context *clCxt = src1.clCxt;
bool hasDouble = clCxt->supportsFeature(FEATURE_CL_DOUBLE);
if (!hasDouble && (src1.depth() == CV_64F || src2.depth() == CV_64F || dst.depth() == CV_64F))
{
CV_Error(CV_OpenCLDoubleNotSupported, "Selected device doesn't support double");
return;
}
CV_Assert(src2.empty() || (!src2.empty() && src1.type() == src2.type() && src1.size() == src2.size()));
CV_Assert(mask.empty() || (!mask.empty() && mask.type() == CV_8UC1 && mask.size() == src1.size()));
CV_Assert(op_type >= ADD && op_type <= MAX);
dst.create(src1.size(), src1.type());
int oclChannels = src1.oclchannels(), depth = src1.depth();
int src1step1 = src1.step / src1.elemSize(), src1offset1 = src1.offset / src1.elemSize();
int src2step1 = src2.step / src2.elemSize(), src2offset1 = src2.offset / src2.elemSize();
int maskstep1 = mask.step, maskoffset1 = mask.offset / mask.elemSize();
int dststep1 = dst.step / dst.elemSize(), dstoffset1 = dst.offset / dst.elemSize();
std::vector<uchar> m;
#ifdef ANDROID
size_t localThreads[3] = { 16, 10, 1 };
#else
size_t localThreads[3] = { 16, 16, 1 };
#endif
size_t globalThreads[3] = { (size_t)dst.cols, (size_t)dst.rows, 1 };
std::string kernelName = "arithm_binary_op";
const char * const typeMap[] = { "uchar", "char", "ushort", "short", "int", "float", "double" };
const char * const WTypeMap[] = { "short", "short", "int", "int", "int", "float", "double" };
const char * const funcMap[] = { "FUNC_ADD", "FUNC_SUB", "FUNC_MUL", "FUNC_DIV", "FUNC_ABS", "FUNC_ABS_DIFF", "FUNC_MIN", "FUNC_MAX" };
const char * const channelMap[] = { "", "", "2", "4", "4" };
bool haveScalar = use_scalar || src2.empty();
int WDepth = depth;
if (haveScalar)
WDepth = hasDouble && WDepth == CV_64F ? CV_64F : CV_32F;
if (op_type == DIV)
WDepth = hasDouble ? CV_64F : CV_32F;
else if (op_type == MUL)
WDepth = hasDouble && (depth == CV_32S || depth == CV_64F) ? CV_64F : CV_32F;
std::string buildOptions = format("-D T=%s%s -D WT=%s%s -D convertToT=convert_%s%s%s -D %s "
"-D convertToWT=convert_%s%s",
typeMap[depth], channelMap[oclChannels],
WTypeMap[WDepth], channelMap[oclChannels],
typeMap[depth], channelMap[oclChannels], (depth >= CV_32F ? "" : (depth == CV_32S ? "_rte" : "_sat_rte")),
funcMap[op_type], WTypeMap[WDepth], channelMap[oclChannels]);
vector<pair<size_t , const void *> > args;
args.push_back( make_pair( sizeof(cl_mem), (void *)&src1.data ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src1step1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src1offset1 ));
if (!src2.empty())
{
args.push_back( make_pair( sizeof(cl_mem), (void *)&src2.data ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src2step1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src2offset1 ));
kernelName += "_mat";
if (haveScalar)
buildOptions += " -D HAVE_SCALAR";
}
if (haveScalar)
{
const int WDepthMap[] = { CV_16S, CV_16S, CV_32S, CV_32S, CV_32S, CV_32F, CV_64F };
m = scalarToVector(scalar, WDepthMap[WDepth], oclChannels, src1.channels());
args.push_back( make_pair( m.size(), (void *)&m[0]));
kernelName += "_scalar";
}
if (!mask.empty())
{
args.push_back( make_pair( sizeof(cl_mem), (void *)&mask.data ));
args.push_back( make_pair( sizeof(cl_int), (void *)&maskstep1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&maskoffset1 ));
kernelName += "_mask";
}
args.push_back( make_pair( sizeof(cl_mem), (void *)&dst.data ));
args.push_back( make_pair( sizeof(cl_int), (void *)&dststep1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&dstoffset1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src1.cols ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src1.rows ));
openCLExecuteKernel(clCxt, mask.empty() ?
(!src2.empty() ? &arithm_add : &arithm_add_scalar) :
(!src2.empty() ? &arithm_add_mask : &arithm_add_scalar_mask),
kernelName, globalThreads, localThreads,
args, -1, -1, buildOptions.c_str());
}
void cv::ocl::add(const oclMat &src1, const oclMat &src2, oclMat &dst, const oclMat &mask)
{
arithmetic_run_generic(src1, src2, Scalar(), mask, dst, ADD);
}
void cv::ocl::add(const oclMat &src1, const Scalar &src2, oclMat &dst, const oclMat &mask)
{
arithmetic_run_generic(src1, oclMat(), src2, mask, dst, ADD);
}
void cv::ocl::subtract(const oclMat &src1, const oclMat &src2, oclMat &dst, const oclMat &mask)
{
arithmetic_run_generic(src1, src2, Scalar(), mask, dst, SUB);
}
void cv::ocl::subtract(const oclMat &src1, const Scalar &src2, oclMat &dst, const oclMat &mask)
{
arithmetic_run_generic(src1, oclMat(), src2, mask, dst, SUB);
}
void cv::ocl::multiply(const oclMat &src1, const oclMat &src2, oclMat &dst, double scalar)
{
const bool use_scalar = !(std::abs(scalar - 1.0) < std::numeric_limits<double>::epsilon());
arithmetic_run_generic(src1, src2, Scalar::all(scalar), oclMat(), dst, MUL, use_scalar);
}
void cv::ocl::multiply(double scalar, const oclMat &src, oclMat &dst)
{
arithmetic_run_generic(src, oclMat(), Scalar::all(scalar), oclMat(), dst, MUL);
}
void cv::ocl::divide(const oclMat &src1, const oclMat &src2, oclMat &dst, double scalar)
{
const bool use_scalar = !(std::abs(scalar - 1.0) < std::numeric_limits<double>::epsilon());
arithmetic_run_generic(src1, src2, Scalar::all(scalar), oclMat(), dst, DIV, use_scalar);
}
void cv::ocl::divide(double scalar, const oclMat &src, oclMat &dst)
{
arithmetic_run_generic(src, oclMat(), Scalar::all(scalar), oclMat(), dst, DIV);
}
void cv::ocl::min(const oclMat &src1, const oclMat &src2, oclMat &dst)
{
arithmetic_run_generic(src1, src2, Scalar::all(0), oclMat(), dst, MIN);
}
void cv::ocl::max(const oclMat &src1, const oclMat &src2, oclMat &dst)
{
arithmetic_run_generic(src1, src2, Scalar::all(0), oclMat(), dst, MAX);
}
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////Abs, Absdiff ////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
void cv::ocl::abs(const oclMat &src, oclMat &dst)
{
// explicitly uses use_scalar (even if zero) so that the correct kernel is used
arithmetic_run_generic(src, oclMat(), Scalar(), oclMat(), dst, ABS, true);
}
void cv::ocl::absdiff(const oclMat &src1, const oclMat &src2, oclMat &dst)
{
arithmetic_run_generic(src1, src2, Scalar(), oclMat(), dst, ABS_DIFF);
}
void cv::ocl::absdiff(const oclMat &src1, const Scalar &src2, oclMat &dst)
{
arithmetic_run_generic(src1, oclMat(), src2, oclMat(), dst, ABS_DIFF);
}
//////////////////////////////////////////////////////////////////////////////
///////////////////////////////// compare ///////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
static void compare_run(const oclMat &src1, const oclMat &src2, oclMat &dst, int cmpOp,
string kernelName, const cv::ocl::ProgramEntry* source)
{
dst.create(src1.size(), CV_8UC1);
int depth = src1.depth();
size_t localThreads[3] = { 64, 4, 1 };
size_t globalThreads[3] = { (size_t)dst.cols, (size_t)dst.rows, 1 };
int src1step1 = src1.step1(), src1offset1 = src1.offset / src1.elemSize1();
int src2step1 = src2.step1(), src2offset1 = src2.offset / src2.elemSize1();
int dststep1 = dst.step1(), dstoffset1 = dst.offset / dst.elemSize1();
const char * const typeMap[] = { "uchar", "char", "ushort", "short", "int", "float", "double" };
const char * operationMap[] = { "==", ">", ">=", "<", "<=", "!=" };
std::string buildOptions = format("-D T=%s -D Operation=%s", typeMap[depth], operationMap[cmpOp]);
vector<pair<size_t , const void *> > args;
args.push_back( make_pair( sizeof(cl_mem), (void *)&src1.data ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src1step1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src1offset1 ));
args.push_back( make_pair( sizeof(cl_mem), (void *)&src2.data ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src2step1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src2offset1 ));
args.push_back( make_pair( sizeof(cl_mem), (void *)&dst.data ));
args.push_back( make_pair( sizeof(cl_int), (void *)&dststep1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&dstoffset1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src1.cols ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src1.rows ));
openCLExecuteKernel(src1.clCxt, source, kernelName, globalThreads, localThreads,
args, -1, -1, buildOptions.c_str());
}
void cv::ocl::compare(const oclMat &src1, const oclMat &src2, oclMat &dst , int cmpOp)
{
if (!src1.clCxt->supportsFeature(FEATURE_CL_DOUBLE) && src1.depth() == CV_64F)
{
CV_Error(CV_OpenCLDoubleNotSupported, "Selected device doesn't support double");
return;
}
CV_Assert(src1.type() == src2.type() && src1.channels() == 1);
CV_Assert(cmpOp >= CMP_EQ && cmpOp <= CMP_NE);
compare_run(src1, src2, dst, cmpOp, "arithm_compare", &arithm_compare);
}
//////////////////////////////////////////////////////////////////////////////
////////////////////////////////// sum //////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
enum { SUM = 0, ABS_SUM, SQR_SUM };
static void arithmetic_sum_buffer_run(const oclMat &src, cl_mem &dst, int groupnum, int type, int ddepth, int vlen)
{
int vElemSize = vlen * src.elemSize();
int src_offset = src.offset / vElemSize, src_step = src.step / vElemSize;
int src_cols = src.cols / vlen, total = src.size().area() / vlen;
vlen *= src.oclchannels();
const char * const typeMap[] = { "uchar", "char", "ushort", "short", "int", "float", "double" };
const char * const funcMap[] = { "FUNC_SUM", "FUNC_ABS_SUM", "FUNC_SQR_SUM" };
const char * const channelMap[] = { " ", " ", "2", "4", "4", "", "", "", "8" };
string buildOptions = format("-D srcT=%s%s -D dstT=%s%s -D convertToDstT=convert_%s%s -D %s",
typeMap[src.depth()], channelMap[vlen], typeMap[ddepth],
channelMap[vlen], typeMap[ddepth], channelMap[vlen], funcMap[type]);
vector<pair<size_t , const void *> > args;
args.push_back( make_pair( sizeof(cl_mem) , (void *)&src.data));
args.push_back( make_pair( sizeof(cl_int) , (void *)&src_step ));
args.push_back( make_pair( sizeof(cl_int) , (void *)&src_offset ));
args.push_back( make_pair( sizeof(cl_int) , (void *)&src_cols ));
args.push_back( make_pair( sizeof(cl_int) , (void *)&total ));
args.push_back( make_pair( sizeof(cl_int) , (void *)&groupnum ));
args.push_back( make_pair( sizeof(cl_mem) , (void *)&dst ));
size_t globalThreads[3] = { (size_t)groupnum * 256, 1, 1 };
#ifdef ANDROID
openCLExecuteKernel(src.clCxt, &arithm_sum, "arithm_op_sum", globalThreads, NULL,
args, -1, -1, buildOptions.c_str());
#else
size_t localThreads[3] = { 256, 1, 1 };
openCLExecuteKernel(src.clCxt, &arithm_sum, "arithm_op_sum", globalThreads, localThreads,
args, -1, -1, buildOptions.c_str());
#endif
}
template <typename T>
Scalar arithmetic_sum(const oclMat &src, int type, int ddepth)
{
CV_Assert(src.step % src.elemSize() == 0);
size_t groupnum = src.clCxt->getDeviceInfo().maxComputeUnits;
CV_Assert(groupnum != 0);
int vlen = 8 / src.channels(), vElemSize = vlen * src.elemSize1();
while (src.offset % vElemSize != 0 || src.step % vElemSize != 0 || src.cols % vlen != 0)
vlen >>= 1, vElemSize >>= 1;
int dbsize = groupnum * src.oclchannels() * vlen;
Context *clCxt = src.clCxt;
AutoBuffer<T> _buf(dbsize);
T *p = (T*)_buf;
memset(p, 0, dbsize * sizeof(T));
cl_mem dstBuffer = openCLCreateBuffer(clCxt, CL_MEM_WRITE_ONLY, dbsize * sizeof(T));
arithmetic_sum_buffer_run(src, dstBuffer, groupnum, type, ddepth, vlen);
openCLReadBuffer(clCxt, dstBuffer, (void *)p, dbsize * sizeof(T));
openCLFree(dstBuffer);
Scalar s = Scalar::all(0.0);
for (int i = 0; i < dbsize; )
for (int j = 0; j < src.oclchannels(); j++, i++)
s.val[j] += p[i];
return s;
}
typedef Scalar (*sumFunc)(const oclMat &src, int type, int ddepth);
Scalar cv::ocl::sum(const oclMat &src)
{
if (!src.clCxt->supportsFeature(FEATURE_CL_DOUBLE) && src.depth() == CV_64F)
{
CV_Error(CV_OpenCLDoubleNotSupported, "Selected device doesn't support double");
return Scalar::all(0);
}
static sumFunc functab[3] =
{
arithmetic_sum<int>,
arithmetic_sum<float>,
arithmetic_sum<double>
};
int ddepth = std::max(src.depth(), CV_32S);
sumFunc func = functab[ddepth - CV_32S];
return func(src, SUM, ddepth);
}
Scalar cv::ocl::absSum(const oclMat &src)
{
int sdepth = src.depth();
if (!src.clCxt->supportsFeature(FEATURE_CL_DOUBLE) && sdepth == CV_64F)
{
CV_Error(CV_OpenCLDoubleNotSupported, "Selected device doesn't support double");
return cv::Scalar::all(0);
}
if (sdepth == CV_8U || sdepth == CV_16U)
return sum(src);
static sumFunc functab[3] =
{
arithmetic_sum<int>,
arithmetic_sum<float>,
arithmetic_sum<double>
};
int ddepth = std::max(sdepth, CV_32S);
sumFunc func = functab[ddepth - CV_32S];
return func(src, ABS_SUM, ddepth);
}
Scalar cv::ocl::sqrSum(const oclMat &src)
{
if (!src.clCxt->supportsFeature(FEATURE_CL_DOUBLE) && src.depth() == CV_64F)
{
CV_Error(CV_OpenCLDoubleNotSupported, "Selected device doesn't support double");
return cv::Scalar::all(0);
}
static sumFunc functab[3] =
{
arithmetic_sum<int>,
arithmetic_sum<float>,
arithmetic_sum<double>
};
int ddepth = std::max(src.depth(), CV_32S);
sumFunc func = functab[ddepth - CV_32S];
return func(src, SQR_SUM, ddepth);
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////// meanStdDev //////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
void cv::ocl::meanStdDev(const oclMat &src, Scalar &mean, Scalar &stddev)
{
if (src.depth() == CV_64F && !src.clCxt->supportsFeature(FEATURE_CL_DOUBLE))
{
CV_Error(CV_OpenCLDoubleNotSupported, "Selected device doesn't support double");
return;
}
double total = 1.0 / src.size().area();
mean = sum(src);
stddev = sqrSum(src);
for (int i = 0; i < 4; ++i)
{
mean[i] *= total;
stddev[i] = std::sqrt(std::max(stddev[i] * total - mean.val[i] * mean.val[i] , 0.));
}
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////// minMax /////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
template <typename T, typename WT>
static void arithmetic_minMax_run(const oclMat &src, const oclMat & mask, cl_mem &dst, int vlen, int groupnum)
{
const char * const typeMap[] = { "uchar", "char", "ushort", "short", "int", "float", "double" };
const char * const channelMap[] = { " ", " ", "2", "4", "4", "", "", "", "8" };
ostringstream stream;
stream << "-D T=" << typeMap[src.depth()] << channelMap[vlen];
if (numeric_limits<T>::is_integer)
{
stream << " -D MAX_VAL=" << (WT)numeric_limits<T>::max();
stream << " -D MIN_VAL=" << (WT)numeric_limits<T>::min();
}
else
stream << " -D DEPTH_" << src.depth();
stream << " -D vlen=" << vlen;
std::string buildOptions = stream.str();
int vElemSize = src.elemSize1() * vlen, src_cols = src.cols / vlen;
int src_step = src.step / vElemSize, src_offset = src.offset / vElemSize;
int mask_step = mask.step / vlen, mask_offset = mask.offset / vlen;
int total = src.size().area() / vlen;
vector<pair<size_t , const void *> > args;
args.push_back( make_pair( sizeof(cl_mem) , (void *)&src.data));
args.push_back( make_pair( sizeof(cl_int) , (void *)&src_step ));
args.push_back( make_pair( sizeof(cl_int) , (void *)&src_offset ));
args.push_back( make_pair( sizeof(cl_int) , (void *)&src.rows ));
args.push_back( make_pair( sizeof(cl_int) , (void *)&src_cols ));
args.push_back( make_pair( sizeof(cl_int) , (void *)&total));
args.push_back( make_pair( sizeof(cl_int) , (void *)&groupnum));
args.push_back( make_pair( sizeof(cl_mem) , (void *)&dst));
if (!mask.empty())
{
args.push_back( make_pair( sizeof(cl_mem) , (void *)&mask.data ));
args.push_back( make_pair( sizeof(cl_int) , (void *)&mask_step ));
args.push_back( make_pair( sizeof(cl_int) , (void *)&mask_offset ));
buildOptions += " -D WITH_MASK";
}
size_t globalThreads[3] = { (size_t)groupnum * 256, 1, 1 };
size_t localThreads[3] = { 256, 1, 1 };
// kernel use fixed grid size, replace lt on NULL is impossible without kernel changes
openCLExecuteKernel(src.clCxt, &arithm_minMax, "arithm_op_minMax", globalThreads, localThreads,
args, -1, -1, buildOptions.c_str());
}
template <typename T, typename WT>
void arithmetic_minMax(const oclMat &src, double *minVal, double *maxVal, const oclMat &mask)
{
size_t groupnum = src.clCxt->getDeviceInfo().maxComputeUnits;
CV_Assert(groupnum != 0);
int vlen = mask.empty() ? 8 : 1, vElemSize = vlen * src.elemSize1();
while (src.offset % vElemSize != 0 || src.step % vElemSize != 0 || src.cols % vlen != 0)
{
vlen >>= 1;
vElemSize >>= 1;
}
int dbsize = groupnum * 2 * vElemSize;
oclMat buf;
ensureSizeIsEnough(1, dbsize, CV_8UC1, buf);
cl_mem buf_data = reinterpret_cast<cl_mem>(buf.data);
arithmetic_minMax_run<T, WT>(src, mask, buf_data, vlen, groupnum);
Mat matbuf = Mat(buf);
T *p = matbuf.ptr<T>();
if (minVal != NULL)
{
*minVal = std::numeric_limits<double>::max();
for (int i = 0, end = vlen * (int)groupnum; i < end; i++)
*minVal = *minVal < p[i] ? *minVal : p[i];
}
if (maxVal != NULL)
{
*maxVal = -std::numeric_limits<double>::max();
for (int i = vlen * (int)groupnum, end = i << 1; i < end; i++)
*maxVal = *maxVal > p[i] ? *maxVal : p[i];
}
}
typedef void (*minMaxFunc)(const oclMat &src, double *minVal, double *maxVal, const oclMat &mask);
void cv::ocl::minMax(const oclMat &src, double *minVal, double *maxVal, const oclMat &mask)
{
CV_Assert(src.channels() == 1);
CV_Assert(src.size() == mask.size() || mask.empty());
CV_Assert(src.step % src.elemSize1() == 0);
if (minVal == NULL && maxVal == NULL)
return;
if (!src.clCxt->supportsFeature(FEATURE_CL_DOUBLE) && src.depth() == CV_64F)
{
CV_Error(CV_OpenCLDoubleNotSupported, "Selected device doesn't support double");
return;
}
static minMaxFunc functab[] =
{
arithmetic_minMax<uchar, int>,
arithmetic_minMax<char, int>,
arithmetic_minMax<ushort, int>,
arithmetic_minMax<short, int>,
arithmetic_minMax<int, int>,
arithmetic_minMax<float, float>,
arithmetic_minMax<double, double>,
0
};
minMaxFunc func = functab[src.depth()];
CV_Assert(func != 0);
func(src, minVal, maxVal, mask);
}
//////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// norm /////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
double cv::ocl::norm(const oclMat &src1, int normType)
{
CV_Assert((normType & NORM_RELATIVE) == 0);
return norm(src1, oclMat(), normType);
}
static void arithm_absdiff_nonsaturate_run(const oclMat & src1, const oclMat & src2, oclMat & diff, int ntype)
{
Context *clCxt = src1.clCxt;
if (!clCxt->supportsFeature(FEATURE_CL_DOUBLE) && src1.depth() == CV_64F)
{
CV_Error(CV_OpenCLDoubleNotSupported, "Selected device doesn't support double");
return;
}
CV_Assert(src1.step % src1.elemSize() == 0 && (src2.empty() || src2.step % src2.elemSize() == 0));
if (src2.empty() && (src1.depth() == CV_8U || src1.depth() == CV_16U))
{
src1.convertTo(diff, CV_32S);
return;
}
int ddepth = std::max(src1.depth(), CV_32S);
if (ntype == NORM_L2)
ddepth = std::max<int>(CV_32F, ddepth);
diff.create(src1.size(), CV_MAKE_TYPE(ddepth, src1.channels()));
CV_Assert(diff.step % diff.elemSize() == 0);
int oclChannels = src1.oclchannels(), sdepth = src1.depth();
int src1step1 = src1.step / src1.elemSize(), src1offset1 = src1.offset / src1.elemSize();
int src2step1 = src2.step / src2.elemSize(), src2offset1 = src2.offset / src2.elemSize();
int diffstep1 = diff.step / diff.elemSize(), diffoffset1 = diff.offset / diff.elemSize();
string kernelName = "arithm_absdiff_nonsaturate";
#ifdef ANDROID
size_t localThreads[3] = { 16, 10, 1 };
#else
size_t localThreads[3] = { 16, 16, 1 };
#endif
size_t globalThreads[3] = { (size_t)diff.cols, (size_t)diff.rows, 1 };
const char * const typeMap[] = { "uchar", "char", "ushort", "short", "int", "float", "double" };
const char * const channelMap[] = { "", "", "2", "4", "4" };
std::string buildOptions = format("-D srcT=%s%s -D dstT=%s%s -D convertToDstT=convert_%s%s",
typeMap[sdepth], channelMap[oclChannels],
typeMap[ddepth], channelMap[oclChannels],
typeMap[ddepth], channelMap[oclChannels]);
vector<pair<size_t , const void *> > args;
args.push_back( make_pair( sizeof(cl_mem), (void *)&src1.data ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src1step1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src1offset1 ));
if (!src2.empty())
{
args.push_back( make_pair( sizeof(cl_mem), (void *)&src2.data ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src2step1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src2offset1 ));
kernelName += "_binary";
buildOptions += " -D BINARY";
}
args.push_back( make_pair( sizeof(cl_mem), (void *)&diff.data ));
args.push_back( make_pair( sizeof(cl_int), (void *)&diffstep1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&diffoffset1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src1.cols ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src1.rows ));
openCLExecuteKernel(clCxt, &arithm_absdiff_nonsaturate,
kernelName, globalThreads, localThreads,
args, -1, -1, buildOptions.c_str());
}
double cv::ocl::norm(const oclMat &src1, const oclMat &src2, int normType)
{
if (!src1.clCxt->supportsFeature(FEATURE_CL_DOUBLE) && src1.depth() == CV_64F)
{
CV_Error(CV_OpenCLDoubleNotSupported, "Selected device doesn't support double");
return -1;
}
CV_Assert(src2.empty() || (src1.type() == src2.type() && src1.size() == src2.size()));
bool isRelative = (normType & NORM_RELATIVE) != 0;
normType &= NORM_TYPE_MASK;
CV_Assert(normType == NORM_INF || normType == NORM_L1 || normType == NORM_L2);
Scalar s;
int cn = src1.channels();
double r = 0;
oclMat diff;
arithm_absdiff_nonsaturate_run(src1, src2, diff, normType);
switch (normType)
{
case NORM_INF:
diff = diff.reshape(1);
minMax(diff, NULL, &r);
break;
case NORM_L1:
s = sum(diff);
for (int i = 0; i < cn; ++i)
r += s[i];
break;
case NORM_L2:
s = sqrSum(diff);
for (int i = 0; i < cn; ++i)
r += s[i];
r = std::sqrt(r);
break;
}
if (isRelative)
r = r / (norm(src2, normType) + DBL_EPSILON);
return r;
}
//////////////////////////////////////////////////////////////////////////////
////////////////////////////////// flip //////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
enum { FLIP_COLS = 1 << 0, FLIP_ROWS = 1 << 1, FLIP_BOTH = FLIP_ROWS | FLIP_COLS };
static void arithmetic_flip_run(const oclMat &src, oclMat &dst, string kernelName, int flipType)
{
int cols = dst.cols, rows = dst.rows;
if ((cols == 1 && flipType == FLIP_COLS) ||
(rows == 1 && flipType == FLIP_ROWS) ||
(rows == 1 && cols == 1 && flipType == FLIP_BOTH))
{
src.copyTo(dst);
return;
}
cols = flipType == FLIP_COLS ? divUp(cols, 2) : cols;
rows = flipType & FLIP_ROWS ? divUp(rows, 2) : rows;
const char * const channelMap[] = { "", "", "2", "4", "4" };
const char * const typeMap[] = { "uchar", "char", "ushort", "short", "int", "float", "double" };
std::string buildOptions = format("-D T=%s%s", typeMap[dst.depth()], channelMap[dst.oclchannels()]);
size_t localThreads[3] = { 64, 4, 1 };
size_t globalThreads[3] = { (size_t)cols, (size_t)rows, 1 };
int elemSize = src.elemSize();
int src_step = src.step / elemSize, src_offset = src.offset / elemSize;
int dst_step = dst.step / elemSize, dst_offset = dst.offset / elemSize;
vector<pair<size_t , const void *> > args;
args.push_back( make_pair( sizeof(cl_mem), (void *)&src.data ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src_step ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src_offset ));
args.push_back( make_pair( sizeof(cl_mem), (void *)&dst.data ));
args.push_back( make_pair( sizeof(cl_int), (void *)&dst_step ));
args.push_back( make_pair( sizeof(cl_int), (void *)&dst_offset ));
args.push_back( make_pair( sizeof(cl_int), (void *)&dst.rows ));
args.push_back( make_pair( sizeof(cl_int), (void *)&dst.cols ));
args.push_back( make_pair( sizeof(cl_int), (void *)&rows ));
args.push_back( make_pair( sizeof(cl_int), (void *)&cols ));
openCLExecuteKernel(src.clCxt, &arithm_flip, kernelName, globalThreads, localThreads, args,
-1, -1, buildOptions.c_str());
}
void cv::ocl::flip(const oclMat &src, oclMat &dst, int flipCode)
{
if (!src.clCxt->supportsFeature(FEATURE_CL_DOUBLE) && src.depth() == CV_64F)
{
CV_Error(CV_OpenCLDoubleNotSupported, "Selected device doesn't support double");
return;
}
dst.create(src.size(), src.type());
if (flipCode == 0)
arithmetic_flip_run(src, dst, "arithm_flip_rows", FLIP_ROWS);
else if (flipCode > 0)
arithmetic_flip_run(src, dst, "arithm_flip_cols", FLIP_COLS);
else
arithmetic_flip_run(src, dst, "arithm_flip_rows_cols", FLIP_BOTH);
}
//////////////////////////////////////////////////////////////////////////////
////////////////////////////////// LUT //////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
static void arithmetic_lut_run(const oclMat &src, const oclMat &lut, oclMat &dst, string kernelName)
{
int sdepth = src.depth();
int src_step1 = src.step1(), dst_step1 = dst.step1();
int src_offset1 = src.offset / src.elemSize1(), dst_offset1 = dst.offset / dst.elemSize1();
int lut_offset1 = lut.offset / lut.elemSize1() + (sdepth == CV_8U ? 0 : 128) * lut.channels();
int cols1 = src.cols * src.oclchannels();
size_t localSize[] = { 16, 16, 1 };
size_t globalSize[] = { (size_t)(lut.channels() == 1 ? cols1 : src.cols), (size_t)src.rows, 1 };
const char * const typeMap[] = { "uchar", "char", "ushort", "short", "int", "float", "double" };
std::string buildOptions = format("-D srcT=%s -D dstT=%s", typeMap[sdepth], typeMap[dst.depth()]);
vector<pair<size_t , const void *> > args;
args.push_back( make_pair( sizeof(cl_mem), (void *)&src.data ));
args.push_back( make_pair( sizeof(cl_mem), (void *)&lut.data ));
args.push_back( make_pair( sizeof(cl_mem), (void *)&dst.data ));
args.push_back( make_pair( sizeof(cl_int), (void *)&cols1));
args.push_back( make_pair( sizeof(cl_int), (void *)&src.rows ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src_offset1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&lut_offset1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&dst_offset1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src_step1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&dst_step1 ));
openCLExecuteKernel(src.clCxt, &arithm_LUT, kernelName, globalSize, localSize,
args, lut.oclchannels(), -1, buildOptions.c_str());
}
void cv::ocl::LUT(const oclMat &src, const oclMat &lut, oclMat &dst)
{
if (!lut.clCxt->supportsFeature(FEATURE_CL_DOUBLE) && lut.depth() == CV_64F)
{
CV_Error(CV_OpenCLDoubleNotSupported, "Selected device doesn't support double");
return;
}
int cn = src.channels(), depth = src.depth();
CV_Assert(depth == CV_8U || depth == CV_8S);
CV_Assert(lut.channels() == 1 || lut.channels() == src.channels());
CV_Assert(lut.rows == 1 && lut.cols == 256);
dst.create(src.size(), CV_MAKETYPE(lut.depth(), cn));
arithmetic_lut_run(src, lut, dst, "LUT");
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////// exp log /////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
static void arithmetic_exp_log_run(const oclMat &src, oclMat &dst, string kernelName, const cv::ocl::ProgramEntry* source)
{
Context *clCxt = src.clCxt;
if (!clCxt->supportsFeature(FEATURE_CL_DOUBLE) && src.depth() == CV_64F)
{
CV_Error(CV_OpenCLDoubleNotSupported, "Selected device doesn't support double");
return;
}
CV_Assert( src.depth() == CV_32F || src.depth() == CV_64F);
dst.create(src.size(), src.type());
int ddepth = dst.depth();
int cols1 = src.cols * src.oclchannels();
int srcoffset1 = src.offset / src.elemSize1(), dstoffset1 = dst.offset / dst.elemSize1();
int srcstep1 = src.step1(), dststep1 = dst.step1();
#ifdef ANDROID
size_t localThreads[3] = { 64, 2, 1 };
#else
size_t localThreads[3] = { 64, 4, 1 };
#endif
size_t globalThreads[3] = { (size_t)dst.cols, (size_t)dst.rows, 1 };
std::string buildOptions = format("-D srcT=%s",
ddepth == CV_32F ? "float" : "double");
vector<pair<size_t , const void *> > args;
args.push_back( make_pair( sizeof(cl_mem), (void *)&src.data ));
args.push_back( make_pair( sizeof(cl_mem), (void *)&dst.data ));
args.push_back( make_pair( sizeof(cl_int), (void *)&cols1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src.rows ));
args.push_back( make_pair( sizeof(cl_int), (void *)&srcoffset1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&dstoffset1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&srcstep1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&dststep1 ));
openCLExecuteKernel(clCxt, source, kernelName, globalThreads, localThreads,
args, src.oclchannels(), -1, buildOptions.c_str());
}
void cv::ocl::exp(const oclMat &src, oclMat &dst)
{
arithmetic_exp_log_run(src, dst, "arithm_exp", &arithm_exp);
}
void cv::ocl::log(const oclMat &src, oclMat &dst)
{
arithmetic_exp_log_run(src, dst, "arithm_log", &arithm_log);
}
//////////////////////////////////////////////////////////////////////////////
////////////////////////////// magnitude phase ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////
static void arithmetic_magnitude_phase_run(const oclMat &src1, const oclMat &src2, oclMat &dst, string kernelName)
{
int depth = dst.depth();
#ifdef ANDROID
size_t localThreads[3] = { 64, 2, 1 };
#else
size_t localThreads[3] = { 64, 4, 1 };
#endif
size_t globalThreads[3] = { (size_t)dst.cols, (size_t)dst.rows, 1 };
int src1_step = src1.step / src1.elemSize(), src1_offset = src1.offset / src1.elemSize();
int src2_step = src2.step / src2.elemSize(), src2_offset = src2.offset / src2.elemSize();
int dst_step = dst.step / dst.elemSize(), dst_offset = dst.offset / dst.elemSize();
vector<pair<size_t , const void *> > args;
args.push_back( make_pair( sizeof(cl_mem), (void *)&src1.data ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src1_step ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src1_offset ));
args.push_back( make_pair( sizeof(cl_mem), (void *)&src2.data ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src2_step ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src2_offset ));
args.push_back( make_pair( sizeof(cl_mem), (void *)&dst.data ));
args.push_back( make_pair( sizeof(cl_int), (void *)&dst_step ));
args.push_back( make_pair( sizeof(cl_int), (void *)&dst_offset ));
args.push_back( make_pair( sizeof(cl_int), (void *)&dst.rows ));
args.push_back( make_pair( sizeof(cl_int), (void *)&dst.cols ));
const char * const channelMap[] = { "", "", "2", "4", "4" };
std::string buildOptions = format("-D T=%s%s", depth == CV_32F ? "float" : "double", channelMap[dst.channels()]);
openCLExecuteKernel(src1.clCxt, &arithm_magnitude, kernelName, globalThreads, localThreads, args, -1, -1, buildOptions.c_str());
}
void cv::ocl::magnitude(const oclMat &src1, const oclMat &src2, oclMat &dst)
{
if (!src1.clCxt->supportsFeature(FEATURE_CL_DOUBLE) && src1.depth() == CV_64F)
{
CV_Error(CV_OpenCLDoubleNotSupported, "Selected device doesn't support double");
return;
}
CV_Assert(src1.type() == src2.type() && src1.size() == src2.size() &&
(src1.depth() == CV_32F || src1.depth() == CV_64F));
dst.create(src1.size(), src1.type());
arithmetic_magnitude_phase_run(src1, src2, dst, "arithm_magnitude");
}
static void arithmetic_phase_run(const oclMat &src1, const oclMat &src2, oclMat &dst, string kernelName, const cv::ocl::ProgramEntry* source)
{
int depth = dst.depth(), cols1 = src1.cols * src1.oclchannels();
int src1step1 = src1.step / src1.elemSize1(), src1offset1 = src1.offset / src1.elemSize1();
int src2step1 = src2.step / src2.elemSize1(), src2offset1 = src2.offset / src2.elemSize1();
int dststep1 = dst.step / dst.elemSize1(), dstoffset1 = dst.offset / dst.elemSize1();
#ifdef ANDROID
size_t localThreads[3] = { 64, 2, 1 };
#else
size_t localThreads[3] = { 64, 4, 1 };
#endif
size_t globalThreads[3] = { (size_t)cols1, (size_t)dst.rows, 1 };
vector<pair<size_t , const void *> > args;
args.push_back( make_pair( sizeof(cl_mem), (void *)&src1.data ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src1step1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src1offset1 ));
args.push_back( make_pair( sizeof(cl_mem), (void *)&src2.data ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src2step1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&src2offset1 ));
args.push_back( make_pair( sizeof(cl_mem), (void *)&dst.data ));
args.push_back( make_pair( sizeof(cl_int), (void *)&dststep1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&dstoffset1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&cols1 ));
args.push_back( make_pair( sizeof(cl_int), (void *)&dst.rows ));
openCLExecuteKernel(src1.clCxt, source, kernelName, globalThreads, localThreads, args, -1, depth);
}
void cv::ocl::phase(const oclMat &x, const oclMat &y, oclMat &Angle, bool angleInDegrees)
{
if (!x.clCxt->supportsFeature(FEATURE_CL_DOUBLE) && x.depth() == CV_64F)
{
CV_Error(CV_OpenCLDoubleNotSupported, "Selected device doesn't support double");
return;
}
CV_Assert(x.type() == y.type() && x.size() == y.size() && (x.depth() == CV_32F || x.depth() == CV_64F));
CV_Assert(x.step % x.elemSize() == 0 && y.step % y.elemSize() == 0);
Angle.create(x.size(), x.type());
arithmetic_phase_run(x, y, Angle, angleInDegrees ? "arithm_phase_indegrees" : "arithm_phase_inradians", &arithm_phase);
}
//////////////////////////////////////////////////////////////////////////////
////////////////////////////////// cartToPolar ///////////////////////////////
//////////////////////////////////////////////////////////////////////////////
static void arithmetic_cartToPolar_run(const oclMat &src1, const oclMat &src2, oclMat &dst_mag, oclMat &dst_cart,
string kernelName, bool angleInDegrees)
{
int channels = src1.oclchannels();
int depth = src1.depth();