# UMAT cannot invoke GPU

**URL:** <https://forum.opencv.org/t/umat-cannot-invoke-gpu/16088>\
**Category:** Android/Java\
**Tags:** umat\
**Created:** [January 8, 2024, 8:51am UTC](https://forum.opencv.org/t/umat-cannot-invoke-gpu/16088 "2024-01-08T08:51:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![junyouwei](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@junyouwei](https://forum.opencv.org/u/junyouwei)\
**Post date:** [January 8, 2024, 8:51am UTC](https://forum.opencv.org/t/umat-cannot-invoke-gpu/16088/1 "2024-01-08T08:51:53Z")

</div>

Hi experts,

I use UMat to do picture operation via Android studio NDK and C++ language, but looks cannot invoke GPU.  
if I switch to Android studio NDK java, looks it can.  
for C++, code as below:  
cv::Mat originalImage;  
cv::UMat uimage;  
originalImage = cv::imread(“/data/local/tmp/pic/pic5.jpg”);  
originalImage.copyTo(uimage);  
cv::resize(uimage, uimage, cv::Size(640, 480), fx, fy, cv::INTER\_LINEAR);

for Java, it’s similar. read picture via Mat, then copyto UMat, and do operations.

can anyone provide some suggestions?  
thanks.

---

<div class="post-metadata">

**Author:** ![faning-wang](https://avatars.discourse-cdn.com/v4/letter/f/ac91a4/32.png) [@faning-wang](https://forum.opencv.org/u/faning-wang)\
**Post date:** [January 8, 2024, 2:21pm UTC](https://forum.opencv.org/t/umat-cannot-invoke-gpu/16088/2 "2024-01-08T14:21:25Z")

</div>

> [@junyouwei](#):
>
> Android Studio NDK

I don’t know how to do it on Android Studio NDK, but I know how to do it on SWISchip RK3568, first you need to manually open something like this  
ocl::setUseOpenCL(true);  
Secondly, we should pay attention to whether the image we read is double (CV\_64F) type data UMat, UMat matrix or GPU does not support double (CV\_64F) type data

---

<div class="post-metadata">

**Author:** ![junyouwei](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@junyouwei](https://forum.opencv.org/u/junyouwei)\
**Post date:** [January 8, 2024, 2:36pm UTC](https://forum.opencv.org/t/umat-cannot-invoke-gpu/16088/3 "2024-01-08T14:36:35Z")

</div>

Hi Faning,  
Thanks a lot for your reply.  
my chip is Qualcomm6490.  
it can trigger it via java code, but c++ doesn’t work.  
and I don’t know how to debug it, like how to enable log and get it, even there has log module, but it doesn’t help.

I guess it’s caused by OpenCL nested in OpenCV, the OpenCL doesn’t support.  
but only log can confirm it.

---

<div class="post-metadata">

**Author:** ![junyouwei](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@junyouwei](https://forum.opencv.org/u/junyouwei)\
**Post date:** [January 8, 2024, 2:39pm UTC](https://forum.opencv.org/t/umat-cannot-invoke-gpu/16088/4 "2024-01-08T14:39:50Z")

</div>

even I set as below, but OpenCL still not available.

```
cv::ocl::setUseOpenCL(true);
cv::ocl::useOpenCL();
__android_log_print(ANDROID_LOG_INFO, "OpenCV", "OpenCL is %s",(cv::ocl::haveOpenCL() ? "available" : "not available"));

```

---

<div class="post-metadata">

**Author:** ![faning-wang](https://avatars.discourse-cdn.com/v4/letter/f/ac91a4/32.png) [@faning-wang](https://forum.opencv.org/u/faning-wang)\
**Post date:** [January 8, 2024, 2:45pm UTC](https://forum.opencv.org/t/umat-cannot-invoke-gpu/16088/5 "2024-01-08T14:45:09Z")

</div>

Another point I forgot to mention to you is that not all OpenCV functions support OpenCl, the support is based on InputArray or OutputArray, for example, the input and output are Array  
void filter2D(InputArray src,OutputArray dst,int ddepth,InputArray kernel,  
Point anchor=Point(-1, -1),double delta=0, int borderType=BORDER\_DEFAULT )  
For example, not supported: Input specifies Mat  
void calcHist( const Mat\* images, int nimages, const int\* channels, InputArray mask, OutputArray hist, int dims, const int\* histSize, const float\*\* ranges, bool uniform=true, bool accumulate=false );

---

<div class="post-metadata">

**Author:** ![faning-wang](https://avatars.discourse-cdn.com/v4/letter/f/ac91a4/32.png) [@faning-wang](https://forum.opencv.org/u/faning-wang)\
**Post date:** [January 8, 2024, 2:48pm UTC](https://forum.opencv.org/t/umat-cannot-invoke-gpu/16088/6 "2024-01-08T14:48:39Z")

</div>

If OpenCL is available, print “available”; Otherwise print “not available”.  
If your device prints “not available”, which means the name does not support OpenCl, it may not have a GPU

---

<div class="post-metadata">

**Author:** ![junyouwei](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@junyouwei](https://forum.opencv.org/u/junyouwei)\
**Post date:** [January 8, 2024, 2:55pm UTC](https://forum.opencv.org/t/umat-cannot-invoke-gpu/16088/7 "2024-01-08T14:55:11Z")

</div>

but very strange, if using java code, it can trigger it.  
java code is much more simple, just add implementation in AndroidManifest.xml file. like:

implementation(“org.bytedeco:javacv-platform:1.5.9”)  
implementation(“org.bytedeco:opencv-platform:4.7.0-1.5.9”)

c++ code, I download opencv sdk from website, and compile the static library in.  
but still doesn’t work.  
I guess it’s caused by OpenCL module nested in OpenCV

---

<div class="post-metadata">

**Author:** ![faning-wang](https://avatars.discourse-cdn.com/v4/letter/f/ac91a4/32.png) [@faning-wang](https://forum.opencv.org/u/faning-wang)\
**Post date:** [January 9, 2024, 12:45am UTC](https://forum.opencv.org/t/umat-cannot-invoke-gpu/16088/8 "2024-01-09T00:45:19Z")

</div>

It’s possible. I’ve just been exposed to this area and gained more knowledge. Thank you
