diff options
Diffstat (limited to 'Microbenchmarks/STREAM/dpu')
-rw-r--r-- | Microbenchmarks/STREAM/dpu/add.c | 103 | ||||
-rw-r--r-- | Microbenchmarks/STREAM/dpu/copy.c | 75 | ||||
-rw-r--r-- | Microbenchmarks/STREAM/dpu/copyw.c | 101 | ||||
-rw-r--r-- | Microbenchmarks/STREAM/dpu/scale.c | 103 | ||||
-rw-r--r-- | Microbenchmarks/STREAM/dpu/triad.c | 105 |
5 files changed, 487 insertions, 0 deletions
diff --git a/Microbenchmarks/STREAM/dpu/add.c b/Microbenchmarks/STREAM/dpu/add.c new file mode 100644 index 0000000..faf6504 --- /dev/null +++ b/Microbenchmarks/STREAM/dpu/add.c @@ -0,0 +1,103 @@ +/* +* STREAM Add +* +*/ +#include <stdint.h> +#include <stdio.h> +#include <defs.h> +#include <mram.h> +#include <alloc.h> +#include <perfcounter.h> +#include <barrier.h> + +#include "../support/common.h" +#include "../support/cyclecount.h" + +__host dpu_arguments_t DPU_INPUT_ARGUMENTS; +__host dpu_results_t DPU_RESULTS[NR_TASKLETS]; + +// Add +static void add_dpu(T *bufferC, T *bufferA, T *bufferB) { + + #pragma unroll + for (unsigned int i = 0; i < BLOCK_SIZE / sizeof(T); i++){ + bufferC[i] = bufferA[i] + bufferB[i]; + } + +} + +// Barrier +BARRIER_INIT(my_barrier, NR_TASKLETS); + +extern int main_kernel1(void); + +int (*kernels[nr_kernels])(void) = {main_kernel1}; + +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){ // Initialize once the cycle counter + mem_reset(); // Reset the heap + + perfcounter_config(COUNT_CYCLES, true); + } + perfcounter_cycles cycles; + // Barrier + barrier_wait(&my_barrier); +#ifndef WRAM + timer_start(&cycles); // START TIMER +#endif + + uint32_t input_size_dpu = DPU_INPUT_ARGUMENTS.size / sizeof(T); + + dpu_results_t *result = &DPU_RESULTS[tasklet_id]; + result->cycles = 0; + + // Address of the current processing block in MRAM + uint32_t mram_base_addr_A = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2)); + uint32_t mram_base_addr_B = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2) + input_size_dpu * sizeof(T)); + uint32_t mram_base_addr_C = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2) + 2 * input_size_dpu * sizeof(T)); + + // Initialize a local cache to store the MRAM block + T *cache_A = (T *) mem_alloc(BLOCK_SIZE); + T *cache_B = (T *) mem_alloc(BLOCK_SIZE); + + for(unsigned int byte_index = 0; byte_index < input_size_dpu * sizeof(T); byte_index += BLOCK_SIZE * NR_TASKLETS){ + + // Load cache with current MRAM block + mram_read((__mram_ptr void const*)(mram_base_addr_A + byte_index), cache_A, BLOCK_SIZE); + mram_read((__mram_ptr void const*)(mram_base_addr_B + byte_index), cache_B, BLOCK_SIZE); + +#ifdef WRAM + // Barrier + barrier_wait(&my_barrier); + timer_start(&cycles); // START TIMER +#endif + + // Add + add_dpu(cache_B, cache_A, cache_B); + +#ifdef WRAM + result->cycles += timer_stop(&cycles); // STOP TIMER + // Barrier + barrier_wait(&my_barrier); +#endif + + // Write cache to current MRAM block + mram_write(cache_B, (__mram_ptr void*)(mram_base_addr_C + byte_index), BLOCK_SIZE); + + } + +#ifndef WRAM + result->cycles = timer_stop(&cycles); // STOP TIMER +#endif + return 0; +} diff --git a/Microbenchmarks/STREAM/dpu/copy.c b/Microbenchmarks/STREAM/dpu/copy.c new file mode 100644 index 0000000..ff4df42 --- /dev/null +++ b/Microbenchmarks/STREAM/dpu/copy.c @@ -0,0 +1,75 @@ +/* +* STREAM Copy +* +*/ +#include <stdint.h> +#include <stdio.h> +#include <defs.h> +#include <mram.h> +#include <alloc.h> +#include <perfcounter.h> +#include <barrier.h> + +#include "../support/common.h" +#include "../support/cyclecount.h" + +__host dpu_arguments_t DPU_INPUT_ARGUMENTS; +__host dpu_results_t DPU_RESULTS[NR_TASKLETS]; + +// Barrier +BARRIER_INIT(my_barrier, NR_TASKLETS); + +extern int main_kernel1(void); + +int (*kernels[nr_kernels])(void) = {main_kernel1}; + +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){ // Initialize once the cycle counter + mem_reset(); // Reset the heap + + perfcounter_config(COUNT_CYCLES, true); + } + perfcounter_cycles cycles; + // Barrier + barrier_wait(&my_barrier); +#ifndef WRAM + timer_start(&cycles); // START TIMER +#endif + + uint32_t input_size_dpu = DPU_INPUT_ARGUMENTS.size / sizeof(T); + + dpu_results_t *result = &DPU_RESULTS[tasklet_id]; + result->cycles = 0; + + // Address of the current processing block in MRAM + uint32_t mram_base_addr_A = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2)); + uint32_t mram_base_addr_B = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2) + input_size_dpu * sizeof(T)); + + // Initialize a local cache to store the MRAM block + T *cache_A = (T *) mem_alloc(BLOCK_SIZE); + + for(unsigned int byte_index = 0; byte_index < input_size_dpu * sizeof(T); byte_index += BLOCK_SIZE * NR_TASKLETS){ + + // Load cache with current MRAM block + mram_read((__mram_ptr void const*)(mram_base_addr_A + byte_index), cache_A, BLOCK_SIZE); + + // Write cache to current MRAM block + mram_write(cache_A, (__mram_ptr void*)(mram_base_addr_B + byte_index), BLOCK_SIZE); + + } + +#ifndef WRAM + result->cycles = timer_stop(&cycles); // STOP TIMER +#endif + return 0; +} diff --git a/Microbenchmarks/STREAM/dpu/copyw.c b/Microbenchmarks/STREAM/dpu/copyw.c new file mode 100644 index 0000000..eff7a3b --- /dev/null +++ b/Microbenchmarks/STREAM/dpu/copyw.c @@ -0,0 +1,101 @@ +/* +* STREAM Copy (WRAM) +* +*/ +#include <stdint.h> +#include <stdio.h> +#include <defs.h> +#include <mram.h> +#include <alloc.h> +#include <perfcounter.h> +#include <barrier.h> + +#include "../support/common.h" +#include "../support/cyclecount.h" + +__host dpu_arguments_t DPU_INPUT_ARGUMENTS; +__host dpu_results_t DPU_RESULTS[NR_TASKLETS]; + +// Copy +static void copyw_dpu(T *bufferB, T *bufferA) { + + #pragma unroll + for (unsigned int i = 0; i < BLOCK_SIZE / sizeof(T); i++){ + bufferB[i] = bufferA[i]; + } + +} + +// Barrier +BARRIER_INIT(my_barrier, NR_TASKLETS); + +extern int main_kernel1(void); + +int (*kernels[nr_kernels])(void) = {main_kernel1}; + +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){ // Initialize once the cycle counter + mem_reset(); // Reset the heap + + perfcounter_config(COUNT_CYCLES, true); + } + perfcounter_cycles cycles; + // Barrier + barrier_wait(&my_barrier); +#ifndef WRAM + timer_start(&cycles); // START TIMER +#endif + + uint32_t input_size_dpu = DPU_INPUT_ARGUMENTS.size / sizeof(T); + + dpu_results_t *result = &DPU_RESULTS[tasklet_id]; + result->cycles = 0; + + // Address of the current processing block in MRAM + uint32_t mram_base_addr_A = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2)); + uint32_t mram_base_addr_B = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2) + input_size_dpu * sizeof(T)); + + // Initialize a local cache to store the MRAM block + T *cache_A = (T *) mem_alloc(BLOCK_SIZE); + T *cache_B = (T *) mem_alloc(BLOCK_SIZE); + + for(unsigned int byte_index = 0; byte_index < input_size_dpu * sizeof(T); byte_index += BLOCK_SIZE * NR_TASKLETS){ + + // Load cache with current MRAM block + mram_read((__mram_ptr void const*)(mram_base_addr_A + byte_index), cache_A, BLOCK_SIZE); + +#ifdef WRAM + // Barrier + barrier_wait(&my_barrier); + timer_start(&cycles); // START TIMER +#endif + + // Copy + copyw_dpu(cache_B, cache_A); + +#ifdef WRAM + result->cycles += timer_stop(&cycles); // STOP TIMER + // Barrier + barrier_wait(&my_barrier); +#endif + + // Write cache to current MRAM block + mram_write(cache_B, (__mram_ptr void*)(mram_base_addr_B + byte_index), BLOCK_SIZE); + + } + +#ifndef WRAM + result->cycles = timer_stop(&cycles); // STOP TIMER +#endif + return 0; +} diff --git a/Microbenchmarks/STREAM/dpu/scale.c b/Microbenchmarks/STREAM/dpu/scale.c new file mode 100644 index 0000000..4247aac --- /dev/null +++ b/Microbenchmarks/STREAM/dpu/scale.c @@ -0,0 +1,103 @@ +/* +* STREAM Scale +* +*/ +#include <stdint.h> +#include <stdio.h> +#include <defs.h> +#include <mram.h> +#include <alloc.h> +#include <perfcounter.h> +#include <barrier.h> + +#include "../support/common.h" +#include "../support/cyclecount.h" + +__host dpu_arguments_t DPU_INPUT_ARGUMENTS; +__host dpu_results_t DPU_RESULTS[NR_TASKLETS]; + +// Scale +static void scale_dpu(T *bufferB, T *bufferA, T scalar) { + + #pragma unroll + for (unsigned int i = 0; i < BLOCK_SIZE / sizeof(T); i++){ + bufferB[i] = scalar * bufferA[i]; + } + +} + +// Barrier +BARRIER_INIT(my_barrier, NR_TASKLETS); + +extern int main_kernel1(void); + +int (*kernels[nr_kernels])(void) = {main_kernel1}; + +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){ // Initialize once the cycle counter + mem_reset(); // Reset the heap + + perfcounter_config(COUNT_CYCLES, true); + } + perfcounter_cycles cycles; + // Barrier + barrier_wait(&my_barrier); +#ifndef WRAM + timer_start(&cycles); // START TIMER +#endif + + uint32_t input_size_dpu = DPU_INPUT_ARGUMENTS.size / sizeof(T); + + T scalar = (T)input_size_dpu; // Simply use this number as a scalar + + dpu_results_t *result = &DPU_RESULTS[tasklet_id]; + result->cycles = 0; + + // Address of the current processing block in MRAM + uint32_t mram_base_addr_A = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2)); + uint32_t mram_base_addr_B = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2) + input_size_dpu * sizeof(T)); + + // Initialize a local cache to store the MRAM block + T *cache_A = (T *) mem_alloc(BLOCK_SIZE); + T *cache_B = (T *) mem_alloc(BLOCK_SIZE); + + for(unsigned int byte_index = 0; byte_index < input_size_dpu * sizeof(T); byte_index += BLOCK_SIZE * NR_TASKLETS){ + + // Load cache with current MRAM block + mram_read((__mram_ptr void const*)(mram_base_addr_A + byte_index), cache_A, BLOCK_SIZE); + +#ifdef WRAM + // Barrier + barrier_wait(&my_barrier); + timer_start(&cycles); // START TIMER +#endif + + // Scale + scale_dpu(cache_B, cache_A, scalar); + +#ifdef WRAM + result->cycles += timer_stop(&cycles); // STOP TIMER + // Barrier + barrier_wait(&my_barrier); +#endif + + // Write cache to current MRAM block + mram_write(cache_B, (__mram_ptr void*)(mram_base_addr_B + byte_index), BLOCK_SIZE); + + } + +#ifndef WRAM + result->cycles = timer_stop(&cycles); // STOP TIMER +#endif + return 0; +} diff --git a/Microbenchmarks/STREAM/dpu/triad.c b/Microbenchmarks/STREAM/dpu/triad.c new file mode 100644 index 0000000..e81cb59 --- /dev/null +++ b/Microbenchmarks/STREAM/dpu/triad.c @@ -0,0 +1,105 @@ +/* +* STREAM Triad +* +*/ +#include <stdint.h> +#include <stdio.h> +#include <defs.h> +#include <mram.h> +#include <alloc.h> +#include <perfcounter.h> +#include <barrier.h> + +#include "../support/common.h" +#include "../support/cyclecount.h" + +__host dpu_arguments_t DPU_INPUT_ARGUMENTS; +__host dpu_results_t DPU_RESULTS[NR_TASKLETS]; + +// Triad +static void triad_dpu(T *bufferC, T *bufferA, T *bufferB, T scalar) { + + #pragma unroll + for (unsigned int i = 0; i < BLOCK_SIZE / sizeof(T); i++){ + bufferC[i] = bufferA[i] + scalar * bufferB[i]; + } + +} + +// Barrier +BARRIER_INIT(my_barrier, NR_TASKLETS); + +extern int main_kernel1(void); + +int (*kernels[nr_kernels])(void) = {main_kernel1}; + +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){ // Initialize once the cycle counter + mem_reset(); // Reset the heap + + perfcounter_config(COUNT_CYCLES, true); + } + perfcounter_cycles cycles; + // Barrier + barrier_wait(&my_barrier); +#ifndef WRAM + timer_start(&cycles); // START TIMER +#endif + + uint32_t input_size_dpu = DPU_INPUT_ARGUMENTS.size / sizeof(T); + + T scalar = (T)input_size_dpu; // Simply use this number as a scalar + + dpu_results_t *result = &DPU_RESULTS[tasklet_id]; + result->cycles = 0; + + // Address of the current processing block in MRAM + uint32_t mram_base_addr_A = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2)); + uint32_t mram_base_addr_B = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2) + input_size_dpu * sizeof(T)); + uint32_t mram_base_addr_C = (uint32_t)(DPU_MRAM_HEAP_POINTER + (tasklet_id << BLOCK_SIZE_LOG2) + 2 * input_size_dpu * sizeof(T)); + + // Initialize a local cache to store the MRAM block + T *cache_A = (T *) mem_alloc(BLOCK_SIZE); + T *cache_B = (T *) mem_alloc(BLOCK_SIZE); + + for(unsigned int byte_index = 0; byte_index < input_size_dpu * sizeof(T); byte_index += BLOCK_SIZE * NR_TASKLETS){ + + // Load cache with current MRAM block + mram_read((__mram_ptr void const*)(mram_base_addr_A + byte_index), cache_A, BLOCK_SIZE); + mram_read((__mram_ptr void const*)(mram_base_addr_B + byte_index), cache_B, BLOCK_SIZE); + +#ifdef WRAM + // Barrier + barrier_wait(&my_barrier); + timer_start(&cycles); // START TIMER +#endif + + // Triad + triad_dpu(cache_B, cache_A, cache_B, scalar); + +#ifdef WRAM + result->cycles += timer_stop(&cycles); // STOP TIMER + // Barrier + barrier_wait(&my_barrier); +#endif + + // Write cache to current MRAM block + mram_write(cache_B, (__mram_ptr void*)(mram_base_addr_C + byte_index), BLOCK_SIZE); + + } + +#ifndef WRAM + result->cycles = timer_stop(&cycles); // STOP TIMER +#endif + return 0; +} |