From 1d0c283508df92939709eaa6f99f626f3bfefa4a Mon Sep 17 00:00:00 2001 From: peng xiao Date: Tue, 28 May 2013 17:27:55 +0800 Subject: [PATCH] Fix a bug when pushing pointers of arguments into std::vector. When argument pointers pushed into an vector and the pointers point to address on stack, we need to make sure they are valid until kernels are successfully flushed onto the queue. --- modules/ocl/src/arithm.cpp | 7 ++++--- modules/ocl/src/imgproc.cpp | 8 +++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/modules/ocl/src/arithm.cpp b/modules/ocl/src/arithm.cpp index ed2515dc6d..9e5b7130ad 100644 --- a/modules/ocl/src/arithm.cpp +++ b/modules/ocl/src/arithm.cpp @@ -413,11 +413,11 @@ static void arithmetic_scalar_run(const oclMat &src, oclMat &dst, string kernelN args.push_back( make_pair( sizeof(cl_int), (void *)&cols )); args.push_back( make_pair( sizeof(cl_int), (void *)&dst_step1 )); + float f_scalar = (float)scalar; if(src.clCxt->supportsFeature(Context::CL_DOUBLE)) args.push_back( make_pair( sizeof(cl_double), (void *)&scalar )); else { - float f_scalar = (float)scalar; args.push_back( make_pair( sizeof(cl_float), (void *)&f_scalar)); } @@ -1687,10 +1687,11 @@ void bitwise_run(const oclMat &src1, const oclMat &src2, oclMat &dst, string ker args.push_back( make_pair( sizeof(cl_int), (void *)&cols )); args.push_back( make_pair( sizeof(cl_int), (void *)&dst_step1 )); + T scalar; if(_scalar != NULL) { double scalar1 = *((double *)_scalar); - T scalar = (T)scalar1; + scalar = (T)scalar1; args.push_back( make_pair( sizeof(T), (void *)&scalar )); } @@ -2307,9 +2308,9 @@ static void arithmetic_pow_run(const oclMat &src1, double p, oclMat &dst, string args.push_back( make_pair( sizeof(cl_int), (void *)&dst.rows )); args.push_back( make_pair( sizeof(cl_int), (void *)&cols )); args.push_back( make_pair( sizeof(cl_int), (void *)&dst_step1 )); + float pf = p; if(!src1.clCxt->supportsFeature(Context::CL_DOUBLE)) { - float pf = p; args.push_back( make_pair( sizeof(cl_float), (void *)&pf )); } else diff --git a/modules/ocl/src/imgproc.cpp b/modules/ocl/src/imgproc.cpp index ee1e92a712..bbec07a5c0 100644 --- a/modules/ocl/src/imgproc.cpp +++ b/modules/ocl/src/imgproc.cpp @@ -269,7 +269,7 @@ namespace cv size_t globalThreads[3] = {glbSizeX, glbSizeY, 1}; size_t localThreads[3] = {blkSizeX, blkSizeY, 1}; - + float borderFloat[4] = {(float)borderValue[0], (float)borderValue[1], (float)borderValue[2], (float)borderValue[3]}; vector< pair > args; if(map1.channels() == 2) { @@ -289,9 +289,8 @@ namespace cv args.push_back( make_pair(sizeof(cl_int), (void *)&map1.cols)); args.push_back( make_pair(sizeof(cl_int), (void *)&map1.rows)); args.push_back( make_pair(sizeof(cl_int), (void *)&cols)); - float borderFloat[4] = {(float)borderValue[0], (float)borderValue[1], (float)borderValue[2], (float)borderValue[3]}; - - if(src.clCxt->supportsFeature(Context::CL_DOUBLE)) + + if(src.clCxt->supportsFeature(Context::CL_DOUBLE)) { args.push_back( make_pair(sizeof(cl_double4), (void *)&borderValue)); } @@ -325,7 +324,6 @@ namespace cv } else { - float borderFloat[4] = {(float)borderValue[0], (float)borderValue[1], (float)borderValue[2], (float)borderValue[3]}; args.push_back( make_pair(sizeof(cl_float4), (void *)&borderFloat)); } }