# UMat support float32?

**URL:** <https://forum.opencv.org/t/umat-support-float32/5428>\
**Category:** C++\
**Tags:** tapi, umat\
**Created:** [September 30, 2021, 6:30pm UTC](https://forum.opencv.org/t/umat-support-float32/5428 "2021-09-30T18:30:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![carter54](https://avatars.discourse-cdn.com/v4/letter/c/3ec8ea/32.png) [@carter54](https://forum.opencv.org/u/carter54)\
**Post date:** [September 30, 2021, 6:30pm UTC](https://forum.opencv.org/t/umat-support-float32/5428/1 "2021-09-30T18:30:40Z")

</div>

##### 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

```auto
#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);
    }
}

```

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [September 30, 2021, 6:49pm UTC](https://forum.opencv.org/t/umat-support-float32/5428/2 "2021-09-30T18:49:30Z")

</div>

> [@carter54](#):
>
> Does UMat support float32 data type?

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)

---

<div class="post-metadata">

**Author:** ![carter54](https://avatars.discourse-cdn.com/v4/letter/c/3ec8ea/32.png) [@carter54](https://forum.opencv.org/u/carter54)\
**Post date:** [October 8, 2021, 1:37am UTC](https://forum.opencv.org/t/umat-support-float32/5428/3 "2021-10-08T01:37:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [October 8, 2021, 3:48pm UTC](https://forum.opencv.org/t/umat-support-float32/5428/4 "2021-10-08T15:48:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![carter54](https://avatars.discourse-cdn.com/v4/letter/c/3ec8ea/32.png) [@carter54](https://forum.opencv.org/u/carter54)\
**Post date:** [October 11, 2021, 3:19am UTC](https://forum.opencv.org/t/umat-support-float32/5428/5 "2021-10-11T03:19:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [October 11, 2021, 6:01am UTC](https://forum.opencv.org/t/umat-support-float32/5428/6 "2021-10-11T06:01:34Z")

</div>

UMat does. it’s a container.

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

---

<div class="post-metadata">

**Author:** ![carter54](https://avatars.discourse-cdn.com/v4/letter/c/3ec8ea/32.png) [@carter54](https://forum.opencv.org/u/carter54)\
**Post date:** [October 11, 2021, 6:18am UTC](https://forum.opencv.org/t/umat-support-float32/5428/8 "2021-10-11T06:18:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [October 11, 2021, 8:00am UTC](https://forum.opencv.org/t/umat-support-float32/5428/9 "2021-10-11T08:00:50Z")

</div>

you [dive into the src of it](https://github.com/opencv/opencv/blob/39c3334147ec02761b117f180c9c4518be18d1fa/modules/imgproc/src/bilateral_filter.dispatch.cpp#L403)  
(to find, that there’s only a CV\_8U ocl implementation)

---

<div class="post-metadata">

**Author:** ![carter54](https://avatars.discourse-cdn.com/v4/letter/c/3ec8ea/32.png) [@carter54](https://forum.opencv.org/u/carter54)\
**Post date:** [October 11, 2021, 8:17am UTC](https://forum.opencv.org/t/umat-support-float32/5428/10 "2021-10-11T08:17:23Z")

</div>

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