Cuda 8 errors when using two 1080 GPUs in multithreading way

I am on CentOS 7.2 with 2 GTX 1080 cards (All my programs run fine with cuda 7.5 and 980 Ti). After upgrading to cuda 8 rc and 2 new 1080 cards, my program works fine with only one 1080 card but got errors with two 1080 cards. My program is multi-threaded, and compiled with ‘–default-stream per-thread’

The error codes are 29 or 30, which mean:

/**
     * This indicates that a CUDA Runtime API call cannot be executed because
     * it is being called during process shut down, at a point in time after
     * CUDA driver has been unloaded.
     */
    cudaErrorCudartUnloading              =     29,

    /**
     * This indicates that an unknown internal error has occurred.
     */
    cudaErrorUnknown                      =     30,

So any idea about this?

This probably can’t be debugged without looking at the code. Nevertheless, I usually see something like this when there are CUDA API calls in destructors. Since it’s possible for destructors to be called after application tear-down has begun, CUDA calls in destructors can throw this error and may be problematic.

If you don’t have any situation like that, then I would carefully analyze your multi-threading scenario to see if you are actually (possibly) initiating application shutdown, (e.g. with exit(0) or the like, perhaps in a CUDA API error checking macro) while your multi-threaded app is still running. If that is the case, then one thread could have started app shutdown while other threads are still running (and possibly issuing a CUDA API call) which could lead to this as well.

May be I should re-check my code. But one thing I don’t quite understand: The code are not changed and they work all fine on old arch(cuda 7.5 + 980 Ti), and the issue seems only occur with 2 GPU being used. Are you sure this is not a bug with cuda(or the driver) itself, or something has changed internally in cuda 8(or in pascal cards)?

And I do have cuda API calls in object destructor, and this is not allowed? Sorry first time heard of this and why? Please

No, I’m not sure of anything. I was just trying to offer some advice.

Follow whatever path seems sensible to you.

regarding cuda calls in destructors, you may wish to read this:

[url]c++ - cuda call fails in destructor - Stack Overflow

@txbob That might be the point, but all my errors were related to cudaMalloc, cudaMallocHost or cudaMemset. So far I haven’t seen any errors reported by cuda API calls in destructors. The errors were located in normal functions. All the cuda API calls in destructors are cufftDestroy, cudaFree and cudaFreeHost. Is this the case of what you said?

It’s wiered. I have tested my code many times and the error was caused by ‘cudaMallocHost’ and then some other errors related to memory manipulations. Sometimes it was caused by some other popular deep learning library(not my code). But the first error must be ‘cudaMallocHost’. (error code is 30)

Can you post the output of DeviceQuery OP?

@ldaddr

./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 2 CUDA Capable device(s)

Device 0: "Graphics Device"
  CUDA Driver Version / Runtime Version          8.0 / 8.0
  CUDA Capability Major/Minor version number:    6.1
  Total amount of global memory:                 8113 MBytes (8507555840 bytes)
  (20) Multiprocessors, (128) CUDA Cores/MP:     2560 CUDA Cores
  GPU Max Clock rate:                            1734 MHz (1.73 GHz)
  Memory Clock rate:                             5005 Mhz
  Memory Bus Width:                              256-bit
  L2 Cache Size:                                 2097152 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
  Maximum Layered 1D Texture Size, (num) layers  1D=(32768), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(32768, 32768), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  2048
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 2 copy engine(s)
  Run time limit on kernels:                     No
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 1 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

Device 1: "Graphics Device"
  CUDA Driver Version / Runtime Version          8.0 / 8.0
  CUDA Capability Major/Minor version number:    6.1
  Total amount of global memory:                 8113 MBytes (8507555840 bytes)
  (20) Multiprocessors, (128) CUDA Cores/MP:     2560 CUDA Cores
  GPU Max Clock rate:                            1734 MHz (1.73 GHz)
  Memory Clock rate:                             5005 Mhz
  Memory Bus Width:                              256-bit
  L2 Cache Size:                                 2097152 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
  Maximum Layered 1D Texture Size, (num) layers  1D=(32768), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(32768, 32768), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  2048
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 2 copy engine(s)
  Run time limit on kernels:                     No
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 2 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
> Peer access from Graphics Device (GPU0) -> Graphics Device (GPU1) : Yes
> Peer access from Graphics Device (GPU1) -> Graphics Device (GPU0) : Yes

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 8.0, CUDA Runtime Version = 8.0, NumDevs = 2, Device0 = Graphics Device, Device1 = Graphics Device
Result = PASS

Thank you super mucho cysin for providing this information ^_^

Are you using 367.18 which support GTX1080 http://www.nvidia.com/download/driverResults.aspx/103732/en-us?

@lw yes I am using 367.18

It compiles right? Have you processed it through the Nvidia profiler?