From a2dc69e61014f91e744ac63adce681c38cb24c84 Mon Sep 17 00:00:00 2001 From: Romaric JODIN Date: Mon, 1 Jun 2020 11:42:34 +0200 Subject: [PATCH] checksum: update copy_from and log --- .clang-format | 6 ++++++ checksum/common/common.h | 7 +++++++ checksum/dpu/dpu.c | 7 +++---- checksum/host/host.c | 29 ++++++++++++++--------------- checksum/host/host.py | 19 ++++++------------- 5 files changed, 36 insertions(+), 32 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..7acd9e9 --- /dev/null +++ b/.clang-format @@ -0,0 +1,6 @@ +--- +BasedOnStyle: Webkit +ColumnLimit: 130 +PointerAlignment: Right +ForEachMacros: ['DPU_FOREACH', 'DPU_RANK_FOREACH'] +... diff --git a/checksum/common/common.h b/checksum/common/common.h index e58762b..56161f6 100644 --- a/checksum/common/common.h +++ b/checksum/common/common.h @@ -13,9 +13,16 @@ #define BUFFER_SIZE (8 << 20) /* Structure used by both the host and the dpu to communicate information */ + +#include + typedef struct { uint32_t checksum; uint32_t cycles; +} dpu_result_t; + +typedef struct { + dpu_result_t tasklet_result[NR_TASKLETS]; } dpu_results_t; #endif /* __COMMON_H__ */ diff --git a/checksum/dpu/dpu.c b/checksum/dpu/dpu.c index f0194fc..634fe67 100644 --- a/checksum/dpu/dpu.c +++ b/checksum/dpu/dpu.c @@ -40,7 +40,7 @@ #define BLOCK_SIZE (256) __dma_aligned uint8_t DPU_CACHES[NR_TASKLETS][BLOCK_SIZE]; -__host dpu_results_t DPU_RESULTS[NR_TASKLETS]; +__host dpu_results_t DPU_RESULTS; __mram_noinit uint8_t DPU_BUFFER[BUFFER_SIZE]; @@ -53,15 +53,14 @@ int main() { uint32_t tasklet_id = me(); uint8_t *cache = DPU_CACHES[tasklet_id]; - dpu_results_t *result = &DPU_RESULTS[tasklet_id]; + dpu_result_t *result = &DPU_RESULTS.tasklet_result[tasklet_id]; uint32_t checksum = 0; /* Initialize once the cycle counter */ if (tasklet_id == 0) perfcounter_config(COUNT_CYCLES, true); - for (uint32_t buffer_idx = tasklet_id * BLOCK_SIZE; buffer_idx < BUFFER_SIZE; - buffer_idx += (NR_TASKLETS * BLOCK_SIZE)) { + for (uint32_t buffer_idx = tasklet_id * BLOCK_SIZE; buffer_idx < BUFFER_SIZE; buffer_idx += (NR_TASKLETS * BLOCK_SIZE)) { /* load cache with current mram block. */ mram_read(&DPU_BUFFER[buffer_idx], cache, BLOCK_SIZE); diff --git a/checksum/host/host.c b/checksum/host/host.c index 1120492..7ddb91c 100644 --- a/checksum/host/host.c +++ b/checksum/host/host.c @@ -20,7 +20,6 @@ */ #include -#include #include #include #include @@ -82,30 +81,30 @@ int main() printf("Run program on DPU(s)\n"); DPU_ASSERT(dpu_launch(dpu_set, DPU_SYNCHRONOUS)); - { - unsigned int each_dpu; - printf("Display DPU Logs\n"); - DPU_FOREACH (dpu_set, dpu, each_dpu) { - printf("DPU#%d:\n", each_dpu); - DPU_ASSERT(dpu_log_read(dpu, stdout)); - } + DPU_FOREACH (dpu_set, dpu) { + DPU_ASSERT(dpu_log_read(dpu, stdout)); } printf("Retrieve results\n"); - DPU_FOREACH (dpu_set, dpu) { + dpu_results_t results[nr_of_dpus]; + uint32_t each_dpu; + DPU_FOREACH (dpu_set, dpu, each_dpu) { + DPU_ASSERT(dpu_prepare_xfer(dpu, &results[each_dpu])); + } + DPU_ASSERT(dpu_push_xfer(dpu_set, DPU_XFER_FROM_DPU, XSTR(DPU_RESULTS), 0, sizeof(dpu_results_t), DPU_XFER_DEFAULT)); + + DPU_FOREACH (dpu_set, dpu, each_dpu) { bool dpu_status; dpu_checksum = 0; dpu_cycles = 0; // Retrieve tasklet results and compute the final checksum. for (unsigned int each_tasklet = 0; each_tasklet < NR_TASKLETS; each_tasklet++) { - dpu_results_t result; - DPU_ASSERT( - dpu_copy_from(dpu, XSTR(DPU_RESULTS), each_tasklet * sizeof(dpu_results_t), &result, sizeof(dpu_results_t))); + dpu_result_t *result = &results[each_dpu].tasklet_result[each_tasklet]; - dpu_checksum += result.checksum; - if (result.cycles > dpu_cycles) - dpu_cycles = result.cycles; + dpu_checksum += result->checksum; + if (result->cycles > dpu_cycles) + dpu_cycles = result->cycles; } dpu_status = (dpu_checksum == theoretical_checksum); diff --git a/checksum/host/host.py b/checksum/host/host.py index a035359..995fdb2 100644 --- a/checksum/host/host.py +++ b/checksum/host/host.py @@ -15,8 +15,8 @@ # limitations under the License. +from dpu import DpuSet import argparse -from dpu import driver import os import random import struct @@ -37,9 +37,8 @@ def main(nr_dpus, nr_tasklets): ok = True - with driver.allocate(nr_dpus) as dpus: + with DpuSet(nr_dpus, binary = DPU_BINARY, log = sys.stdout) as dpus: print('Allocated {} DPU(s)'.format(len(dpus))) - dpus.load(DPU_BINARY) # Create an "input file" with arbitrary data. # Compute its theoretical checksum value. @@ -51,23 +50,17 @@ def main(nr_dpus, nr_tasklets): print('Run program on DPU(s)') dpus.exec() - print('Display DPU Logs') - for idx, dpu in enumerate(dpus): - print('DPU#{}:'.format(idx)) - dpu.log() + results = [bytearray(RESULT_SIZE * nr_tasklets) for _ in dpus] + dpus.copy(results, DPU_RESULTS) print('Retrieve results') - for dpu in dpus: + for dpu, result in zip(dpus, results): dpu_checksum = 0 dpu_cycles = 0 # Retrieve tasklet results and compute the final checksum. for task_id in range(nr_tasklets): - result = bytearray(RESULT_SIZE) - - dpu.copy(result, DPU_RESULTS, RESULT_SIZE, task_id * RESULT_SIZE) - - result_checksum, result_cycles = struct.unpack("