From: Peng Xiao Date: Sat, 13 Apr 2013 03:39:13 +0000 (+0800) Subject: Pass query type T into kernel X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~1314^2~1334^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fd1528795e7bbc8d7a59885a4387807abbc23f96;p=platform%2Fupstream%2Fopencv.git Pass query type T into kernel --- diff --git a/modules/ocl/src/brute_force_matcher.cpp b/modules/ocl/src/brute_force_matcher.cpp index c76ba33..7edc594 100644 --- a/modules/ocl/src/brute_force_matcher.cpp +++ b/modules/ocl/src/brute_force_matcher.cpp @@ -64,6 +64,8 @@ namespace cv static const int OPT_SIZE = 100; +static const char * T_ARR [] = {"uchar", "char", "ushort", "short", "int", "float", "double"}; + template < int BLOCK_SIZE, int MAX_DESC_LEN/*, typename Mask*/ > void matchUnrolledCached(const oclMat &query, const oclMat &train, const oclMat &/*mask*/, const oclMat &trainIdx, const oclMat &distance, int distType) @@ -78,7 +80,9 @@ void matchUnrolledCached(const oclMat &query, const oclMat &train, const oclMat vector< pair > args; char opt [OPT_SIZE] = ""; - sprintf(opt, "-D DIST_TYPE=%d -D BLOCK_SIZE=%d -D MAX_DESC_LEN=%d", distType, block_size, m_size); + sprintf(opt, + "-D T=%s -D DIST_TYPE=%d -D BLOCK_SIZE=%d -D MAX_DESC_LEN=%d", + T_ARR[query.depth()], distType, block_size, m_size); if(globalSize[0] != 0) { @@ -119,7 +123,9 @@ void match(const oclMat &query, const oclMat &train, const oclMat &/*mask*/, vector< pair > args; char opt [OPT_SIZE] = ""; - sprintf(opt, "-D DIST_TYPE=%d -D BLOCK_SIZE=%d", distType, block_size); + sprintf(opt, + "-D T=%s -D DIST_TYPE=%d -D BLOCK_SIZE=%d", + T_ARR[query.depth()], distType, block_size); if(globalSize[0] != 0) { @@ -162,7 +168,9 @@ void matchUnrolledCached(const oclMat &query, const oclMat &train, float maxDist vector< pair > args; char opt [OPT_SIZE] = ""; - sprintf(opt, "-D DIST_TYPE=%d -D BLOCK_SIZE=%d -D MAX_DESC_LEN=%d", distType, block_size, m_size); + sprintf(opt, + "-D T=%s -D DIST_TYPE=%d -D BLOCK_SIZE=%d -D MAX_DESC_LEN=%d", + T_ARR[query.depth()], distType, block_size, m_size); if(globalSize[0] != 0) { @@ -202,7 +210,9 @@ void radius_match(const oclMat &query, const oclMat &train, float maxDistance, c vector< pair > args; char opt [OPT_SIZE] = ""; - sprintf(opt, "-D DIST_TYPE=%d -D BLOCK_SIZE=%d", distType, block_size); + sprintf(opt, + "-D T=%s -D DIST_TYPE=%d -D BLOCK_SIZE=%d", + T_ARR[query.depth()], distType, block_size); if(globalSize[0] != 0) { @@ -300,7 +310,9 @@ void knn_matchUnrolledCached(const oclMat &query, const oclMat &train, const ocl vector< pair > args; char opt [OPT_SIZE] = ""; - sprintf(opt, "-D DIST_TYPE=%d -D BLOCK_SIZE=%d -D MAX_DESC_LEN=%d", distType, block_size, m_size); + sprintf(opt, + "-D T=%s -D DIST_TYPE=%d -D BLOCK_SIZE=%d -D MAX_DESC_LEN=%d", + T_ARR[query.depth()], distType, block_size, m_size); if(globalSize[0] != 0) { @@ -334,7 +346,9 @@ void knn_match(const oclMat &query, const oclMat &train, const oclMat &/*mask*/, vector< pair > args; char opt [OPT_SIZE] = ""; - sprintf(opt, "-D DIST_TYPE=%d -D BLOCK_SIZE=%d", distType, block_size); + sprintf(opt, + "-D T=%s -D DIST_TYPE=%d -D BLOCK_SIZE=%d", + T_ARR[query.depth()], distType, block_size); if(globalSize[0] != 0) { @@ -368,7 +382,10 @@ void calcDistanceUnrolled(const oclMat &query, const oclMat &train, const oclMat vector< pair > args; char opt [OPT_SIZE] = ""; - sprintf(opt, "-D DIST_TYPE=%d", distType); + sprintf(opt, + "-D T=%s -D DIST_TYPE=%d -D BLOCK_SIZE=%d -D MAX_DESC_LEN=%d", + T_ARR[query.depth()], distType, block_size, m_size); + if(globalSize[0] != 0) { args.push_back( make_pair( sizeof(cl_mem), (void *)&query.data )); @@ -401,7 +418,10 @@ void calcDistance(const oclMat &query, const oclMat &train, const oclMat &/*mask vector< pair > args; char opt [OPT_SIZE] = ""; - sprintf(opt, "-D DIST_TYPE=%d", distType); + sprintf(opt, + "-D T=%s -D DIST_TYPE=%d -D BLOCK_SIZE=%d", + T_ARR[query.depth()], distType, block_size); + if(globalSize[0] != 0) { args.push_back( make_pair( sizeof(cl_mem), (void *)&query.data )); diff --git a/modules/ocl/src/opencl/brute_force_match.cl b/modules/ocl/src/opencl/brute_force_match.cl index 7446c77..db13249 100644 --- a/modules/ocl/src/opencl/brute_force_match.cl +++ b/modules/ocl/src/opencl/brute_force_match.cl @@ -47,6 +47,10 @@ #pragma OPENCL EXTENSION cl_khr_global_int32_base_atomics:enable #define MAX_FLOAT 3.40282e+038f +#ifndef T +#define T float +#endif + #ifndef BLOCK_SIZE #define BLOCK_SIZE 16 #endif @@ -54,7 +58,11 @@ #define MAX_DESC_LEN 64 #endif -int bit1Count(float x) +#ifndef DIST_TYPE +#define DIST_TYPE 0 +#endif + +int bit1Count(int x) { int c = 0; int ix = (int)x; @@ -63,13 +71,9 @@ int bit1Count(float x) c += ix & 0x1; ix >>= 1; } - return (float)c; + return c; } -#ifndef DIST_TYPE -#define DIST_TYPE 0 -#endif - #if (DIST_TYPE == 0) #define DIST(x, y) fabs((x) - (y)) #elif (DIST_TYPE == 1)