-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ON HOLD] Unit Tests for CPX mode #1319
Open
saurabhAMD
wants to merge
2
commits into
ROCm:develop
Choose a base branch
from
saurabhAMD:cpxUT
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+156
−30
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
#include <cstdlib> | ||
#include <unistd.h> | ||
#include <sys/wait.h> | ||
#include <iostream> | ||
#include <unordered_map> | ||
|
||
namespace RcclUnitTesting | ||
{ | ||
|
@@ -88,6 +90,117 @@ namespace RcclUnitTesting | |
return TEST_SUCCESS; | ||
} | ||
|
||
|
||
std::string execCommand(const char* cmd) { | ||
std::array<char, 128> buffer; | ||
std::string result; | ||
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose); | ||
if (!pipe) { | ||
throw std::runtime_error("popen() failed!"); | ||
} | ||
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { | ||
result += buffer.data(); | ||
} | ||
return result; | ||
} | ||
|
||
|
||
int getDevicePriority (std::vector<int> *gpuPriorityOrder){ | ||
// Prepare parent->child pipe | ||
int pipefd[2]; | ||
if (pipe(pipefd) == -1) { | ||
ERROR("Unable to create parent->child pipe for getting the device priority vector.\n"); | ||
return TEST_FAIL; | ||
} | ||
pid_t pid = fork(); | ||
if (0 == pid) { | ||
std::vector<int> result; | ||
try { | ||
std::string log = execCommand("rocm-smi --showuniqueid"); | ||
std::unordered_map<std::string, std::vector<int>> uniqueIdToGpuIndexes; | ||
std::string::size_type pos = 0; | ||
|
||
while ((pos = log.find("GPU[", pos)) != std::string::npos) { | ||
int gpuIndex = std::stoi(log.substr(pos + 4)); | ||
std::string::size_type idPos = log.find("Unique ID:", pos); | ||
if (idPos == std::string::npos) break; | ||
std::string::size_type idEnd = log.find_first_of(" \n", idPos + 11); | ||
std::string uniqueId = log.substr(idPos + 11, idEnd - (idPos + 11)); | ||
uniqueIdToGpuIndexes[uniqueId].push_back(gpuIndex); | ||
pos = log.find('\n', pos); | ||
} | ||
|
||
// Create a vector of pairs for sorting unique IDs based on the number of associated GPUs | ||
std::vector<std::pair<std::string, std::vector<int>>> sortedIds(uniqueIdToGpuIndexes.begin(), uniqueIdToGpuIndexes.end()); | ||
std::sort(sortedIds.begin(), sortedIds.end(), [](const auto& a, const auto& b) { | ||
return a.second.size() > b.second.size(); | ||
}); | ||
|
||
for (const auto& pair : sortedIds) { | ||
result.insert(result.end(), pair.second.begin(), pair.second.end()); | ||
} | ||
} catch (const std::exception& e) { | ||
std::cerr << "Error: " << e.what() << std::endl; | ||
return 1; | ||
} | ||
if (write(pipefd[1], result.data(), gpuPriorityOrder->size() * sizeof(int)) != gpuPriorityOrder->size() * sizeof(int)) return TEST_FAIL; | ||
close(pipefd[0]); | ||
close(pipefd[1]); | ||
exit(EXIT_SUCCESS); | ||
} | ||
else { | ||
int status; | ||
if (read(pipefd[0], gpuPriorityOrder->data(), gpuPriorityOrder->size() * sizeof(int)) != gpuPriorityOrder->size() * sizeof(int)) return TEST_FAIL; | ||
waitpid(pid, &status, 0); | ||
assert(!status); | ||
close(pipefd[0]); | ||
close(pipefd[1]); | ||
} | ||
return TEST_SUCCESS; | ||
return 0; | ||
} | ||
|
||
|
||
int getDeviceMode (bool *cpxMode){ | ||
// Prepare parent->child pipe | ||
int pipefd[2]; | ||
if (pipe(pipefd) == -1) | ||
{ | ||
ERROR("Unable to create parent->child pipe for getting the device mode\n"); | ||
return TEST_FAIL; | ||
} | ||
pid_t pid = fork(); | ||
if (0 == pid) | ||
{ | ||
bool iscpxMode = false; | ||
try { | ||
std::string log = execCommand("rocm-smi --showcomputepartition"); | ||
bool foundCPX = log.find("CPX") != std::string::npos; | ||
if (foundCPX) { | ||
iscpxMode = true; | ||
} | ||
} catch (const std::exception& e) { | ||
std::cerr << "Error: " << e.what() << std::endl; | ||
return 1; | ||
} | ||
if (write(pipefd[1], &iscpxMode, sizeof(iscpxMode)) != sizeof(iscpxMode)) return TEST_FAIL; | ||
close(pipefd[0]); | ||
close(pipefd[1]); | ||
exit(EXIT_SUCCESS); | ||
} | ||
else { | ||
int status; | ||
if (read(pipefd[0], cpxMode, sizeof(*cpxMode)) != sizeof(*cpxMode)) return TEST_FAIL; | ||
waitpid(pid, &status, 0); | ||
assert(!status); | ||
close(pipefd[0]); | ||
close(pipefd[1]); | ||
} | ||
return TEST_SUCCESS; | ||
return 0; | ||
} | ||
|
||
|
||
EnvVars::EnvVars() | ||
{ | ||
// Collect number of GPUs available | ||
|
@@ -115,6 +228,18 @@ namespace RcclUnitTesting | |
// Total number of reduction ops | ||
int numOps = ncclNumOps; | ||
|
||
gpuPriorityOrder.resize(numDetectedGpus); | ||
for(int i=0;i<numDetectedGpus;i++){ | ||
gpuPriorityOrder[i] = i; | ||
} | ||
if(isGfx94) { | ||
bool cpxMode = false; | ||
getDeviceMode(&cpxMode); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The return value of |
||
if(cpxMode) { | ||
onlyPow2Gpus = true; | ||
getDevicePriority(&gpuPriorityOrder); | ||
} | ||
} | ||
std::vector<std::string> redOpStrings = GetEnvVarsList("UT_REDOPS"); | ||
for (auto s : redOpStrings) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious why
rocm-smi
is run in a fork process?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we cannot use HIP call prior to launching unless it is inside another child process. You can refer to line 207 for this comment. The same procedure is used for other features such as finding the architecture of the system as in line 211.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In your case, I think
popen
already forks and creates a pipe internally, so you may not need your own fork. If so,getDeviceMode
andgetDevicePriority
can be simplified.