Skip to content

Commit

Permalink
AnyCore now randomly selects a core at the executeOn level. (#119)
Browse files Browse the repository at this point in the history
* AnyCore now randomly selects a core at the executeOn level.

* bugfix
  • Loading branch information
AdityaAtulTewari authored Jun 14, 2024
1 parent 6478593 commit 56256b2
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 19 deletions.
5 changes: 5 additions & 0 deletions pando-rt/include/pando-rt/execution/execute_on_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
#include "../status.hpp"
#include "export.h"
#include "task.hpp"
#include <pando-rt/benchmark/counters.hpp>
#include <random>

extern counter::Record<std::minstd_rand> perCoreRNG;
extern counter::Record<std::uniform_int_distribution<std::int8_t>> perCoreDist;

namespace pando {

Expand Down
4 changes: 3 additions & 1 deletion pando-rt/src/execute_on.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ Status detail::executeOn(Place place, Task task) {

const auto& coreDims = getCoreDims();
if (place.core == anyCore) {
auto coreIdx = perCoreDist.getLocal()(perCoreRNG.getLocal());
assert(coreIdx < pando::getCoreDims().x);
// anyCore: get scheduler core queue
const CoreIndex schedulerCoreIndex(coreDims.x, 0);
const CoreIndex schedulerCoreIndex(coreIdx, 0);
place.core = schedulerCoreIndex;
} else {
if ((place.core < CoreIndex{0, 0}) ||
Expand Down
4 changes: 2 additions & 2 deletions pando-rt/src/start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "drvx/drvx.hpp"
#endif

constexpr std::uint64_t STEAL_THRESH_HOLD_SIZE = 32;
constexpr std::uint64_t STEAL_THRESH_HOLD_SIZE = 16;

constexpr bool IDLE_TIMER_ENABLE = false;
counter::Record<std::int64_t> idleCount = counter::Record<std::int64_t>();
Expand Down Expand Up @@ -80,7 +80,7 @@ extern "C" int __start(int argc, char** argv) {
break;

case SchedulerFailState::STEAL:
for(std::int8_t i = 0; i <= coreDims.x && !task.has_value(); i++) {
for(std::int8_t i = 0; i < coreDims.x && !task.has_value(); i++) {
auto* otherQueue = pando::Cores::getTaskQueue(pando::Place{thisPlace.node, thisPlace.pod, pando::CoreIndex(i, 0)});
if(!otherQueue || otherQueue == queue) {continue;}
if(otherQueue->getApproxSize() > STEAL_THRESH_HOLD_SIZE) {
Expand Down
32 changes: 16 additions & 16 deletions pando-rt/test/execution/test_bulk_execute_on.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@

namespace {

pando::NodeSpecificStorage<std::int64_t> counter;
pando::NodeSpecificStorage<std::int64_t> nodeCounter;

struct IncrementCounter {
void operator()(std::int64_t val) {
pando::atomicIncrement(counter.getPointer(), val, std::memory_order_relaxed);
pando::atomicIncrement(nodeCounter.getPointer(), val, std::memory_order_relaxed);
}
};

struct IncrementCounters {
void operator()(std::int64_t x, std::int64_t y) {
pando::atomicIncrement(&counter, x, std::memory_order_relaxed);
pando::atomicIncrement(&counter, y, std::memory_order_relaxed);
pando::atomicIncrement(&nodeCounter, x, std::memory_order_relaxed);
pando::atomicIncrement(&nodeCounter, y, std::memory_order_relaxed);
}
};

} // namespace

TEST(BulkExecuteOn, ThisNode) {
counter = 0;
nodeCounter = 0;

const auto& thisPlace = pando::getCurrentPlace();
const pando::Place place{thisPlace.node, pando::PodIndex{0, 0}, pando::CoreIndex{0, 0}};
Expand All @@ -43,42 +43,42 @@ TEST(BulkExecuteOn, ThisNode) {
pando::Status::Success);

pando::waitUntil([&] {
return pando::atomicLoad(&counter, std::memory_order_relaxed) == 10;
return pando::atomicLoad(&nodeCounter, std::memory_order_relaxed) == 10;
});

EXPECT_EQ(pando::atomicLoad(&counter, std::memory_order_relaxed), 10);
EXPECT_EQ(pando::atomicLoad(&nodeCounter, std::memory_order_relaxed), 10);
}

TEST(BulkExecuteOn, ThisNodeAnyPod) {
counter = 0;
nodeCounter = 0;

EXPECT_EQ(pando::bulkExecuteOn(pando::anyPod, IncrementCounter{}, std::make_tuple(1),
std::make_tuple(2), std::make_tuple(3), std::make_tuple(4)),
pando::Status::Success);

pando::waitUntil([&] {
return pando::atomicLoad(&counter, std::memory_order_relaxed) == 10;
return pando::atomicLoad(&nodeCounter, std::memory_order_relaxed) == 10;
});

EXPECT_EQ(pando::atomicLoad(&counter, std::memory_order_relaxed), 10);
EXPECT_EQ(pando::atomicLoad(&nodeCounter, std::memory_order_relaxed), 10);
}

TEST(BulkExecuteOn, ThisNodeAnyCore) {
counter = 0;
nodeCounter = 0;

EXPECT_EQ(pando::bulkExecuteOn(pando::anyCore, IncrementCounter{}, std::make_tuple(1),
std::make_tuple(2), std::make_tuple(3), std::make_tuple(4)),
pando::Status::Success);

pando::waitUntil([&] {
return pando::atomicLoad(&counter, std::memory_order_relaxed) == 10;
return pando::atomicLoad(&nodeCounter, std::memory_order_relaxed) == 10;
});

EXPECT_EQ(pando::atomicLoad(&counter, std::memory_order_relaxed), 10);
EXPECT_EQ(pando::atomicLoad(&nodeCounter, std::memory_order_relaxed), 10);
}

TEST(BulkExecuteOn, ThisNodeMultipleArgs) {
counter = 0;
nodeCounter = 0;

const auto& thisPlace = pando::getCurrentPlace();
const pando::Place place{thisPlace.node, pando::PodIndex{0, 0}, pando::CoreIndex{0, 0}};
Expand All @@ -89,8 +89,8 @@ TEST(BulkExecuteOn, ThisNodeMultipleArgs) {
pando::Status::Success);

pando::waitUntil([&] {
return pando::atomicLoad(&counter, std::memory_order_relaxed) == 20;
return pando::atomicLoad(&nodeCounter, std::memory_order_relaxed) == 20;
});

EXPECT_EQ(pando::atomicLoad(&counter, std::memory_order_relaxed), 20);
EXPECT_EQ(pando::atomicLoad(&nodeCounter, std::memory_order_relaxed), 20);
}

0 comments on commit 56256b2

Please sign in to comment.