|
|
|
@ -4451,42 +4451,46 @@ String kernelToStr(InputArray _kernel, int ddepth, const char * name) |
|
|
|
|
if (!src.empty()) \
|
|
|
|
|
{ \
|
|
|
|
|
CV_Assert(src.isMat() || src.isUMat()); \
|
|
|
|
|
int ctype = src.type(), ccn = CV_MAT_CN(ctype); \
|
|
|
|
|
Size csize = src.size(); \
|
|
|
|
|
cols.push_back(ccn * csize.width); \
|
|
|
|
|
if (ctype != type) \
|
|
|
|
|
int ctype = src.type(), ccn = CV_MAT_CN(ctype), cdepth = CV_MAT_DEPTH(ctype), \
|
|
|
|
|
ckercn = vectorWidths[cdepth], cwidth = ccn * csize.width; \
|
|
|
|
|
if (cwidth < ckercn || ckercn <= 0) \
|
|
|
|
|
return 1; \
|
|
|
|
|
cols.push_back(cwidth); \
|
|
|
|
|
if (strat == OCL_VECTOR_OWN && ctype != ref_type) \
|
|
|
|
|
return 1; \
|
|
|
|
|
offsets.push_back(src.offset()); \
|
|
|
|
|
steps.push_back(src.step()); \
|
|
|
|
|
dividers.push_back(ckercn * CV_ELEM_SIZE1(ctype)); \
|
|
|
|
|
kercns.push_back(ckercn); \
|
|
|
|
|
} \
|
|
|
|
|
} \
|
|
|
|
|
while ((void)0, 0) |
|
|
|
|
|
|
|
|
|
int predictOptimalVectorWidth(InputArray src1, InputArray src2, InputArray src3, |
|
|
|
|
InputArray src4, InputArray src5, InputArray src6, |
|
|
|
|
InputArray src7, InputArray src8, InputArray src9) |
|
|
|
|
InputArray src7, InputArray src8, InputArray src9, |
|
|
|
|
OclVectorStrategy strat) |
|
|
|
|
{ |
|
|
|
|
int type = src1.type(), depth = CV_MAT_DEPTH(type), cn = CV_MAT_CN(type), esz1 = CV_ELEM_SIZE1(depth); |
|
|
|
|
Size ssize = src1.size(); |
|
|
|
|
const ocl::Device & d = ocl::Device::getDefault(); |
|
|
|
|
int ref_type = src1.type(); |
|
|
|
|
|
|
|
|
|
int vectorWidths[] = { d.preferredVectorWidthChar(), d.preferredVectorWidthChar(), |
|
|
|
|
d.preferredVectorWidthShort(), d.preferredVectorWidthShort(), |
|
|
|
|
d.preferredVectorWidthInt(), d.preferredVectorWidthFloat(), |
|
|
|
|
d.preferredVectorWidthDouble(), -1 }, kercn = vectorWidths[depth]; |
|
|
|
|
d.preferredVectorWidthDouble(), -1 }; |
|
|
|
|
|
|
|
|
|
// if the device says don't use vectors
|
|
|
|
|
if (vectorWidths[0] == 1) |
|
|
|
|
{ |
|
|
|
|
// it's heuristic
|
|
|
|
|
int vectorWidthsOthers[] = { 16, 16, 8, 8, 1, 1, 1, -1 }; |
|
|
|
|
kercn = vectorWidthsOthers[depth]; |
|
|
|
|
vectorWidths[CV_8U] = vectorWidths[CV_8S] = 16; |
|
|
|
|
vectorWidths[CV_16U] = vectorWidths[CV_16S] = 8; |
|
|
|
|
vectorWidths[CV_32S] = vectorWidths[CV_32F] = vectorWidths[CV_64F] = 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (ssize.width * cn < kercn || kercn <= 0) |
|
|
|
|
return 1; |
|
|
|
|
|
|
|
|
|
std::vector<size_t> offsets, steps, cols; |
|
|
|
|
std::vector<int> dividers, kercns; |
|
|
|
|
PROCESS_SRC(src1); |
|
|
|
|
PROCESS_SRC(src2); |
|
|
|
|
PROCESS_SRC(src3); |
|
|
|
@ -4498,27 +4502,24 @@ int predictOptimalVectorWidth(InputArray src1, InputArray src2, InputArray src3, |
|
|
|
|
PROCESS_SRC(src9); |
|
|
|
|
|
|
|
|
|
size_t size = offsets.size(); |
|
|
|
|
int wsz = kercn * esz1; |
|
|
|
|
std::vector<int> dividers(size, wsz); |
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < size; ++i) |
|
|
|
|
while (offsets[i] % dividers[i] != 0 || steps[i] % dividers[i] != 0 || cols[i] % dividers[i] != 0) |
|
|
|
|
dividers[i] >>= 1; |
|
|
|
|
while (offsets[i] % dividers[i] != 0 || steps[i] % dividers[i] != 0 || cols[i] % kercns[i] != 0) |
|
|
|
|
dividers[i] >>= 1, kercns[i] >>= 1; |
|
|
|
|
|
|
|
|
|
// default strategy
|
|
|
|
|
for (size_t i = 0; i < size; ++i) |
|
|
|
|
if (dividers[i] != wsz) |
|
|
|
|
{ |
|
|
|
|
kercn = 1; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// another strategy
|
|
|
|
|
// width = *std::min_element(dividers.begin(), dividers.end());
|
|
|
|
|
int kercn = *std::min_element(kercns.begin(), kercns.end()); |
|
|
|
|
|
|
|
|
|
return kercn; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int predictOptimalVectorWidthMax(InputArray src1, InputArray src2, InputArray src3, |
|
|
|
|
InputArray src4, InputArray src5, InputArray src6, |
|
|
|
|
InputArray src7, InputArray src8, InputArray src9) |
|
|
|
|
{ |
|
|
|
|
return predictOptimalVectorWidth(src1, src2, src3, src4, src5, src6, src7, src8, src9, OCL_VECTOR_MAX); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#undef PROCESS_SRC |
|
|
|
|
|
|
|
|
|
|
|
|
|
|