Stream doesn't synchronize when operating from a thread? #536
-
Hello, First of all, many thanks for this great library. This makes it much easier to work with CUDA APIs :) I have a question that may be orthogonal to this particular library (unless it's a bug)? I am using an async CUDA stream ( Is that thread + cudaStreamSynchronize scenario supported? Am I using the API correctly? Here is a snippet reproducing what I have. The ASSERT is failing, i.e., the line before doesn't wait for copies to finish. void distributed_stream_loader_t::start() {
// The thread which operate CUDA streams
cpp_thread = std::thread(&distributed_stream_loader_t::async_process, this);
}
void distributed_stream_loader_t::async_process() {
// Creation of the CUDA async stream, from within the thread
auto device = cuda::device::current::get();
std::generate_n(
std::back_inserter(m_streams), 1,
[&device]() {
return device.create_stream(cuda::stream::async);
}
);
// Infinite loop executing CUDA async copies on the stream
while (true) {
...
for (size_t j = 0; j < num_targets; j++) {
cuda::memory::async::copy(
dest_targets->data_ptr<long int>() + batch.aug_size,
t_label.data_ptr(),
t_label.element_size(),
m_streams[0]
);
}
...
// Synchronization of the stream
m_streams[0].synchronize();
//or cuda::device::current::get().synchronize();
// This makes sure that the copies are finished..... this is failing
ASSERT(async_copies_finished);
}
} Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Not related to that library, closing. |
Beta Was this translation helpful? Give feedback.
Not related to that library, closing.