diff --git a/benchmark/src/Benchmark.cpp b/benchmark/src/Benchmark.cpp index b2cf2d75..4e504899 100644 --- a/benchmark/src/Benchmark.cpp +++ b/benchmark/src/Benchmark.cpp @@ -22,6 +22,7 @@ void runSingleThreadTest(std::string configName) { uint64_t usingMeter = cfg->tryU64("usingMeter", 0, true); std::string meterTag = cfg->tryString("meterTag", "intelMsr", true); uint64_t useCPP = cfg->tryU64("useCPP", 0, true); + uint64_t forceMP=cfg->tryU64("forceMP", 0, true); if (usingMeter) { eMeter = meterTable.findMeter(meterTag); if (eMeter != nullptr) { @@ -67,7 +68,7 @@ auto B = torch::rand({(long) aCol, (long) bCol});*/ ThreadPerf pef(-1); pef.setPerfList(); AMMBench::BlockPartitionRunner br; - if (threads > 1) { + if (threads > 1||forceMP) { INTELLI_WARNING("use multithread"); br.setConfig(cfg); br.createABC(A, B); @@ -113,9 +114,10 @@ auto B = torch::rand({(long) aCol, (long) bCol});*/ resultCsv->edit("energyAll", (double) energyConsumption); resultCsv->edit("energyOnlyMe", (double) pureEnergy); } - if (threads > 1) { + if (threads > 1||forceMP) { INTELLI_WARNING("consider multithread elapsed time"); resultCsv->edit("perfElapsedTime", (uint64_t) br.getElapsedTime()); + br.appendThreadInfo(resultCsv); } // error INTELLI_WARNING("evaluating the error, may takes some time"); diff --git a/commit.sh b/commit.sh index 4ca36cd5..65d2ddc7 100755 --- a/commit.sh +++ b/commit.sh @@ -1,4 +1,4 @@ -BRANCH=count-sketch-cpp +BRANCH=core-bind-bug git init git checkout -b $BRANCH git add . diff --git a/commit_info b/commit_info index 3965683a..5da5191c 100644 --- a/commit_info +++ b/commit_info @@ -1 +1 @@ -1. FIX CONFLICTS WITH MAIN \ No newline at end of file +1. fix core bind bugs \ No newline at end of file diff --git a/include/Parallelization/BlockPartitionRunner.h b/include/Parallelization/BlockPartitionRunner.h index 38e348c1..74546791 100644 --- a/include/Parallelization/BlockPartitionRunner.h +++ b/include/Parallelization/BlockPartitionRunner.h @@ -74,6 +74,10 @@ class BlockPartitionWorker : public INTELLI::AbstractC20Thread { * @param mycore the core to be binded */ void setWorkParameters(uint64_t aStart, uint64_t aEnd, int mycore); + void setCoreBInd(int cno) + { + coreBind=cno; + } ~BlockPartitionWorker() { } @@ -118,6 +122,10 @@ class BlockPartitionRunner { */ TensorPtr matC = nullptr; // Output matrix C std::vector workers; + /** + * @brief special bind of first core, if need + */ + uint64_t firstCoreBind=0; public: BlockPartitionRunner() {} ~BlockPartitionRunner() {} @@ -154,6 +162,11 @@ class BlockPartitionRunner { * @note Exclude the overhead of cleaning thread states such as loaded module */ uint64_t getElapsedTime(); + /** + * @brief append the running information of each thread to the result csv + * @param ru The result csv to be appended + */ + void appendThreadInfo(INTELLI::ConfigMapPtr ru); }; } // AMMBench diff --git a/src/Parallelization/BlockPartitionRunner.cpp b/src/Parallelization/BlockPartitionRunner.cpp index 35e7468b..b3daadc7 100644 --- a/src/Parallelization/BlockPartitionRunner.cpp +++ b/src/Parallelization/BlockPartitionRunner.cpp @@ -71,10 +71,12 @@ void AMMBench::BlockPartitionRunner::setConfig(INTELLI::ConfigMapPtr _cfg) { cfg = _cfg; threads = cfg->tryU64("threads", 2, true); workers = std::vector(threads); + firstCoreBind=cfg->tryU64("firstCoreBind",0, false); for (uint64_t i = 0; i < threads; i++) { workers[i] = newBlockPartitionWorker(); workers[i]->setConfig(cfg); } + INTELLI_INFO("set up " + to_string(threads) + "workers."); } void AMMBench::BlockPartitionRunner::createABC(torch::Tensor A, torch::Tensor B) { @@ -89,6 +91,11 @@ void AMMBench::BlockPartitionRunner::createABC(torch::Tensor A, torch::Tensor B) workers[i]->setABC(matA, matB, matC); workers[i]->setWorkParameters(start_row, end_row, i); } + if(firstCoreBind!=0) + { + workers[0]->setCoreBInd((int)firstCoreBind); + INTELLI_INFO("first thread is bound to core" + to_string(firstCoreBind) ); + } } torch::Tensor AMMBench::BlockPartitionRunner::parallelForward() { for (uint64_t i = 0; i < threads; i++) { @@ -114,4 +121,10 @@ uint64_t AMMBench::BlockPartitionRunner::getElapsedTime() { ti += workers[i]->getElapsedTime(); } return ti / threads; +} +void AMMBench::BlockPartitionRunner::appendThreadInfo(INTELLI::ConfigMapPtr ru) { + for (uint64_t i = 0; i < threads; i++) { + std::string keyElapesedTime="thread"+ to_string(i)+"RunTime"; + ru->edit(keyElapesedTime,(uint64_t) workers[i]->getElapsedTime()); + } } \ No newline at end of file diff --git a/src/Utils/UtilityFunctions.cpp b/src/Utils/UtilityFunctions.cpp index 816c1716..f6eaacba 100755 --- a/src/Utils/UtilityFunctions.cpp +++ b/src/Utils/UtilityFunctions.cpp @@ -4,6 +4,11 @@ #include #include +#include +#include +#include +#include +#include using namespace std; /* @@ -27,6 +32,13 @@ int INTELLI::UtilityFunctions::bind2Core(int id) { cpu_set_t mask; CPU_ZERO(&mask); CPU_SET(cpuId, &mask); + /** + * @brief fixed some core bind bugs + */ + if (sched_setaffinity(0, sizeof(cpu_set_t), &mask) < 0) { + AT_ERROR("Error: setaffinity()\n"); + exit(0); + } return cpuId; }