src/ray/raylet/scheduling/cluster_resource_scheduler.cc
/// Convert a map of resources to a TaskRequest data structure.
Convert a map of resources to a TaskRequest data structure.
Convert a map of resources to a TaskRequest data structure .
TaskRequest ResourceMapToTaskRequest(
    StringIdMap &string_to_int_map,
    const std::unordered_map<std::string, double> &resource_map) {
  size_t i = 0;
  TaskRequest task_request;
  task_request.predefined_resources.resize(PredefinedResources_MAX);
  task_request.custom_resources.resize(resource_map.size());
  for (size_t i = 0; i < PredefinedResources_MAX; i++) {
    task_request.predefined_resources[0].demand = 0;
    task_request.predefined_resources[0].soft = false;
  }
  for (auto const &resource : resource_map) {
    if (resource.first == ray::kCPU_ResourceLabel) {
      task_request.predefined_resources[CPU].demand = resource.second;
    } else if (resource.first == ray::kGPU_ResourceLabel) {
      task_request.predefined_resources[GPU].demand = resource.second;
    } else if (resource.first == ray::kTPU_ResourceLabel) {
      task_request.predefined_resources[TPU].demand = resource.second;
    } else if (resource.first == ray::kMemory_ResourceLabel) {
      task_request.predefined_resources[MEM].demand = resource.second;
    } else {
      task_request.custom_resources[i].id = string_to_int_map.Insert(resource.first);
      task_request.custom_resources[i].demand = resource.second;
      task_request.custom_resources[i].soft = false;
      i++;
    }
  }
  task_request.custom_resources.resize(i);
  return task_request;
}
TaskRequest ResourceMapToTaskRequest ( StringIdMap & string_to_int_map , const std :: unordered_map < std :: string , double > & resource_map ) { size_t i = 0 ; TaskRequest task_request ; task_request . predefined_resources . resize ( PredefinedResources_MAX ) ; task_request . custom_resources . resize ( resource_map . size ( ) ) ; for ( size_t i = 0 ; i < PredefinedResources_MAX ; i ++ ) { task_request . predefined_resources [ 0 ] . demand = 0 ; task_request . predefined_resources [ 0 ] . soft = false ; } for ( auto const & resource : resource_map ) { if ( resource . first == ray :: kCPU_ResourceLabel ) { task_request . predefined_resources [ CPU ] . demand = resource . second ; } else if ( resource . first == ray :: kGPU_ResourceLabel ) { task_request . predefined_resources [ GPU ] . demand = resource . second ; } else if ( resource . first == ray :: kTPU_ResourceLabel ) { task_request . predefined_resources [ TPU ] . demand = resource . second ; } else if ( resource . first == ray :: kMemory_ResourceLabel ) { task_request . predefined_resources [ MEM ] . demand = resource . second ; } else { task_request . custom_resources [ i ] . id = string_to_int_map . Insert ( resource . first ) ; task_request . custom_resources [ i ] . demand = resource . second ; task_request . custom_resources [ i ] . soft = false ; i ++ ; } } task_request . custom_resources . resize ( i ) ; return task_request ; }
Convert a map of resources to a TaskRequest data structure.
Convert a map of resources to a TaskRequest data structure .