@@ -332,10 +332,10 @@ DeviceManager::DeviceManager()
|
332 | 332 | |
333 | 333 | sortDevices(); |
334 | 334 | |
335 | | -for(int i = 0; i < nDevices; i++) { |
336 | | - setActiveDevice(i, cuDevices[i].nativeId); |
337 | | - CUDA_CHECK(cudaStreamCreate(&streams[i])); |
338 | | -} |
| 335 | +// Initialize all streams to 0. |
| 336 | +// Streams will be created in setActiveDevice() |
| 337 | +for(int i = 0; i < (int)MAX_DEVICES; i++) |
| 338 | + streams[i] = (cudaStream_t)0; |
339 | 339 | |
340 | 340 | const char* deviceENV = getenv("AF_CUDA_DEFAULT_DEVICE"); |
341 | 341 | if(!deviceENV) { |
@@ -381,6 +381,11 @@ int DeviceManager::setActiveDevice(int device, int nId)
|
381 | 381 | if(nId == -1) nId = getDeviceNativeId(device); |
382 | 382 | CUDA_CHECK(cudaSetDevice(nId)); |
383 | 383 | activeDev = device; |
| 384 | + |
| 385 | +if(!streams[device]) { |
| 386 | +CUDA_CHECK(cudaStreamCreate(&streams[device])); |
| 387 | + } |
| 388 | + |
384 | 389 | return old; |
385 | 390 | } |
386 | 391 | } |
|