summaryrefslogtreecommitdiff
path: root/BFS/host/app.c
diff options
context:
space:
mode:
Diffstat (limited to 'BFS/host/app.c')
-rw-r--r--BFS/host/app.c144
1 files changed, 75 insertions, 69 deletions
diff --git a/BFS/host/app.c b/BFS/host/app.c
index 9ba7ffb..4431193 100644
--- a/BFS/host/app.c
+++ b/BFS/host/app.c
@@ -3,9 +3,24 @@
* BFS Host Application Source File
*
*/
+#if ASPECTC
+extern "C" {
+#endif
+
#include <dpu.h>
#include <dpu_log.h>
+#ifndef ENERGY
+#define ENERGY 0
+#endif
+#if ENERGY
+#include <dpu_probe.h>
+#endif
+
+#if ASPECTC
+}
+#endif
+
#include <assert.h>
#include <getopt.h>
#include <stdio.h>
@@ -14,18 +29,11 @@
#include <unistd.h>
#include "mram-management.h"
-#include "../support/common.h"
-#include "../support/graph.h"
-#include "../support/params.h"
-#include "../support/timer.h"
-#include "../support/utils.h"
-
-#ifndef ENERGY
-#define ENERGY 0
-#endif
-#if ENERGY
-#include <dpu_probe.h>
-#endif
+#include "common.h"
+#include "graph.h"
+#include "params.h"
+#include "timer.h"
+#include "utils.h"
#define DPU_BINARY "./bin/dpu_code"
@@ -44,10 +52,6 @@ int main(int argc, char **argv)
double tenergy = 0;
#endif
- printf
- ("WITH_ALLOC_OVERHEAD=%d WITH_LOAD_OVERHEAD=%d WITH_FREE_OVERHEAD=%d\n",
- WITH_ALLOC_OVERHEAD, WITH_LOAD_OVERHEAD, WITH_FREE_OVERHEAD);
-
// Allocate DPUs and load binary
struct dpu_set_t dpu_set, dpu;
uint32_t numDPUs, numRanks;
@@ -59,7 +63,7 @@ int main(int argc, char **argv)
#if WITH_ALLOC_OVERHEAD
stopTimer(&timer, 0);
#else
- timer.time[0] = 0;
+ zeroTimer(&timer, 0);
#endif
#if WITH_LOAD_OVERHEAD
@@ -69,7 +73,7 @@ int main(int argc, char **argv)
#if WITH_LOAD_OVERHEAD
stopTimer(&timer, 0);
#else
- timer.time[1] = 0;
+ zeroTimer(&timer, 1);
#endif
DPU_ASSERT(dpu_get_nr_dpus(dpu_set, &numDPUs));
@@ -86,10 +90,10 @@ int main(int argc, char **argv)
uint32_t numNodes = csrGraph.numNodes;
uint32_t *nodePtrs = csrGraph.nodePtrs;
uint32_t *neighborIdxs = csrGraph.neighborIdxs;
- uint32_t *nodeLevel = calloc(numNodes, sizeof(uint32_t)); // Node's BFS level (initially all 0 meaning not reachable)
- uint64_t *visited = calloc(numNodes / 64, sizeof(uint64_t)); // Bit vector with one bit per node
- uint64_t *currentFrontier = calloc(numNodes / 64, sizeof(uint64_t)); // Bit vector with one bit per node
- uint64_t *nextFrontier = calloc(numNodes / 64, sizeof(uint64_t)); // Bit vector with one bit per node
+ uint32_t *nodeLevel = (uint32_t*)calloc(numNodes, sizeof(uint32_t)); // Node's BFS level (initially all 0 meaning not reachable)
+ uint64_t *visited = (uint64_t*)calloc(numNodes / 64, sizeof(uint64_t)); // Bit vector with one bit per node
+ uint64_t *currentFrontier = (uint64_t*)calloc(numNodes / 64, sizeof(uint64_t)); // Bit vector with one bit per node
+ uint64_t *nextFrontier = (uint64_t*)calloc(numNodes / 64, sizeof(uint64_t)); // Bit vector with one bit per node
setBit(nextFrontier[0], 0); // Initialize frontier to first node
uint32_t level = 1;
@@ -182,19 +186,27 @@ int main(int argc, char **argv)
PRINT_INFO(p.verbosity >= 2,
" Copying data to DPU");
startTimer(&timer, 2, t0ini++);
- copyToDPU(dpu, (uint8_t *) dpuNodePtrs_h, dpuNodePtrs_m,
- (dpuNumNodes + 1) * sizeof(uint32_t));
- copyToDPU(dpu, (uint8_t *) dpuNeighborIdxs_h,
- dpuNeighborIdxs_m,
- dpuNumNeighbors * sizeof(uint32_t));
- copyToDPU(dpu, (uint8_t *) dpuNodeLevel_h,
- dpuNodeLevel_m,
- dpuNumNodes * sizeof(uint32_t));
- copyToDPU(dpu, (uint8_t *) visited, dpuVisited_m,
- numNodes / 64 * sizeof(uint64_t));
- copyToDPU(dpu, (uint8_t *) nextFrontier,
- dpuNextFrontier_m,
- numNodes / 64 * sizeof(uint64_t));
+
+ DPU_ASSERT(dpu_copy_to(dpu, DPU_MRAM_HEAP_POINTER_NAME,
+ dpuNodePtrs_m, (uint8_t *) dpuNodePtrs_h,
+ ROUND_UP_TO_MULTIPLE_OF_8((dpuNumNodes + 1) * sizeof(uint32_t))));
+
+ DPU_ASSERT(dpu_copy_to(dpu, DPU_MRAM_HEAP_POINTER_NAME,
+ dpuNeighborIdxs_m, (uint8_t *) dpuNeighborIdxs_h,
+ ROUND_UP_TO_MULTIPLE_OF_8(dpuNumNeighbors * sizeof(uint32_t))));
+
+ DPU_ASSERT(dpu_copy_to(dpu, DPU_MRAM_HEAP_POINTER_NAME,
+ dpuNodeLevel_m, (uint8_t *) dpuNodeLevel_h,
+ ROUND_UP_TO_MULTIPLE_OF_8(dpuNumNodes * sizeof(uint32_t))));
+
+ DPU_ASSERT(dpu_copy_to(dpu, DPU_MRAM_HEAP_POINTER_NAME,
+ dpuVisited_m, (uint8_t *) visited,
+ ROUND_UP_TO_MULTIPLE_OF_8(numNodes / 64 * sizeof(uint64_t))));
+
+ DPU_ASSERT(dpu_copy_to(dpu, DPU_MRAM_HEAP_POINTER_NAME,
+ dpuNextFrontier_m, (uint8_t *) nextFrontier,
+ ROUND_UP_TO_MULTIPLE_OF_8(numNodes / 64 * sizeof(uint64_t))));
+
// NOTE: No need to copy current frontier because it is written before being read
stopTimer(&timer, 2);
//loadTime += getElapsedTime(timer);
@@ -204,8 +216,9 @@ int main(int argc, char **argv)
PRINT_INFO(p.verbosity >= 2,
" Copying parameters to DPU");
startTimer(&timer, 2, t1ini++);
- copyToDPU(dpu, (uint8_t *) & dpuParams[dpuIdx],
- dpuParams_m[dpuIdx], sizeof(struct DPUParams));
+ DPU_ASSERT(dpu_copy_to(dpu, DPU_MRAM_HEAP_POINTER_NAME,
+ dpuParams_m[dpuIdx], (uint8_t *) & dpuParams[dpuIdx],
+ ROUND_UP_TO_MULTIPLE_OF_8(sizeof(struct DPUParams))));
stopTimer(&timer, 2);
//loadTime += getElapsedTime(timer);
@@ -244,19 +257,15 @@ int main(int argc, char **argv)
uint32_t dpuNumNodes = dpuParams[dpuIdx].dpuNumNodes;
if (dpuNumNodes > 0) {
if (dpuIdx == 0) {
- copyFromDPU(dpu,
- dpuParams[dpuIdx].
- dpuNextFrontier_m,
- (uint8_t *) currentFrontier,
- numNodes / 64 *
- sizeof(uint64_t));
+ DPU_ASSERT(dpu_copy_from(dpu, DPU_MRAM_HEAP_POINTER_NAME,
+ dpuParams[dpuIdx].dpuNextFrontier_m,
+ (uint8_t *) currentFrontier,
+ ROUND_UP_TO_MULTIPLE_OF_8(numNodes / 64 * sizeof(uint64_t))));
} else {
- copyFromDPU(dpu,
- dpuParams[dpuIdx].
- dpuNextFrontier_m,
- (uint8_t *) nextFrontier,
- numNodes / 64 *
- sizeof(uint64_t));
+ DPU_ASSERT(dpu_copy_from(dpu, DPU_MRAM_HEAP_POINTER_NAME,
+ dpuParams[dpuIdx].dpuNextFrontier_m,
+ (uint8_t *) nextFrontier,
+ ROUND_UP_TO_MULTIPLE_OF_8(numNodes / 64 * sizeof(uint64_t))));
for (uint32_t i = 0; i < numNodes / 64;
++i) {
currentFrontier[i] |=
@@ -283,19 +292,15 @@ int main(int argc, char **argv)
dpuParams[dpuIdx].dpuNumNodes;
if (dpuNumNodes > 0) {
// Copy current frontier to all DPUs (place in next frontier and DPU will update visited and copy to current frontier)
- copyToDPU(dpu,
- (uint8_t *) currentFrontier,
- dpuParams[dpuIdx].
- dpuNextFrontier_m,
- numNodes / 64 *
- sizeof(uint64_t));
+ DPU_ASSERT(dpu_copy_to(dpu, DPU_MRAM_HEAP_POINTER_NAME,
+ dpuParams[dpuIdx].dpuNextFrontier_m,
+ (uint8_t *) currentFrontier,
+ ROUND_UP_TO_MULTIPLE_OF_8(numNodes / 64 * sizeof(uint64_t))));
// Copy new level to DPU
dpuParams[dpuIdx].level = level;
- copyToDPU(dpu,
- (uint8_t *) &
- dpuParams[dpuIdx],
- dpuParams_m[dpuIdx],
- sizeof(struct DPUParams));
+ DPU_ASSERT(dpu_copy_to(dpu, DPU_MRAM_HEAP_POINTER_NAME,
+ dpuParams_m[dpuIdx], (uint8_t *) &dpuParams[dpuIdx],
+ ROUND_UP_TO_MULTIPLE_OF_8(sizeof(struct DPUParams))));
++dpuIdx;
}
}
@@ -313,9 +318,10 @@ int main(int argc, char **argv)
uint32_t dpuNumNodes = dpuParams[dpuIdx].dpuNumNodes;
if (dpuNumNodes > 0) {
uint32_t dpuStartNodeIdx = dpuIdx * numNodesPerDPU;
- copyFromDPU(dpu, dpuParams[dpuIdx].dpuNodeLevel_m,
- (uint8_t *) (nodeLevel + dpuStartNodeIdx),
- dpuNumNodes * sizeof(float));
+ DPU_ASSERT(dpu_copy_from(dpu, DPU_MRAM_HEAP_POINTER_NAME,
+ dpuParams[dpuIdx].dpuNodeLevel_m,
+ (uint8_t *) (nodeLevel + dpuStartNodeIdx),
+ ROUND_UP_TO_MULTIPLE_OF_8(dpuNumNodes * sizeof(float))));
}
++dpuIdx;
}
@@ -325,7 +331,7 @@ int main(int argc, char **argv)
// Calculating result on CPU
PRINT_INFO(p.verbosity >= 1, "Calculating result on CPU");
- uint32_t *nodeLevelReference = calloc(numNodes, sizeof(uint32_t)); // Node's BFS level (initially all 0 meaning not reachable)
+ uint32_t *nodeLevelReference = (uint32_t*) calloc(numNodes, sizeof(uint32_t)); // Node's BFS level (initially all 0 meaning not reachable)
memset(nextFrontier, 0, numNodes / 64 * sizeof(uint64_t));
setBit(nextFrontier[0], 0); // Initialize frontier to first node
nextFrontierEmpty = 0;
@@ -395,7 +401,7 @@ int main(int argc, char **argv)
#if WITH_FREE_OVERHEAD
stopTimer(&timer, 7);
#else
- timer.time[7] = 0;
+ zeroTimer(&timer, 7);
#endif
// Verify the result
@@ -412,9 +418,9 @@ int main(int argc, char **argv)
}
if (status) {
- printf
+ dfatool_printf
("[::] BFS-UMEM | n_dpus=%d n_ranks=%d n_tasklets=%d e_type=%s n_elements=%d "
- "| throughput_pim_MBps=%f throughput_MBps=%f", numDPUs,
+ "| throughput_pim_MBps=%f throughput_MBps=%f", numDPUs, numRanks,
NR_TASKLETS, "uint32_t", numNodes,
numNodes * sizeof(uint32_t) / (timer.time[2] +
timer.time[3]),
@@ -423,12 +429,12 @@ int main(int argc, char **argv)
timer.time[2] +
timer.time[3] +
timer.time[4]));
- printf(" throughput_pim_MOpps=%f throughput_MOpps=%f",
+ dfatool_printf(" throughput_pim_MOpps=%f throughput_MOpps=%f",
numNodes / (timer.time[2] + timer.time[3]),
numNodes / (timer.time[0] + timer.time[1] +
timer.time[2] + timer.time[3] +
timer.time[4]));
- printf
+ dfatool_printf
(" latency_alloc_us=%f latency_load_us=%f latency_write_us=%f latency_kernel_us=%f latency_sync_us=%f latency_read_us=%f latency_cpu_us=%f latency_free_us=%f\n",
timer.time[0], timer.time[1], timer.time[2], timer.time[3],
timer.time[4], timer.time[5], timer.time[6],