opencv / opencv

Open Source Computer Vision Library
https://opencv.org
Apache License 2.0
75.69k stars 55.61k forks source link

OpenCL code for BFMatcher throws with w Intel Iris, works w NVidia A2000 #25436

Open Tobiidave opened 2 weeks ago

Tobiidave commented 2 weeks ago

System Information

GPU: Intel Iris Xe Graphics OpenCV 4.8 and 4.9

Detailed description

Some preparation steps makes the Ocl Kernel throw compilation errors when running "KnnMatch"

---- log file [ INFO:0@1.952] global ocl.cpp:1012 cv::ocl::OpenCLExecutionContext::Impl::getInitializedExecutionContext OpenCL: device=Intel(R) Iris(R) Xe Graphics [ INFO:0@2.907] global ocl.cpp:5370 cv::ocl::Context::Impl::init_buffer_pools OpenCL: Initializing buffer pool for context@0 with max capacity: poolSize=134217728 poolSizeHostPtr=134217728 [ INFO:0@2.908] global ocl.cpp:410 cv::ocl::OpenCLBinaryCacheConfigurator::OpenCLBinaryCacheConfigurator Successfully initialized OpenCL cache directory: C:\Users\dsum\AppData\Local\Temp\opencv\4.x\opencl_cache\ [ INFO:0@2.909] global ocl.cpp:434 cv::ocl::OpenCLBinaryCacheConfigurator::prepareCacheDirectoryForContext Preparing OpenCL cache configuration for context: Intel_RCorporation--Intel_R__Iris_R__Xe_Graphics--31_0_101_4575 OpenCL program build log: features2d/brute_force_match Status -11: CL_BUILD_PROGRAM_FAILURE -D T=float -D TN=float4 -D kercn=4 -D T_FLOAT -D DIST_TYPE=6 -D BLOCK_SIZE=16 -D MAX_DESC_LEN=16 -D INTEL_DEVICE 1:86:1: error: assigning to 'result_type' (aka 'int') from incompatible type 'int4' (vector of 4 'int' values) DIST(s_query[lidy BLOCK_SIZE_ODD + j], s_train[j BLOCK_SIZE_ODD + lidx]); ^~~~~~~~~~~~~~~~ 1:72:30: note: expanded from macro 'DIST'

define DIST(x, y) result += popcount( (x) ^ (y) )

                         ^  ~~~~~~~~~~~~~~~~~~~~~

1:101:1: error: assigning to 'result_type' (aka 'int') from incompatible type 'int4' (vector of 4 'int' values) DIST(s_query[lidy BLOCK_SIZE_ODD + j], s_train[j BLOCK_SIZE_ODD + lidx]); ^~~~~~~~~~~~~~~~ 1:72:30: note: expanded from macro 'DIST'

define DIST(x, y) result += popcount( (x) ^ (y) )

Steps to reproduce

include "gtest/gtest.h"

include <opencv2/core/core.hpp>

include <opencv2/videoio.hpp>

include <opencv2/imgproc/imgproc.hpp>

include <opencv2/highgui/highgui.hpp>

include <opencv2/stitching.hpp>

include <opencv2\core\ocl.hpp>

include "CameraModel.h"

include "RealWorldMapper.h"

using namespace cv;

TEST(OclCompatibility, BruteForceMatcher) { int dim = 2;

int queryDescCount;
int countFactor;

UMat uquery, utrain;

queryDescCount = 3000; // must be even number because we split train data in some cases in two
countFactor = 4; // do not change it

cv::Mat queryBuf, trainBuf;
cv::Mat image;

queryBuf.create(queryDescCount, 4, CV_32FC1);
cv::RNG rng(0);
rng.fill(queryBuf, cv::RNG::UNIFORM, cv::Scalar::all(0), cv::Scalar::all(3));
queryBuf.convertTo(queryBuf, CV_32FC1);

trainBuf.create(queryBuf.size(), queryBuf.type());

uquery = queryBuf.getUMat(cv::ACCESS_FAST);
utrain = trainBuf.getUMat(cv::ACCESS_FAST);
const int knn = 2;

cv::BFMatcher matcher(cv::NORM_HAMMING, false);

std::vector< std::vector<cv::DMatch> > matches;

ASSERT_NO_THROW(matcher.knnMatch(uquery, utrain, matches, knn));

ASSERT_EQ(static_cast<size_t>(queryDescCount), matches.size());

}

Issue submission checklist

opencv-alalek commented 2 weeks ago

Please provide dump of there outputs:

Tobiidave commented 2 weeks ago

I am on Windows; I don't have these tools