Skip to content

Commit

Permalink
Refactor the code that print the test output (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
CongMa13 authored Jan 21, 2025
1 parent a5b50a8 commit 7910010
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 204 deletions.
150 changes: 61 additions & 89 deletions test/01_contraction/contraction_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,29 @@ namespace hiptensor

std::ostream& ContractionTest::printHeader(std::ostream& stream /* = std::cout */) const
{
return stream << "TypeA, TypeB, TypeC, " << "TypeD, TypeCompute, "
<< "Algorithm, Operator, " << "WorkSizePreference, LogLevel, "
<< "Lengths, Strides, Modes, Alpha," << "Beta, elapsedMs, "
<< "Problem Size(GFlops), " << "TFlops/s, " << "TotalBytes, " << "Result"
<< std::endl;
// clang-format off
return stream
<< "TypeA," // 1
<< "TypeB," // 2
<< "TypeC," // 3
<< "TypeD," // 4
<< "TypeCompute," // 5
<< "Algorithm," // 6
<< "Operator," // 7
<< "WorkSizePreference," // 8
<< "LogLevel," // 9
<< "Lengths," // 10
<< "Strides," // 11
<< "Modes," // 12
<< "Alpha," // 13
<< "Beta," // 14
<< "elapsedMs," // 15
<< "Problem Size(GFlops)," // 16
<< "TFlops," // 17
<< "TotalBytes," // 18
<< "Result" // 19
<< std::endl;
// clang-format on
}

std::ostream& ContractionTest::printKernel(std::ostream& stream) const
Expand All @@ -111,96 +129,50 @@ namespace hiptensor
auto alpha = std::get<8>(param);
auto beta = std::get<9>(param);

stream << hipTypeToString(testType[0]) << ", " << hipTypeToString(testType[1]) << ", "
<< hipTypeToString(testType[2]) << ", " << hipTypeToString(testType[3]) << ", "
<< computeTypeToString(convertToComputeType(testType[4])) << ", "
<< algoTypeToString(algorithm) << ", " << opTypeToString(operatorType) << ", "
<< workSizePrefToString(workSizePref) << ", " << logLevelToString(logLevel) << ", [";

for(int i = 0; i < lengths.size(); i++)
{
if(i != 0)
{
stream << ", ";
}
stream << "[";
for(int j = 0; j < lengths[i].size(); j++)
{
if(j != 0)
{
stream << ", ";
}
stream << lengths[i][j];
}
stream << "]";
}
stream << "], [";

if(!strides.empty())
{
for(int i = 0; i < strides.size(); i++)
{
if(i != 0)
{
stream << ", ";
}
stream << "[";
for(int j = 0; j < strides[i].size(); j++)
{
if(j != 0)
{
stream << ", ";
}
stream << strides[i][j];
}
stream << "]";
}
}
stream << "], [";

if(!modes.empty())
{
for(int i = 0; i < modes.size(); i++)
{
if(i != 0)
{
stream << ", ";
}
stream << "[";
for(int j = 0; j < modes[i].size(); j++)
{
if(j != 0)
{
stream << ", ";
}
stream << modes[i][j];
}
stream << "]";
}
}
stream << "], " << alpha << ", " << beta << ", ";
// clang-format off
stream
<< hipTypeToString(testType[0]) << "," // 1
<< hipTypeToString(testType[1]) << "," // 2
<< hipTypeToString(testType[2]) << "," // 3
<< hipTypeToString(testType[3]) << "," // 4
<< computeTypeToString(convertToComputeType(testType[4])) << "," // 5
<< algoTypeToString(algorithm) << "," // 6
<< opTypeToString(operatorType) << "," // 7
<< workSizePrefToString(workSizePref) << "," // 8
<< logLevelToString(logLevel) << ","; // 9
printContainerInCsv(lengths, stream) << ","; // 10
printContainerInCsv(strides, stream) << ","; // 11
printContainerInCsv(modes, stream) << ","; // 12
printContainerInCsv(alpha, stream) << ","; // 13
printContainerInCsv(beta, stream) << ","; // 14
// clang-format on

if(!mRunFlag)
{
stream << "n/a" << ", " << "n/a" << ", " << "n/a" << ", " << "n/a" << ", " << "SKIPPED"
<< std::endl;
// clang-format off
stream
<< "n/a" << "," // 15
<< "n/a" << "," // 16
<< "n/a" << "," // 17
<< "n/a" << "," // 18
<< "SKIPPED" // 19
<< std::endl;
// clang-format on
}
else
{

stream << mElapsedTimeMs << ", " << mTotalGFlops << ", " << mMeasuredTFlopsPerSec
<< ", " << mTotalBytes << ", ";

auto& testOptions = HiptensorOptions::instance();

if(testOptions->performValidation())
{
stream << ((bool)mValidationResult ? "PASSED" : "FAILED") << std::endl;
}
else
{
stream << "BENCH" << std::endl;
}
auto isPerformValidation = HiptensorOptions::instance()->performValidation();
auto result = isPerformValidation ? (mValidationResult ? "PASSED" : "FAILED") : "BENCH";

// clang-format off
stream
<< mElapsedTimeMs << "," // 15
<< mTotalGFlops << "," // 16
<< mMeasuredTFlopsPerSec << "," // 17
<< mTotalBytes << "," // 18
<< result // 19
<< std::endl;
// clang-format on
}

return stream;
Expand Down
101 changes: 43 additions & 58 deletions test/02_permutation/permutation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,21 @@ namespace hiptensor

std::ostream& PermutationTest::printHeader(std::ostream& stream /* = std::cout */) const
{
return stream << "TypeIn, TypeCompute, "
<< "Operators , LogLevel, "
<< "Lengths, PermutedOrder, "
<< "Alpha, elapsedMs, "
<< "Problem Size(GFlops), "
<< "TFlops/s, "
<< "TotalBytes, "
<< "Result" << std::endl;
// clang-format off
return stream << "TypeIn," // 1
<< "TypeCompute," // 2
<< "Operators," // 3
<< "LogLevel," // 4
<< "Lengths," // 5
<< "PermutedOrder," // 6
<< "Alpha," // 7
<< "ElapsedMs," // 8
<< "Problem Size(GFlops)," // 9
<< "TFlops," // 10
<< "TotalBytes," // 11
<< "Result" // 12
<< std::endl;
// clang-format on
}

std::ostream& PermutationTest::printKernel(std::ostream& stream) const
Expand All @@ -99,62 +106,40 @@ namespace hiptensor
auto alpha = std::get<4>(param);
auto operators = std::get<5>(param);

stream << hipTypeToString(testType[0]) << ", "
<< computeTypeToString(convertToComputeType(testType[1])) << ", "
<< opTypeToString(operators[0]) << ", " << opTypeToString(operators[1]) << ", "
<< logLevelToString(logLevel) << ", [";

for(int i = 0; i < lengths.size(); i++)
{
if(i != 0)
{
stream << ", ";
}
stream << lengths[i];
}
stream << "], [";

if(!permutedDims.empty())
{
for(int i = 0; i < permutedDims.size(); i++)
{
if(i != 0)
{
stream << ", ";
}
stream << permutedDims[i];
}
}
stream << "], " << alpha << ", ";
// clang-format off
stream << hipTypeToString(testType[0]) << "," // 1
<< computeTypeToString(convertToComputeType(testType[1])) << "," // 2
<< "[ " << opTypeToString(operators[0]) << " " << opTypeToString(operators[1]) << "]," // 3
<< logLevelToString(logLevel) << ","; // 4
printContainerInCsv(lengths, stream) << ","; // 5
printContainerInCsv(permutedDims, stream) << ","; // 6
stream << alpha << ","; // 7
// clang-format on

if(!mRunFlag)
{
stream << "n/a"
<< ", "
<< "n/a"
<< ", "
<< "n/a"
<< ", "
<< "n/a"
<< ", "
<< "SKIPPED" << std::endl;
// clang-format off
stream << "n/a" << "," // 8
<< "n/a" << "," // 9
<< "n/a" << "," // 10
<< "n/a" << "," // 11
<< "SKIPPED" // 12
<< std::endl;
// clang-format on
}
else
{

stream << mElapsedTimeMs << ", " << mTotalGFlops << ", " << mMeasuredTFlopsPerSec
<< ", " << mTotalBytes << ", ";

auto& testOptions = HiptensorOptions::instance();

if(testOptions->performValidation())
{
stream << ((bool)mValidationResult ? "PASSED" : "FAILED") << std::endl;
}
else
{
stream << "BENCH" << std::endl;
}
auto isPerformValidation = HiptensorOptions::instance()->performValidation();
auto result = isPerformValidation ? (mValidationResult ? "PASSED" : "FAILED") : "BENCH";

// clang-format off
stream << mElapsedTimeMs << "," //8
<< mTotalGFlops << "," //9
<< mMeasuredTFlopsPerSec << "," //10
<< mTotalBytes << "," //11
<< result //12
<< std::endl;
// clang-format on
}

return stream;
Expand Down
Loading

0 comments on commit 7910010

Please sign in to comment.