Skip to content

Commit

Permalink
Updated for node index type stabalization. (#92)
Browse files Browse the repository at this point in the history
* Updated for node index

* Update examples to match
  • Loading branch information
AdityaAtulTewari authored May 13, 2024
1 parent 7ae5e38 commit 8934226
Show file tree
Hide file tree
Showing 22 changed files with 246 additions and 47 deletions.
151 changes: 134 additions & 17 deletions examples/benchmark_pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <pando-lib-galois/containers/host_local_storage.hpp>
#include <pando-lib-galois/containers/pod_local_storage.hpp>
#include <pando-rt/memory/address_translation.hpp>
#include <pando-rt/memory/memory_guard.hpp>
#include <pando-rt/pando-rt.hpp>

Expand All @@ -15,59 +16,175 @@
* This benchmarks various types of pointer dereferences
*/

std::uint64_t currentLocation = 100;
std::uint64_t nodeDims = 100;

template <typename T>
struct CacheRef {
pando::GlobalPtr<T> globalPtr;
std::uint64_t cacheLoc;
T* cachePtr;

private:
bool tryToCache() {
if (cacheLoc == nodeDims) {
std::uint64_t nodeIndex = pando::extractNodeIndex(globalPtr.address).id;
if (currentLocation == nodeIndex) {
cacheLoc = nodeIndex;
cachePtr = globalPtr.operator->();
return true;
}
}
return false;
}

public:
operator T() const {
if (cacheLoc == currentLocation || tryToCache()) {
return *cachePtr;
} else {
return *globalPtr;
}
}

CacheRef<T> operator=(const T& value) {
if (cacheLoc == currentLocation || tryToCache()) {
*cachePtr = value;
} else {
*globalPtr = value;
}
return this;
}
template <typename U>
CacheRef<T> operator+=(const U& y) {
if (cacheLoc == currentLocation || tryToCache()) {
*cachePtr += y;
} else {
*globalPtr += y;
}
return *this;
}
};

template <typename T>
struct CachePtr {
CacheRef<T> ref;

CacheRef<T> operator*() {
return ref;
}
};

void printUsageExit(char* argv0) {
std::cerr << "Usage: " << argv0 << " -n numAccesses" << std::endl;
std::cerr << "Usage: " << argv0 << " -n numAccesses [-r] [-g] [-c]" << std::endl;
std::exit(EXIT_FAILURE);
}

enum POINTER : std::uint64_t { REGULAR = 0x1 << 0, GLOBALPTR = 0x1 << 1, CACHEPTR = 0x1 << 2 };

int pandoMain(int argc, char** argv) {
auto thisPlace = pando::getCurrentPlace();
currentLocation = thisPlace.node.id;
nodeDims = pando::getNodeDims().id;
if (thisPlace.node.id == 0) {
galois::HostLocalStorageHeap::HeapInit();
galois::PodLocalStorageHeap::HeapInit();
optind = 0;

std::uint64_t numAccesses = 0;
std::uint64_t ptrTypes = 0;

int opt;
while ((opt = getopt(argc, argv, "n:s:f:dm")) != -1) {
while ((opt = getopt(argc, argv, "n:rgc")) != -1) {
switch (opt) {
case 'n':
numAccesses = strtoull(optarg, nullptr, 10);
break;
case 'r':
ptrTypes |= REGULAR;
break;
case 'g':
ptrTypes |= GLOBALPTR;
break;
case 'c':
ptrTypes |= CACHEPTR;
break;
default:
printUsageExit(argv[0]);
}
}

// Checks
if (numAccesses == 0) {
printUsageExit(argv[0]);
}
if (ptrTypes == 0) {
printUsageExit(argv[0]);
}

// Initialize Regular
std::uint64_t* ptr = (std::uint64_t*)malloc(sizeof(std::uint64_t));

// Initialize GlobalPtr
pando::GlobalPtr<std::uint64_t> gptr;
pando::LocalStorageGuard<std::uint64_t> gptrGuard(gptr, 1);

// Initialize CachePtr
CachePtr<std::uint64_t> cptr;
pando::LocalStorageGuard<std::uint64_t> cptrGuard(cptr.ref.globalPtr, 1);
cptr.ref.cacheLoc = nodeDims;

std::array<std::uint64_t, 16> simpleArr;
for (std::uint64_t i = 0; i < simpleArr.size(); i++) {
simpleArr[i] = i;
}

*ptr = 0;
auto normalBegin = std::chrono::high_resolution_clock::now();
for (std::uint64_t i = 0; i < numAccesses; i++) {
*ptr += simpleArr[i % simpleArr.size()];
std::chrono::time_point<std::chrono::high_resolution_clock> normalBegin, normalEnd;
std::chrono::time_point<std::chrono::high_resolution_clock> gptrBegin, gptrEnd;
std::chrono::time_point<std::chrono::high_resolution_clock> cptrBegin, cptrEnd;
if (ptrTypes & REGULAR) {
*ptr = 0;
normalBegin = std::chrono::high_resolution_clock::now();
for (std::uint64_t i = 0; i < numAccesses; i++) {
*ptr += simpleArr[i % simpleArr.size()];
}
normalEnd = std::chrono::high_resolution_clock::now();
}
auto normalEnd = std::chrono::high_resolution_clock::now();
*gptr = 0;
auto gptrBegin = std::chrono::high_resolution_clock::now();
for (std::uint64_t i = 0; i < numAccesses; i++) {
*gptr += simpleArr[i % simpleArr.size()];

if (ptrTypes & GLOBALPTR) {
*gptr = 0;
gptrBegin = std::chrono::high_resolution_clock::now();
for (std::uint64_t i = 0; i < numAccesses; i++) {
*gptr += simpleArr[i % simpleArr.size()];
}
gptrEnd = std::chrono::high_resolution_clock::now();
}

auto gptrEnd = std::chrono::high_resolution_clock::now();
if (ptrTypes & CACHEPTR) {
*gptr = 0;
cptrBegin = std::chrono::high_resolution_clock::now();
for (std::uint64_t i = 0; i < numAccesses; i++) {
*cptr += simpleArr[i % simpleArr.size()];
}
cptrEnd = std::chrono::high_resolution_clock::now();
}

std::cout << "Normal Pointer took: "
<< std::chrono::duration_cast<std::chrono::nanoseconds>(normalEnd - normalBegin)
<< "\n Global Pointer took: "
<< std::chrono::duration_cast<std::chrono::nanoseconds>(gptrEnd - gptrBegin)
<< std::endl;
if (ptrTypes & REGULAR) {
std::cout << "Normal Pointer took: "
<< std::chrono::duration_cast<std::chrono::nanoseconds>(normalEnd - normalBegin)
<< "\n";
}
if (ptrTypes & GLOBALPTR) {
std::cout << "Global Pointer took: "
<< std::chrono::duration_cast<std::chrono::nanoseconds>(gptrEnd - gptrBegin)
<< "\n";
}
if (ptrTypes & CACHEPTR) {
std::cout << "Cache Pointer took: "
<< std::chrono::duration_cast<std::chrono::nanoseconds>(cptrEnd - cptrBegin)
<< "\n";
}
std::cout << std::flush;
}
pando::waitAll();
return 0;
Expand Down
2 changes: 1 addition & 1 deletion pando-rt/examples/gups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int pandoMain(int argc, char** argv) {

const auto thisPlace = pando::getCurrentPlace();
const auto placeDims = pando::getPlaceDims();
std::printf("Configuration (nodes, pods, cores): (%i), (%i,%i), (%i,%i)\n", placeDims.node.id,
std::printf("Configuration (nodes, pods, cores): (%li), (%i,%i), (%i,%i)\n", placeDims.node.id,
placeDims.pod.x, placeDims.pod.y, placeDims.core.x, placeDims.core.y);

const auto tableByteCount = tableSize * sizeof(std::int64_t);
Expand Down
2 changes: 1 addition & 1 deletion pando-rt/examples/gups_no_tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int pandoMain(int argc, char** argv) {
std::printf("Table size per node: %lu, updates / thread: %lu\n", tableSize, threadUpdates);

const auto placeDims = pando::getPlaceDims();
std::printf("Configuration (nodes, pods, cores): (%i), (%i,%i), (%i,%i)\n", placeDims.node.id,
std::printf("Configuration (nodes, pods, cores): (%li), (%i,%i), (%i,%i)\n", placeDims.node.id,
placeDims.pod.x, placeDims.pod.y, placeDims.core.x, placeDims.core.y);

const auto tableByteCount = tableSize * sizeof(std::int64_t);
Expand Down
6 changes: 3 additions & 3 deletions pando-rt/examples/helloworld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ void greetings(int level) {
PANDO_CHECK(pando::executeOn(otherPlace, &greetings, level + 1));
}

std::printf("%s/%i: Hello from node %i, pod x=%i,y=%i, core x=%i,y=%i\n", __func__, level,
std::printf("%s/%i: Hello from node %li, pod x=%i,y=%i, core x=%i,y=%i\n", __func__, level,
thisPlace.node.id, thisPlace.pod.x, thisPlace.pod.y, thisPlace.core.x,
thisPlace.core.y);
}
Expand All @@ -30,14 +30,14 @@ void nodeGreetings(int level) {
PANDO_CHECK(
pando::executeOn(pando::Place{rightNode, {}, pando::anyCore}, &nodeGreetings, level + 1));
}
std::printf("%s/%i: Hello from node %i, pod x=%i,y=%i, core x=%i,y=%i\n", __func__, level,
std::printf("%s/%i: Hello from node %li, pod x=%i,y=%i, core x=%i,y=%i\n", __func__, level,
thisPlace.node.id, thisPlace.pod.x, thisPlace.pod.y, thisPlace.core.x,
thisPlace.core.y);
}

int pandoMain(int, char**) {
const auto placeDims = pando::getPlaceDims();
std::printf("Configuration (nodes, pods, cores): (%i), (%i,%i), (%i,%i)\n", placeDims.node.id,
std::printf("Configuration (nodes, pods, cores): (%li), (%i,%i), (%i,%i)\n", placeDims.node.id,
placeDims.pod.x, placeDims.pod.y, placeDims.core.x, placeDims.core.y);

const auto thisPlace = pando::getCurrentPlace();
Expand Down
2 changes: 1 addition & 1 deletion pando-rt/examples/memory_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void allocate() {

int pandoMain(int, char**) {
const auto placeDims = pando::getPlaceDims();
std::printf("Configuration (nodes, pods, cores): (%i), (%i,%i), (%i,%i)\n", placeDims.node.id,
std::printf("Configuration (nodes, pods, cores): (%li), (%i,%i), (%i,%i)\n", placeDims.node.id,
placeDims.pod.x, placeDims.pod.y, placeDims.core.x, placeDims.core.y);

const auto thisPlace = pando::getCurrentPlace();
Expand Down
2 changes: 1 addition & 1 deletion pando-rt/examples/multi_pxns/allcores_reduce_values.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ void correctnessCheck(pando::GlobalPtr<pando::GlobalPtr<std::int64_t>> output,

int pandoMain(int, char**) {
const auto placeDims = pando::getPlaceDims();
std::printf("Configuration (nodes, pods, cores): (%i), (%i,%i), (%i,%i).\n", placeDims.node.id,
std::printf("Configuration (nodes, pods, cores): (%li), (%i,%i), (%i,%i).\n", placeDims.node.id,
placeDims.pod.x, placeDims.pod.y, placeDims.core.x, placeDims.core.y);

if (placeDims.core.x == 0 || placeDims.core.y == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void correctnessCheck(pando::GlobalPtr<pando::GlobalPtr<std::int64_t>> output,

int pandoMain(int, char**) {
const auto placeDims = pando::getPlaceDims();
std::printf("Configuration (nodes, pods, cores): (%i), (%i,%i), (%i,%i).\n", placeDims.node.id,
std::printf("Configuration (nodes, pods, cores): (%li), (%i,%i), (%i,%i).\n", placeDims.node.id,
placeDims.pod.x, placeDims.pod.y, placeDims.core.x, placeDims.core.y);

if (placeDims.core.x == 0 || placeDims.core.y == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void correctnessCheck(pando::GlobalPtr<pando::GlobalPtr<std::int64_t>> output,

int pandoMain(int, char**) {
const auto placeDims = pando::getPlaceDims();
std::printf("Configuration (nodes, pods, cores): (%i), (%i,%i), (%i,%i).\n", placeDims.node.id,
std::printf("Configuration (nodes, pods, cores): (%li), (%i,%i), (%i,%i).\n", placeDims.node.id,
placeDims.pod.x, placeDims.pod.y, placeDims.core.x, placeDims.core.y);

if (placeDims.core.x == 0 || placeDims.core.y == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void correctnessCheck(pando::GlobalPtr<pando::GlobalPtr<std::int64_t>> output,
for (std::int32_t c = 0; c < numCoresPerNode; ++c) {
std::int16_t ownerPXN = (c % placeDims.node.id);
if (localArray[c] != std::int64_t{ownerPXN * (placeDims.node.id - 1) + 1}) {
std::printf("%i %i %li\n", pando::getCurrentPlace().node.id, c, (int64_t)localArray[c]);
std::printf("%li %i %li\n", pando::getCurrentPlace().node.id, c, (int64_t)localArray[c]);
check_correctness = false;
}
}
Expand All @@ -183,7 +183,7 @@ void correctnessCheck(pando::GlobalPtr<pando::GlobalPtr<std::int64_t>> output,

int pandoMain(int, char**) {
const auto placeDims = pando::getPlaceDims();
std::printf("Configuration (nodes, pods, cores): (%i), (%i,%i), (%i,%i).\n", placeDims.node.id,
std::printf("Configuration (nodes, pods, cores): (%li), (%i,%i), (%i,%i).\n", placeDims.node.id,
placeDims.pod.x, placeDims.pod.y, placeDims.core.x, placeDims.core.y);

if (placeDims.core.x == 0 || placeDims.core.y == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void waitUntil(pando::GlobalPtr<bool> dones, std::int16_t numNodes) {

int pandoMain(int, char**) {
const auto placeDims = pando::getPlaceDims();
std::printf("Configuration (nodes, pods, cores): (%i), (%i,%i), (%i,%i).\n", placeDims.node.id,
std::printf("Configuration (nodes, pods, cores): (%li), (%i,%i), (%i,%i).\n", placeDims.node.id,
placeDims.pod.x, placeDims.pod.y, placeDims.core.x, placeDims.core.y);

if (placeDims.core.x == 0 || placeDims.core.y == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void waitUntil(pando::GlobalPtr<bool> dones, std::int16_t numNodes) {

int pandoMain(int, char**) {
const auto placeDims = pando::getPlaceDims();
std::printf("Configuration (nodes, pods, cores): (%i), (%i,%i), (%i,%i).\n", placeDims.node.id,
std::printf("Configuration (nodes, pods, cores): (%li), (%i,%i), (%i,%i).\n", placeDims.node.id,
placeDims.pod.x, placeDims.pod.y, placeDims.core.x, placeDims.core.y);

if (placeDims.core.x == 0 || placeDims.core.y == 0) {
Expand Down
2 changes: 1 addition & 1 deletion pando-rt/examples/single_pxn/onecore_increment_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void increase(std::int64_t v) {

int pandoMain(int, char**) {
const auto placeDims = pando::getPlaceDims();
std::printf("Configuration (nodes, pods, cores): (%i), (%i,%i), (%i,%i)\n", placeDims.node.id,
std::printf("Configuration (nodes, pods, cores): (%li), (%i,%i), (%i,%i)\n", placeDims.node.id,
placeDims.pod.x, placeDims.pod.y, placeDims.core.x, placeDims.core.y);
const auto thisPlace = pando::getCurrentPlace();

Expand Down
2 changes: 1 addition & 1 deletion pando-rt/examples/single_pxn/onecore_scatter_values.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void correctnessCheck(pando::GlobalPtr<std::int64_t> output) {

int pandoMain(int, char**) {
const auto placeDims = pando::getPlaceDims();
std::printf("Configuration (nodes, pods, cores): (%i), (%i,%i), (%i,%i)\n", placeDims.node.id,
std::printf("Configuration (nodes, pods, cores): (%li), (%i,%i), (%i,%i)\n", placeDims.node.id,
placeDims.pod.x, placeDims.pod.y, placeDims.core.x, placeDims.core.y);

if (placeDims.core.x == 0 || placeDims.core.y == 0) {
Expand Down
4 changes: 2 additions & 2 deletions pando-rt/examples/single_pxn/pass_value_in_allcores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ constexpr std::int64_t solution{5};
void readValue(pando::GlobalPtr<std::int64_t> sharedValue, pando::GlobalPtr<bool> checkSolution) {
if (*sharedValue == solution) {
auto thisPlace = pando::getCurrentPlace();
std::printf("[node %i, pod x=%i,y=%i, core x=%i,y=%i] read value: %li\n", thisPlace.node.id,
std::printf("[node %li, pod x=%i,y=%i, core x=%i,y=%i] read value: %li\n", thisPlace.node.id,
thisPlace.pod.x, thisPlace.pod.y, thisPlace.core.x, thisPlace.core.y,
static_cast<std::int64_t>(*sharedValue));
(*checkSolution) = true;
Expand Down Expand Up @@ -49,7 +49,7 @@ void incrementValue(pando::GlobalPtr<std::int64_t> sharedValue,

int pandoMain(int, char**) {
const auto placeDims = pando::getPlaceDims();
std::printf("Configuration (nodes, pods, cores): (%i), (%i,%i), (%i,%i)\n", placeDims.node.id,
std::printf("Configuration (nodes, pods, cores): (%li), (%i,%i), (%i,%i)\n", placeDims.node.id,
placeDims.pod.x, placeDims.pod.y, placeDims.core.x, placeDims.core.y);

if (placeDims.core.x == 0 || placeDims.core.y == 0) {
Expand Down
4 changes: 2 additions & 2 deletions pando-rt/examples/single_pxn/pass_value_in_twocores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ constexpr std::int64_t solution{5};
void readValue(pando::GlobalPtr<std::int64_t> sharedValue) {
if (*sharedValue == solution) {
auto thisPlace = pando::getCurrentPlace();
std::printf("[node %i, pod x=%i,y=%i, core x=%i,y=%i] read value: %li\n", thisPlace.node.id,
std::printf("[node %li, pod x=%i,y=%i, core x=%i,y=%i] read value: %li\n", thisPlace.node.id,
thisPlace.pod.x, thisPlace.pod.y, thisPlace.core.x, thisPlace.core.y,
static_cast<std::int64_t>(*sharedValue));
}
Expand Down Expand Up @@ -46,7 +46,7 @@ void incrementValue(pando::GlobalPtr<std::int64_t> sharedValue) {

int pandoMain(int, char**) {
const auto placeDims = pando::getPlaceDims();
std::printf("Configuration (nodes, pods, cores): (%i), (%i,%i), (%i,%i)\n", placeDims.node.id,
std::printf("Configuration (nodes, pods, cores): (%li), (%i,%i), (%i,%i)\n", placeDims.node.id,
placeDims.pod.x, placeDims.pod.y, placeDims.core.x, placeDims.core.y);

if (placeDims.core.x == 0 || placeDims.core.y == 0) {
Expand Down
2 changes: 1 addition & 1 deletion pando-rt/examples/single_pxn/serial_tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void incrementValue(pando::GlobalPtr<std::int16_t> sharedValue,

int pandoMain(int, char**) {
const auto placeDims = pando::getPlaceDims();
std::printf("Configuration (nodes, pods, cores): (%i), (%i,%i), (%i,%i)\n", placeDims.node.id,
std::printf("Configuration (nodes, pods, cores): (%li), (%i,%i), (%i,%i)\n", placeDims.node.id,
placeDims.pod.x, placeDims.pod.y, placeDims.core.x, placeDims.core.y);

if (placeDims.core.x == 0 || placeDims.core.y == 0) {
Expand Down
2 changes: 1 addition & 1 deletion pando-rt/examples/single_pxn/twocores_scatter_values.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void correctnessCheck(pando::GlobalPtr<std::int64_t> output) {

int pandoMain(int, char**) {
const auto placeDims = pando::getPlaceDims();
std::printf("Configuration (nodes, pods, cores): (%i), (%i,%i), (%i,%i)\n", placeDims.node.id,
std::printf("Configuration (nodes, pods, cores): (%li), (%i,%i), (%i,%i)\n", placeDims.node.id,
placeDims.pod.x, placeDims.pod.y, placeDims.core.x, placeDims.core.y);

if (placeDims.core.x * placeDims.core.y < 2) {
Expand Down
Loading

0 comments on commit 8934226

Please sign in to comment.