diff --git a/benchmark/src/Benchmark.cpp b/benchmark/src/Benchmark.cpp index ff429fd5..0a1d9b0f 100644 --- a/benchmark/src/Benchmark.cpp +++ b/benchmark/src/Benchmark.cpp @@ -17,6 +17,7 @@ void runSingleThreadTest(std::string configName) { cfg->fromFile(configName); AMMBench::MatrixLoaderTable mLoaderTable; uint64_t sketchDimension; + ConfigMapPtr breakDownResult= nullptr; sketchDimension = cfg->tryU64("sketchDimension", 50, true); uint64_t coreBind = cfg->tryU64("coreBind", 0, true); uint64_t usingMeter = cfg->tryU64("usingMeter", 0, true); @@ -81,6 +82,7 @@ auto B = torch::rand({(long) aCol, (long) bCol});*/ if (eMeter != nullptr) { eMeter->stopMeter(); } + breakDownResult=br.getBreakDown(); } else { AMMBench::CPPAlgoTable cppAlgoTable; std::string cppAlgoTag = cfg->tryString("cppAlgoTag", "mm", true); @@ -101,7 +103,10 @@ auto B = torch::rand({(long) aCol, (long) bCol});*/ if (eMeter != nullptr) { eMeter->stopMeter(); } - + if(useCPP && cppAlgoPtr) + { + breakDownResult=cppAlgoPtr->getBreakDown(); + } } std::string ruName = "default"; @@ -130,8 +135,15 @@ auto B = torch::rand({(long) aCol, (long) bCol});*/ resultCsv->edit("froError", (double) froError); resultCsv->edit("errorBoundRatio", (double) errorBoundRatio); resultCsv->toFile(ruName + ".csv"); - INTELLI_INFO("Done. here is result"); + INTELLI_INFO("Done. here is overall result"); std::cout << resultCsv->toString() << endl; + if(breakDownResult) + { + INTELLI_INFO("I also have some break down result"); + std::cout << breakDownResult->toString() << endl; + breakDownResult->toFile(ruName+"_breakdown.csv"); + } + } int main(int argc, char **argv) { diff --git a/commit.sh b/commit.sh index 17cba7b4..b480b72a 100755 --- a/commit.sh +++ b/commit.sh @@ -1,4 +1,4 @@ -BRANCH=NIGHTLY_TEST +BRANCH=BREAKDOWN git init git checkout -b $BRANCH git add . diff --git a/commit_info b/commit_info index 3f6df389..56d57e1d 100644 --- a/commit_info +++ b/commit_info @@ -1,2 +1 @@ -1. Update the example scripts in scripts/scanThreads -2. Add the parameter passing logic to CPPAlgos \ No newline at end of file +1. add the function of exporting algorithm breakdown \ No newline at end of file diff --git a/include/CPPAlgos/AbstractCPPAlgo.h b/include/CPPAlgos/AbstractCPPAlgo.h index db35fd82..d0504289 100644 --- a/include/CPPAlgos/AbstractCPPAlgo.h +++ b/include/CPPAlgos/AbstractCPPAlgo.h @@ -21,6 +21,17 @@ namespace AMMBench { * @brief The abstract class of c++ algos */ class AbstractCPPAlgo { + protected: + /** + * @brief the default time break dowm variables + * @note By default, we decompose each AMM as + * - buildA, to translate A matrix + * - buildB, to translate B matrix + * - fABTime, to conduct mm or table look-up over the reduced A,B + * - postProcessTime, if f(A,B) is not the finall result, measure the time spend for post process + */ + uint64_t buildATime=0,buildBTime=0,fABTime=0,postProcessTime=0; + public: AbstractCPPAlgo() { @@ -40,7 +51,11 @@ class AbstractCPPAlgo { * @return the output c matrix */ virtual torch::Tensor amm(torch::Tensor A, torch::Tensor B, uint64_t sketchSize); - + /** + * @brief to get the breakdown of this algorithm, returned as a config map + * @return the key-value table breakdown in ConfigMapPtr; + */ + virtual INTELLI::ConfigMapPtr getBreakDown(); }; /** * @ingroup AMMBENCH_CppAlgos diff --git a/include/Parallelization/BlockPartitionRunner.h b/include/Parallelization/BlockPartitionRunner.h index 9df87b8b..b4d5e11d 100644 --- a/include/Parallelization/BlockPartitionRunner.h +++ b/include/Parallelization/BlockPartitionRunner.h @@ -82,7 +82,12 @@ class BlockPartitionWorker : public INTELLI::AbstractC20Thread { } uint64_t getElapsedTime(); - + /** + * @brief to export the algorithm breakdown + * @note only valid for c++ algo + * @return the key-value table breakdown in ConfigMapPtr; + */ + virtual INTELLI::ConfigMapPtr getBreakDown(); }; /** * @ingroup PARTITION_RUNNER @@ -169,6 +174,12 @@ class BlockPartitionRunner { * @param ru The result csv to be appended */ void appendThreadInfo(INTELLI::ConfigMapPtr ru); + /** + * @brief to export the algorithm breakdown + * @note only valid for c++ algo + * @return the key-value table breakdown in ConfigMapPtr; + */ + virtual INTELLI::ConfigMapPtr getBreakDown(); }; } // AMMBench diff --git a/src/CPPAlgos/AbstractCPPAlgo.cpp b/src/CPPAlgos/AbstractCPPAlgo.cpp index 57d9367b..c78b6dea 100644 --- a/src/CPPAlgos/AbstractCPPAlgo.cpp +++ b/src/CPPAlgos/AbstractCPPAlgo.cpp @@ -4,11 +4,25 @@ // #include +#include +#include void AMMBench::AbstractCPPAlgo::setConfig(INTELLI::ConfigMapPtr cfg) { assert(cfg); } torch::Tensor AMMBench::AbstractCPPAlgo::amm(torch::Tensor A, torch::Tensor B, uint64_t sketchSize) { - std::cout << sketchSize; - INTELLI_INFO("I am mm"); - return torch::matmul(A, B); + assert(sketchSize); + struct timeval tstart; + //INTELLI_INFO("I am mm"); + gettimeofday(&tstart,NULL); + auto C= torch::matmul(A, B); + fABTime=INTELLI::UtilityFunctions::timeLastUs(tstart); + return C; +} +INTELLI::ConfigMapPtr AMMBench::AbstractCPPAlgo::getBreakDown() { + INTELLI::ConfigMapPtr cfg = newConfigMap(); + cfg->edit("buildATime", (uint64_t)buildATime); + cfg->edit("buildBTime", (uint64_t)buildBTime); + cfg->edit("fABTime", (uint64_t)fABTime); + cfg->edit("postProcessTime",(uint64_t)postProcessTime); + return cfg; } \ No newline at end of file diff --git a/src/CPPAlgos/INT8CPPAlgo.cpp b/src/CPPAlgos/INT8CPPAlgo.cpp index 595e4330..0f52e87e 100644 --- a/src/CPPAlgos/INT8CPPAlgo.cpp +++ b/src/CPPAlgos/INT8CPPAlgo.cpp @@ -38,7 +38,7 @@ torch::Tensor AMMBench::INT8CPPAlgo::amm(torch::Tensor A, torch::Tensor B, uint6 scalingB = torch::abs(B).max().item() / 127.0; auto ta = (A / scalingA).to(torch::kInt8); auto tb = (B / scalingB).to(torch::kInt8); - // torch::matmul(ta, tb); + torch::matmul(ta, tb); return torch::zeros({A.size(0), B.size(1)}); return torch::matmul(ta, tb).to(torch::kFloat) * scalingA * scalingB; //return C*scalingA*scalingB/127.0/127.0; diff --git a/src/Parallelization/BlockPartitionRunner.cpp b/src/Parallelization/BlockPartitionRunner.cpp index 383ce986..fdefe7d4 100644 --- a/src/Parallelization/BlockPartitionRunner.cpp +++ b/src/Parallelization/BlockPartitionRunner.cpp @@ -67,6 +67,13 @@ void AMMBench::BlockPartitionWorker::inlineMain() { gettimeofday(&tend, NULL); //std::cout<getBreakDown(); + } + return nullptr; +} uint64_t AMMBench::BlockPartitionWorker::getElapsedTime() { return INTELLI::UtilityFunctions::timeLast(tstart, tend); } @@ -133,4 +140,8 @@ void AMMBench::BlockPartitionRunner::appendThreadInfo(INTELLI::ConfigMapPtr ru) std::string keyElapesedTime = "thread" + to_string(i) + "RunTime"; ru->edit(keyElapesedTime, (uint64_t) workers[i]->getElapsedTime()); } +} + +INTELLI::ConfigMapPtr AMMBench::BlockPartitionRunner::getBreakDown() { + return workers[0]->getBreakDown(); } \ No newline at end of file