在OpenCV中使用地址消毒器

using address sanitizer with OpenCV

本文关键字:地址 OpenCV      更新时间:2023-10-16

我正在尝试使用谷歌的地址消毒与CUDA项目,更准确地说与OpenCV CUDA功能。然而,在第一次cuda调用时,我得到了一个"内存不足"错误。

OpenCV Error: Gpu API call (out of memory) in getDevice, file opencv-2.4.11/src/opencv-2.4.11/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp, line 664
terminate called after throwing an instance of 'cv::Exception'
  what():  opencv-2.4.11/src/opencv-2.4.11/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp:664: error: (-217) out of memory in function getDevice

可以用

复制
#include <opencv2/gpu/gpu.hpp>
int main()
{
  cv::gpu::printCudaDeviceInfo(cv::gpu::getDevice());
  return 0;
}
编制

clang++ -fsanitize=address -lstdc++ -lopencv_gpu -lopencv_core -o sanitizer sanitizer.cpp && LD_LIBRARY_PATH=/usr/local/lib ./sanitizer

我在gcc中得到了相同的结果。我也试过将cuda函数列入黑名单,但没有结果。

现在使用cuda不使用opencv:

#include <cuda_runtime.h>
int main()
{
  int count = -1;
  cudaGetDevice(&count);
  cout << "Device count: " << count << endl;
  return 0;
}
clang++ -O1 -g -fsanitize=address -fsanitize-blacklist=asan.blacklist -stdlib=libstdc++ -lstdc++ -I/opt/cuda/include -L/opt/cuda/lib64 -lcudart  -o sanitizer sanitizer.cpp && ./sanitizer

消毒程序在内存泄漏时停止:

=================================================================
==25344==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 136 byte(s) in 1 object(s) allocated from:
    #0 0x4bc4a2  (/home/pluc/work/tests/sanitizer+0x4bc4a2)
    #1 0x7f71f0fa69ba  (<unknown module>)
SUMMARY: AddressSanitizer: 136 byte(s) leaked in 1 allocation(s).

我的问题是如何使用地址杀毒器来杀毒我的软件而不会被这个卡住?我怎样才能把所有cuda相关的电话都列入黑名单呢?

我没有找到任何相关的一个著名的网络搜索引擎。就像人们不使用cuda或asan或两者。难道男人们只有cuda完全残疾的体格吗?

我猜asan是有一个艰难的时间与cuda内存管理,但我正在寻找一种方法来使用这个工具为我的代码库的其余部分至少。

对于在这里寻找的人:我找到的解决方案(基于@BenC提到的相关github问题)是运行export ASAN_OPTIONS=protect_shadow_gap=0

我还没有成功地找到一种方法来改变编译时的行为