Skip to content

Commit

Permalink
Create a few CUDA events per thread pool thread
Browse files Browse the repository at this point in the history
Signed-off-by: Joaquin Anton Guirao <janton@nvidia.com>
  • Loading branch information
jantonguirao committed Jul 22, 2024
1 parent fc77109 commit 820495b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions dali/pipeline/util/thread_pool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "dali/core/cuda_error.h"
#include "dali/core/device_guard.h"
#include "dali/core/nvtx.h"
#include "dali/core/cuda_event_pool.h"
#include "dali/core/cuda_event.h"

namespace dali {

Expand All @@ -41,6 +43,24 @@ ThreadPool::ThreadPool(int num_thread, int device_id, bool set_affinity, const c
make_string("[DALI][TP", i, "]", name)));
}
tl_errors_.resize(num_thread);

if (device_id != CPU_ONLY_DEVICE_ID) {
static int num_events_per_thread = -1;
if (num_events_per_thread < 0) {
const char *num_events_per_thread_env = std::getenv("DALI_NUM_EVENTS_PER_THREAD");
num_events_per_thread = !num_events_per_thread_env || atoi(num_events_per_thread_env);
}
if (num_events_per_thread < 0)
num_events_per_thread = 4;

DeviceGuard dg(device_id);
auto &event_pool = CUDAEventPool::instance();

int num_events = num_thread * num_events_per_thread;
for (int i = 0; i < num_events; ++i) {
event_pool.Put(CUDAEvent::CreateWithFlags(cudaEventDisableTiming));
}
}
}

ThreadPool::~ThreadPool() {
Expand Down

0 comments on commit 820495b

Please sign in to comment.