diff options
Diffstat (limited to 'BS')
-rw-r--r-- | BS/Makefile | 33 | ||||
-rw-r--r-- | BS/baselines/cpu/Makefile | 26 | ||||
-rw-r--r-- | BS/baselines/cpu/bs_omp.c | 353 | ||||
-rwxr-xr-x | BS/baselines/cpu/run-perf.sh | 6 | ||||
-rwxr-xr-x | BS/benchmark-scripts/ccmcc25-sim.sh | 27 | ||||
-rwxr-xr-x | BS/benchmark-scripts/ccmcc25.sh | 32 | ||||
-rwxr-xr-x | BS/benchmark-scripts/milos-hbm-cxl.sh | 44 | ||||
-rwxr-xr-x | BS/dimes-hetsim-hbm.sh | 2 | ||||
-rwxr-xr-x | BS/dimes-hetsim-nmc.sh | 8 | ||||
-rw-r--r-- | BS/dpu/task.c | 278 | ||||
-rw-r--r-- | BS/host/app.c | 334 | ||||
-rw-r--r--[-rwxr-xr-x] | BS/include/common.h (renamed from BS/support/common.h) | 12 | ||||
-rw-r--r-- | BS/include/dfatool_host.ah | 31 | ||||
-rw-r--r-- | BS/include/params.h | 59 | ||||
-rw-r--r-- | BS/include/timer.h | 5 | ||||
-rwxr-xr-x | BS/run-fgbs24a.sh | 33 | ||||
-rwxr-xr-x | BS/run-paper-strong-full.sh | 26 | ||||
-rwxr-xr-x | BS/run-paper-strong-rank.sh | 25 | ||||
-rwxr-xr-x | BS/run-paper-weak.sh | 28 | ||||
-rwxr-xr-x | BS/run.sh | 28 | ||||
-rw-r--r-- | BS/support/params.h | 52 | ||||
-rwxr-xr-x | BS/support/timer.h | 66 |
22 files changed, 802 insertions, 706 deletions
diff --git a/BS/Makefile b/BS/Makefile index f9c3002..f5f0c67 100644 --- a/BS/Makefile +++ b/BS/Makefile @@ -7,17 +7,34 @@ WITH_LOAD_OVERHEAD ?= 0 WITH_FREE_OVERHEAD ?= 0 WITH_DPUINFO ?= 0 -COMMON_INCLUDES := support HOST_SOURCES := $(wildcard host/*.c) DPU_SOURCES := $(wildcard dpu/*.c) -COMMON_FLAGS := -Wall -Wextra -g -I${COMMON_INCLUDES} -HOST_FLAGS := ${COMMON_FLAGS} -std=c11 -O3 `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DINPUT_SIZE=${INPUT_SIZE} -DPROBLEM_SIZE=${PROBLEM_SIZE} -DWITH_ALLOC_OVERHEAD=${WITH_ALLOC_OVERHEAD} -DWITH_LOAD_OVERHEAD=${WITH_LOAD_OVERHEAD} -DWITH_FREE_OVERHEAD=${WITH_FREE_OVERHEAD} -DWITH_DPUINFO=${WITH_DPUINFO} +aspectc ?= 0 +aspectc_timing ?= 0 +dfatool_timing ?= 1 + +HOST_CC := ${CC} + +COMMON_FLAGS := -Wall -Wextra -g -Iinclude +HOST_FLAGS := ${COMMON_FLAGS} -O3 `dpu-pkg-config --cflags --libs dpu` -DNR_TASKLETS=${NR_TASKLETS} -DNR_DPUS=${NR_DPUS} -DINPUT_SIZE=${INPUT_SIZE} -DPROBLEM_SIZE=${PROBLEM_SIZE} -DWITH_ALLOC_OVERHEAD=${WITH_ALLOC_OVERHEAD} -DWITH_LOAD_OVERHEAD=${WITH_LOAD_OVERHEAD} -DWITH_FREE_OVERHEAD=${WITH_FREE_OVERHEAD} -DWITH_DPUINFO=${WITH_DPUINFO} -DASPECTC=${aspectc} -DDFATOOL_TIMING=${dfatool_timing} DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} +ifeq (${aspectc_timing}, 1) + ASPECTC_HOST_FLAGS += -ainclude/dfatool_host_dpu.ah -ainclude/dfatool_host.ah +endif + +ASPECTC_HOST_FLAGS ?= -a0 + +ifeq (${aspectc}, 1) + HOST_CC = ag++ -r repo.acp -v 0 ${ASPECTC_HOST_FLAGS} --c_compiler ${UPMEM_HOME}/bin/clang++ -p . --Xcompiler +else + HOST_FLAGS += -std=c11 +endif + QUIET = @ -ifdef verbose +ifeq (${verbose}, 1) QUIET = endif @@ -26,10 +43,12 @@ all: bin/bs_host bin/bs_dpu bin: ${QUIET}mkdir -p bin -bin/bs_host: ${HOST_SOURCES} ${COMMON_INCLUDES} bin - ${QUIET}${CC} -o $@ ${HOST_SOURCES} ${HOST_FLAGS} +bin/bs_host: ${HOST_SOURCES} include bin + ${QUIET}cp ../include/dfatool_host_dpu.ah include + ${QUIET}${HOST_CC} -o $@ ${HOST_SOURCES} ${HOST_FLAGS} + ${QUIET}rm -f include/dfatool_host_dpu.ah -bin/bs_dpu: ${DPU_SOURCES} ${COMMON_INCLUDES} bin +bin/bs_dpu: ${DPU_SOURCES} include bin ${QUIET}dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES} clean: diff --git a/BS/baselines/cpu/Makefile b/BS/baselines/cpu/Makefile index b67602f..4c30f65 100644 --- a/BS/baselines/cpu/Makefile +++ b/BS/baselines/cpu/Makefile @@ -1,16 +1,30 @@ -NUMA ?= 0 -NUMA_MEMCPY ?= 0 -FLAGS = +benchmark ?= 1 +debug ?= 0 +native ?= 1 +nop_sync ?= 0 +numa ?= 0 +numa_memcpy ?= 0 + +CFLAGS = +LDFLAGS = + +ifeq (${debug}, 1) + CFLAGS += -g +endif + +ifeq (${native}, 1) + CFLAGS += -march=native +endif -ifeq (${NUMA}, 1) - FLAGS += -lnuma +ifeq (${numa}, 1) + LDFLAGS += -lnuma endif .PHONY: all all: bs_omp bs_omp: bs_omp.c - gcc -Wall -Wextra -pedantic -march=native -O2 -DNUMA=${NUMA} -DNUMA_MEMCPY=${NUMA_MEMCPY} bs_omp.c -o bs_omp -fopenmp ${FLAGS} + gcc -Wall -Wextra -pedantic -O3 ${CFLAGS} -DNUMA=${numa} -DNUMA_MEMCPY=${numa_memcpy} -DNOP_SYNC=${nop_sync} -DWITH_BENCHMARK=${benchmark} bs_omp.c -o bs_omp -fopenmp ${LDFLAGS} bs_omp_O0: bs_omp.c gcc bs_omp.c -o bs_omp_O0 -fopenmp diff --git a/BS/baselines/cpu/bs_omp.c b/BS/baselines/cpu/bs_omp.c index 874299b..5084c41 100644 --- a/BS/baselines/cpu/bs_omp.c +++ b/BS/baselines/cpu/bs_omp.c @@ -7,265 +7,286 @@ #include <assert.h> #include <time.h> #include <stdint.h> + +#if WITH_BENCHMARK #include "timer.h" +#else +#define start(...) +#define stop(...) +#endif #if NUMA #include <numaif.h> #include <numa.h> -void* mp_pages[1]; +void *mp_pages[1]; int mp_status[1]; int mp_nodes[1]; -struct bitmask* bitmask_in; +struct bitmask *bitmask_in; int numa_node_in = -1; int numa_node_cpu = -1; #endif - #if NUMA_MEMCPY -struct bitmask* bitmask_cpu; +struct bitmask *bitmask_cpu; int numa_node_cpu_memcpy = -1; int numa_node_local = -1; int numa_node_in_is_local = 0; #endif - #define DTYPE uint64_t /* * @brief creates a "test file" by filling a bufferwith values */ -void create_test_file(DTYPE * input, uint64_t nr_elements, DTYPE * querys, uint64_t n_querys) { +void create_test_file(DTYPE *input, uint64_t nr_elements, DTYPE *querys, + uint64_t n_querys) +{ - srand(time(NULL)); + srand(time(NULL)); - input[0] = 1; - for (uint64_t i = 1; i < nr_elements; i++) { - input[i] = input[i - 1] + (rand() % 10) + 1; - } + input[0] = 1; + for (uint64_t i = 1; i < nr_elements; i++) { + input[i] = input[i - 1] + (rand() % 10) + 1; + } - for(uint64_t i = 0; i < n_querys; i++) - { - querys[i] = input[rand() % (nr_elements - 2)]; - } + for (uint64_t i = 0; i < n_querys; i++) { + querys[i] = input[rand() % (nr_elements - 2)]; + } } /** * @brief compute output in the host */ -uint64_t binarySearch(DTYPE * input, uint64_t input_size, DTYPE* querys, unsigned n_querys) +uint64_t binarySearch(DTYPE *input, uint64_t input_size, DTYPE *querys, + unsigned n_querys) { uint64_t found = -1; uint64_t q, r, l, m; - - #pragma omp parallel for private(q,r,l,m) - for(q = 0; q < n_querys; q++) - { + +#pragma omp parallel for private(q,r,l,m) + for (q = 0; q < n_querys; q++) { l = 0; r = input_size; - while (l <= r) - { - m = l + (r - l) / 2; - - // Check if x is present at mid - if (input[m] == querys[q]) - { - found += m; + while (l <= r) { + m = l + (r - l) / 2; + + // Check if x is present at mid + if (input[m] == querys[q]) { + found += m; break; } - // If x greater, ignore left half - if (input[m] < querys[q]) - l = m + 1; + // If x greater, ignore left half + if (input[m] < querys[q]) + l = m + 1; - // If x is smaller, ignore right half + // If x is smaller, ignore right half else - r = m - 1; - + r = m - 1; + } - } + } - return found; + return found; } /** * @brief Main of the Host Application. */ - int main(int argc, char **argv) { - (void)argc; - Timer timer; - uint64_t input_size = atol(argv[1]); - uint64_t n_querys = atol(argv[2]); +int main(int argc, char **argv) +{ + (void)argc; +#if WITH_BENCHMARK + Timer timer; +#endif + uint64_t input_size = atol(argv[1]); + uint64_t n_querys = atol(argv[2]); #if NUMA - bitmask_in = numa_parse_nodestring(argv[3]); - numa_node_cpu = atoi(argv[4]); + bitmask_in = numa_parse_nodestring(argv[3]); + numa_node_cpu = atoi(argv[4]); #endif #if NUMA_MEMCPY - bitmask_cpu = numa_parse_nodestring(argv[5]); - numa_node_cpu_memcpy = atoi(argv[6]); + bitmask_cpu = numa_parse_nodestring(argv[5]); + numa_node_cpu_memcpy = atoi(argv[6]); #endif - printf("Vector size: %lu, num searches: %lu\n", input_size, n_querys); + printf("Vector size: %lu, num searches: %lu\n", input_size, n_querys); #if NUMA - if (bitmask_in) { - numa_set_membind(bitmask_in); - numa_free_nodemask(bitmask_in); - } - DTYPE * input = numa_alloc((input_size) * sizeof(DTYPE)); - DTYPE * querys = numa_alloc((n_querys) * sizeof(DTYPE)); + if (bitmask_in) { + numa_set_membind(bitmask_in); + numa_free_nodemask(bitmask_in); + } + DTYPE *input = numa_alloc((input_size) * sizeof(DTYPE)); + DTYPE *querys = numa_alloc((n_querys) * sizeof(DTYPE)); #else - DTYPE * input = malloc((input_size) * sizeof(DTYPE)); - DTYPE * querys = malloc((n_querys) * sizeof(DTYPE)); + DTYPE *input = malloc((input_size) * sizeof(DTYPE)); + DTYPE *querys = malloc((n_querys) * sizeof(DTYPE)); #endif #if NUMA #if NUMA_MEMCPY - if (bitmask_cpu) { - numa_set_membind(bitmask_cpu); - numa_free_nodemask(bitmask_cpu); - } + if (bitmask_cpu) { + numa_set_membind(bitmask_cpu); + numa_free_nodemask(bitmask_cpu); + } #else - struct bitmask *bitmask_all = numa_allocate_nodemask(); - numa_bitmask_setall(bitmask_all); - numa_set_membind(bitmask_all); - numa_free_nodemask(bitmask_all); -#endif // NUMA_MEMCPY + struct bitmask *bitmask_all = numa_allocate_nodemask(); + numa_bitmask_setall(bitmask_all); + numa_set_membind(bitmask_all); + numa_free_nodemask(bitmask_all); +#endif // NUMA_MEMCPY #endif - DTYPE result_host = -1; + DTYPE result_host = -1; - // Create an input file with arbitrary data. - create_test_file(input, input_size, querys, n_querys); + // Create an input file with arbitrary data. + create_test_file(input, input_size, querys, n_querys); #if NUMA - mp_pages[0] = input; - if (move_pages(0, 1, mp_pages, NULL, mp_status, 0) == -1) { - perror("move_pages(A)"); - } - else if (mp_status[0] < 0) { - printf("move_pages error: %d", mp_status[0]); - } - else { - numa_node_in = mp_status[0]; - } - - if (numa_node_cpu != -1) { - if (numa_run_on_node(numa_node_cpu) == -1) { - perror("numa_run_on_node"); - numa_node_cpu = -1; - } - } + mp_pages[0] = input; + if (move_pages(0, 1, mp_pages, NULL, mp_status, 0) == -1) { + perror("move_pages(A)"); + } else if (mp_status[0] < 0) { + printf("move_pages error: %d", mp_status[0]); + } else { + numa_node_in = mp_status[0]; + } + + if (numa_node_cpu != -1) { + if (numa_run_on_node(numa_node_cpu) == -1) { + perror("numa_run_on_node"); + numa_node_cpu = -1; + } + } #endif #if NUMA_MEMCPY - numa_node_in_is_local = ((numa_node_cpu == numa_node_in) || (numa_node_cpu + 8 == numa_node_in)) * 1; + numa_node_in_is_local = ((numa_node_cpu == numa_node_in) + || (numa_node_cpu + 8 == numa_node_in)) * 1; #endif #if NUMA_MEMCPY - DTYPE *input_local = input; - DTYPE *querys_local = querys; - start(&timer, 1, 0); - if (!numa_node_in_is_local) { - input_local = numa_alloc((input_size) * sizeof(DTYPE)); - querys_local = numa_alloc((n_querys) * sizeof(DTYPE)); - } - stop(&timer, 1); - if (!numa_node_in_is_local) { - if (numa_node_cpu_memcpy != -1) { - if (numa_run_on_node(numa_node_cpu_memcpy) == -1) { - perror("numa_run_on_node"); - numa_node_cpu_memcpy = -1; - } - } - } - start(&timer, 2, 0); - if (!numa_node_in_is_local) { - memcpy(input_local, input, input_size * sizeof(DTYPE)); - memcpy(querys_local, querys, n_querys * sizeof(DTYPE)); - } else { - input_local = input; - querys_local = querys; - } - stop(&timer, 2); - if (numa_node_cpu != -1) { - if (numa_run_on_node(numa_node_cpu) == -1) { - perror("numa_run_on_node"); - numa_node_cpu = -1; - } - } - mp_pages[0] = input_local; - if (move_pages(0, 1, mp_pages, NULL, mp_status, 0) == -1) { - perror("move_pages(input_local)"); - } - else if (mp_status[0] < 0) { - printf("move_pages error: %d", mp_status[0]); - } - else { - numa_node_local = mp_status[0]; - } + DTYPE *input_local = input; + DTYPE *querys_local = querys; + start(&timer, 1, 0); + if (!numa_node_in_is_local) { + input_local = numa_alloc((input_size) * sizeof(DTYPE)); + querys_local = numa_alloc((n_querys) * sizeof(DTYPE)); + } + stop(&timer, 1); + if (!numa_node_in_is_local) { + if (numa_node_cpu_memcpy != -1) { + if (numa_run_on_node(numa_node_cpu_memcpy) == -1) { + perror("numa_run_on_node"); + numa_node_cpu_memcpy = -1; + } + } + } + start(&timer, 2, 0); + if (!numa_node_in_is_local) { + memcpy(input_local, input, input_size * sizeof(DTYPE)); + memcpy(querys_local, querys, n_querys * sizeof(DTYPE)); + } else { + input_local = input; + querys_local = querys; + } + stop(&timer, 2); + if (numa_node_cpu != -1) { + if (numa_run_on_node(numa_node_cpu) == -1) { + perror("numa_run_on_node"); + numa_node_cpu = -1; + } + } + mp_pages[0] = input_local; + if (move_pages(0, 1, mp_pages, NULL, mp_status, 0) == -1) { + perror("move_pages(input_local)"); + } else if (mp_status[0] < 0) { + printf("move_pages error: %d", mp_status[0]); + } else { + numa_node_local = mp_status[0]; + } +#endif + +#if NOP_SYNC + for (int rep = 0; rep < 200000; rep++) { + asm volatile ("nop"::); + } #endif - start(&timer, 0, 0); + start(&timer, 0, 0); #if NUMA_MEMCPY - result_host = binarySearch(input_local, input_size - 1, querys_local, n_querys); + result_host = + binarySearch(input_local, input_size - 1, querys_local, n_querys); #else - result_host = binarySearch(input, input_size - 1, querys, n_querys); + result_host = binarySearch(input, input_size - 1, querys, n_querys); +#endif + stop(&timer, 0); + +#if NOP_SYNC + for (int rep = 0; rep < 200000; rep++) { + asm volatile ("nop"::); + } #endif - stop(&timer, 0); #if NUMA_MEMCPY - start(&timer, 3, 0); - if (!numa_node_in_is_local) { - numa_free(input_local, input_size * sizeof(DTYPE)); - numa_free(querys_local, n_querys * sizeof(DTYPE)); - } - stop(&timer, 3); + start(&timer, 3, 0); + if (!numa_node_in_is_local) { + numa_free(input_local, input_size * sizeof(DTYPE)); + numa_free(querys_local, n_querys * sizeof(DTYPE)); + } + stop(&timer, 3); #endif - unsigned int nr_threads = 0; + int status = (result_host); +#if WITH_BENCHMARK + unsigned int nr_threads = 0; #pragma omp parallel #pragma omp atomic - nr_threads++; + nr_threads++; - int status = (result_host); - if (status) { + if (status) { #if NUMA_MEMCPY - printf("[::] BS-CPU-MEMCPY | n_threads=%d e_type=%s n_elements=%lu" - " numa_node_in=%d numa_node_local=%d numa_node_cpu=%d numa_node_cpu_memcpy=%d numa_distance_in_cpu=%d" - " | throughput_MBps=%f throughput_MOpps=%f" - " latency_kernel_us=%f latency_alloc_us=%f latency_memcpy_us=%f latency_free_us=%f latency_total_us=%f\n", - nr_threads, "uint64_t", input_size, - numa_node_in, numa_node_local, numa_node_cpu, numa_node_cpu_memcpy, numa_distance(numa_node_in, numa_node_cpu), - n_querys * sizeof(DTYPE) / timer.time[0], n_querys / timer.time[0], - timer.time[0], timer.time[1], timer.time[2], timer.time[3], - timer.time[0] + timer.time[1] + timer.time[2] + timer.time[3]); + printf + ("[::] BS-CPU-MEMCPY | n_threads=%d e_type=%s n_elements=%lu" + " numa_node_in=%d numa_node_local=%d numa_node_cpu=%d numa_node_cpu_memcpy=%d numa_distance_in_cpu=%d" + " | throughput_MBps=%f throughput_MOpps=%f" + " latency_kernel_us=%f latency_alloc_us=%f latency_memcpy_us=%f latency_free_us=%f latency_total_us=%f\n", + nr_threads, "uint64_t", input_size, numa_node_in, + numa_node_local, numa_node_cpu, numa_node_cpu_memcpy, + numa_distance(numa_node_in, numa_node_cpu), + n_querys * sizeof(DTYPE) / timer.time[0], + n_querys / timer.time[0], timer.time[0], timer.time[1], + timer.time[2], timer.time[3], + timer.time[0] + timer.time[1] + timer.time[2] + + timer.time[3]); #else - printf("[::] BS-CPU | n_threads=%d e_type=%s n_elements=%lu" + printf("[::] BS-CPU | n_threads=%d e_type=%s n_elements=%lu" #if NUMA - " numa_node_in=%d numa_node_cpu=%d numa_distance_in_cpu=%d" + " numa_node_in=%d numa_node_cpu=%d numa_distance_in_cpu=%d" #endif - " | throughput_MBps=%f", - nr_threads, "uint64_t", input_size, + " | throughput_MBps=%f", + nr_threads, "uint64_t", input_size, #if NUMA - numa_node_in, numa_node_cpu, numa_distance(numa_node_in, numa_node_cpu), + numa_node_in, numa_node_cpu, numa_distance(numa_node_in, + numa_node_cpu), #endif - n_querys * sizeof(DTYPE) / timer.time[0]); - printf(" throughput_MOpps=%f latency_us=%f\n", - n_querys / timer.time[0], timer.time[0]); + n_querys * sizeof(DTYPE) / timer.time[0]); + printf(" throughput_MOpps=%f latency_us=%f\n", + n_querys / timer.time[0], timer.time[0]); #endif - } else { - printf("[ERROR]\n"); - } + } else { + printf("[ERROR]\n"); + } +#endif // WITH_BENCHMARK #if NUMA - numa_free(input, input_size * sizeof(DTYPE)); - numa_free(querys, n_querys * sizeof(DTYPE)); + numa_free(input, input_size * sizeof(DTYPE)); + numa_free(querys, n_querys * sizeof(DTYPE)); #else - free(input); - free(querys); + free(input); + free(querys); #endif - - return status ? 0 : 1; + return status ? 0 : 1; } - diff --git a/BS/baselines/cpu/run-perf.sh b/BS/baselines/cpu/run-perf.sh new file mode 100755 index 0000000..5b671e0 --- /dev/null +++ b/BS/baselines/cpu/run-perf.sh @@ -0,0 +1,6 @@ +#!/bin/zsh + +make -B numa=1 + +OMP_NUM_THREADS=1 perf stat record -o t1.perf -e ${(j:,:):-$(grep -v '^#' ../../../perf-events.txt | cut -d ' ' -f 1)} ./bs_omp $((2**29)) 16777216 4 4 +OMP_NUM_THREADS=4 perf stat record -o t4.perf -e ${(j:,:):-$(grep -v '^#' ../../../perf-events.txt | cut -d ' ' -f 1)} ./bs_omp $((2**29)) 16777216 4 4 diff --git a/BS/benchmark-scripts/ccmcc25-sim.sh b/BS/benchmark-scripts/ccmcc25-sim.sh new file mode 100755 index 0000000..05e7f87 --- /dev/null +++ b/BS/benchmark-scripts/ccmcc25-sim.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +mkdir -p log/$(hostname) + +run_benchmark_nmc() { + local "$@" + set -e + make -B NR_DPUS=${nr_dpus} NR_TASKLETS=${nr_tasklets} \ + INPUT_SIZE=${nr_elements} PROBLEM_SIZE=${nr_queries} \ + aspectc=1 aspectc_timing=1 dfatool_timing=0 + bin/bs_host -w 0 -e 5 2>&1 +} + +export -f run_benchmark_nmc + +fn=log/$(hostname)/ccmcc25-sim + +source ~/lib/local/upmem/upmem-2025.1.0-Linux-x86_64/upmem_env.sh simulator + +echo "prim-benchmarks BS $(git describe --all --long) $(git rev-parse HEAD) $(date -R)" >> ${fn}.txt + +parallel -j1 --eta --joblog ${fn}.joblog --resume --header : \ + run_benchmark_nmc nr_dpus={nr_dpus} nr_tasklets=16 nr_elements={nr_elements} nr_queries={nr_queries} \ + ::: nr_dpus 1 2 4 8 16 32 48 64 \ + ::: nr_elements $((2**18)) $((2**19)) $((2**20)) $((2**21)) $((2**22)) \ + ::: nr_queries 512 1024 2048 4096 \ +>> ${fn}.txt diff --git a/BS/benchmark-scripts/ccmcc25.sh b/BS/benchmark-scripts/ccmcc25.sh new file mode 100755 index 0000000..186baf6 --- /dev/null +++ b/BS/benchmark-scripts/ccmcc25.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +mkdir -p log/$(hostname) + +run_benchmark_nmc() { + local "$@" + set -e + sudo limit_ranks_to_numa_node ${numa_rank} + make -B NR_DPUS=${nr_dpus} NR_TASKLETS=${nr_tasklets} \ + INPUT_SIZE=${nr_elements} PROBLEM_SIZE=${nr_queries} \ + aspectc=1 aspectc_timing=1 dfatool_timing=0 + bin/bs_host -w 0 -e 50 2>&1 +} + +export -f run_benchmark_nmc + +for sdk in 2023.2.0 2024.1.0 2024.2.0 2025.1.0; do + + fn=log/$(hostname)/ccmcc25-sdk${sdk} + + source /opt/upmem/upmem-${sdk}-Linux-x86_64/upmem_env.sh + + echo "prim-benchmarks BS $(git describe --all --long) $(git rev-parse HEAD) $(date -R)" >> ${fn}.txt + + parallel -j1 --eta --joblog ${fn}.joblog --resume --header : \ + run_benchmark_nmc nr_dpus={nr_dpus} nr_tasklets=16 numa_rank=any nr_elements={nr_elements} nr_queries={nr_queries} \ + ::: nr_dpus 64 128 256 512 768 1024 1536 2048 2304 \ + ::: nr_elements $((2**20)) $((2**21)) $((2**22)) \ + ::: nr_queries 524288 1048576 2097152 \ + >> ${fn}.txt + +done diff --git a/BS/benchmark-scripts/milos-hbm-cxl.sh b/BS/benchmark-scripts/milos-hbm-cxl.sh new file mode 100755 index 0000000..79d02c7 --- /dev/null +++ b/BS/benchmark-scripts/milos-hbm-cxl.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +cd baselines/cpu +make -B numa=1 + +mkdir -p log/$(hostname) +fn=log/$(hostname)/milos-hbm-cxl + +# * uint64 == 128 MiB +num_queries_hbm=16777216 + +run_benchmark() { + local "$@" + OMP_NUM_THREADS=${nr_threads} ./bs_omp ${input_size} ${num_queries} $ram $cpu 2>&1 + return $? +} + +export -f run_benchmark + +( + +echo "single-node execution, HBM ref (1/2)" >&2 + +# 4 GiB +parallel -j1 --eta --joblog ${fn}.1.joblog --resume --header : \ + run_benchmark i={i} nr_threads={nr_threads} ram={ram} cpu={cpu} \ + input_size=$(perl -E 'say 2 ** 29') num_queries=${num_queries_hbm} \ + ::: i $(seq 1 5) \ + ::: nr_threads 1 2 4 8 12 16 \ + ::: cpu $(seq 0 7) \ + ::: ram $(seq 0 16) + +echo "multi-node execution, HBM ref (2/2)" >&2 + +# 8 GiB +parallel -j1 --eta --joblog ${fn}.2.joblog --resume --header : \ + run_benchmark i={i} nr_threads={nr_threads} ram={ram} cpu={cpu} \ + input_size=$(perl -E 'say 2 ** 30') num_queries=${num_queries_hbm} \ + ::: i $(seq 1 40) \ + ::: nr_threads 32 48 64 96 128 \ + ::: cpu -1 \ + ::: ram $(seq 0 16) + +) >> ${fn}.txt diff --git a/BS/dimes-hetsim-hbm.sh b/BS/dimes-hetsim-hbm.sh index 4e1500d..4a775ae 100755 --- a/BS/dimes-hetsim-hbm.sh +++ b/BS/dimes-hetsim-hbm.sh @@ -1,7 +1,7 @@ #!/bin/bash cd baselines/cpu -make -B NUMA=1 +make -B numa=1 mkdir -p log/$(hostname) fn=log/$(hostname)/dimes-hetsim-hbm diff --git a/BS/dimes-hetsim-nmc.sh b/BS/dimes-hetsim-nmc.sh index 195334b..fa697bf 100755 --- a/BS/dimes-hetsim-nmc.sh +++ b/BS/dimes-hetsim-nmc.sh @@ -3,6 +3,8 @@ mkdir -p log/$(hostname) baselines/cpu/log/$(hostname) fn=log/$(hostname)/dimes-hetsim-nmc +source /opt/upmem/upmem-2024.1.0-Linux-x86_64/upmem_env.sh + # upstream DPU version uses 2048576 * uint64 ≈ 16 MiB (DPU max: 64 MiB) # upstream DPU version uses 2 queries input_size_upstream=2048576 @@ -11,6 +13,8 @@ num_queries_upstream=2 input_size_dpu=$(perl -E 'say 2 ** 22') num_queries_dpu=1048576 +# Make sure that num_queries > input_size! + run_benchmark_nmc() { local "$@" set -e @@ -69,7 +73,7 @@ cd baselines/cpu ( -make -B NUMA=1 NUMA_MEMCPY=1 +make -B numa=1 numa_memcpy=1 echo "CPU single-node upstream-ref with memcpy, copy node == input node (1/6)" >&2 @@ -97,7 +101,7 @@ parallel -j1 --eta --joblog ${fn}.2.joblog --resume --header : \ :::+ cpu 0 1 \ ::: nr_threads 1 2 4 8 12 16 -make -B NUMA=1 +make -B numa=1 echo "CPU single-node upstream-ref (3/6)" >&2 diff --git a/BS/dpu/task.c b/BS/dpu/task.c index acf66f2..5881dd1 100644 --- a/BS/dpu/task.c +++ b/BS/dpu/task.c @@ -17,140 +17,168 @@ __host dpu_arguments_t DPU_INPUT_ARGUMENTS; __host dpu_results_t DPU_RESULTS[NR_TASKLETS]; // Search -static DTYPE search(DTYPE *bufferA, DTYPE searching_for, size_t search_size) { - DTYPE found = -2; - if(bufferA[0] <= searching_for) - { - found = -1; - for (uint32_t i = 0; i < search_size / sizeof(DTYPE); i++){ - if(bufferA[i] == searching_for) - { - found = i; - break; - } - } - } - return found; +static DTYPE search(DTYPE *bufferA, DTYPE searching_for, size_t search_size) +{ + DTYPE found = -2; + if (bufferA[0] <= searching_for) { + found = -1; + for (uint32_t i = 0; i < search_size / sizeof(DTYPE); i++) { + if (bufferA[i] == searching_for) { + found = i; + break; + } + } + } + return found; } BARRIER_INIT(my_barrier, NR_TASKLETS); extern int main_kernel1(void); -int(*kernels[nr_kernels])(void) = {main_kernel1}; +int (*kernels[nr_kernels])(void) = { main_kernel1 }; -int main(void){ - // Kernel - return kernels[DPU_INPUT_ARGUMENTS.kernel](); +int main(void) +{ + // Kernel + return kernels[DPU_INPUT_ARGUMENTS.kernel] (); } // main_kernel1 -int main_kernel1() { - unsigned int tasklet_id = me(); - #if PRINT - printf("tasklet_id = %u\n", tasklet_id); - #endif - if(tasklet_id == 0){ - mem_reset(); // Reset the heap - } - // Barrier - barrier_wait(&my_barrier); - - DTYPE searching_for, found; - uint64_t input_size = DPU_INPUT_ARGUMENTS.input_size; - - // Address of the current processing block in MRAM - uint32_t start_mram_block_addr_A = (uint32_t) DPU_MRAM_HEAP_POINTER; - uint32_t start_mram_block_addr_aux = start_mram_block_addr_A; - uint32_t end_mram_block_addr_A = start_mram_block_addr_A + sizeof(DTYPE) * input_size; - uint32_t current_mram_block_addr_query = end_mram_block_addr_A + tasklet_id * (DPU_INPUT_ARGUMENTS.slice_per_dpu / NR_TASKLETS) * sizeof(DTYPE); - - // Initialize a local cache to store the MRAM block - DTYPE *cache_A = (DTYPE *) mem_alloc(BLOCK_SIZE); - DTYPE *cache_aux_A = (DTYPE *) mem_alloc(BLOCK_SIZE); - DTYPE *cache_aux_B = (DTYPE *) mem_alloc(BLOCK_SIZE); - - dpu_results_t *result = &DPU_RESULTS[tasklet_id]; - - for(uint64_t targets = 0; targets < (DPU_INPUT_ARGUMENTS.slice_per_dpu / NR_TASKLETS); targets++) - { - found = -1; - - mram_read((__mram_ptr void const *) current_mram_block_addr_query, &searching_for, 8); - current_mram_block_addr_query += 8; - - // Initialize input vector boundaries - start_mram_block_addr_A = (uint32_t) DPU_MRAM_HEAP_POINTER; - start_mram_block_addr_aux = start_mram_block_addr_A; - end_mram_block_addr_A = start_mram_block_addr_A + sizeof(DTYPE) * input_size; - - uint32_t current_mram_block_addr_A = start_mram_block_addr_A; - - // Bring first and last values to WRAM - mram_read((__mram_ptr void const *) current_mram_block_addr_A, cache_aux_A, BLOCK_SIZE); - mram_read((__mram_ptr void const *) (end_mram_block_addr_A - BLOCK_SIZE * sizeof(DTYPE)), cache_aux_B, BLOCK_SIZE); - - while(1) - { - // Locate the address of the mid mram block - current_mram_block_addr_A = (start_mram_block_addr_A + end_mram_block_addr_A) / 2; - current_mram_block_addr_A &= WORD_MASK; - - // Boundary check - if(current_mram_block_addr_A < (start_mram_block_addr_A + BLOCK_SIZE)) - { - // Search inside (start_mram_block_addr_A, start_mram_block_addr_A + BLOCK_SIZE) - mram_read((__mram_ptr void const *) start_mram_block_addr_A, cache_A, BLOCK_SIZE); - found = search(cache_A, searching_for, BLOCK_SIZE); - - if(found > -1) - { - result->found = found + (start_mram_block_addr_A - start_mram_block_addr_aux) / sizeof(DTYPE); - } - // Search inside (start_mram_block_addr_A + BLOCK_SIZE, end_mram_block_addr_A) - else - { - size_t remain_bytes_to_search = end_mram_block_addr_A - (start_mram_block_addr_A + BLOCK_SIZE); - mram_read((__mram_ptr void const *) start_mram_block_addr_A + BLOCK_SIZE, cache_A, remain_bytes_to_search); - found = search(cache_A, searching_for, remain_bytes_to_search); - - if(found > -1) - { - result->found = found + (start_mram_block_addr_A + BLOCK_SIZE - start_mram_block_addr_aux) / sizeof(DTYPE); - } - else - { - printf("%lld NOT found\n", searching_for); - } +int main_kernel1() +{ + unsigned int tasklet_id = me(); +#if PRINT + printf("tasklet_id = %u\n", tasklet_id); +#endif + if (tasklet_id == 0) { + mem_reset(); // Reset the heap + } + // Barrier + barrier_wait(&my_barrier); + + DTYPE searching_for, found; + uint64_t input_size = DPU_INPUT_ARGUMENTS.input_size; + + // Address of the current processing block in MRAM + uint32_t start_mram_block_addr_A = (uint32_t) DPU_MRAM_HEAP_POINTER; + uint32_t start_mram_block_addr_aux = start_mram_block_addr_A; + uint32_t end_mram_block_addr_A = + start_mram_block_addr_A + sizeof(DTYPE) * input_size; + uint32_t current_mram_block_addr_query = + end_mram_block_addr_A + + tasklet_id * (DPU_INPUT_ARGUMENTS.slice_per_dpu / NR_TASKLETS) * + sizeof(DTYPE); + + // Initialize a local cache to store the MRAM block + DTYPE *cache_A = (DTYPE *) mem_alloc(BLOCK_SIZE); + DTYPE *cache_aux_A = (DTYPE *) mem_alloc(BLOCK_SIZE); + DTYPE *cache_aux_B = (DTYPE *) mem_alloc(BLOCK_SIZE); + + dpu_results_t *result = &DPU_RESULTS[tasklet_id]; + + for (uint64_t targets = 0; + targets < (DPU_INPUT_ARGUMENTS.slice_per_dpu / NR_TASKLETS); + targets++) { + found = -1; + + mram_read((__mram_ptr void const *) + current_mram_block_addr_query, &searching_for, 8); + current_mram_block_addr_query += 8; + + // Initialize input vector boundaries + start_mram_block_addr_A = (uint32_t) DPU_MRAM_HEAP_POINTER; + start_mram_block_addr_aux = start_mram_block_addr_A; + end_mram_block_addr_A = + start_mram_block_addr_A + sizeof(DTYPE) * input_size; + + uint32_t current_mram_block_addr_A = start_mram_block_addr_A; + + // Bring first and last values to WRAM + mram_read((__mram_ptr void const *)current_mram_block_addr_A, + cache_aux_A, BLOCK_SIZE); + mram_read((__mram_ptr void const *)(end_mram_block_addr_A - + BLOCK_SIZE * sizeof(DTYPE)), + cache_aux_B, BLOCK_SIZE); + + while (1) { + // Locate the address of the mid mram block + current_mram_block_addr_A = + (start_mram_block_addr_A + + end_mram_block_addr_A) / 2; + current_mram_block_addr_A &= WORD_MASK; + + // Boundary check + if (current_mram_block_addr_A < + (start_mram_block_addr_A + BLOCK_SIZE)) { + // Search inside (start_mram_block_addr_A, start_mram_block_addr_A + BLOCK_SIZE) + mram_read((__mram_ptr void const *) + start_mram_block_addr_A, cache_A, + BLOCK_SIZE); + found = + search(cache_A, searching_for, BLOCK_SIZE); + + if (found > -1) { + result->found = + found + (start_mram_block_addr_A - + start_mram_block_addr_aux) + / sizeof(DTYPE); + } + // Search inside (start_mram_block_addr_A + BLOCK_SIZE, end_mram_block_addr_A) + else { + size_t remain_bytes_to_search = + end_mram_block_addr_A - + (start_mram_block_addr_A + + BLOCK_SIZE); + mram_read((__mram_ptr void const *) + start_mram_block_addr_A + + BLOCK_SIZE, cache_A, + remain_bytes_to_search); + found = + search(cache_A, searching_for, + remain_bytes_to_search); + + if (found > -1) { + result->found = + found + + (start_mram_block_addr_A + + BLOCK_SIZE - + start_mram_block_addr_aux) + / sizeof(DTYPE); + } else { + printf("%lld NOT found\n", + searching_for); + } + } + break; + } + // Load cache with current MRAM block + mram_read((__mram_ptr void const *) + current_mram_block_addr_A, cache_A, + BLOCK_SIZE); + + // Search inside block + found = search(cache_A, searching_for, BLOCK_SIZE); + + // If found > -1, we found the searching_for query + if (found > -1) { + result->found = + found + (current_mram_block_addr_A - + start_mram_block_addr_aux) / + sizeof(DTYPE); + break; + } + // If found == -2, we need to discard right part of the input vector + if (found == -2) { + end_mram_block_addr_A = + current_mram_block_addr_A; + } + // If found == -1, we need to discard left part of the input vector + else if (found == -1) { + start_mram_block_addr_A = + current_mram_block_addr_A; + } + } } - break; - } - - // Load cache with current MRAM block - mram_read((__mram_ptr void const *) current_mram_block_addr_A, cache_A, BLOCK_SIZE); - - // Search inside block - found = search(cache_A, searching_for, BLOCK_SIZE); - - // If found > -1, we found the searching_for query - if(found > -1) - { - result->found = found + (current_mram_block_addr_A - start_mram_block_addr_aux) / sizeof(DTYPE); - break; - } - - // If found == -2, we need to discard right part of the input vector - if(found == -2) - { - end_mram_block_addr_A = current_mram_block_addr_A; - } - - // If found == -1, we need to discard left part of the input vector - else if (found == -1) - { - start_mram_block_addr_A = current_mram_block_addr_A; - } - } - } - return 0; + return 0; } diff --git a/BS/host/app.c b/BS/host/app.c index 10d76f1..90d016f 100644 --- a/BS/host/app.c +++ b/BS/host/app.c @@ -7,20 +7,28 @@ #include <stdlib.h> #include <stdbool.h> #include <string.h> -#include <dpu.h> -#include <dpu_log.h> #include <unistd.h> #include <getopt.h> #include <assert.h> #include <time.h> -#if ENERGY -#include <dpu_probe.h> +#if ASPECTC +extern "C" { #endif +#include <dpu.h> +#include <dpu_log.h> #include <dpu_management.h> #include <dpu_target_macros.h> +#if ENERGY +#include <dpu_probe.h> +#endif + +#if ASPECTC +} +#endif + #define XSTR(x) STR(x) #define STR(x) #x @@ -31,7 +39,9 @@ #define DPU_BINARY "./bin/bs_dpu" // Create input arrays -void create_test_file(DTYPE * input, DTYPE * querys, uint64_t nr_elements, uint64_t nr_querys) { +void create_test_file(DTYPE *input, DTYPE *querys, uint64_t nr_elements, + uint64_t nr_querys) +{ input[0] = 1; for (uint64_t i = 1; i < nr_elements; i++) { @@ -43,12 +53,12 @@ void create_test_file(DTYPE * input, DTYPE * querys, uint64_t nr_elements, uint } // Compute output in the host -int64_t binarySearch(DTYPE * input, DTYPE * querys, DTYPE input_size, uint64_t num_querys) +int64_t binarySearch(DTYPE *input, DTYPE *querys, DTYPE input_size, + uint64_t num_querys) { uint64_t result = -1; DTYPE r; - for(uint64_t q = 0; q < num_querys; q++) - { + for (uint64_t q = 0; q < num_querys; q++) { DTYPE l = 0; r = input_size; while (l <= r) { @@ -57,92 +67,96 @@ int64_t binarySearch(DTYPE * input, DTYPE * querys, DTYPE input_size, uint64_t n // XXX shouldn't this short-circuit? // Check if x is present at mid if (input[m] == querys[q]) - result = m; + result = m; // If x greater, ignore left half if (input[m] < querys[q]) - l = m + 1; + l = m + 1; // If x is smaller, ignore right half else - r = m - 1; + r = m - 1; } } return result; } - // Main of the Host Application -int main(int argc, char **argv) { +int main(int argc, char **argv) +{ struct Params p = input_params(argc, argv); struct dpu_set_t dpu_set, dpu; uint32_t nr_of_dpus; - uint32_t nr_of_ranks; + uint32_t nr_of_ranks; uint64_t input_size = INPUT_SIZE; uint64_t num_querys = p.num_querys; DTYPE result_host = -1; - DTYPE result_dpu = -1; + DTYPE result_dpu = -1; - // Timer declaration - Timer timer; + // Timer declaration + Timer timer; - int numa_node_rank = -2; + int numa_node_rank = -2; - // Allocate DPUs and load binary + // Allocate DPUs and load binary #if !WITH_ALLOC_OVERHEAD - DPU_ASSERT(dpu_alloc(NR_DPUS, NULL, &dpu_set)); - timer.time[0] = 0; // alloc + DPU_ASSERT(dpu_alloc(NR_DPUS, NULL, &dpu_set)); + zero(&timer, 0); // alloc #endif #if !WITH_LOAD_OVERHEAD - DPU_ASSERT(dpu_load(dpu_set, DPU_BINARY, NULL)); - DPU_ASSERT(dpu_get_nr_dpus(dpu_set, &nr_of_dpus)); - DPU_ASSERT(dpu_get_nr_ranks(dpu_set, &nr_of_ranks)); - assert(nr_of_dpus == NR_DPUS); - timer.time[1] = 0; // load + DPU_ASSERT(dpu_load(dpu_set, DPU_BINARY, NULL)); + DPU_ASSERT(dpu_get_nr_dpus(dpu_set, &nr_of_dpus)); + DPU_ASSERT(dpu_get_nr_ranks(dpu_set, &nr_of_ranks)); + assert(nr_of_dpus == NR_DPUS); + zero(&timer, 1); // load #endif #if !WITH_FREE_OVERHEAD - timer.time[6] = 0; // free + zero(&timer, 6); // free #endif - #if ENERGY +#if ENERGY struct dpu_probe_t probe; DPU_ASSERT(dpu_probe_init("energy_probe", &probe)); - #endif +#endif // Query number adjustement for proper partitioning - if(num_querys % (NR_DPUS * NR_TASKLETS)) - num_querys = num_querys + (NR_DPUS * NR_TASKLETS - num_querys % (NR_DPUS * NR_TASKLETS)); + if (num_querys % (NR_DPUS * NR_TASKLETS)) + num_querys = + num_querys + (NR_DPUS * NR_TASKLETS - + num_querys % (NR_DPUS * NR_TASKLETS)); - assert(num_querys % (NR_DPUS * NR_TASKLETS) == 0 && "Input dimension"); // Allocate input and querys vectors + assert(num_querys % (NR_DPUS * NR_TASKLETS) == 0 && "Input dimension"); // Allocate input and querys vectors - DTYPE * input = malloc((input_size) * sizeof(DTYPE)); - DTYPE * querys = malloc((num_querys) * sizeof(DTYPE)); + DTYPE *input = (DTYPE*)malloc((input_size) * sizeof(DTYPE)); + DTYPE *querys = (DTYPE*)malloc((num_querys) * sizeof(DTYPE)); // Create an input file with arbitrary data create_test_file(input, querys, input_size, num_querys); // Create kernel arguments - uint64_t slice_per_dpu = num_querys / NR_DPUS; - dpu_arguments_t input_arguments = {input_size, slice_per_dpu, 0}; + uint64_t slice_per_dpu = num_querys / NR_DPUS; + dpu_arguments_t input_arguments = { input_size, slice_per_dpu, (enum kernel)0 }; for (unsigned int rep = 0; rep < p.n_warmup + p.n_reps; rep++) { // Perform input transfers uint64_t i = 0; #if WITH_ALLOC_OVERHEAD - if(rep >= p.n_warmup) { + if (rep >= p.n_warmup) { start(&timer, 0, 0); } DPU_ASSERT(dpu_alloc(NR_DPUS, NULL, &dpu_set)); - if(rep >= p.n_warmup) { + if (rep >= p.n_warmup) { stop(&timer, 0); } #endif #if WITH_DPUINFO printf("DPUs:"); - DPU_FOREACH (dpu_set, dpu) { - int rank = dpu_get_rank_id(dpu_get_rank(dpu_from_set(dpu))) & DPU_TARGET_MASK; + DPU_FOREACH(dpu_set, dpu) { + int rank = + dpu_get_rank_id(dpu_get_rank(dpu_from_set(dpu))) & + DPU_TARGET_MASK; int slice = dpu_get_slice_id(dpu_from_set(dpu)); int member = dpu_get_member_id(dpu_from_set(dpu)); printf(" %d(%d.%d)", rank, slice, member); @@ -150,11 +164,11 @@ int main(int argc, char **argv) { printf("\n"); #endif #if WITH_LOAD_OVERHEAD - if(rep >= p.n_warmup) { + if (rep >= p.n_warmup) { start(&timer, 1, 0); } DPU_ASSERT(dpu_load(dpu_set, DPU_BINARY, NULL)); - if(rep >= p.n_warmup) { + if (rep >= p.n_warmup) { stop(&timer, 1); } DPU_ASSERT(dpu_get_nr_dpus(dpu_set, &nr_of_dpus)); @@ -164,27 +178,35 @@ int main(int argc, char **argv) { // int prev_rank_id = -1; int rank_id = -1; - DPU_FOREACH (dpu_set, dpu) { - rank_id = dpu_get_rank_id(dpu_get_rank(dpu_from_set(dpu))) & DPU_TARGET_MASK; - if ((numa_node_rank != -2) && numa_node_rank != dpu_get_rank_numa_node(dpu_get_rank(dpu_from_set(dpu)))) { + DPU_FOREACH(dpu_set, dpu) { + rank_id = + dpu_get_rank_id(dpu_get_rank(dpu_from_set(dpu))) & + DPU_TARGET_MASK; + if ((numa_node_rank != -2) + && numa_node_rank != + dpu_get_rank_numa_node(dpu_get_rank + (dpu_from_set(dpu)))) { numa_node_rank = -1; } else { - numa_node_rank = dpu_get_rank_numa_node(dpu_get_rank(dpu_from_set(dpu))); + numa_node_rank = + dpu_get_rank_numa_node(dpu_get_rank + (dpu_from_set(dpu))); } /* - if (rank_id != prev_rank_id) { - printf("/dev/dpu_rank%d @ NUMA node %d\n", rank_id, numa_node_rank); - prev_rank_id = rank_id; - } - */ + if (rank_id != prev_rank_id) { + printf("/dev/dpu_rank%d @ NUMA node %d\n", rank_id, numa_node_rank); + prev_rank_id = rank_id; + } + */ } // Compute host solution - if(rep >= p.n_warmup) { + if (rep >= p.n_warmup) { start(&timer, 2, 0); } - result_host = binarySearch(input, querys, input_size - 1, num_querys); - if(rep >= p.n_warmup) { + result_host = + binarySearch(input, querys, input_size - 1, num_querys); + if (rep >= p.n_warmup) { stop(&timer, 2); } @@ -192,103 +214,110 @@ int main(int argc, char **argv) { start(&timer, 3, 0); } - DPU_FOREACH(dpu_set, dpu, i) - { + DPU_FOREACH(dpu_set, dpu, i) { DPU_ASSERT(dpu_prepare_xfer(dpu, &input_arguments)); } - DPU_ASSERT(dpu_push_xfer(dpu_set, DPU_XFER_TO_DPU, "DPU_INPUT_ARGUMENTS", 0, sizeof(input_arguments), DPU_XFER_DEFAULT)); + DPU_ASSERT(dpu_push_xfer + (dpu_set, DPU_XFER_TO_DPU, "DPU_INPUT_ARGUMENTS", 0, + sizeof(input_arguments), DPU_XFER_DEFAULT)); i = 0; - DPU_FOREACH(dpu_set, dpu, i) - { + DPU_FOREACH(dpu_set, dpu, i) { DPU_ASSERT(dpu_prepare_xfer(dpu, input)); } - DPU_ASSERT(dpu_push_xfer(dpu_set, DPU_XFER_TO_DPU, DPU_MRAM_HEAP_POINTER_NAME, 0, input_size * sizeof(DTYPE), DPU_XFER_DEFAULT)); + DPU_ASSERT(dpu_push_xfer + (dpu_set, DPU_XFER_TO_DPU, + DPU_MRAM_HEAP_POINTER_NAME, 0, + input_size * sizeof(DTYPE), DPU_XFER_DEFAULT)); i = 0; - DPU_FOREACH(dpu_set, dpu, i) - { - DPU_ASSERT(dpu_prepare_xfer(dpu, querys + slice_per_dpu * i)); + DPU_FOREACH(dpu_set, dpu, i) { + DPU_ASSERT(dpu_prepare_xfer + (dpu, querys + slice_per_dpu * i)); } - DPU_ASSERT(dpu_push_xfer(dpu_set, DPU_XFER_TO_DPU, DPU_MRAM_HEAP_POINTER_NAME, input_size * sizeof(DTYPE), slice_per_dpu * sizeof(DTYPE), DPU_XFER_DEFAULT)); + DPU_ASSERT(dpu_push_xfer + (dpu_set, DPU_XFER_TO_DPU, + DPU_MRAM_HEAP_POINTER_NAME, + input_size * sizeof(DTYPE), + slice_per_dpu * sizeof(DTYPE), DPU_XFER_DEFAULT)); if (rep >= p.n_warmup) { stop(&timer, 3); } - // Run kernel on DPUs - if (rep >= p.n_warmup) - { + if (rep >= p.n_warmup) { start(&timer, 4, 0); - #if ENERGY +#if ENERGY DPU_ASSERT(dpu_probe_start(&probe)); - #endif +#endif } DPU_ASSERT(dpu_launch(dpu_set, DPU_SYNCHRONOUS)); - if (rep >= p.n_warmup) - { + if (rep >= p.n_warmup) { stop(&timer, 4); - #if ENERGY +#if ENERGY DPU_ASSERT(dpu_probe_stop(&probe)); - #endif +#endif } // Print logs if required - #if PRINT +#if PRINT unsigned int each_dpu = 0; printf("Display DPU Logs\n"); - DPU_FOREACH(dpu_set, dpu) - { + DPU_FOREACH(dpu_set, dpu) { printf("DPU#%d:\n", each_dpu); DPU_ASSERT(dpulog_read_for_dpu(dpu.dpu, stdout)); each_dpu++; } - #endif +#endif // Retrieve results - dpu_results_t* results_retrieve[NR_DPUS]; + dpu_results_t *results_retrieve[NR_DPUS]; if (rep >= p.n_warmup) { start(&timer, 5, 0); } i = 0; - DPU_FOREACH(dpu_set, dpu, i) - { - results_retrieve[i] = (dpu_results_t*)malloc(NR_TASKLETS * sizeof(dpu_results_t)); + DPU_FOREACH(dpu_set, dpu, i) { + results_retrieve[i] = + (dpu_results_t *) malloc(NR_TASKLETS * + sizeof(dpu_results_t)); DPU_ASSERT(dpu_prepare_xfer(dpu, results_retrieve[i])); } - DPU_ASSERT(dpu_push_xfer(dpu_set, DPU_XFER_FROM_DPU, "DPU_RESULTS", 0, NR_TASKLETS * sizeof(dpu_results_t), DPU_XFER_DEFAULT)); - - DPU_FOREACH(dpu_set, dpu, i) - { - for(unsigned int each_tasklet = 0; each_tasklet < NR_TASKLETS; each_tasklet++) - { - if(results_retrieve[i][each_tasklet].found > result_dpu) - { - result_dpu = results_retrieve[i][each_tasklet].found; + DPU_ASSERT(dpu_push_xfer + (dpu_set, DPU_XFER_FROM_DPU, "DPU_RESULTS", 0, + NR_TASKLETS * sizeof(dpu_results_t), + DPU_XFER_DEFAULT)); + + DPU_FOREACH(dpu_set, dpu, i) { + for (unsigned int each_tasklet = 0; + each_tasklet < NR_TASKLETS; each_tasklet++) { + if (results_retrieve[i][each_tasklet].found > + result_dpu) { + result_dpu = + results_retrieve[i][each_tasklet]. + found; } } free(results_retrieve[i]); } - if(rep >= p.n_warmup) { + if (rep >= p.n_warmup) { stop(&timer, 5); } - #if WITH_ALLOC_OVERHEAD #if WITH_FREE_OVERHEAD - if(rep >= p.n_warmup) { + if (rep >= p.n_warmup) { start(&timer, 6, 0); } #endif DPU_ASSERT(dpu_free(dpu_set)); #if WITH_FREE_OVERHEAD - if(rep >= p.n_warmup) { + if (rep >= p.n_warmup) { stop(&timer, 6); } #endif @@ -296,58 +325,91 @@ int main(int argc, char **argv) { int status = (result_dpu == result_host); if (status) { - printf("[" ANSI_COLOR_GREEN "OK" ANSI_COLOR_RESET "] results are equal\n"); + printf("[" ANSI_COLOR_GREEN "OK" ANSI_COLOR_RESET + "] results are equal\n"); if (rep >= p.n_warmup) { - printf("[::] BS-UPMEM | n_dpus=%d n_ranks=%d n_tasklets=%d e_type=%s block_size_B=%d n_elements=%lu", - NR_DPUS, nr_of_ranks, NR_TASKLETS, XSTR(DTYPE), BLOCK_SIZE, input_size); - printf(" b_with_alloc_overhead=%d b_with_load_overhead=%d b_with_free_overhead=%d numa_node_rank=%d ", - WITH_ALLOC_OVERHEAD, WITH_LOAD_OVERHEAD, WITH_FREE_OVERHEAD, numa_node_rank); - printf("| latency_alloc_us=%f latency_load_us=%f latency_cpu_us=%f latency_write_us=%f latency_kernel_us=%f latency_read_us=%f latency_free_us=%f", - timer.time[0], - timer.time[1], - timer.time[2], - timer.time[3], - timer.time[4], - timer.time[5], - timer.time[6]); - printf(" throughput_cpu_MBps=%f throughput_upmem_kernel_MBps=%f throughput_upmem_total_MBps=%f", - num_querys * sizeof(DTYPE) / timer.time[2], - num_querys * sizeof(DTYPE) / (timer.time[4]), - num_querys * sizeof(DTYPE) / (timer.time[0] + timer.time[1] + timer.time[3] + timer.time[4] + timer.time[5] + timer.time[6])); - printf(" throughput_upmem_wxr_MBps=%f throughput_upmem_lwxr_MBps=%f throughput_upmem_alwxr_MBps=%f", - num_querys * sizeof(DTYPE) / (timer.time[3] + timer.time[4] + timer.time[5]), - num_querys * sizeof(DTYPE) / (timer.time[1] + timer.time[3] + timer.time[4] + timer.time[5]), - num_querys * sizeof(DTYPE) / (timer.time[0] + timer.time[1] + timer.time[3] + timer.time[4] + timer.time[5])); - printf(" throughput_cpu_MOpps=%f throughput_upmem_kernel_MOpps=%f throughput_upmem_total_MOpps=%f", - num_querys / timer.time[2], - num_querys / (timer.time[4]), - num_querys / (timer.time[0] + timer.time[1] + timer.time[3] + timer.time[4] + timer.time[5] + timer.time[6])); - printf(" throughput_upmem_wxr_MOpps=%f throughput_upmem_lwxr_MOpps=%f throughput_upmem_alwxr_MOpps=%f\n", - num_querys / (timer.time[3] + timer.time[4] + timer.time[5]), - num_querys / (timer.time[1] + timer.time[3] + timer.time[4] + timer.time[5]), - num_querys / (timer.time[0] + timer.time[1] + timer.time[3] + timer.time[4] + timer.time[5])); + dfatool_printf + ("[::] BS-UPMEM | n_dpus=%d n_ranks=%d n_tasklets=%d e_type=%s block_size_B=%d n_elements=%lu", + NR_DPUS, nr_of_ranks, NR_TASKLETS, + XSTR(DTYPE), BLOCK_SIZE, input_size); + dfatool_printf + (" b_with_alloc_overhead=%d b_with_load_overhead=%d b_with_free_overhead=%d numa_node_rank=%d ", + WITH_ALLOC_OVERHEAD, WITH_LOAD_OVERHEAD, + WITH_FREE_OVERHEAD, numa_node_rank); + dfatool_printf + ("| latency_alloc_us=%f latency_load_us=%f latency_cpu_us=%f latency_write_us=%f latency_kernel_us=%f latency_read_us=%f latency_free_us=%f", + timer.time[0], timer.time[1], + timer.time[2], timer.time[3], + timer.time[4], timer.time[5], + timer.time[6]); + dfatool_printf + (" throughput_cpu_MBps=%f throughput_upmem_kernel_MBps=%f throughput_upmem_total_MBps=%f", + num_querys * sizeof(DTYPE) / timer.time[2], + num_querys * sizeof(DTYPE) / + (timer.time[4]), + num_querys * sizeof(DTYPE) / + (timer.time[0] + timer.time[1] + + timer.time[3] + timer.time[4] + + timer.time[5] + timer.time[6])); + dfatool_printf + (" throughput_upmem_wxr_MBps=%f throughput_upmem_lwxr_MBps=%f throughput_upmem_alwxr_MBps=%f", + num_querys * sizeof(DTYPE) / + (timer.time[3] + timer.time[4] + + timer.time[5]), + num_querys * sizeof(DTYPE) / + (timer.time[1] + timer.time[3] + + timer.time[4] + timer.time[5]), + num_querys * sizeof(DTYPE) / + (timer.time[0] + timer.time[1] + + timer.time[3] + timer.time[4] + + timer.time[5])); + dfatool_printf + (" throughput_cpu_MOpps=%f throughput_upmem_kernel_MOpps=%f throughput_upmem_total_MOpps=%f", + num_querys / timer.time[2], + num_querys / (timer.time[4]), + num_querys / (timer.time[0] + + timer.time[1] + + timer.time[3] + + timer.time[4] + + timer.time[5] + + timer.time[6])); + dfatool_printf + (" throughput_upmem_wxr_MOpps=%f throughput_upmem_lwxr_MOpps=%f throughput_upmem_alwxr_MOpps=%f\n", + num_querys / (timer.time[3] + + timer.time[4] + + timer.time[5]), + num_querys / (timer.time[1] + + timer.time[3] + + timer.time[4] + + timer.time[5]), + num_querys / (timer.time[0] + + timer.time[1] + + timer.time[3] + + timer.time[4] + + timer.time[5])); } } else { - printf("[" ANSI_COLOR_RED "ERROR" ANSI_COLOR_RESET "] results differ!\n"); + printf("[" ANSI_COLOR_RED "ERROR" ANSI_COLOR_RESET + "] results differ!\n"); } } // Print timing results /* - printf("CPU Version Time (ms): "); - print(&timer, 0, p.n_reps); - printf("CPU-DPU Time (ms): "); - print(&timer, 1, p.n_reps); - printf("DPU Kernel Time (ms): "); - print(&timer, 2, p.n_reps); - printf("DPU-CPU Time (ms): "); - print(&timer, 3, p.n_reps); - */ - - #if ENERGY + printf("CPU Version Time (ms): "); + print(&timer, 0, p.n_reps); + printf("CPU-DPU Time (ms): "); + print(&timer, 1, p.n_reps); + printf("DPU Kernel Time (ms): "); + print(&timer, 2, p.n_reps); + printf("DPU-CPU Time (ms): "); + print(&timer, 3, p.n_reps); + */ + +#if ENERGY double energy; DPU_ASSERT(dpu_probe_get(&probe, DPU_ENERGY, DPU_AVERAGE, &energy)); printf("DPU Energy (J): %f\t", energy * num_iterations); - #endif +#endif free(input); #if !WITH_ALLOC_OVERHEAD diff --git a/BS/support/common.h b/BS/include/common.h index dbd050c..d0b2865 100755..100644 --- a/BS/support/common.h +++ b/BS/include/common.h @@ -27,18 +27,20 @@ #define INPUT_SIZE 2048576 #endif +enum kernel { + kernel1 = 0, + nr_kernels = 1, +}; + typedef struct { uint64_t input_size; uint64_t slice_per_dpu; - enum kernels { - kernel1 = 0, - nr_kernels = 1, - } kernel; + enum kernel kernel; } dpu_arguments_t; // Structures used by both the host and the dpu to communicate information typedef struct { - DTYPE found; + DTYPE found; } dpu_results_t; #ifndef ENERGY diff --git a/BS/include/dfatool_host.ah b/BS/include/dfatool_host.ah new file mode 100644 index 0000000..19019a5 --- /dev/null +++ b/BS/include/dfatool_host.ah @@ -0,0 +1,31 @@ +#pragma once + +#include <sys/time.h> +#include "dfatool_host_dpu.ah" + +aspect DfatoolHostTiming : public DfatoolHostDPUTiming { + + unsigned long n_elements, n_queries; + unsigned int element_size; + + virtual int getKernel() { return 1; } + + DfatoolHostTiming() { + element_size = sizeof(uint32_t); + } + + advice call("% input_params(...)"): after() { + Params* p = tjp->result(); + n_elements = INPUT_SIZE; + n_queries = p->num_querys; + printf("[>>] BS | n_dpus=%u n_elements=%lu n_queries=%lu\n", NR_DPUS, n_elements, n_queries); + } + + advice call("% binarySearch(...)") : after() { + printf("[--] BS | n_dpus=%u n_elements=%lu n_queries=%lu\n", NR_DPUS, n_elements, n_queries); + } + + advice execution("% main(...)") : after() { + printf("[<<] BS | n_dpus=%u n_elements=%lu n_queries=%lu\n", NR_DPUS, n_elements, n_queries); + } +}; diff --git a/BS/include/params.h b/BS/include/params.h new file mode 100644 index 0000000..f970eda --- /dev/null +++ b/BS/include/params.h @@ -0,0 +1,59 @@ +#ifndef _PARAMS_H_ +#define _PARAMS_H_ + +#include "common.h" + +typedef struct Params { + long num_querys; + unsigned n_warmup; + unsigned n_reps; +} Params; + +void usage() +{ + fprintf(stderr, + "\nUsage: ./program [options]" + "\n" + "\nGeneral options:" + "\n -h help" + "\n -w <W> # of untimed warmup iterations (default=1)" + "\n -e <E> # of timed repetition iterations (default=3)" + "\n" + "\nBenchmark-specific options:" + "\n -i <I> problem size (default=%d queries)" "\n", PROBLEM_SIZE); +} + +struct Params input_params(int argc, char **argv) +{ + struct Params p; + p.num_querys = PROBLEM_SIZE; + p.n_warmup = 1; + p.n_reps = 3; + + int opt; + while ((opt = getopt(argc, argv, "h:i:w:e:")) >= 0) { + switch (opt) { + case 'h': + usage(); + exit(0); + break; + case 'i': + p.num_querys = atol(optarg); + break; + case 'w': + p.n_warmup = atoi(optarg); + break; + case 'e': + p.n_reps = atoi(optarg); + break; + default: + fprintf(stderr, "\nUnrecognized option!\n"); + usage(); + exit(0); + } + } + assert(NR_DPUS > 0 && "Invalid # of dpus!"); + + return p; +} +#endif diff --git a/BS/include/timer.h b/BS/include/timer.h new file mode 100644 index 0000000..7b80823 --- /dev/null +++ b/BS/include/timer.h @@ -0,0 +1,5 @@ +#pragma once + +#define N_TIMERS 7 +#include "../../include/timer_base.h" +#undef N_TIMERS diff --git a/BS/run-fgbs24a.sh b/BS/run-fgbs24a.sh deleted file mode 100755 index 06f8766..0000000 --- a/BS/run-fgbs24a.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -set -e - -mkdir -p $(hostname) - -ts=$(date +%Y%m%d) - -# BL: use 2^(BL) B blocks for MRAM <-> WRAM transfers on PIM module -# T: data type -# -w: number of un-timed warmup iterations -# -e: number of timed iterations -# -i; ignored, always uses 262144 elements - -( - -echo "prim-benchmarks BS (dfatool fgbs24a edition)" -echo "Started at $(date)" -echo "Revision $(git describe --always)" - -for nr_dpus in 2304 2048 2543; do - for nr_tasklets in 16; do - echo - if make -B NR_DPUS=${nr_dpus} NR_TASKLETS=${nr_tasklets} BL=10; then - timeout --foreground -k 1m 30m bin/bs_host -w 0 -e 100 -i 16777216 || true - fi - if make -B NR_DPUS=${nr_dpus} NR_TASKLETS=${nr_tasklets} BL=10 WITH_ALLOC_OVERHEAD=1 WITH_LOAD_OVERHEAD=1 WITH_FREE_OVERHEAD=1; then - timeout --foreground -k 1m 30m bin/bs_host -w 0 -e 100 -i 16777216 || true - fi - done -done -echo "Completed at $(date)" -) | tee "$(hostname)/${ts}-fgbs24a.txt" diff --git a/BS/run-paper-strong-full.sh b/BS/run-paper-strong-full.sh deleted file mode 100755 index a6129aa..0000000 --- a/BS/run-paper-strong-full.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -set -e - -# BL: use 2^(BL) B blocks for MRAM <-> WRAM transfers on PIM module -# T: data type -# -w: number of un-timed warmup iterations -# -e: number of timed iterations -# -i; ignored, always uses 262144 elements - -( - -echo "prim-benchmarks BS strong-full (dfatool edition)" -echo "Started at $(date)" -echo "Revision $(git describe --always)" - -# >2048 are not part of uptsream -for nr_dpus in 2543 2304 256 512 1024 2048; do - for nr_tasklets in 1 2 4 8 16; do - echo - if make -B NR_DPUS=${nr_dpus} NR_TASKLETS=${nr_tasklets} BL=10 verbose=1; then - timeout --foreground -k 1m 30m bin/bs_host -w 0 -e 100 -i 16777216 || true - fi - done -done -) | tee log-paper-strong-full.txt diff --git a/BS/run-paper-strong-rank.sh b/BS/run-paper-strong-rank.sh deleted file mode 100755 index c2d4f36..0000000 --- a/BS/run-paper-strong-rank.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -set -e - -# BL: use 2^(BL) B blocks for MRAM <-> WRAM transfers on PIM module -# T: data type -# -w: number of un-timed warmup iterations -# -e: number of timed iterations -# -i; ignored, always uses 262144 elements - -( - -echo "prim-benchmarks BS strong-rank (dfatool edition)" -echo "Started at $(date)" -echo "Revision $(git describe --always)" - -for nr_dpus in 1 4 16 64; do - for nr_tasklets in 1 2 4 8 16; do - echo - if make -B NR_DPUS=${nr_dpus} NR_TASKLETS=${nr_tasklets} BL=10 verbose=1; then - timeout --foreground -k 1m 30m bin/bs_host -w 0 -e 100 -i 262144 || true - fi - done -done -) | tee log-paper-strong-rank.txt diff --git a/BS/run-paper-weak.sh b/BS/run-paper-weak.sh deleted file mode 100755 index a27c547..0000000 --- a/BS/run-paper-weak.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -set -e - -# BL: use 2^(BL) B blocks for MRAM <-> WRAM transfers on PIM module -# T: data type -# -w: number of un-timed warmup iterations -# -e: number of timed iterations -# -i; ignored, always uses 262144 elements -# ... so the weak rank script might be bogus - -( - -echo "prim-benchmarks BS weak (dfatool edition)" -echo "Started at $(date)" -echo "Revision $(git describe --always)" - -for nr_dpus in 1 4 16 64; do - for nr_tasklets in 1 2 4 8 16; do - echo - # original Makefile sets PROBLEM_SIZE=2, for some reason. - if make -B NR_DPUS=${nr_dpus} NR_TASKLETS=${nr_tasklets} BL=10 verbose=1 PROBLEM_SIZE=2; then - i=$(( nr_dpus * 262144 )) - timeout --foreground -k 1m 30m bin/bs_host -w 0 -e 100 -i $i || true - fi - done -done -) | tee log-paper-weak.txt diff --git a/BS/run.sh b/BS/run.sh deleted file mode 100755 index 0c67c93..0000000 --- a/BS/run.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash - -set -e - -# BL: use 2^(BL) B blocks for MRAM <-> WRAM transfers on PIM module -# T: data type -# -w: number of un-timed warmup iterations -# -e: number of timed iterations -# -i; ignored, always uses 262144 elements - -( - -echo "prim-benchmarks BS (dfatool edition)" -echo "Started at $(date)" -echo "Revision $(git describe --always)" - -for i in 262144 16777216; do - for nr_dpus in 1 4 8 16 32 64 128 256 512 768 1024 1536 2048 2304 2542; do - for nr_tasklets in 8 12 16; do - echo - if make -B NR_DPUS=${nr_dpus} NR_TASKLETS=${nr_tasklets} BL=10; then - timeout --foreground -k 1m 30m bin/bs_host -w 0 -e 100 -i $i || true - fi - done - done -done -echo "Completed at $(date)" -) | tee "log-$(hostname)-ndpus.txt" diff --git a/BS/support/params.h b/BS/support/params.h deleted file mode 100644 index 02bd750..0000000 --- a/BS/support/params.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef _PARAMS_H_ -#define _PARAMS_H_ - -#include "common.h" - -typedef struct Params { - long num_querys; - unsigned n_warmup; - unsigned n_reps; -}Params; - -void usage() { - fprintf(stderr, - "\nUsage: ./program [options]" - "\n" - "\nGeneral options:" - "\n -h help" - "\n -w <W> # of untimed warmup iterations (default=1)" - "\n -e <E> # of timed repetition iterations (default=3)" - "\n" - "\nBenchmark-specific options:" - "\n -i <I> problem size (default=2 queries)" - "\n"); - } - - struct Params input_params(int argc, char **argv) { - struct Params p; - p.num_querys = PROBLEM_SIZE; - p.n_warmup = 1; - p.n_reps = 3; - - int opt; - while((opt = getopt(argc, argv, "h:i:w:e:")) >= 0) { - switch(opt) { - case 'h': - usage(); - exit(0); - break; - case 'i': p.num_querys = atol(optarg); break; - case 'w': p.n_warmup = atoi(optarg); break; - case 'e': p.n_reps = atoi(optarg); break; - default: - fprintf(stderr, "\nUnrecognized option!\n"); - usage(); - exit(0); - } - } - assert(NR_DPUS > 0 && "Invalid # of dpus!"); - - return p; - } - #endif diff --git a/BS/support/timer.h b/BS/support/timer.h deleted file mode 100755 index ff1ae1b..0000000 --- a/BS/support/timer.h +++ /dev/null @@ -1,66 +0,0 @@ -/*
- * Copyright (c) 2016 University of Cordoba and University of Illinois
- * All rights reserved.
- *
- * Developed by: IMPACT Research Group
- * University of Cordoba and University of Illinois
- * http://impact.crhc.illinois.edu/
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * with the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * > Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimers.
- * > Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimers in the
- * documentation and/or other materials provided with the distribution.
- * > Neither the names of IMPACT Research Group, University of Cordoba,
- * University of Illinois nor the names of its contributors may be used
- * to endorse or promote products derived from this Software without
- * specific prior written permission.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
- * THE SOFTWARE.
- *
- */
-
-#include <sys/time.h>
-
-typedef struct Timer{
-
- struct timeval startTime[7];
- struct timeval stopTime[7];
- double time[7];
-
-}Timer;
-
-void start(Timer *timer, int i, int rep) {
- if(rep == 0) {
- timer->time[i] = 0.0;
- }
- gettimeofday(&timer->startTime[i], NULL);
-}
-
-void stop(Timer *timer, int i) {
- gettimeofday(&timer->stopTime[i], NULL);
- timer->time[i] += (timer->stopTime[i].tv_sec - timer->startTime[i].tv_sec) * 1000000.0 +
- (timer->stopTime[i].tv_usec - timer->startTime[i].tv_usec);
-}
-
-void print(Timer *timer, int i, int REP) { printf("%f\t", timer->time[i] / (1000 * REP)); }
-
-void printall(Timer *timer, int maxt) {
- for (int i = 0; i <= maxt; i++) {
- printf(" timer%d_us=%f", i, timer->time[i]);
- }
- printf("\n");
-}
|