我的程序是一个管道,它包含多个内核和 memcpys。每个任务将通过具有不同输入数据的相同管道。主机代码在处理任务时首先会选择一个 Channel,它是暂存器内存和 CUDA 对象的封装。在最后一个阶段之后,我将记录一个事件,然后去处理下一个任务。
主要流水线逻辑如下。问题是不同流中的操作不重叠。我附上了处理 10 个任务的时间表。您可以看到流中的任何操作都没有重叠。对于每个内核,一个块中有 256 个线程,一个网格中有 5 个块。用于 memcpy 的所有缓冲区都已固定,我确信我已满足这些要求用于重叠内核执行和数据传输。有人可以帮我找出原因吗?谢谢。
环境信息
GPU:Tesla K40m (GK110)
Max Warps/SM:64
Max Thread Blocks/SM:16
Max Threads/SM:2048
CUDA版本:8.0
void execute_task_pipeline(int stage, MyTask *task, Channel *channel) {
assert(channel->taken);
assert(!task->finish());
GPUParam *para = &channel->para;
assert(para->col_num > 0);
assert(para->row_num > 0);
// copy vid_list to device
CUDA_ASSERT( cudaMemcpyAsync(para->vid_list_d, task->vid_list.data(),
sizeof(uint) * para->row_num, cudaMemcpyHostToDevice, channel->stream) );
k_get_slot_id_list<<<WK_GET_BLOCKS(para->row_num),
WK_CUDA_NUM_THREADS, 0, channel->stream>>>(
vertices_d,
para->vid_list_d,
para->slot_id_list_d,
config.num_buckets,
para->row_num);
k_get_edge_list<<<WK_GET_BLOCKS(para->row_num),
WK_CUDA_NUM_THREADS, 0, channel->stream>>>(
vertices_d,
para->slot_id_list_d,
para->edge_size_list_d,
para->offset_list_d,
para->row_num);
k_calc_prefix_sum(para, channel->stream);
k_update_result_table_k2u<<<WK_GET_BLOCKS(para->row_num),
WK_CUDA_NUM_THREADS, 0, channel->stream>>>(
edges_d,
para->vid_list_d,
para->updated_result_table_d,
para->prefix_sum_list_d,
para->offset_list_d,
para->col_num,
para->row_num);
para->col_num += 1;
// copy result back to host
CUDA_ASSERT( cudaMemcpyAsync(&(channel->num_new_rows), para->prefix_sum_list_d + para->row_num - 1,
sizeof(uint), cudaMemcpyDeviceToHost, channel->stream) );
// copy result to host memory
CUDA_ASSERT( cudaMemcpyAsync(channel->h_buf, para->updated_result_table_d,
channel->num_new_rows * (para->col_num + 1), cudaMemcpyDeviceToHost, channel->stream) );
// insert a finish event in the end of pipeline
CUDA_ASSERT( cudaEventRecord(channel->fin_event, channel->stream) );
}