}
}
- "uchar",
- "char",
- "ushort",
- "short",
- "int",
- "float -D T_FLOAT",
+ static const int OPT_SIZE = 100;
+
+ static const char * T_ARR [] = {
++ "uchar",
++ "char",
++ "ushort",
++ "short",
++ "int",
++ "float -D T_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)
const size_t smemSize = (BLOCK_SIZE * (MAX_DESC_LEN >= 2 * BLOCK_SIZE ? MAX_DESC_LEN : 2 * BLOCK_SIZE) + BLOCK_SIZE * BLOCK_SIZE) * sizeof(int);
int block_size = BLOCK_SIZE;
int m_size = MAX_DESC_LEN;
- vector< pair<size_t, const void *> > args;
+ std::vector< std::pair<size_t, const void *> > args;
- sprintf(opt,
- "-D T=%s -D DIST_TYPE=%d -D BLOCK_SIZE=%d -D MAX_DESC_LEN=%d",
+ char opt [OPT_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)
{
- args.push_back( make_pair( sizeof(cl_mem), (void *)&query.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&train.data ));
- //args.push_back( make_pair( sizeof(cl_mem), (void *)&mask.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&trainIdx.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&distance.data ));
- args.push_back( make_pair( smemSize, (void *)NULL));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.rows ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.cols ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&train.rows ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&train.cols ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.step ));
-
- std::string kernelName = "BruteForceMatch_UnrollMatch";
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&query.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&train.data ));
+ //args.push_back( std::make_pair( sizeof(cl_mem), (void *)&mask.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&trainIdx.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&distance.data ));
+ args.push_back( std::make_pair( smemSize, (void *)NULL));
- args.push_back( std::make_pair( sizeof(cl_int), (void *)&block_size ));
- args.push_back( std::make_pair( sizeof(cl_int), (void *)&m_size ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.rows ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.cols ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&train.rows ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&train.cols ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.step ));
- args.push_back( std::make_pair( sizeof(cl_int), (void *)&distType ));
+
+ String kernelName = "BruteForceMatch_UnrollMatch";
- openCLExecuteKernel(ctx, &brute_force_match, kernelName, globalSize, localSize, args, -1, query.depth());
+ openCLExecuteKernel(ctx, &brute_force_match, kernelName, globalSize, localSize, args, -1, -1, opt);
}
}
size_t localSize[] = {BLOCK_SIZE, BLOCK_SIZE, 1};
const size_t smemSize = (2 * BLOCK_SIZE * BLOCK_SIZE) * sizeof(int);
int block_size = BLOCK_SIZE;
- vector< pair<size_t, const void *> > args;
+ std::vector< std::pair<size_t, const void *> > args;
- sprintf(opt,
- "-D T=%s -D DIST_TYPE=%d -D BLOCK_SIZE=%d",
+ char opt [OPT_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)
{
- args.push_back( make_pair( sizeof(cl_mem), (void *)&query.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&train.data ));
- //args.push_back( make_pair( sizeof(cl_mem), (void *)&mask.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&trainIdx.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&distance.data ));
- args.push_back( make_pair( smemSize, (void *)NULL));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.rows ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.cols ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&train.rows ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&train.cols ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.step ));
-
- std::string kernelName = "BruteForceMatch_Match";
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&query.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&train.data ));
+ //args.push_back( std::make_pair( sizeof(cl_mem), (void *)&mask.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&trainIdx.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&distance.data ));
+ args.push_back( std::make_pair( smemSize, (void *)NULL));
- args.push_back( std::make_pair( sizeof(cl_int), (void *)&block_size ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.rows ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.cols ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&train.rows ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&train.cols ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.step ));
- args.push_back( std::make_pair( sizeof(cl_int), (void *)&distType ));
+
+ String kernelName = "BruteForceMatch_Match";
- openCLExecuteKernel(ctx, &brute_force_match, kernelName, globalSize, localSize, args, -1, query.depth());
+ openCLExecuteKernel(ctx, &brute_force_match, kernelName, globalSize, localSize, args, -1, -1, opt);
}
}
const size_t smemSize = (2 * BLOCK_SIZE * BLOCK_SIZE) * sizeof(int);
int block_size = BLOCK_SIZE;
int m_size = MAX_DESC_LEN;
- vector< pair<size_t, const void *> > args;
+ std::vector< std::pair<size_t, const void *> > args;
- sprintf(opt,
- "-D T=%s -D DIST_TYPE=%d -D BLOCK_SIZE=%d -D MAX_DESC_LEN=%d",
+ char opt [OPT_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)
{
- args.push_back( make_pair( sizeof(cl_mem), (void *)&query.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&train.data ));
- args.push_back( make_pair( sizeof(cl_float), (void *)&maxDistance ));
- //args.push_back( make_pair( sizeof(cl_mem), (void *)&mask.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&trainIdx.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&distance.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&nMatches.data ));
- args.push_back( make_pair( smemSize, (void *)NULL));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.rows ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.cols ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&train.rows ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&train.cols ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&trainIdx.cols ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.step ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&trainIdx.step ));
-
- std::string kernelName = "BruteForceMatch_RadiusUnrollMatch";
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&query.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&train.data ));
+ args.push_back( std::make_pair( sizeof(cl_float), (void *)&maxDistance ));
+ //args.push_back( std::make_pair( sizeof(cl_mem), (void *)&mask.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&trainIdx.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&distance.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&nMatches.data ));
+ args.push_back( std::make_pair( smemSize, (void *)NULL));
- args.push_back( std::make_pair( sizeof(cl_int), (void *)&block_size ));
- args.push_back( std::make_pair( sizeof(cl_int), (void *)&m_size ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.rows ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.cols ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&train.rows ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&train.cols ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&trainIdx.cols ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.step ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&trainIdx.step ));
- args.push_back( std::make_pair( sizeof(cl_int), (void *)&distType ));
+
+ String kernelName = "BruteForceMatch_RadiusUnrollMatch";
- openCLExecuteKernel(ctx, &brute_force_match, kernelName, globalSize, localSize, args, -1, query.depth());
+ openCLExecuteKernel(ctx, &brute_force_match, kernelName, globalSize, localSize, args, -1, -1, opt);
}
}
size_t localSize[] = {BLOCK_SIZE, BLOCK_SIZE, 1};
const size_t smemSize = (2 * BLOCK_SIZE * BLOCK_SIZE) * sizeof(int);
int block_size = BLOCK_SIZE;
- vector< pair<size_t, const void *> > args;
+ std::vector< std::pair<size_t, const void *> > args;
- sprintf(opt,
- "-D T=%s -D DIST_TYPE=%d -D BLOCK_SIZE=%d",
+ char opt [OPT_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)
{
- args.push_back( make_pair( sizeof(cl_mem), (void *)&query.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&train.data ));
- args.push_back( make_pair( sizeof(cl_float), (void *)&maxDistance ));
- //args.push_back( make_pair( sizeof(cl_mem), (void *)&mask.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&trainIdx.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&distance.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&nMatches.data ));
- args.push_back( make_pair( smemSize, (void *)NULL));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.rows ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.cols ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&train.rows ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&train.cols ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&trainIdx.cols ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.step ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&trainIdx.step ));
-
- std::string kernelName = "BruteForceMatch_RadiusMatch";
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&query.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&train.data ));
+ args.push_back( std::make_pair( sizeof(cl_float), (void *)&maxDistance ));
+ //args.push_back( std::make_pair( sizeof(cl_mem), (void *)&mask.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&trainIdx.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&distance.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&nMatches.data ));
+ args.push_back( std::make_pair( smemSize, (void *)NULL));
- args.push_back( std::make_pair( sizeof(cl_int), (void *)&block_size ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.rows ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.cols ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&train.rows ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&train.cols ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&trainIdx.cols ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.step ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&trainIdx.step ));
- args.push_back( std::make_pair( sizeof(cl_int), (void *)&distType ));
+
+ String kernelName = "BruteForceMatch_RadiusMatch";
- openCLExecuteKernel(ctx, &brute_force_match, kernelName, globalSize, localSize, args, -1, query.depth());
+ openCLExecuteKernel(ctx, &brute_force_match, kernelName, globalSize, localSize, args, -1, -1, opt);
}
}
const size_t smemSize = (BLOCK_SIZE * (MAX_DESC_LEN >= BLOCK_SIZE ? MAX_DESC_LEN : BLOCK_SIZE) + BLOCK_SIZE * BLOCK_SIZE) * sizeof(int);
int block_size = BLOCK_SIZE;
int m_size = MAX_DESC_LEN;
- vector< pair<size_t, const void *> > args;
+ std::vector< std::pair<size_t, const void *> > args;
- sprintf(opt,
- "-D T=%s -D DIST_TYPE=%d -D BLOCK_SIZE=%d -D MAX_DESC_LEN=%d",
+ char opt [OPT_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)
{
- args.push_back( make_pair( sizeof(cl_mem), (void *)&query.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&train.data ));
- //args.push_back( make_pair( sizeof(cl_mem), (void *)&mask.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&trainIdx.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&distance.data ));
- args.push_back( make_pair( smemSize, (void *)NULL));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.rows ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.cols ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&train.rows ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&train.cols ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.step ));
-
- std::string kernelName = "BruteForceMatch_knnUnrollMatch";
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&query.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&train.data ));
+ //args.push_back( std::make_pair( sizeof(cl_mem), (void *)&mask.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&trainIdx.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&distance.data ));
+ args.push_back( std::make_pair( smemSize, (void *)NULL));
- args.push_back( std::make_pair( sizeof(cl_int), (void *)&block_size ));
- args.push_back( std::make_pair( sizeof(cl_int), (void *)&m_size ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.rows ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.cols ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&train.rows ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&train.cols ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.step ));
- args.push_back( std::make_pair( sizeof(cl_int), (void *)&distType ));
+
+ String kernelName = "BruteForceMatch_knnUnrollMatch";
- openCLExecuteKernel(ctx, &brute_force_match, kernelName, globalSize, localSize, args, -1, query.depth());
+ openCLExecuteKernel(ctx, &brute_force_match, kernelName, globalSize, localSize, args, -1, -1, opt);
}
}
size_t localSize[] = {BLOCK_SIZE, BLOCK_SIZE, 1};
const size_t smemSize = (2 * BLOCK_SIZE * BLOCK_SIZE) * sizeof(int);
int block_size = BLOCK_SIZE;
- vector< pair<size_t, const void *> > args;
+ std::vector< std::pair<size_t, const void *> > args;
- sprintf(opt,
- "-D T=%s -D DIST_TYPE=%d -D BLOCK_SIZE=%d",
+ char opt [OPT_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)
{
- args.push_back( make_pair( sizeof(cl_mem), (void *)&query.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&train.data ));
- //args.push_back( make_pair( sizeof(cl_mem), (void *)&mask.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&trainIdx.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&distance.data ));
- args.push_back( make_pair( smemSize, (void *)NULL));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.rows ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.cols ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&train.rows ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&train.cols ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.step ));
-
- std::string kernelName = "BruteForceMatch_knnMatch";
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&query.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&train.data ));
+ //args.push_back( std::make_pair( sizeof(cl_mem), (void *)&mask.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&trainIdx.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&distance.data ));
+ args.push_back( std::make_pair( smemSize, (void *)NULL));
- args.push_back( std::make_pair( sizeof(cl_int), (void *)&block_size ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.rows ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.cols ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&train.rows ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&train.cols ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.step ));
- args.push_back( std::make_pair( sizeof(cl_int), (void *)&distType ));
+
+ String kernelName = "BruteForceMatch_knnMatch";
- openCLExecuteKernel(ctx, &brute_force_match, kernelName, globalSize, localSize, args, -1, query.depth());
+ openCLExecuteKernel(ctx, &brute_force_match, kernelName, globalSize, localSize, args, -1, -1, opt);
}
}
const size_t smemSize = (2 * BLOCK_SIZE * BLOCK_SIZE) * sizeof(int);
int block_size = BLOCK_SIZE;
int m_size = MAX_DESC_LEN;
- vector< pair<size_t, const void *> > args;
+ std::vector< std::pair<size_t, const void *> > args;
- sprintf(opt,
- "-D T=%s -D DIST_TYPE=%d -D BLOCK_SIZE=%d -D MAX_DESC_LEN=%d",
+ char opt [OPT_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)
{
- args.push_back( make_pair( sizeof(cl_mem), (void *)&query.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&train.data ));
- //args.push_back( make_pair( sizeof(cl_mem), (void *)&mask.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&allDist.data ));
- args.push_back( make_pair( smemSize, (void *)NULL));
- args.push_back( make_pair( sizeof(cl_int), (void *)&block_size ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&m_size ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.rows ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.cols ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&train.rows ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&train.cols ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.step ));
-
- std::string kernelName = "BruteForceMatch_calcDistanceUnrolled";
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&query.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&train.data ));
+ //args.push_back( std::make_pair( sizeof(cl_mem), (void *)&mask.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&allDist.data ));
+ args.push_back( std::make_pair( smemSize, (void *)NULL));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&block_size ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&m_size ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.rows ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.cols ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&train.rows ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&train.cols ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.step ));
- args.push_back( std::make_pair( sizeof(cl_int), (void *)&distType ));
+
+ String kernelName = "BruteForceMatch_calcDistanceUnrolled";
- openCLExecuteKernel(ctx, &brute_force_match, kernelName, globalSize, localSize, args, -1, query.depth());
+ openCLExecuteKernel(ctx, &brute_force_match, kernelName, globalSize, localSize, args, -1, -1, opt);
}
}
size_t localSize[] = {BLOCK_SIZE, BLOCK_SIZE, 1};
const size_t smemSize = (2 * BLOCK_SIZE * BLOCK_SIZE) * sizeof(int);
int block_size = BLOCK_SIZE;
- vector< pair<size_t, const void *> > args;
+ std::vector< std::pair<size_t, const void *> > args;
- sprintf(opt,
- "-D T=%s -D DIST_TYPE=%d -D BLOCK_SIZE=%d",
+ char opt [OPT_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)
{
- args.push_back( make_pair( sizeof(cl_mem), (void *)&query.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&train.data ));
- //args.push_back( make_pair( sizeof(cl_mem), (void *)&mask.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&allDist.data ));
- args.push_back( make_pair( smemSize, (void *)NULL));
- args.push_back( make_pair( sizeof(cl_int), (void *)&block_size ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.rows ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.cols ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&train.rows ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&train.cols ));
- args.push_back( make_pair( sizeof(cl_int), (void *)&query.step ));
-
- std::string kernelName = "BruteForceMatch_calcDistance";
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&query.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&train.data ));
+ //args.push_back( std::make_pair( sizeof(cl_mem), (void *)&mask.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&allDist.data ));
+ args.push_back( std::make_pair( smemSize, (void *)NULL));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&block_size ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.rows ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.cols ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&train.rows ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&train.cols ));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.step ));
- args.push_back( std::make_pair( sizeof(cl_int), (void *)&distType ));
+
+ String kernelName = "BruteForceMatch_calcDistance";
- openCLExecuteKernel(ctx, &brute_force_match, kernelName, globalSize, localSize, args, -1, query.depth());
+ openCLExecuteKernel(ctx, &brute_force_match, kernelName, globalSize, localSize, args, -1, -1, opt);
}
}
for (int i = 0; i < k; ++i)
{
- vector< pair<size_t, const void *> > args;
+ std::vector< std::pair<size_t, const void *> > args;
- args.push_back( make_pair( sizeof(cl_mem), (void *)&allDist.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&trainIdx.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&distance.data ));
- args.push_back( make_pair( sizeof(cl_mem), (void *)&i));
- args.push_back( make_pair( sizeof(cl_int), (void *)&block_size ));
- //args.push_back( make_pair( sizeof(cl_int), (void *)&train.rows ));
- //args.push_back( make_pair( sizeof(cl_int), (void *)&train.cols ));
- //args.push_back( make_pair( sizeof(cl_int), (void *)&query.step ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&allDist.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&trainIdx.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&distance.data ));
+ args.push_back( std::make_pair( sizeof(cl_mem), (void *)&i));
+ args.push_back( std::make_pair( sizeof(cl_int), (void *)&block_size ));
+ //args.push_back( std::make_pair( sizeof(cl_int), (void *)&train.rows ));
+ //args.push_back( std::make_pair( sizeof(cl_int), (void *)&train.cols ));
+ //args.push_back( std::make_pair( sizeof(cl_int), (void *)&query.step ));
- openCLExecuteKernel(ctx, &brute_force_match, kernelName, globalSize, localSize, args, trainIdx.depth(), -1);
+ openCLExecuteKernel(ctx, &brute_force_match, kernelName, globalSize, localSize, args, -1, -1);
}
}
{
if (query.empty() || train.empty())
return;
-
+
- // match1 doesn't support signed char type, match2 only support float, hamming support uchar, ushort and int
- int callType = query.depth();
- if (callType != 5)
- CV_Error(Error::StsUnsupportedFormat, "BruteForceMatch OpenCL only support float type query!\n");
-
- if ((distType == 0 && callType == 1 ) || (distType == 1 && callType != 5) || (distType == 2 && (callType != 0
- || callType != 2 || callType != 4)))
- {
- CV_Error(Error::BadDepth, "BruteForceMatch OpenCL only support float type query!\n");
- }
-
CV_Assert(query.channels() == 1 && query.depth() < CV_64F);
CV_Assert(train.cols == query.cols && train.type() == query.type());
- trainIdx.create(1, query.rows, CV_32S);
- distance.create(1, query.rows, CV_32F);
+ ensureSizeIsEnough(1, query.rows, CV_32S, trainIdx);
+ ensureSizeIsEnough(1, query.rows, CV_32F, distance);
matchDispatcher(query, train, mask, trainIdx, distance, distType);
+
+ return;
}
-void cv::ocl::BruteForceMatcher_OCL_base::matchDownload(const oclMat &trainIdx, const oclMat &distance, vector<DMatch> &matches)
+void cv::ocl::BruteForceMatcher_OCL_base::matchDownload(const oclMat &trainIdx, const oclMat &distance, std::vector<DMatch> &matches)
{
if (trainIdx.empty() || distance.empty())
return;
}
}
-void cv::ocl::BruteForceMatcher_OCL_base::match(const oclMat &query, const oclMat &train, vector<DMatch> &matches, const oclMat &mask)
+void cv::ocl::BruteForceMatcher_OCL_base::match(const oclMat &query, const oclMat &train, std::vector<DMatch> &matches, const oclMat &mask)
{
- CV_Assert(mask.empty()); // mask is not supported at the moment
+ assert(mask.empty()); // mask is not supported at the moment
oclMat trainIdx, distance;
matchSingle(query, train, trainIdx, distance, mask);
matchDownload(trainIdx, distance, matches);
if (query.empty() || trainCollection.empty())
return;
- // match1 doesn't support signed char type, match2 only support float, hamming support uchar, ushort and int
- int callType = query.depth();
- if (callType != 5)
- CV_Error(Error::StsUnsupportedFormat, "BruteForceMatch OpenCL only support float type query!\n");
-
- if ((distType == 0 && callType == 1 ) || (distType == 1 && callType != 5) || (distType == 2 && (callType != 0
- || callType != 2 || callType != 4)))
- {
- CV_Error(Error::BadDepth, "BruteForceMatch OpenCL only support float type query!\n");
- }
-
CV_Assert(query.channels() == 1 && query.depth() < CV_64F);
-
+
- trainIdx.create(1, query.rows, CV_32S);
- imgIdx.create(1, query.rows, CV_32S);
- distance.create(1, query.rows, CV_32F);
+ const int nQuery = query.rows;
+
+ ensureSizeIsEnough(1, nQuery, CV_32S, trainIdx);
+ ensureSizeIsEnough(1, nQuery, CV_32S, imgIdx);
+ ensureSizeIsEnough(1, nQuery, CV_32F, distance);
matchDispatcher(query, (const oclMat *)trainCollection.ptr(), trainCollection.cols, masks, trainIdx, imgIdx, distance, distType);
+
+ return;
}
-void cv::ocl::BruteForceMatcher_OCL_base::matchDownload(const oclMat &trainIdx, const oclMat &imgIdx, const oclMat &distance, vector<DMatch> &matches)
+void cv::ocl::BruteForceMatcher_OCL_base::matchDownload(const oclMat &trainIdx, const oclMat &imgIdx, const oclMat &distance, std::vector<DMatch> &matches)
{
if (trainIdx.empty() || imgIdx.empty() || distance.empty())
return;
trainIdx.setTo(Scalar::all(-1));
kmatchDispatcher(query, train, k, mask, trainIdx, distance, allDist, distType);
+
+ return;
}
-void cv::ocl::BruteForceMatcher_OCL_base::knnMatchDownload(const oclMat &trainIdx, const oclMat &distance, vector< vector<DMatch> > &matches, bool compactResult)
+void cv::ocl::BruteForceMatcher_OCL_base::knnMatchDownload(const oclMat &trainIdx, const oclMat &distance, std::vector< std::vector<DMatch> > &matches, bool compactResult)
{
if (trainIdx.empty() || distance.empty())
return;
temp.reserve(2 * k);
matches.resize(query.rows);
- std::for_each(matches.begin(), matches.end(), std::bind2nd(std::mem_fun_ref(&std::vector<DMatch>::reserve), k));
- for_each(matches.begin(), matches.end(), bind2nd(mem_fun_ref(&vector<DMatch>::reserve), k));
++ for_each(matches.begin(), matches.end(), bind2nd(mem_fun_ref(&std::vector<DMatch>::reserve), k));
for (size_t imgIdx = 0, size = trainDescCollection.size(); imgIdx < size; ++imgIdx)
{
if (compactResult)
{
- std::vector< std::vector<DMatch> >::iterator new_end = std::remove_if(matches.begin(), matches.end(), std::mem_fun_ref(&std::vector<DMatch>::empty));
- vector< vector<DMatch> >::iterator new_end = remove_if(matches.begin(), matches.end(), mem_fun_ref(&vector<DMatch>::empty));
++ std::vector< std::vector<DMatch> >::iterator new_end = remove_if(matches.begin(), matches.end(), mem_fun_ref(&std::vector<DMatch>::empty));
matches.erase(new_end, matches.end());
}
}