Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion flagcx/core/cost_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ flagcxResult_t flagcxAlgoTimeEstimator::getAlgoTime(float *time) {
const char *interServerTopoFile =
flagcxGetEnv("FLAGCX_INTERSERVER_ROUTE_FILE");
if (enableTopoDetect && interServerTopoFile &&
strcmp(enableTopoDetect, "TRUE") == 0) {
(strcmp(enableTopoDetect, "TRUE") == 0 ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try strcasecmp instead

strcmp(enableTopoDetect, "True") == 0)) {
Comment on lines +13 to +14

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Instead of checking for "TRUE" and "True" separately, using a case-insensitive comparison would be more robust and cleaner. The strcasecmp function (from <strings.h>) can handle all cases like "TRUE", "True", and "true" with a single call, simplifying the code. This same pattern is repeated in other files in this pull request.

      strcasecmp(enableTopoDetect, "TRUE") == 0) {

// algo time estimator depends on cluster level topology detection
float preHomoTime, heteroTime, postHomoTime;
INFO(FLAGCX_GRAPH, "COST_MODEL: getting time for prehomo funcs");
Expand Down
2 changes: 1 addition & 1 deletion flagcx/core/init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ static flagcxResult_t flagcxCommInitRankFunc(struct flagcxAsyncJob *job_) {
}
FLAGCXCHECK(flagcxNetInit(comm));
INFO(FLAGCX_INIT, "Using network %s", comm->netAdaptor->name);
if (env && strcmp(env, "TRUE") == 0) {
if (env && (strcmp(env, "TRUE") == 0 || strcmp(env, "True") == 0)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To make the environment variable check more robust, consider using a case-insensitive string comparison. The strcasecmp function from <strings.h> would handle all variations like "TRUE", "True", and "true", which simplifies the condition and improves maintainability.

Suggested change
if (env && (strcmp(env, "TRUE") == 0 || strcmp(env, "True") == 0)) {
if (env && strcasecmp(env, "TRUE") == 0) {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This env is useless and we can remove it.

INFO(FLAGCX_INIT, "getting busId for cudaDev %d", comm->cudaDev);
FLAGCXCHECK(getBusId(comm->cudaDev, &comm->busId));
INFO(FLAGCX_INIT, "getting commHash for rank %d", comm->rank);
Expand Down
3 changes: 2 additions & 1 deletion flagcx/core/topo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,8 @@ flagcxResult_t flagcxGetLocalNetFromGpu(int apu, int *dev,
}

if (strlen(name) == 0 && enable_topo_detect &&
strcmp(enable_topo_detect, "TRUE") == 0) {
(strcmp(enable_topo_detect, "TRUE") == 0 ||
strcmp(enable_topo_detect, "True") == 0)) {
Comment on lines +540 to +541

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

A case-insensitive comparison using strcasecmp (from <strings.h>) would be a more robust and cleaner way to check this environment variable. It would handle various capitalizations like "TRUE", "True", and "true" in a single function call.

      (strcmp(enable_topo_detect, "TRUE") == 0 || strcasecmp(enable_topo_detect, "True") == 0)) {

FLAGCXCHECK(flagcxTopoGetLocalNet(comm->topoServer, comm->rank, dev));
}

Expand Down
9 changes: 5 additions & 4 deletions flagcx/flagcx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,10 @@ flagcxResult_t flagcxCommInitRank(flagcxComm_t *comm, int nranks,
struct flagcxNicDistance *nicDistanceData;
FLAGCXCHECK(flagcxCalloc(&nicDistanceData, nranks));
const char *enableTopoDetect = flagcxGetEnv("FLAGCX_ENABLE_TOPO_DETECT");
if (enableTopoDetect && strcmp(enableTopoDetect, "TRUE") ==
0) { // safety check nic distance is only
// available after topo detection
if (enableTopoDetect && (strcmp(enableTopoDetect, "TRUE") == 0 ||
strcmp(enableTopoDetect, "True") ==
0)) { // safety check nic distance is only
Comment on lines +487 to +489

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This logic for checking the environment variable is duplicated in several files. Using a case-insensitive comparison like strcasecmp would simplify this condition and make it more robust. To improve maintainability and avoid code duplication, consider creating a shared helper function for this check.

    if (enableTopoDetect && strcasecmp(enableTopoDetect, "TRUE") == 0) { // safety check nic distance is only

// available after topo detection
FLAGCXCHECK(flagcxGetNicDistance((*comm)->hetero_comm->topoServer, rank,
nicDistanceData + rank));
} else {
Expand Down Expand Up @@ -1762,4 +1763,4 @@ flagcxResult_t flagcxGroupEnd(flagcxComm_t comm) {
}
}
return flagcxSuccess;
}
}