Segmentation fault with thread sanitizer in CUDA 10.1 update 1

Hi, all
We have develop a CUDA project with CUDA 8 for a long time, and try to upgrade to CUDA 10.1 in recent, but when we use ThreadSanitizer to detect data race, it will crash in create primary context.

I just write a simple code to test :

#include <iostream>
#include <cuda.h>
#include <cuda_runtime.h>

int main(void)
{
    cudaError e = cudaFree( 0 );
    std::cout << e << "\n";
    return 0;
}

compile with flag -fsanitize=thread :

nvcc -I/usr/local/cuda/include -L/usr/local/cuda/lib -lcuda -lcudart -Xcompiler -fsanitize=thread main.cu -o main

and get segfault result :

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff48ff700 (LWP 6098)]
[New Thread 0x7fffec93c700 (LWP 6102)]
[New Thread 0x7fffec13b700 (LWP 6103)]
[New Thread 0x7fffeb93a700 (LWP 6106)]

Thread 1 "main" received signal SIGSEGV, Segmentation fault.
0x00007ffff2d9d781 in ?? () from /usr/lib/x86_64-linux-gnu/libcuda.so.1
(gdb) where
#0  0x00007ffff2d9d781 in ?? () from /usr/lib/x86_64-linux-gnu/libcuda.so.1
#1  0x00007ffff2c77c11 in ?? () from /usr/lib/x86_64-linux-gnu/libcuda.so.1
#2  0x00007ffff2d5b9cf in ?? () from /usr/lib/x86_64-linux-gnu/libcuda.so.1
#3  0x00007ffff2d82633 in ?? () from /usr/lib/x86_64-linux-gnu/libcuda.so.1
#4  0x00007ffff2d82d83 in ?? () from /usr/lib/x86_64-linux-gnu/libcuda.so.1
#5  0x00007ffff2d90b7a in ?? () from /usr/lib/x86_64-linux-gnu/libcuda.so.1
#6  0x00007ffff2d4df47 in ?? () from /usr/lib/x86_64-linux-gnu/libcuda.so.1
#7  0x00007ffff2d4f3cf in ?? () from /usr/lib/x86_64-linux-gnu/libcuda.so.1
#8  0x00007ffff2c7fedc in ?? () from /usr/lib/x86_64-linux-gnu/libcuda.so.1
#9  0x00007ffff2de254a in cuDevicePrimaryCtxRetain () from /usr/lib/x86_64-linux-gnu/libcuda.so.1
#10 0x00007ffff6ace4f0 in ?? () from /usr/local/cuda/lib64/libcudart.so.10.1
#11 0x00007ffff6ace65c in ?? () from /usr/local/cuda/lib64/libcudart.so.10.1
#12 0x00007ffff6acf191 in ?? () from /usr/local/cuda/lib64/libcudart.so.10.1
#13 0x00007ffff6ad15a8 in ?? () from /usr/local/cuda/lib64/libcudart.so.10.1
#14 0x00007ffff6ac382e in ?? () from /usr/local/cuda/lib64/libcudart.so.10.1
#15 0x00007ffff6aad67e in ?? () from /usr/local/cuda/lib64/libcudart.so.10.1
#16 0x00007ffff6ae50c1 in cudaFree () from /usr/local/cuda/lib64/libcudart.so.10.1
#17 0x0000000000400de4 in main ()

I also write a driver API (cuCtxCreate) test code, but still get segfault.

Of course, it’s work fine if we no add flag -fsanitize=thread.

Environment:
OS : ubuntu 16.04
device : GTX 1080
CUDA : 10.1 update 1
driver : 418.67

CUDA 8 and CUDA 10 run with ThreadSanitizer is fine, have anyone get same issue?

my suggestion would be to report a bug. The instructions are linked in a sticky post at the top of this forum.

Setting the environment variable ASAN_OPTIONS=protect_shadow_gap=0 may work wonders.