Skip to content

Commit

Permalink
checksum: update copy_from and log
Browse files Browse the repository at this point in the history
  • Loading branch information
Romaric JODIN committed Jun 1, 2020
1 parent b953887 commit a2dc69e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 32 deletions.
6 changes: 6 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
BasedOnStyle: Webkit
ColumnLimit: 130
PointerAlignment: Right
ForEachMacros: ['DPU_FOREACH', 'DPU_RANK_FOREACH']
...
7 changes: 7 additions & 0 deletions checksum/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@
#define BUFFER_SIZE (8 << 20)

/* Structure used by both the host and the dpu to communicate information */

#include <stdint.h>

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__ */
7 changes: 3 additions & 4 deletions checksum/dpu/dpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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);
Expand Down
29 changes: 14 additions & 15 deletions checksum/host/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/

#include <dpu.h>
#include <dpu_log.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 6 additions & 13 deletions checksum/host/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# limitations under the License.


from dpu import DpuSet
import argparse
from dpu import driver
import os
import random
import struct
Expand All @@ -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.
Expand All @@ -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("<II", result)
result_checksum, result_cycles = struct.unpack_from("<II", result, task_id * RESULT_SIZE)
dpu_checksum += result_checksum
dpu_cycles = max(dpu_cycles, result_cycles)

Expand Down

0 comments on commit a2dc69e

Please sign in to comment.