├── .clang-format ├── .gitignore ├── LICENSE ├── Makefile ├── README.md └── checksum ├── .gitignore ├── Makefile ├── common └── common.h ├── dpu └── dpu.c └── host ├── host.c └── host.py /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | BasedOnStyle: Webkit 3 | ColumnLimit: 130 4 | PointerAlignment: Right 5 | ForEachMacros: ['DPU_FOREACH', 'DPU_RANK_FOREACH'] 6 | ... 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | cd checksum ; make all 3 | 4 | clean: 5 | cd checksum ; make clean 6 | 7 | test: 8 | cd checksum ; make test 9 | 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![UPMEM Logo](https://www.upmem.com/wp-content/uploads/2018/05/Logo-original-wesbite.png) 2 | 3 | The UPMEM Processing-In-Memory solution consists of a pool of programmable co-processors, the DPUs, integrated in the memory. 4 | 5 | # Content 6 | Examples of DPU programs generated with UPMEM DPU SDK 7 | 8 | # Requirements 9 | 10 | * The [UPMEM DPU SDK](https://sdk.upmem.com/) 11 | * GNU make and GCC, to build the application 12 | 13 | # Building the programs 14 | 15 | `make` to build the programs. 16 | 17 | `make clean` removes the resulting builds. 18 | 19 | # Executing 20 | 21 | The simplest way to execute the programs is to run *make test*. 22 | Otherwise, you may run individual tests manually by executing the binary generated in the *build* folder of the targeted program. 23 | 24 | # List of demo programs 25 | 26 | ## checksum 27 | 28 | The host application generates a random file of 8MB, and schedules multiple DPUs co-processors to compute the checksum on this file. 29 | As sanity check it compares host result with the DPU results, and prints out the DPU performances: 30 | * Total number of DPU cycles executed 31 | * The number of DPU cycles per byte processed 32 | 33 | Macros can be used to change the dimensions of the program: 34 | * NR_TASKLETS set the number of tasklets used by the dpu program (default: 16) 35 | * NR_DPUS set the number of dpus used by the host program (default: 1) 36 | 37 | example: `make test NR_TASKLETS=1 NR_DPUS=DPU_ALLOCATE_ALL` 38 | 39 | Two implementations of the Host application are provided: 40 | * `host.c` using the C Host API 41 | * `host.py` using the Python Host API 42 | 43 | `make test` will run both implementations. Use the Makefile targets `test_c` or `test_python` to specify an implementation. 44 | 45 | Note: because the input file is randomly generated, the checksum may differ between the two implementations. 46 | 47 | # SDK Documentation 48 | https://sdk.upmem.com/stable/ 49 | -------------------------------------------------------------------------------- /checksum/.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | 3 | .clangd/ 4 | compile_commands.json 5 | -------------------------------------------------------------------------------- /checksum/Makefile: -------------------------------------------------------------------------------- 1 | DPU_DIR := dpu 2 | HOST_DIR := host 3 | BUILDDIR ?= build 4 | NR_TASKLETS ?= 16 5 | NR_DPUS ?= 1 6 | 7 | define conf_filename 8 | ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2).conf 9 | endef 10 | CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS}) 11 | 12 | HOST_PYTHON_SCRIPT := ${HOST_DIR}/host.py 13 | HOST_TARGET := ${BUILDDIR}/checksum_host 14 | DPU_TARGET := ${BUILDDIR}/checksum_dpu 15 | 16 | COMMON_INCLUDES := common 17 | HOST_SOURCES := $(wildcard ${HOST_DIR}/*.c) 18 | DPU_SOURCES := $(wildcard ${DPU_DIR}/*.c) 19 | 20 | .PHONY: all clean test 21 | 22 | __dirs := $(shell mkdir -p ${BUILDDIR}) 23 | 24 | COMMON_FLAGS := -Wall -Wextra -Werror -g -I${COMMON_INCLUDES} 25 | HOST_FLAGS := ${COMMON_FLAGS} -std=c11 -O3 `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} 26 | DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} 27 | 28 | all: ${HOST_TARGET} ${DPU_TARGET} 29 | 30 | ${CONF}: 31 | $(RM) $(call conf_filename,*,*) 32 | touch ${CONF} 33 | 34 | ${HOST_TARGET}: ${HOST_SOURCES} ${COMMON_INCLUDES} ${CONF} 35 | $(CC) -o $@ ${HOST_SOURCES} ${HOST_FLAGS} 36 | 37 | ${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF} 38 | dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES} 39 | 40 | clean: 41 | $(RM) -r $(BUILDDIR) 42 | 43 | test_c: ${HOST_TARGET} ${DPU_TARGET} 44 | ./${HOST_TARGET} 45 | 46 | test_python: ${DPU_TARGET} 47 | python3 ${HOST_PYTHON_SCRIPT} ${NR_DPUS} ${NR_TASKLETS} 48 | 49 | test: test_c test_python 50 | 51 | -------------------------------------------------------------------------------- /checksum/common/common.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMMON_H__ 2 | #define __COMMON_H__ 3 | 4 | #define XSTR(x) STR(x) 5 | #define STR(x) #x 6 | 7 | /* DPU variable that will be read of write by the host */ 8 | #define DPU_BUFFER dpu_mram_buffer 9 | #define DPU_CACHES dpu_wram_caches 10 | #define DPU_RESULTS dpu_wram_results 11 | 12 | /* Size of the buffer on which the checksum will be performed */ 13 | #define BUFFER_SIZE (8 << 20) 14 | 15 | /* Structure used by both the host and the dpu to communicate information */ 16 | 17 | #include 18 | 19 | typedef struct { 20 | uint32_t checksum; 21 | uint32_t cycles; 22 | } dpu_result_t; 23 | 24 | typedef struct { 25 | dpu_result_t tasklet_result[NR_TASKLETS]; 26 | } dpu_results_t; 27 | 28 | #endif /* __COMMON_H__ */ 29 | -------------------------------------------------------------------------------- /checksum/dpu/dpu.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2017 - uPmem 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * An example of checksum computation with multiple tasklets. 19 | * 20 | * Every tasklet processes specific areas of the MRAM, following the "rake" 21 | * strategy: 22 | * - Tasklet number T is first processing block number TxN, where N is a 23 | * constant block size 24 | * - It then handles block number (TxN) + (NxM) where M is the number of 25 | * scheduled tasklets 26 | * - And so on... 27 | * 28 | * The host is in charge of computing the final checksum by adding all the 29 | * individual results. 30 | */ 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #include "common.h" 38 | 39 | /* Use blocks of 256 bytes */ 40 | #define BLOCK_SIZE (256) 41 | 42 | __dma_aligned uint8_t DPU_CACHES[NR_TASKLETS][BLOCK_SIZE]; 43 | __host dpu_results_t DPU_RESULTS; 44 | 45 | __mram_noinit uint8_t DPU_BUFFER[BUFFER_SIZE]; 46 | 47 | /** 48 | * @fn main 49 | * @brief main function executed by each tasklet 50 | * @return the checksum result 51 | */ 52 | int main() 53 | { 54 | uint32_t tasklet_id = me(); 55 | uint8_t *cache = DPU_CACHES[tasklet_id]; 56 | dpu_result_t *result = &DPU_RESULTS.tasklet_result[tasklet_id]; 57 | uint32_t checksum = 0; 58 | 59 | /* Initialize once the cycle counter */ 60 | if (tasklet_id == 0) 61 | perfcounter_config(COUNT_CYCLES, true); 62 | 63 | for (uint32_t buffer_idx = tasklet_id * BLOCK_SIZE; buffer_idx < BUFFER_SIZE; buffer_idx += (NR_TASKLETS * BLOCK_SIZE)) { 64 | 65 | /* load cache with current mram block. */ 66 | mram_read(&DPU_BUFFER[buffer_idx], cache, BLOCK_SIZE); 67 | 68 | /* computes the checksum of a cached block */ 69 | for (uint32_t cache_idx = 0; cache_idx < BLOCK_SIZE; cache_idx++) { 70 | checksum += cache[cache_idx]; 71 | } 72 | } 73 | 74 | /* keep the 32-bit LSB on the 64-bit cycle counter */ 75 | result->cycles = (uint32_t)perfcounter_get(); 76 | result->checksum = checksum; 77 | 78 | printf("[%02d] Checksum = 0x%08x\n", tasklet_id, result->checksum); 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /checksum/host/host.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2019 - UPMEM 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file host.c 19 | * @brief Template for a Host Application Source File. 20 | */ 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "common.h" 28 | 29 | #ifndef DPU_BINARY 30 | #define DPU_BINARY "build/checksum_dpu" 31 | #endif 32 | 33 | #define ANSI_COLOR_RED "\x1b[31m" 34 | #define ANSI_COLOR_GREEN "\x1b[32m" 35 | #define ANSI_COLOR_RESET "\x1b[0m" 36 | 37 | static uint8_t test_file[BUFFER_SIZE]; 38 | 39 | /** 40 | * @brief creates a "test file" 41 | * 42 | * @return the theorical checksum value 43 | */ 44 | static uint32_t create_test_file() 45 | { 46 | uint32_t checksum = 0; 47 | srand(0); 48 | 49 | for (unsigned int i = 0; i < BUFFER_SIZE; i++) { 50 | test_file[i] = (unsigned char)(rand()); 51 | checksum += test_file[i]; 52 | } 53 | 54 | return checksum; 55 | } 56 | 57 | /** 58 | * @brief Main of the Host Application. 59 | */ 60 | int main() 61 | { 62 | struct dpu_set_t dpu_set, dpu; 63 | uint32_t nr_of_dpus; 64 | uint32_t theoretical_checksum, dpu_checksum; 65 | uint32_t dpu_cycles; 66 | bool status = true; 67 | 68 | DPU_ASSERT(dpu_alloc(NR_DPUS, NULL, &dpu_set)); 69 | DPU_ASSERT(dpu_load(dpu_set, DPU_BINARY, NULL)); 70 | 71 | DPU_ASSERT(dpu_get_nr_dpus(dpu_set, &nr_of_dpus)); 72 | printf("Allocated %d DPU(s)\n", nr_of_dpus); 73 | 74 | // Create an "input file" with arbitrary data. 75 | // Compute its theoretical checksum value. 76 | theoretical_checksum = create_test_file(); 77 | 78 | printf("Load input data\n"); 79 | DPU_ASSERT(dpu_copy_to(dpu_set, XSTR(DPU_BUFFER), 0, test_file, BUFFER_SIZE)); 80 | 81 | printf("Run program on DPU(s)\n"); 82 | DPU_ASSERT(dpu_launch(dpu_set, DPU_SYNCHRONOUS)); 83 | 84 | DPU_FOREACH (dpu_set, dpu) { 85 | DPU_ASSERT(dpu_log_read(dpu, stdout)); 86 | } 87 | 88 | printf("Retrieve results\n"); 89 | dpu_results_t results[nr_of_dpus]; 90 | uint32_t each_dpu; 91 | DPU_FOREACH (dpu_set, dpu, each_dpu) { 92 | DPU_ASSERT(dpu_prepare_xfer(dpu, &results[each_dpu])); 93 | } 94 | DPU_ASSERT(dpu_push_xfer(dpu_set, DPU_XFER_FROM_DPU, XSTR(DPU_RESULTS), 0, sizeof(dpu_results_t), DPU_XFER_DEFAULT)); 95 | 96 | DPU_FOREACH (dpu_set, dpu, each_dpu) { 97 | bool dpu_status; 98 | dpu_checksum = 0; 99 | dpu_cycles = 0; 100 | 101 | // Retrieve tasklet results and compute the final checksum. 102 | for (unsigned int each_tasklet = 0; each_tasklet < NR_TASKLETS; each_tasklet++) { 103 | dpu_result_t *result = &results[each_dpu].tasklet_result[each_tasklet]; 104 | 105 | dpu_checksum += result->checksum; 106 | if (result->cycles > dpu_cycles) 107 | dpu_cycles = result->cycles; 108 | } 109 | 110 | dpu_status = (dpu_checksum == theoretical_checksum); 111 | status = status && dpu_status; 112 | 113 | printf("DPU execution time = %g cycles\n", (double)dpu_cycles); 114 | printf("performance = %g cycles/byte\n", (double)dpu_cycles / BUFFER_SIZE); 115 | printf("checksum computed by the DPU = 0x%08x\n", dpu_checksum); 116 | printf("actual checksum value = 0x%08x\n", theoretical_checksum); 117 | if (dpu_status) { 118 | printf("[" ANSI_COLOR_GREEN "OK" ANSI_COLOR_RESET "] checksums are equal\n"); 119 | } else { 120 | printf("[" ANSI_COLOR_RED "ERROR" ANSI_COLOR_RESET "] checksums differ!\n"); 121 | } 122 | } 123 | 124 | DPU_ASSERT(dpu_free(dpu_set)); 125 | return status ? 0 : -1; 126 | } 127 | -------------------------------------------------------------------------------- /checksum/host/host.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Copyright (c) 2020 - UPMEM 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | 18 | from dpu import DpuSet 19 | from dpu import ALLOCATE_ALL 20 | import argparse 21 | import os 22 | import random 23 | import struct 24 | import sys 25 | 26 | DPU_BINARY = 'build/checksum_dpu' 27 | 28 | DPU_BUFFER = 'dpu_mram_buffer' 29 | DPU_RESULTS = 'dpu_wram_results' 30 | BUFFER_SIZE = 8 << 20 31 | RESULT_SIZE = 8 32 | 33 | ANSI_COLOR_RED = '\x1b[31m' 34 | ANSI_COLOR_GREEN = '\x1b[32m' 35 | ANSI_COLOR_RESET = '\x1b[0m' 36 | 37 | 38 | def main(nr_dpus, nr_tasklets): 39 | ok = True 40 | 41 | with DpuSet(nr_dpus, binary = DPU_BINARY, log = sys.stdout) as dpus: 42 | print('Allocated {} DPU(s)'.format(len(dpus))) 43 | 44 | # Create an "input file" with arbitrary data. 45 | # Compute its theoretical checksum value. 46 | theoretical_checksum, test_file = create_test_file() 47 | 48 | print('Load input data') 49 | dpus.copy(DPU_BUFFER, test_file) 50 | 51 | print('Run program on DPU(s)') 52 | dpus.exec() 53 | 54 | results = [bytearray(RESULT_SIZE * nr_tasklets) for _ in dpus] 55 | dpus.copy(results, DPU_RESULTS) 56 | 57 | print('Retrieve results') 58 | for dpu, result in zip(dpus, results): 59 | dpu_checksum = 0 60 | dpu_cycles = 0 61 | 62 | # Retrieve tasklet results and compute the final checksum. 63 | for task_id in range(nr_tasklets): 64 | result_checksum, result_cycles = struct.unpack_from("