summaryrefslogtreecommitdiff
path: root/BS
diff options
context:
space:
mode:
authorBirte Kristina Friesel <birte.friesel@uos.de>2025-01-16 08:10:18 +0100
committerBirte Kristina Friesel <birte.friesel@uos.de>2025-01-16 08:10:18 +0100
commit0b704b7ce9437e7769f561401518fc8320db37de (patch)
tree320af84b21c940ee78f84f176e19ef41d368fbd3 /BS
parent4072fd2debd280cfa3401e193cf5ecc23a1dd4f3 (diff)
BS: dos2unix; indent -linux
Diffstat (limited to 'BS')
-rw-r--r--BS/baselines/cpu/bs_omp.c345
-rw-r--r--BS/dpu/task.c278
-rw-r--r--BS/host/app.c318
-rwxr-xr-xBS/support/common.h2
-rw-r--r--BS/support/params.h91
-rwxr-xr-xBS/support/timer.h137
6 files changed, 632 insertions, 539 deletions
diff --git a/BS/baselines/cpu/bs_omp.c b/BS/baselines/cpu/bs_omp.c
index 871792d..2e4c300 100644
--- a/BS/baselines/cpu/bs_omp.c
+++ b/BS/baselines/cpu/bs_omp.c
@@ -19,275 +19,274 @@
#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];
- }
+ for (uint64_t i = 0; i < n_querys; i++) {
+ querys[i] = input[rand() % nr_elements];
+ }
}
/**
* @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;
+int main(int argc, char **argv)
+{
+ (void)argc;
#if WITH_BENCHMARK
- Timer timer;
+ Timer timer;
#endif
- uint64_t input_size = atol(argv[1]);
- uint64_t n_querys = atol(argv[2]);
+ 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" ::);
- }
+ 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);
+ stop(&timer, 0);
#if NOP_SYNC
- for(int rep = 0; rep < 200000; rep++) {
- asm volatile("nop" ::);
- }
+ for (int rep = 0; rep < 200000; rep++) {
+ asm volatile ("nop"::);
+ }
#endif
#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
- int status = (result_host);
+ int status = (result_host);
#if WITH_BENCHMARK
- unsigned int nr_threads = 0;
+ unsigned int nr_threads = 0;
#pragma omp parallel
#pragma omp atomic
- nr_threads++;
+ nr_threads++;
- 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");
- }
-#endif // WITH_BENCHMARK
+ } 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/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 f267645..217ea99 100644
--- a/BS/host/app.c
+++ b/BS/host/app.c
@@ -31,7 +31,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)
+{
srand(time(NULL));
@@ -45,12 +47,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) {
@@ -59,92 +61,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));
+ timer.time[0] = 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);
+ timer.time[1] = 0; // load
#endif
#if !WITH_FREE_OVERHEAD
- timer.time[6] = 0; // free
+ timer.time[6] = 0; // 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 = malloc((input_size) * sizeof(DTYPE));
+ DTYPE *querys = 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, 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);
@@ -152,11 +158,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));
@@ -166,27 +172,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);
}
@@ -194,103 +208,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
@@ -298,58 +319,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]));
+ 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]));
}
} 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/support/common.h
index dbd050c..54adc39 100755
--- a/BS/support/common.h
+++ b/BS/support/common.h
@@ -38,7 +38,7 @@ typedef struct {
// 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/support/params.h b/BS/support/params.h
index 02bd750..c91202f 100644
--- a/BS/support/params.h
+++ b/BS/support/params.h
@@ -4,49 +4,56 @@
#include "common.h"
typedef struct Params {
- long num_querys;
- unsigned n_warmup;
- unsigned n_reps;
-}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");
- }
+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;
+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!");
+ 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
+ return p;
+}
+#endif
diff --git a/BS/support/timer.h b/BS/support/timer.h
index ff1ae1b..256447a 100755
--- a/BS/support/timer.h
+++ b/BS/support/timer.h
@@ -1,66 +1,71 @@
-/*
- * 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");
-}
+/*
+ * 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");
+}