简体   繁体   中英

using address sanitizer with OpenCV

I'm trying to use Google's Address Sanitizer with a CUDA project, more precisely with OpenCV cuda functions. However I got an 'out of memory' error on the first cuda call.

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

It can be reproduced with

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

compiled with

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

I've got the same result with gcc. I've also tried blacklisting cuda functions without result.

Now using cuda without 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

The sanitizer stops on a memory leak:

=================================================================
==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).

My question is how can I use the address sanitizer to sanitize my software without getting stuck with this? How can I at least properly blacklist all cuda related calls?

I didn't find anything relevant on a famous web search engine . It's like people don't use cuda or asan or both. Do guys just have a build with cuda completly disabled?

I'm guessing asan is having a hard time with cuda memory management but I'm looking for a way to use this tool for the rest of my codebase at least.

For people looking here: The solution I have found (based on the related github issue mentioned by @BenC) is to run export ASAN_OPTIONS=protect_shadow_gap=0 .

I have not succeeded in finding a way to change the behavior when compiling yet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM