UMat support float32?

System information (version)
  • OpenCV => 4.5.3
  • Operating System / Platform => Windows 64 Bit
  • Compiler => Visual Studio 2019
Detailed description

I try to use UMat in cv::bilateralFilter function to optimize the performance.
if the UMat data type is int8, I can see a huge improving performance when using UMat
However, when I convert the data type to float32, the time to run cv::bilateralFilter function is the same for Mat and UMat.

Does UMat support float32 data type?

Steps to reproduce
#include <iostream>
#include <opencv2/opencv.hpp>

#define TB__(A) int64 A; A = cv::getTickCount()
#define TE__(A) std::cout << #A << " : " << 1.E3 * double(cv::getTickCount() - A)/double(cv::getTickFrequency()) << "ms" << std::endl


int filter_d = 10;
int sigma_color = 5; 
int sigma_space = 5;
bool use_opencl = true;


int main(int argc, char** argv)
{
    //bilateralFilterTest
    std::string image_path = "path to a image";
    cv::Mat inMat = cv::imread(image_path, 0);
    inMat.convertTo(inMat, CV_32FC3);  // convert image type from int8 to float32
    cv::Mat outMat;
    
    if (use_opencl) {
        cv::UMat inMat_;
        cv::UMat outMat_;
        inMat.copyTo(inMat_);
        TB__(bilateralFilterFunctionTest);
        cv::bilateralFilter(inMat_, outMat_, filter_d, sigma_color, sigma_space);
        TE__(bilateralFilterFunctionTest);
    }
    else {
        TB__(bilateralFilterFunctionTest);
        cv::bilateralFilter(inMat, outMat, filter_d, sigma_color, sigma_space);
        TE__(bilateralFilterFunctionTest);
    }
}

ofc. it does.
imo, you’re asking the wrong question, which probably should be:

 why is the ocl implementation of `bilateralFilter` so slow for float32 input ?

then, for proper profiling, you want to average like 500 calls to bilateralFilter, not measure a single shot. (kernels need to be compiled, caches be warmed, etc)

Hi, berak~ Thx for your reply.
I did test 500 times for the same image in a loop and could not see any difference in execution time using UMat.

monitor the usage of your CPU and GPU (use Task Manager). what do you see?

Hi crackwitz~ I monitor the usage of my CPU and GPU and I didn’t see any GPU usage when I set use_opencl = true.

If I delete this line,
inMat.convertTo(inMat, CV_32FC3);
The inMat data format is int8, I can see the use of GPU when I run the code.

This is the reason I asked whether UMat support float32 data type.

The GPU in my PC is Inter(R) UHD Graphics 630

UMat does. it’s a container.

the algorithm might not have an OpenCL path for that data type.

Thx for your reply~ Is there any place to check the UMat support for cv::bilateralFilter with float32?

you dive into the src of it
(to find, that there’s only a CV_8U ocl implementation)

1 Like

I see~ cheers mate!
I will submit an issue and ask for this feature on github

1 Like