From e7cc6c14b0605adb82d0d5fbc9d21bb9c076f9f6 Mon Sep 17 00:00:00 2001 From: Meena Karunanidhi Date: Thu, 19 Sep 2024 15:30:07 +0000 Subject: [PATCH 1/3] Add Benchmark output --- library/src/data_types.cpp | 107 ++++++++++++++- library/src/include/data_types.hpp | 4 + test/01_contraction/contraction_test.cpp | 168 +++++++++++++++++++++-- test/01_contraction/contraction_test.hpp | 9 +- test/02_permutation/permutation_test.cpp | 107 +++++++++++++++ test/02_permutation/permutation_test.hpp | 7 + test/03_reduction/reduction_test.cpp | 106 ++++++++++++++ test/03_reduction/reduction_test.hpp | 7 + 8 files changed, 501 insertions(+), 14 deletions(-) diff --git a/library/src/data_types.cpp b/library/src/data_types.cpp index b17de958..179fd514 100644 --- a/library/src/data_types.cpp +++ b/library/src/data_types.cpp @@ -1,4 +1,4 @@ -/******************************************************************************* +library/src/data_types.cpp/******************************************************************************* * * MIT License * @@ -350,6 +350,111 @@ namespace hiptensor return "HIP_TYPE_NONE"; } } + + std::string opTypeToString(hiptensorOperator_t opType) + { + if(opType == HIPTENSOR_OP_IDENTITY) + { + return "HIPTENSOR_OP_IDENTITY"; + } + else if(opType == HIPTENSOR_OP_SQRT) + { + return "HIPTENSOR_OP_SQRT"; + } + else if(opType == HIPTENSOR_OP_ADD) + { + return "HIPTENSOR_OP_ADD"; + } + else if(opType == HIPTENSOR_OP_MUL) + { + return "HIPTENSOR_OP_MUL"; + } + else if(opType == HIPTENSOR_OP_MAX) + { + return "HIPTENSOR_OP_MAX"; + } + else if(opType == HIPTENSOR_OP_MIN) + { + return "HIPTENSOR_OP_MIN"; + } + else + { + return "HIPTENSOR_OP_UNKNOWN"; + } + } + + std::string algoTypeToString(hiptensorAlgo_t algoType) + { + if(algoType == HIPTENSOR_ALGO_ACTOR_CRITIC) + { + return "HIPTENSOR_ALGO_ACTOR_CRITIC"; + } + else if(algoType == HIPTENSOR_ALGO_DEFAULT) + { + return "HIPTENSOR_ALGO_DEFAULT"; + } + else if(algoType == HIPTENSOR_ALGO_DEFAULT_PATIENT) + { + return "HIPTENSOR_ALGO_DEFAULT_PATIENT"; + } + else + { + return "HIPTENSOR_ALGO_UNKNOWN"; + } + } + + std::string logLevelToString(hiptensorLogLevel_t logLevel) + { + if(logLevel == HIPTENSOR_LOG_LEVEL_OFF) + { + return "HIPTENSOR_LOG_LEVEL_OFF"; + } + else if(logLevel == HIPTENSOR_LOG_LEVEL_ERROR) + { + return "HIPTENSOR_LOG_LEVEL_ERROR"; + } + else if(logLevel == HIPTENSOR_LOG_LEVEL_PERF_TRACE) + { + return "HIPTENSOR_LOG_LEVEL_PERF_TRACE"; + } + else if(logLevel == HIPTENSOR_LOG_LEVEL_PERF_HINT) + { + return "HIPTENSOR_LOG_LEVEL_PERF_HINT"; + } + else if(logLevel == HIPTENSOR_LOG_LEVEL_HEURISTICS_TRACE) + { + return "HIPTENSOR_LOG_LEVEL_HEURISTICS_TRACE"; + } + else if(logLevel == HIPTENSOR_LOG_LEVEL_API_TRACE) + { + return "HIPTENSOR_LOG_LEVEL_API_TRACE"; + } + else + { + return "HIPTENSOR_LOG_LEVEL_UNKNOWN"; + } + } + + std::string workSizePrefToString(hiptensorWorksizePreference_t workSize) + { + if(workSize == HIPTENSOR_WORKSPACE_MIN) + { + return "HIPTENSOR_WORKSPACE_MIN"; + } + else if(workSize == HIPTENSOR_WORKSPACE_RECOMMENDED) + { + return "HIPTENSOR_WORKSPACE_RECOMMENDED"; + } + else if(workSize == HIPTENSOR_WORKSPACE_MAX) + { + return "HIPTENSOR_WORKSPACE_MAX"; + } + else + { + return "HIPTENSOR_WORKSPACE_UNKNOWN"; + } + } + } // namespace hiptensor bool operator==(hipDataType hipType, hiptensorComputeType_t computeType) diff --git a/library/src/include/data_types.hpp b/library/src/include/data_types.hpp index 59e70f2a..4ca9a968 100644 --- a/library/src/include/data_types.hpp +++ b/library/src/include/data_types.hpp @@ -110,6 +110,10 @@ namespace hiptensor std::string computeTypeToString(hiptensorComputeType_t computeType); std::string hipTypeToString(hipDataType hipType); + std::string opTypeToString(hiptensorOperator_t opType); + std::string algoTypeToString(hiptensorAlgo_t algoType); + std::string opTypeToString(hiptensorOperator_t opType); + std::string workSizePrefToString(hiptensorWorksizePreference_t workSize); } // namespace hiptensor bool operator==(hipDataType hipType, hiptensorComputeType_t computeType); diff --git a/test/01_contraction/contraction_test.cpp b/test/01_contraction/contraction_test.cpp index 631e6cd4..fff22a7a 100644 --- a/test/01_contraction/contraction_test.cpp +++ b/test/01_contraction/contraction_test.cpp @@ -78,6 +78,8 @@ namespace hiptensor mRunFlag = true; mValidationResult = false; mMaxRelativeError = 0.0; + + mElapsedTimeMs = mTotalGFlops = mMeasuredTFlopsPerSec = mTotalBytes = 0.0; } ContractionResource* ContractionTest::getResource() const @@ -85,6 +87,93 @@ namespace hiptensor return DataStorage::instance().get(); } + 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; + } + + std::ostream& ContractionTest::printKernel(std::ostream& stream) const + { + auto param = Base::GetParam(); + auto testType = std::get<0>(param); + auto algorithm = std::get<1>(param); + auto operatorType = std::get<2>(param); + auto workSizePref = std::get<3>(param); + auto logLevel = std::get<4>(param); + auto lengths = std::get<5>(param); + auto strides = std::get<6>(param); + auto modes = std::get<7>(param); + 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++) { + stream << "[" ; + for(int j = 0; j < lengths[i].size(); j++) { + stream << lengths[i][j] << ", "; + } + stream << "], "; + } + stream << "], ["; + + if(!strides.empty()) { + for(int i = 0; i < strides.size(); i++) { + stream << "[" ; + for(int j = 0; j < strides[i].size(); j++) { + stream << strides[i][j] << ", "; + } + stream << "], "; + } + } + stream << "], ["; + + if(!modes.empty()) { + for(int i = 0; i < modes.size(); i++) { + stream << "[" ; + for(int j = 0; j < modes[i].size(); j++) { + stream << modes[i][j] << ", "; + } + stream << "],"; + } + } + stream << "], " << alpha << "," << beta << ", "; + + if(!mRunFlag) + { + stream << "n/a" + << ", " + << "n/a" + << ", " + << "n/a" + << ", " + << "n/a" + << ", " + << "SKIPPED" << std::endl; + } + else + { + + stream << mElapsedTimeMs << ", " << mTotalGFlops << ", " << mMeasuredTFlopsPerSec + << ", " << mTotalBytes << ", " + <<((bool)mValidationResult ? "PASSED" : "FAILED") + << std::endl; + } + + return stream; + } + void ContractionTest::SetUp() { // reset API log buffer @@ -413,20 +502,21 @@ namespace hiptensor void ContractionTest::reportResults(std::ostream& stream, hipDataType DDataType, hiptensorComputeType_t computeType, + bool omitHeader, bool omitSkipped, bool omitFailed, bool omitPassed) const { + if(!omitHeader) + { + printHeader(stream); + } + // Conditionally print outputs if((mRunFlag || !omitSkipped) && (mValidationResult || !omitFailed) && (!mValidationResult || !omitPassed)) { - if(mPrintTypes) - { - ContractionTest::sAPILogBuff - << "TypeA/B/C/D: " << hipTypeToString(DDataType) - << ", ComputeType: " << computeTypeToString(computeType) << std::endl; - } + printKernel(stream); stream << ContractionTest::sAPILogBuff.str(); @@ -658,6 +748,11 @@ namespace hiptensor auto resource = getResource(); + hipEvent_t startEvent, stopEvent; + CHECK_HIP_ERROR(hipEventCreate(&startEvent)); + CHECK_HIP_ERROR(hipEventCreate(&stopEvent)); + CHECK_HIP_ERROR(hipEventRecord(startEvent)); + CHECK_HIPTENSOR_ERROR(hiptensorContraction(handle, &plan, (void*)&alphaBuf, @@ -670,6 +765,54 @@ namespace hiptensor worksize, 0 /* stream */)); + CHECK_HIP_ERROR(hipEventRecord(stopEvent)); + CHECK_HIP_ERROR(hipEventSynchronize(stopEvent)) + + auto timeMs = 0.0f; + CHECK_HIP_ERROR(hipEventElapsedTime(&timeMs, startEvent, stopEvent)); + + size_t totalLength = std::accumulate(d_ms_ns.mLengths.begin(), + d_ms_ns.mLengths.end(), + size_t(1), + std::multiplies()); + + uint32_t hops = desc.mTensorMode[2].size() / 2; + auto iter = std::find(desc.mTensorMode[0].cbegin(), desc.mTensorMode[0].cend(), desc.mTensorMode[2][desc.mTensorMode[2].size() - 1]); + if(iter != desc.mTensorMode[0].cend()) + { + auto offset = std::distance(desc.mTensorMode[0].cbegin(), iter); + totalLength *= std::accumulate(a_ms_ks.mLengths.begin() + offset, + a_ms_ks.mLengths.begin() + offset + hops, + size_t(1), + std::multiplies()); + } + + mElapsedTimeMs = float64_t(timeMs); + mTotalGFlops = 2.0 * totalLength; + mMeasuredTFlopsPerSec = mTotalGFlops / mElapsedTimeMs; + + size_t sizeA = std::accumulate(a_ms_ks.mLengths.begin(), + a_ms_ks.mLengths.end(), + hipDataTypeSize(ADataType), + std::multiplies()); + + size_t sizeB = std::accumulate(b_ns_ks.mLengths.begin(), + b_ns_ks.mLengths.end(), + hipDataTypeSize(BDataType), + std::multiplies()); + + size_t sizeD = std::accumulate(d_ms_ns.mLengths.begin(), + d_ms_ns.mLengths.end(), + hipDataTypeSize(DDataType), + std::multiplies()); + + mTotalBytes = sizeA + sizeB + sizeD; + mTotalBytes += (betaBuf.mReal != 0.0) ? sizeD : 0; + mTotalBytes /= (1e9 * mElapsedTimeMs); + + CHECK_HIP_ERROR(hipEventDestroy(startEvent)); + CHECK_HIP_ERROR(hipEventDestroy(stopEvent)); + CHECK_HIPTENSOR_ERROR(hiptensorContractionReference(&plan, (void*)&alphaBuf, resource->hostA().get(), @@ -695,12 +838,6 @@ namespace hiptensor DDataType, workspace)); - size_t elementsCD = std::accumulate(d_ms_ns.mLengths.begin(), - d_ms_ns.mLengths.end(), - size_t{1}, - std::multiplies()); - - int sizeD = elementsCD * hipDataTypeSize(DDataType); auto reference = resource->allocDevice(sizeD); resource->copyData(reference, resource->hostD(), sizeD); @@ -727,6 +864,11 @@ namespace hiptensor tolerance += epsilon * 2; } + size_t elementsCD = std::accumulate(d_ms_ns.mLengths.begin(), + d_ms_ns.mLengths.end(), + size_t{1}, + std::multiplies()); + if(DDataType == HIP_R_16F) { std::tie(mValidationResult, mMaxRelativeError) @@ -775,6 +917,7 @@ namespace hiptensor reportResults(std::cout, DDataType, computeType, + false, loggingOptions->omitSkipped(), loggingOptions->omitFailed(), loggingOptions->omitPassed()); @@ -785,6 +928,7 @@ namespace hiptensor reportResults(loggingOptions->ostream().fstream(), DDataType, computeType, + false, loggingOptions->omitSkipped(), loggingOptions->omitFailed(), loggingOptions->omitPassed()); diff --git a/test/01_contraction/contraction_test.hpp b/test/01_contraction/contraction_test.hpp index f0fb93c8..adec6895 100644 --- a/test/01_contraction/contraction_test.hpp +++ b/test/01_contraction/contraction_test.hpp @@ -1,4 +1,4 @@ -/******************************************************************************* + /******************************************************************************* * * MIT License * @@ -89,6 +89,9 @@ namespace hiptensor ContractionResource* getResource() const; + std::ostream& printHeader(std::ostream& stream) const; + std::ostream& printKernel(std::ostream& stream) const; + void SetUp() final; void TearDown() final; @@ -98,6 +101,7 @@ namespace hiptensor void reportResults(std::ostream& stream, hipDataType DDataType, hiptensorComputeType_t computeType, + bool omitHeader, bool omitSkipped, bool omitFailed, bool omitPassed) const; @@ -123,6 +127,9 @@ namespace hiptensor // Output buffer static std::stringstream sAPILogBuff; + + // Performance + float64_t mElapsedTimeMs, mTotalGFlops, mMeasuredTFlopsPerSec, mTotalBytes; }; } // namespace hiptensor diff --git a/test/02_permutation/permutation_test.cpp b/test/02_permutation/permutation_test.cpp index e5c72141..bf303a45 100644 --- a/test/02_permutation/permutation_test.cpp +++ b/test/02_permutation/permutation_test.cpp @@ -72,6 +72,69 @@ namespace hiptensor mRunFlag = true; mValidationResult = false; mMaxRelativeError = 0.0; + + mElapsedTimeMs = mTotalGFlops = mMeasuredTFlopsPerSec = mTotalBytes = 0.0; + } + + 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; + } + + std::ostream& PermutationTest::printKernel(std::ostream& stream) const + { + auto param = Base::GetParam(); + auto testType = std::get<0>(param); + auto logLevel = std::get<1>(param); + auto lengths = std::get<2>(param); + auto permutedDims = std::get<3>(param); + 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++) { + stream << lengths[i] << ", "; + } + stream << "], ["; + + if(!permutedDims.empty()) { + for(int i = 0; i < permutedDims.size(); i++) { + stream << permutedDims[i] << ", "; + } + } + stream << "], " << alpha << ", "; + + if(!mRunFlag) + { + stream << "n/a" + << ", " + << "n/a" + << ", " + << "n/a" + << ", " + << "n/a" + << ", " + << "SKIPPED" << std::endl; + } + else + { + + stream << mElapsedTimeMs << ", " << mTotalGFlops << ", " << mMeasuredTFlopsPerSec + << ", " << mTotalBytes << ", " + <<((bool)mValidationResult ? "PASSED" : "FAILED") + << std::endl; + } + + return stream; } PermutationResource* PermutationTest::getResource() const @@ -120,16 +183,24 @@ namespace hiptensor void PermutationTest::reportResults(std::ostream& stream, hipDataType dataType, + bool omitHeader, bool omitSkipped, bool omitFailed, bool omitPassed) const { + if(!omitHeader) + { + printHeader(stream); + } + // Conditionally print outputs if((mRunFlag || !omitSkipped) && (mValidationResult || !omitFailed) && (!mValidationResult || !omitPassed)) { stream << PermutationTest::sAPILogBuff.str(); + printKernel(stream); + if(mPrintElements) { auto resource = getResource(); @@ -250,6 +321,12 @@ namespace hiptensor { *(reinterpret_cast(&alphaValue)) = static_cast(alpha); } + + hipEvent_t startEvent, stopEvent; + CHECK_HIP_ERROR(hipEventCreate(&startEvent)); + CHECK_HIP_ERROR(hipEventCreate(&stopEvent)); + CHECK_HIP_ERROR(hipEventRecord(startEvent)); + CHECK_HIPTENSOR_ERROR(hiptensorPermutation(handle, &alphaValue, resource->deviceA().get(), @@ -260,6 +337,34 @@ namespace hiptensor modeB.data(), computeDataType, 0 /* stream */)); + + + CHECK_HIP_ERROR(hipEventRecord(stopEvent)); + CHECK_HIP_ERROR(hipEventSynchronize(stopEvent)) + + auto timeMs = 0.0f; + CHECK_HIP_ERROR(hipEventElapsedTime(&timeMs, startEvent, stopEvent)); + + size_t sizeA = std::accumulate(extentA.begin(), + extentA.end(), + hipDataTypeSize(abDataType), + std::multiplies()); + + size_t sizeB = std::accumulate(extentB.begin(), + extentB.end(), + hipDataTypeSize(abDataType), + std::multiplies()); + + mElapsedTimeMs = float64_t(timeMs); + mTotalGFlops = 2.0 * ((sizeA * sizeB) / hipDataTypeSize(abDataType)); + mMeasuredTFlopsPerSec = mTotalGFlops / mElapsedTimeMs; + + mTotalBytes = sizeA + sizeB; + mTotalBytes /= (1e9 * mElapsedTimeMs); + + CHECK_HIP_ERROR(hipEventDestroy(startEvent)); + CHECK_HIP_ERROR(hipEventDestroy(stopEvent)); + resource->copyBToHost(); if(abDataType == HIP_R_32F) @@ -314,6 +419,7 @@ namespace hiptensor { reportResults(std::cout, abDataType, + false, loggingOptions->omitSkipped(), loggingOptions->omitFailed(), loggingOptions->omitPassed()); @@ -323,6 +429,7 @@ namespace hiptensor { reportResults(loggingOptions->ostream().fstream(), abDataType, + false, loggingOptions->omitSkipped(), loggingOptions->omitFailed(), loggingOptions->omitPassed()); diff --git a/test/02_permutation/permutation_test.hpp b/test/02_permutation/permutation_test.hpp index 25b79339..860d0599 100644 --- a/test/02_permutation/permutation_test.hpp +++ b/test/02_permutation/permutation_test.hpp @@ -70,6 +70,9 @@ namespace hiptensor bool checkSizes() const; void reset(); + std::ostream& printHeader(std::ostream& stream) const; + std::ostream& printKernel(std::ostream& stream) const; + PermutationResource* getResource() const; void SetUp() final; @@ -80,6 +83,7 @@ namespace hiptensor void reportResults(std::ostream& stream, hipDataType DDataType, + bool omitHeader, bool omitSkipped, bool omitFailed, bool omitPassed) const; @@ -99,6 +103,9 @@ namespace hiptensor // Output buffer static std::stringstream sAPILogBuff; + + // Performance + float64_t mElapsedTimeMs, mTotalGFlops, mMeasuredTFlopsPerSec, mTotalBytes; }; } // namespace hiptensor diff --git a/test/03_reduction/reduction_test.cpp b/test/03_reduction/reduction_test.cpp index 0bceaac6..9489229a 100644 --- a/test/03_reduction/reduction_test.cpp +++ b/test/03_reduction/reduction_test.cpp @@ -101,6 +101,8 @@ namespace hiptensor mRunFlag = true; mValidationResult = false; mMaxRelativeError = 0.0; + + mElapsedTimeMs = mTotalGFlops = mMeasuredTFlopsPerSec = mTotalBytes = 0.0; } ReductionResource* ReductionTest::getResource() const @@ -108,6 +110,67 @@ namespace hiptensor return DataStorage::instance().get(); } + std::ostream& ReductionTest::printHeader(std::ostream& stream /* = std::cout */) const + { + return stream << "TypeIn, TypeCompute, " + << "Operator, LogLevel, " + << "Lengths, ReOrder, " + << "Alpha, Beta, elapsedMs, " + << "Problem Size(GFlops), " + << "TFlops/s, " + << "TotalBytes, " + << "Result" << std::endl; + } + + std::ostream& ReductionTest::printKernel(std::ostream& stream) const + { + auto param = Base::GetParam(); + auto testType = std::get<0>(param); + auto logLevel = std::get<1>(param); + auto lengths = std::get<2>(param); + auto outputDims = std::get<3>(param); + auto alpha = std::get<4>(param); + auto beta = std::get<5>(param); + auto op = std::get<6>(param); + + stream << hipTypeToString(testType[0]) << ", " << computeTypeToString(convertToComputeType(testType[1])) << ", " << opTypeToString(op) << ", " << logLevelToString(logLevel) << ", ["; + + for(int i = 0; i < lengths.size(); i++) { + stream << lengths[i] << ", "; + } + stream << "], ["; + + if(!outputDims.empty()) { + for(int i = 0; i < outputDims.size(); i++) { + stream << outputDims[i] << ", "; + } + } + stream << "], " << alpha << ", " << beta << ", "; + + if(!mRunFlag) + { + stream << "n/a" + << ", " + << "n/a" + << ", " + << "n/a" + << ", " + << "n/a" + << ", " + << "SKIPPED" << std::endl; + } + else + { + + stream << mElapsedTimeMs << ", " << mTotalGFlops << ", " << mMeasuredTFlopsPerSec + << ", " << mTotalBytes << ", " + <<((bool)mValidationResult ? "PASSED" : "FAILED") + << std::endl; + } + + return stream; + } + void ReductionTest::SetUp() { // reset API log buffer @@ -161,16 +224,24 @@ namespace hiptensor void ReductionTest::reportResults(std::ostream& stream, hipDataType dataType, + bool omitHeader, bool omitSkipped, bool omitFailed, bool omitPassed) const { + if(!omitHeader) + { + printHeader(stream); + } + // Conditionally print outputs if((mRunFlag || !omitSkipped) && (mValidationResult || !omitFailed) && (!mValidationResult || !omitPassed)) { stream << ReductionTest::sAPILogBuff.str(); + printKernel(stream); + if(mPrintElements) { auto resource = getResource(); @@ -341,6 +412,12 @@ namespace hiptensor double betaValue{}; writeVal(&alphaValue, computeDataType, {computeDataType, alpha}); writeVal(&betaValue, computeDataType, {computeDataType, beta}); + + hipEvent_t startEvent, stopEvent; + CHECK_HIP_ERROR(hipEventCreate(&startEvent)); + CHECK_HIP_ERROR(hipEventCreate(&stopEvent)); + CHECK_HIP_ERROR(hipEventRecord(startEvent)); + CHECK_HIPTENSOR_ERROR(hiptensorReduction(handle, (const void*)&alphaValue, resource->deviceA().get(), @@ -359,6 +436,33 @@ namespace hiptensor worksize, 0 /* stream */)); + CHECK_HIP_ERROR(hipEventRecord(stopEvent)); + CHECK_HIP_ERROR(hipEventSynchronize(stopEvent)) + + auto timeMs = 0.0f; + CHECK_HIP_ERROR(hipEventElapsedTime(&timeMs, startEvent, stopEvent)); + + size_t sizeA = std::accumulate(extentA.begin(), + extentA.end(), + hipDataTypeSize(acDataType), + std::multiplies()); + + size_t sizeCD = std::accumulate(extentC.begin(), + extentC.end(), + hipDataTypeSize(acDataType), + std::multiplies()); + + mElapsedTimeMs = float64_t(timeMs); + mTotalGFlops = 2.0 * ((sizeA * sizeCD) / hipDataTypeSize(acDataType)); + mMeasuredTFlopsPerSec = mTotalGFlops / mElapsedTimeMs; + + mTotalBytes = sizeA + sizeCD; + mTotalBytes += (betaValue != 0.0) ? sizeCD : 0; + mTotalBytes /= (1e9 * mElapsedTimeMs); + + CHECK_HIP_ERROR(hipEventDestroy(startEvent)); + CHECK_HIP_ERROR(hipEventDestroy(stopEvent)); + resource->copyOutputToHost(); CHECK_HIPTENSOR_ERROR(hiptensorReductionReference(&alphaValue, @@ -432,6 +536,7 @@ namespace hiptensor { reportResults(std::cout, acDataType, + false, loggingOptions->omitSkipped(), loggingOptions->omitFailed(), loggingOptions->omitPassed()); @@ -441,6 +546,7 @@ namespace hiptensor { reportResults(loggingOptions->ostream().fstream(), acDataType, + false, loggingOptions->omitSkipped(), loggingOptions->omitFailed(), loggingOptions->omitPassed()); diff --git a/test/03_reduction/reduction_test.hpp b/test/03_reduction/reduction_test.hpp index ffe0ad90..cb7d65ef 100644 --- a/test/03_reduction/reduction_test.hpp +++ b/test/03_reduction/reduction_test.hpp @@ -73,6 +73,9 @@ namespace hiptensor ReductionResource* getResource() const; + std::ostream& printHeader(std::ostream& stream) const; + std::ostream& printKernel(std::ostream& stream) const; + void SetUp() final; void TearDown() final; @@ -81,6 +84,7 @@ namespace hiptensor void reportResults(std::ostream& stream, hipDataType DDataType, + bool omitHeader, bool omitSkipped, bool omitFailed, bool omitPassed) const; @@ -100,6 +104,9 @@ namespace hiptensor // Output buffer static std::stringstream sAPILogBuff; + + // Performance + float64_t mElapsedTimeMs, mTotalGFlops, mMeasuredTFlopsPerSec, mTotalBytes; }; } // namespace hiptensor From 14cf58e365b86b45c5a34c79f34ad13a5881d5d0 Mon Sep 17 00:00:00 2001 From: Meena Karunanidhi Date: Thu, 19 Sep 2024 15:39:03 +0000 Subject: [PATCH 2/3] Refactor --- library/src/data_types.cpp | 2 +- test/01_contraction/contraction_test.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/src/data_types.cpp b/library/src/data_types.cpp index 179fd514..9b69b9f1 100644 --- a/library/src/data_types.cpp +++ b/library/src/data_types.cpp @@ -1,4 +1,4 @@ -library/src/data_types.cpp/******************************************************************************* +/******************************************************************************* * * MIT License * diff --git a/test/01_contraction/contraction_test.hpp b/test/01_contraction/contraction_test.hpp index adec6895..7f7cb313 100644 --- a/test/01_contraction/contraction_test.hpp +++ b/test/01_contraction/contraction_test.hpp @@ -1,4 +1,4 @@ - /******************************************************************************* +/******************************************************************************* * * MIT License * From 7e5283261ec3cadb7d5aa157a863fdbf96c08199 Mon Sep 17 00:00:00 2001 From: Meena Karunanidhi Date: Thu, 19 Sep 2024 18:20:33 +0000 Subject: [PATCH 3/3] Address comments --- library/src/include/data_types.hpp | 2 +- test/01_contraction/contraction_test.cpp | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/library/src/include/data_types.hpp b/library/src/include/data_types.hpp index 4ca9a968..452fda8f 100644 --- a/library/src/include/data_types.hpp +++ b/library/src/include/data_types.hpp @@ -112,7 +112,7 @@ namespace hiptensor std::string hipTypeToString(hipDataType hipType); std::string opTypeToString(hiptensorOperator_t opType); std::string algoTypeToString(hiptensorAlgo_t algoType); - std::string opTypeToString(hiptensorOperator_t opType); + std::string logLevelToString(hiptensorLogLevel_t); std::string workSizePrefToString(hiptensorWorksizePreference_t workSize); } // namespace hiptensor diff --git a/test/01_contraction/contraction_test.cpp b/test/01_contraction/contraction_test.cpp index fff22a7a..d5e8c46e 100644 --- a/test/01_contraction/contraction_test.cpp +++ b/test/01_contraction/contraction_test.cpp @@ -864,10 +864,7 @@ namespace hiptensor tolerance += epsilon * 2; } - size_t elementsCD = std::accumulate(d_ms_ns.mLengths.begin(), - d_ms_ns.mLengths.end(), - size_t{1}, - std::multiplies()); + size_t elementsCD = sizeD / hipDataTypeSize(ADataType); if(DDataType == HIP_R_16F) {