Skip to content

Instantly share code, notes, and snippets.

@edman007
Created April 15, 2023 14:17
Show Gist options
  • Save edman007/3e9e943251bd2a11fea421d27db0eb17 to your computer and use it in GitHub Desktop.
Save edman007/3e9e943251bd2a11fea421d27db0eb17 to your computer and use it in GitHub Desktop.
OpenCV Leak
/*
* This causes a massive leak on debian bullseye with a Vega3 GPU (no working drivers)
*
* It also prints this message due to bad drivers (they simply don't exist for this GPU, so I'm relying on SW fallbacks)
*
OpenCL program build log: imgproc/resize
Status -11: CL_BUILD_PROGRAM_FAILURE
-D INTER_NEAREST -D T=uchar3 -D T1=uchar -D cn=3 -D AMD_DEVICE
fatal error: cannot open file '/usr/lib/clc/gfx909-amdgcn-mesa-mesa3d.bc': No such file or directory
*
* Valgrind identifies these sources (and many more similar spots):
==297010== 2,960,000 bytes in 10,000 blocks are possibly lost in loss record 6,403 of 6,405
==297010== at 0x4838DEF: operator new(unsigned long) (vg_replace_malloc.c:342)
==297010== by 0x10742EB8: clover::intrusive_ref<clover::hard_event> clover::create<clover::hard_event, clover::command_queue&, int, clover::ref_vector<clover::event>&, std::function<void (clover::event&)> >(clover::command_queue&, int&&, clover::ref_vector<clover::event>&, std::function<void (clover::event&)>&&) [clone .isra.0] (pointer.hpp:241)
==297010== by 0x107436AE: clEnqueueReadBuffer (transfer.cpp:343)
==297010== by 0x4FA56A2: cv::ocl::OpenCLAllocator::map(cv::UMatData*, cv::AccessFlag) const (ocl.cpp:5706)
==297010== by 0x4FF35A6: cv::UMat::getMat(cv::AccessFlag) const (umatrix.cpp:1032)
==297010== by 0x4F59747: cv::_InputArray::getMat_(int) const (matrix_wrap.cpp:100)
==297010== by 0x4AC4C16: cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int) (in /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.4.5.1)
==297010== by 0x109335: TestMat::exec(cv::UMat&) (opencv.cpp:33)
==297010== by 0x109409: run(cv::Mat&) (opencv.cpp:41)
==297010== by 0x1094EF: main (opencv.cpp:47)
==297010==
==297010== 2,960,000 bytes in 10,000 blocks are possibly lost in loss record 6,404 of 6,405
==297010== at 0x4838DEF: operator new(unsigned long) (vg_replace_malloc.c:342)
==297010== by 0x10742EB8: clover::intrusive_ref<clover::hard_event> clover::create<clover::hard_event, clover::command_queue&, int, clover::ref_vector<clover::event>&, std::function<void (clover::event&)> >(clover::command_queue&, int&&, clover::ref_vector<clover::event>&, std::function<void (clover::event&)>&&) [clone .isra.0] (pointer.hpp:241)
==297010== by 0x10743960: clEnqueueWriteBuffer (transfer.cpp:376)
==297010== by 0x4FA51D4: cv::ocl::OpenCLAllocator::unmap(cv::UMatData*) const (ocl.cpp:5777)
==297010== by 0x4F23BC1: cv::Mat::release() (matrix.cpp:554)
==297010== by 0x4F23BDC: cv::Mat::~Mat() (matrix.cpp:483)
==297010== by 0x4AC4A39: cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int) (in /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.4.5.1)
==297010== by 0x109335: TestMat::exec(cv::UMat&) (opencv.cpp:33)
==297010== by 0x109409: run(cv::Mat&) (opencv.cpp:41)
==297010== by 0x1094EF: main (opencv.cpp:47)
==297010==
==297010== 2,960,000 bytes in 10,000 blocks are possibly lost in loss record 6,405 of 6,405
==297010== at 0x4838DEF: operator new(unsigned long) (vg_replace_malloc.c:342)
==297010== by 0x10742EB8: clover::intrusive_ref<clover::hard_event> clover::create<clover::hard_event, clover::command_queue&, int, clover::ref_vector<clover::event>&, std::function<void (clover::event&)> >(clover::command_queue&, int&&, clover::ref_vector<clover::event>&, std::function<void (clover::event&)>&&) [clone .isra.0] (pointer.hpp:241)
==297010== by 0x10743960: clEnqueueWriteBuffer (transfer.cpp:376)
==297010== by 0x4FA51D4: cv::ocl::OpenCLAllocator::unmap(cv::UMatData*) const (ocl.cpp:5777)
==297010== by 0x4F23BC1: cv::Mat::release() (matrix.cpp:554)
==297010== by 0x4F23BDC: cv::Mat::~Mat() (matrix.cpp:483)
==297010== by 0x4AC4A45: cv::resize(cv::_InputArray const&, cv::_OutputArray const&, cv::Size_<int>, double, double, int) (in /usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.4.5.1)
==297010== by 0x109335: TestMat::exec(cv::UMat&) (opencv.cpp:33)
==297010== by 0x109409: run(cv::Mat&) (opencv.cpp:41)
==297010== by 0x1094EF: main (opencv.cpp:47)
*
*/
#include <opencv2/core/va_intel.hpp>
#include <opencv2/objdetect.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/videoio.hpp>
#include <iostream>
#include <iomanip>
class TestMat {
public:
TestMat();
~TestMat();
void exec(cv::UMat &in);
private:
cv::UMat buf;
};
TestMat::TestMat(){
std::cout << "Construct" << std::endl;
}
TestMat::~TestMat(){
std::cout << "Destruct" << std::endl;
}
void TestMat::exec(cv::UMat &in){
cv::resize(in, buf, cv::Size(), 0.125, 0.125, cv::INTER_NEAREST);
}
void run(cv::Mat &in){
cv::UMat uin;
in.copyTo(uin);
TestMat test;
for (int i = 0; i < 10000; i++){
test.exec(uin);
}
}
int main(int argc, char** argv) {
cv::Mat input = cv::imread("input.png");
run(input);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment