Skip to content

Commit

Permalink
Call cudaSetDevice() in all thread pool worker threads.
Browse files Browse the repository at this point in the history
Possible fix for #63.
  • Loading branch information
mmp committed Oct 21, 2020
1 parent 00bfa32 commit 8578a3e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/pbrt/gpu/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,10 @@ void GPUInit() {
CUDA_CHECK(cudaDeviceSetCacheConfig(cudaFuncCachePreferL1));
}

void GPUThreadInit() {
int device = Options->gpuDevice ? *Options->gpuDevice : 0;
LOG_VERBOSE("Selecting GPU device %d", device);
CUDA_CHECK(cudaSetDevice(device));
}

} // namespace pbrt
1 change: 1 addition & 0 deletions src/pbrt/gpu/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace pbrt {

void GPUInit();
void GPUThreadInit();

} // namespace pbrt

Expand Down
7 changes: 7 additions & 0 deletions src/pbrt/util/parallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

#include <pbrt/util/check.h>
#include <pbrt/util/print.h>
#ifdef PBRT_BUILD_GPU_RENDERER
#include <pbrt/gpu/init.h>
#endif // PBRT_BUILD_GPU_RENDERER

#include <iterator>
#include <list>
Expand Down Expand Up @@ -110,6 +113,10 @@ void ThreadPool::workerFunc(int tIndex) {
LOG_VERBOSE("Started execution in worker thread %d", tIndex);
ThreadIndex = tIndex;

#ifdef PBRT_BUILD_GPU_RENDERER
GPUThreadInit();
#endif // PBRT_BUILD_GPU_RENDERER

std::unique_lock<std::mutex> lock(mutex);
while (!shutdownThreads)
WorkOrWait(&lock);
Expand Down

0 comments on commit 8578a3e

Please sign in to comment.