Skip to content

Commit

Permalink
fix GPU data race
Browse files Browse the repository at this point in the history
Previously, the prefetch GPU -> top GPU and prefetch CPU -> prefetch GPU
copies were launched concurrently in separate streams, allowing the next
batch to be copied in before the current one is read.

This patch explicitly synchronizes the prefetch -> top copy wrt the
host, preventing the CPU -> GPU from being launched until its
completion.
  • Loading branch information
longjon committed Aug 30, 2015
1 parent 4c561fd commit 846f2c3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/caffe/layers/base_data_layer.cu
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ void BasePrefetchingDataLayer<Dtype>::Forward_gpu(
caffe_copy(batch->label_.count(), batch->label_.gpu_data(),
top[1]->mutable_gpu_data());
}

// Ensure the copy is synchronous wrt the host, so that the next batch isn't
// copied in meanwhile.
CUDA_CHECK(cudaStreamSynchronize(cudaStreamDefault));
prefetch_free_.push(batch);
}

Expand Down

0 comments on commit 846f2c3

Please sign in to comment.