* Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
* MindIE is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
* http://license.coscl.org.cn/MulanPSL2
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
#pragma once
#include <map>
#include <sstream>
#include <string>
#include <vector>
#include "request_response/callback.h"
#include "utils/common_util.h"
namespace mindie_llm {
struct DeviceInfo {
std::string deviceIp;
int64_t devicePhysicalId;
int64_t superDeviceId = -1;
};
inline std::ostream &operator<<(std::ostream &os, const DeviceInfo &info) {
os << "DeviceInfo{" << "deviceIp: \"" << info.deviceIp << "\", "
<< "devicePhysicalId: " << info.devicePhysicalId << ", "
<< "superDeviceId: ";
if (info.superDeviceId == -1) {
os << "null";
} else {
os << info.superDeviceId;
}
os << "}";
return os;
}
struct GlobalIpInfo {
std::string role = "none";
bool needInit = false;
bool needSwitch = false;
uint32_t localInstanceId;
uint32_t instanceIdxInPod;
uint32_t numInstancesPerPod;
uint32_t flexPrefillPercentage{0};
bool isSingleContainer = false;
std::vector<std::string> localHostIpList;
std::string localSuperPodId;
std::vector<uint64_t> localDpInstanceIds;
std::vector<std::string> localDeviceIps;
std::vector<std::string> localDeviceLogicalIds;
std::vector<std::string> localDevicePhysicalIds;
std::vector<std::string> localSuperDeviceIds;
std::vector<std::string> localDeviceRankIds;
std::map<uint64_t, std::string> superPodIdInfo;
std::map<uint64_t, int64_t> failLinkInstanceIDAndReason;
std::map<uint64_t, int64_t> spInfo;
std::map<uint64_t, int64_t> cpInfo;
std::map<uint64_t, std::vector<DeviceInfo>> linkIpInfo;
std::map<uint64_t, std::vector<DeviceInfo>> unlinkIpInfo;
std::map<uint64_t, std::vector<std::string>> hostIpInfo;
std::map<uint64_t, std::vector<std::string>> unlinkHostIpInfo;
void ClearIpInfo() {
linkIpInfo.clear();
unlinkIpInfo.clear();
}
void ResetRetryState() {
needSwitch = false;
unlinkIpInfo.clear();
}
std::string ToString() const {
std::ostringstream oss;
oss << "role: " << role << "\n"
<< "needInit: " << std::boolalpha << needInit << "\n"
<< "needSwitch: " << std::boolalpha << needSwitch << "\n"
<< "localInstanceId: " << localInstanceId << "\n"
<< "localDpInstanceIds: " << VectorToString(localDpInstanceIds) << "\n"
<< "localHostIp: " << VectorToString(localHostIpList) << "\n"
<< "localDeviceIps: " << VectorToString(localDeviceIps) << "\n"
<< "localDeviceLogicalIds: " << VectorToString(localDeviceLogicalIds) << "\n"
<< "localDevicePhysicalIds: " << VectorToString(localDevicePhysicalIds) << "\n"
<< "localDeviceRankIds: " << VectorToString(localDeviceRankIds) << "\n"
<< "hostIpInfo: " << MapToString(hostIpInfo) << "\n"
<< "failLinkInstanceIDAndReason: " << MapToString(failLinkInstanceIDAndReason) << "\n"
<< "spSize: " << MapToString(spInfo) << "\n"
<< "cpSize: " << MapToString(cpInfo) << "\n"
<< "linkIpInfo: " << MapToString(linkIpInfo) << "\n"
<< "unlinkIpInfo: " << MapToString(unlinkIpInfo) << "\n";
return oss.str();
}
};
}