diff --git a/README.md b/README.md index b377574..18dfffd 100644 --- a/README.md +++ b/README.md @@ -36,5 +36,13 @@ Macros can be used to change the dimensions of the program: example: `make test NR_TASKLETS=1 NR_DPUS=DPU_ALLOCATE_ALL` +Two implementations of the Host application are provided: +* `host.c` using the C Host API +* `host.py` using the Python Host API + +`make test` will run both implementations. Use the Makefile targets `test_c` or `test_python` to specify an implementation. + +Note: because the input file is randomly generated, the checksum may differ between the two implementations. + # SDK Documentation https://sdk.upmem.com/stable/ diff --git a/checksum/Makefile b/checksum/Makefile index 132705d..9bfc18b 100644 --- a/checksum/Makefile +++ b/checksum/Makefile @@ -9,6 +9,7 @@ define conf_filename endef CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS}) +HOST_PYTHON_SCRIPT := ${HOST_DIR}/host.py HOST_TARGET := ${BUILDDIR}/checksum_host DPU_TARGET := ${BUILDDIR}/checksum_dpu @@ -39,6 +40,11 @@ ${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF} clean: $(RM) -r $(BUILDDIR) -test: all +test_c: ${HOST_TARGET} ${DPU_TARGET} ./${HOST_TARGET} +test_python: ${DPU_TARGET} + python3 ${HOST_PYTHON_SCRIPT} ${NR_DPUS} ${NR_TASKLETS} + +test: test_c test_python + diff --git a/checksum/host/host.py b/checksum/host/host.py new file mode 100644 index 0000000..a035359 --- /dev/null +++ b/checksum/host/host.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python3 + +# Copyright (c) 2020 - UPMEM +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import argparse +from dpu import driver +import os +import random +import struct +import sys + +DPU_BINARY = 'build/checksum_dpu' + +DPU_BUFFER = 'dpu_mram_buffer' +DPU_RESULTS = 'dpu_wram_results' +BUFFER_SIZE = 8 << 20 +RESULT_SIZE = 8 + +ANSI_COLOR_RED = '\x1b[31m' +ANSI_COLOR_GREEN = '\x1b[32m' +ANSI_COLOR_RESET = '\x1b[0m' + + +def main(nr_dpus, nr_tasklets): + ok = True + + with driver.allocate(nr_dpus) 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. + theoretical_checksum, test_file = create_test_file() + + print('Load input data') + dpus.copy(DPU_BUFFER, test_file) + + print('Run program on DPU(s)') + dpus.exec() + + print('Display DPU Logs') + for idx, dpu in enumerate(dpus): + print('DPU#{}:'.format(idx)) + dpu.log() + + print('Retrieve results') + for dpu in dpus: + 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("