src/ray/raylet/scheduling/cluster_resource_scheduler.cc
/// Convert a map of resources to a TaskRequest data structure.
///
/// \param string_to_int_map: Map between names and ids maintained by the
/// \param resource_map_total: Total capacities of resources we want to convert.
/// \param resource_map_available: Available capacities of resources we want to convert.
///
/// \request Conversion result to a TaskRequest data structure.
Convert a map of resources to a TaskRequest data structure.
\param string_to_int_map: Map between names and ids maintained by the
\param resource_map_total: Total capacities of resources we want to convert.
\param resource_map_available: Available capacities of resources we want to convert.

\request Conversion result to a TaskRequest data structure.
Convert a map of resources to a TaskRequest data structure . \ param string_to_int_map : Map between names and ids maintained by the \ param resource_map_total : Total capacities of resources we want to convert . \ param resource_map_available : Available capacities of resources we want to convert . \ request Conversion result to a TaskRequest data structure .
NodeResources ResourceMapToNodeResources(
    StringIdMap &string_to_int_map,
    const std::unordered_map<std::string, double> &resource_map_total,
    const std::unordered_map<std::string, double> &resource_map_available) {
  NodeResources node_resources;
  node_resources.predefined_resources.resize(PredefinedResources_MAX);
  for (size_t i = 0; i < PredefinedResources_MAX; i++) {
    node_resources.predefined_resources[i].total =
        node_resources.predefined_resources[i].available = 0;
  }
  for (auto const &resource : resource_map_total) {
    ResourceCapacity resource_capacity;
    resource_capacity.total = resource.second;
    auto it = resource_map_available.find(resource.first);
    if (it == resource_map_available.end()) {
      resource_capacity.available = 0;
    } else {
      resource_capacity.available = it->second;
    }
    if (resource.first == ray::kCPU_ResourceLabel) {
      node_resources.predefined_resources[CPU] = resource_capacity;
    } else if (resource.first == ray::kGPU_ResourceLabel) {
      node_resources.predefined_resources[GPU] = resource_capacity;
    } else if (resource.first == ray::kTPU_ResourceLabel) {
      node_resources.predefined_resources[TPU] = resource_capacity;
    } else if (resource.first == ray::kMemory_ResourceLabel) {
      node_resources.predefined_resources[MEM] = resource_capacity;
    } else {
      node_resources.custom_resources.emplace(string_to_int_map.Insert(resource.first),
                                              resource_capacity);
    }
  }
  return node_resources;
}
NodeResources ResourceMapToNodeResources ( StringIdMap & string_to_int_map , const std :: unordered_map < std :: string , double > & resource_map_total , const std :: unordered_map < std :: string , double > & resource_map_available ) { NodeResources node_resources ; node_resources . predefined_resources . resize ( PredefinedResources_MAX ) ; for ( size_t i = 0 ; i < PredefinedResources_MAX ; i ++ ) { node_resources . predefined_resources [ i ] . total = node_resources . predefined_resources [ i ] . available = 0 ; } for ( auto const & resource : resource_map_total ) { ResourceCapacity resource_capacity ; resource_capacity . total = resource . second ; auto it = resource_map_available . find ( resource . first ) ; if ( it == resource_map_available . end ( ) ) { resource_capacity . available = 0 ; } else { resource_capacity . available = it -> second ; } if ( resource . first == ray :: kCPU_ResourceLabel ) { node_resources . predefined_resources [ CPU ] = resource_capacity ; } else if ( resource . first == ray :: kGPU_ResourceLabel ) { node_resources . predefined_resources [ GPU ] = resource_capacity ; } else if ( resource . first == ray :: kTPU_ResourceLabel ) { node_resources . predefined_resources [ TPU ] = resource_capacity ; } else if ( resource . first == ray :: kMemory_ResourceLabel ) { node_resources . predefined_resources [ MEM ] = resource_capacity ; } else { node_resources . custom_resources . emplace ( string_to_int_map . Insert ( resource . first ) , resource_capacity ) ; } } return node_resources ; }
Convert a map of resources to a TaskRequest data structure.
Convert a map of resources to a TaskRequest data structure .
// This is a custom resource.