Repository: pytorch
Issue: PyTorch streams are not cuda-memcheck clean
Labels: module: cuda,triaged

## 🐛 Bug

PyTorch streams are not cuda-memcheck clean

## To Reproduce

Steps to reproduce the behavior:

Create the following PyTorch script, which initializes our stream pool:

```
import torch
torch.cuda.Stream()
```

Run it with `cuda-memcheck`. You'll get 64 warnings. Here's a few:

```
========= Program hit cudaErrorCudartUnloading (error 29) due to "driver shutting down" on CUDA API call to cudaStreamDestroy. 
=========     Saved host backtrace up to driver entry point at error
=========     Host Frame:/usr/lib64/nvidia/libcuda.so.1 [0x3478e3]
=========     Host Frame:/data/users/ezyang/pytorch-tmp/torch/lib/libcaffe2_gpu.so [0x2ae05de]
=========     Host Frame:/data/users/ezyang/pytorch-tmp/torch/lib/libcaffe2_gpu.so (_ZNSt6vectorISt5arrayI19CUDAStreamInternalsLm32EESaIS2_EED1Ev + 0x57) [0x2662317]
=========     Host Frame:/lib64/libc.so.6 [0x39bd9]
=========     Host Frame:/lib64/libc.so.6 [0x39c27]
=========     Host Frame:/lib64/libc.so.6 (__libc_start_main + 0xfc) [0x2244c]
=========     Host Frame:python [0x1c7773]
=========
========= Program hit cudaErrorCudartUnloading (error 29) due to "driver shutting down" on CUDA API call to cudaStreamDestroy. 
=========     Saved host backtrace up to driver entry point at error
=========     Host Frame:/usr/lib64/nvidia/libcuda.so.1 [0x3478e3]
=========     Host Frame:/data/users/ezyang/pytorch-tmp/torch/lib/libcaffe2_gpu.so [0x2ae05de]
=========     Host Frame:/data/users/ezyang/pytorch-tmp/torch/lib/libcaffe2_gpu.so (_ZNSt6vectorISt5arrayI19CUDAStreamInternalsLm32EESaIS2_EED1Ev + 0x57) [0x2662317]
=========     Host Frame:/lib64/libc.so.6 [0x39bd9]
=========     Host Frame:/lib64/libc.so.6 [0x39c27]
=========     Host Frame:/lib64/libc.so.6 (__libc_start_main + 0xfc) [0x2244c]
=========     Host Frame:python [0x1c7773]
=========
========= Program hit cudaErrorCudartUnloading (error 29) due to "driver shutting down" on CUDA API call to cudaStreamDestroy. 
=========     Saved host backtrace up to driver entry point at error
=========     Host Frame:/usr/lib64/nvidia/libcuda.so.1 [0x3478e3]
=========     Host Frame:/data/users/ezyang/pytorch-tmp/torch/lib/libcaffe2_gpu.so [0x2ae05de]
=========     Host Frame:/data/users/ezyang/pytorch-tmp/torch/lib/libcaffe2_gpu.so (_ZNSt6vectorISt5arrayI19CUDAStreamInternalsLm32EESaIS2_EED1Ev + 0x57) [0x2662317]
=========     Host Frame:/lib64/libc.so.6 [0x39bd9]
=========     Host Frame:/lib64/libc.so.6 [0x39c27]
=========     Host Frame:/lib64/libc.so.6 (__libc_start_main + 0xfc) [0x2244c]
=========     Host Frame:python [0x1c7773]
=========
========= ERROR SUMMARY: 64 errors
```

## Expected behavior

No errors

## Environment

```
Collecting environment information...
PyTorch version: 1.0.0a0+583731d
Is debug build: No
CUDA used to build PyTorch: 9.2.88

OS: CentOS Linux 7 (Core)
GCC version: (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28)
CMake version: version 3.11.1

Python version: 3.6
Is CUDA available: Yes
CUDA runtime version: 9.2.88
GPU models and configuration: 
GPU 0: Tesla M40
GPU 1: Tesla M40
GPU 2: Tesla M40
GPU 3: Tesla M40
GPU 4: Tesla M40
GPU 5: Tesla M40
GPU 6: Tesla M40
GPU 7: Tesla M40

Nvidia driver version: 396.26
cuDNN version: Probably one of the following:
/usr/local/cuda-9.2/targets/x86_64-linux/lib/libcudnn.so.7.1.2
/usr/local/cuda-9.2/targets/x86_64-linux/lib/libcudnn.so.7.1.4
/usr/local/cuda-9.2/targets/x86_64-linux/lib/libcudnn_static.a

Versions of relevant libraries:
[pip] numpy (1.14.3)
[pip] onnx (1.2.1, /data/users/ezyang/pytorch-tmp/third_party/onnx)
[pip] torch (1.0.0a0+583731d, /data/users/ezyang/pytorch-tmp)
[pip] torch-complex (0.0.1, /data/users/ezyang/complex)
[pip] torchvision (0.2.1)
[conda] magma-cuda91              2.3.0                         1    pytorch
[conda] torchvision               0.2.1                     <pip>
```

## Additional context

CC @mruberry 

cc @ngimel