天天看点

把几个任务分配到几个设备上的代码

比如,吾有几个任务,想平均分配到几个设备上,怎么办?

  1. 如果能均分当然好办。
  2. 不能均分,把多出的任务分给前几个。
//先计算每个GPU上要承载几个任务
 
//平均分配
int tpg    = task_count/nGpuCount;
 
//如果有剩下的,再加1。这样前几个GPU多一个任务。
int left   = task_count % nGpuCount;
if (left != 0)
{
    tpg++;
}
 
//以任务序号,计算使用哪个GPU
int gpu_id = i/tpg;