src/runtime/machine_model.cc
// assume each GPU has nvlinks to the other GPUs on the same node and the nvlinks have the same latency and bandwidth
assume each GPU has nvlinks to the other GPUs on the same node and the nvlinks have the same latency and bandwidth
assume each GPU has nvlinks to the other GPUs on the same node and the nvlinks have the same latency and bandwidth
void EnhancedMachineModel::add_nvlinks(float latency, float bandwidth)
{
  int num_gpus_per_node = num_gpus_per_socket * num_sockets_per_node;
  num_nvlinks_per_node = num_gpus_per_node * (num_gpus_per_node - 1) / 2;
  for (int i = 0; i < num_nodes; i++) {
    int node_id = i;
    int socket_id = i * num_sockets_per_node;
    nvlinks.push_back({});
    for (int j = 0; j < num_nvlinks_per_node * 2; j++) {
      int nvlink_id = node_id * num_nvlinks_per_node * 2 + j;
      std::string nvlink_name = "NVLINK " + std::to_string(nvlink_id);
      nvlinks[i].push_back(new CommDevice(nvlink_name, CommDevice::NVLINK_COMM, node_id, socket_id, nvlink_id, latency, bandwidth));
    }
    for (int j = 0; j < num_sockets_per_node; j++) {
      int src_socket_id = i * num_sockets_per_node + j;
      for (int k = 0; k < num_gpus_per_socket; k++) {
        MemDevice *src_gpu_fb_mem = gpu_fb_mems[src_socket_id][k];
        int src_local_id = j * num_gpus_per_socket + k;
        for (int l = 0; l < num_sockets_per_node; l++) {
          int tar_socket_id = i * num_sockets_per_node + l;
          for (int m = 0; m < num_gpus_per_socket; m++) {
            MemDevice *tar_gpu_fb_mem = gpu_fb_mems[tar_socket_id][m];
            int tar_local_id = l * num_gpus_per_socket + m;
            if (src_local_id != tar_local_id) {
              int local_nvlink_id = src_local_id * (num_gpus_per_node - 1) + tar_local_id;
              if (tar_local_id > src_local_id) {
                local_nvlink_id--;
              }
              attach_nvlink(src_gpu_fb_mem, tar_gpu_fb_mem, nvlinks[i][local_nvlink_id]);
              printf("add nvlink: gpu_fb_mem %d , gpu_fb_mem %d, nvlink %d %d\n", src_gpu_fb_mem->device_id, tar_gpu_fb_mem->device_id, node_id, local_nvlink_id);
            }
          }
        }
      }
    }
  }
}
void EnhancedMachineModel :: add_nvlinks ( float latency , float bandwidth ) { int num_gpus_per_node = num_gpus_per_socket * num_sockets_per_node ; num_nvlinks_per_node = num_gpus_per_node * ( num_gpus_per_node - 1 ) / 2 ; for ( int i = 0 ; i < num_nodes ; i ++ ) { int node_id = i ; int socket_id = i * num_sockets_per_node ; nvlinks . push_back ( { } ) ; for ( int j = 0 ; j < num_nvlinks_per_node * 2 ; j ++ ) { int nvlink_id = node_id * num_nvlinks_per_node * 2 + j ; std :: string nvlink_name = " " + std :: to_string ( nvlink_id ) ; nvlinks [ i ] . push_back ( new CommDevice ( nvlink_name , CommDevice :: NVLINK_COMM , node_id , socket_id , nvlink_id , latency , bandwidth ) ) ; } for ( int j = 0 ; j < num_sockets_per_node ; j ++ ) { int src_socket_id = i * num_sockets_per_node + j ; for ( int k = 0 ; k < num_gpus_per_socket ; k ++ ) { MemDevice * src_gpu_fb_mem = gpu_fb_mems [ src_socket_id ] [ k ] ; int src_local_id = j * num_gpus_per_socket + k ; for ( int l = 0 ; l < num_sockets_per_node ; l ++ ) { int tar_socket_id = i * num_sockets_per_node + l ; for ( int m = 0 ; m < num_gpus_per_socket ; m ++ ) { MemDevice * tar_gpu_fb_mem = gpu_fb_mems [ tar_socket_id ] [ m ] ; int tar_local_id = l * num_gpus_per_socket + m ; if ( src_local_id != tar_local_id ) { int local_nvlink_id = src_local_id * ( num_gpus_per_node - 1 ) + tar_local_id ; if ( tar_local_id > src_local_id ) { local_nvlink_id -- ; } attach_nvlink ( src_gpu_fb_mem , tar_gpu_fb_mem , nvlinks [ i ] [ local_nvlink_id ] ) ; printf ( " \n " , src_gpu_fb_mem -> device_id , tar_gpu_fb_mem -> device_id , node_id , local_nvlink_id ) ; } } } } } } }
assume each GPU has nvlinks to the other GPUs on the same node and the nvlinks have the same latency and bandwidth
assume each GPU has nvlinks to the other GPUs on the same node and the nvlinks have the same latency and bandwidth