diff options
Diffstat (limited to 'SCAN-SSA')
-rw-r--r-- | SCAN-SSA/Makefile | 46 | ||||
-rw-r--r-- | SCAN-SSA/dpu/task.c | 172 | ||||
-rw-r--r-- | SCAN-SSA/host/app.c | 294 | ||||
-rwxr-xr-x | SCAN-SSA/run.sh | 11 | ||||
-rwxr-xr-x | SCAN-SSA/support/common.h | 69 | ||||
-rw-r--r-- | SCAN-SSA/support/params.h | 56 | ||||
-rwxr-xr-x | SCAN-SSA/support/timer.h | 59 |
7 files changed, 707 insertions, 0 deletions
diff --git a/SCAN-SSA/Makefile b/SCAN-SSA/Makefile new file mode 100644 index 0000000..4930e70 --- /dev/null +++ b/SCAN-SSA/Makefile @@ -0,0 +1,46 @@ +DPU_DIR := dpu +HOST_DIR := host +BUILDDIR ?= bin +NR_DPUS ?= 1 +NR_TASKLETS ?= 16 +BL ?= 10 +TYPE ?= INT64 +ENERGY ?= 0 + +define conf_filename + ${BUILDDIR}/.NR_DPUS_$(1)_NR_TASKLETS_$(2)_BL_$(3)_TYPE_$(4).conf +endef +CONF := $(call conf_filename,${NR_DPUS},${NR_TASKLETS},${BL},${TYPE}) + +HOST_TARGET := ${BUILDDIR}/host_code +DPU_TARGET := ${BUILDDIR}/dpu_code + +COMMON_INCLUDES := support +HOST_SOURCES := $(wildcard ${HOST_DIR}/*.c) +DPU_SOURCES := $(wildcard ${DPU_DIR}/*.c) + +.PHONY: all clean test + +__dirs := $(shell mkdir -p ${BUILDDIR}) + +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} -DBL=${BL} -D${TYPE} -DENERGY=${ENERGY} +DPU_FLAGS := ${COMMON_FLAGS} -O2 -DNR_TASKLETS=${NR_TASKLETS} -DBL=${BL} -D${TYPE} + +all: ${HOST_TARGET} ${DPU_TARGET} + +${CONF}: + $(RM) $(call conf_filename,*,*) + touch ${CONF} + +${HOST_TARGET}: ${HOST_SOURCES} ${COMMON_INCLUDES} ${CONF} + $(CC) -o $@ ${HOST_SOURCES} ${HOST_FLAGS} + +${DPU_TARGET}: ${DPU_SOURCES} ${COMMON_INCLUDES} ${CONF} + dpu-upmem-dpurte-clang ${DPU_FLAGS} -o $@ ${DPU_SOURCES} + +clean: + $(RM) -r $(BUILDDIR) + +test: all + ./${HOST_TARGET} diff --git a/SCAN-SSA/dpu/task.c b/SCAN-SSA/dpu/task.c new file mode 100644 index 0000000..c6871f7 --- /dev/null +++ b/SCAN-SSA/dpu/task.c @@ -0,0 +1,172 @@ +/* +* Scan with multiple tasklets (Scan-scan-add) +* +*/ +#include <stdint.h> +#include <stdio.h> +#include <defs.h> +#include <mram.h> +#include <alloc.h> +#include <perfcounter.h> +#include <handshake.h> +#include <barrier.h> + +#include "../support/common.h" + +__host dpu_arguments_t DPU_INPUT_ARGUMENTS; +__host dpu_results_t DPU_RESULTS[NR_TASKLETS]; + +// Array for communication between adjacent tasklets +T message[NR_TASKLETS]; +T message_partial_count; + +// Scan in each tasklet +static T scan(T *output, T *input){ + output[0] = input[0]; + #pragma unroll + for(unsigned int j = 1; j < REGS; j++) { + output[j] = output[j - 1] + input[j]; + } + return output[REGS - 1]; +} + +// Handshake with adjacent tasklets +static T handshake_sync(T l_count, unsigned int tasklet_id){ + T p_count; + // Wait and read message + if(tasklet_id != 0){ + handshake_wait_for(tasklet_id - 1); + p_count = message[tasklet_id]; + } + else + p_count = 0; + // Write message and notify + if(tasklet_id < NR_TASKLETS - 1){ + message[tasklet_id + 1] = p_count + l_count; + handshake_notify(); + } + return p_count; +} + +// Barrier +BARRIER_INIT(my_barrier, NR_TASKLETS); + +// Add in each tasklet +static void add(T *output, T p_count){ + #pragma unroll + for(unsigned int j = 0; j < REGS; j++) { + output[j] += p_count; + } +} + +extern int main_kernel1(void); +extern int main_kernel2(void); + +int (*kernels[nr_kernels])(void) = {main_kernel1, main_kernel2}; + +int main(void) { + // Kernel + return kernels[DPU_INPUT_ARGUMENTS.kernel](); +} + +// Scan-(handshake)scan +int main_kernel1() { +#if 1 // Comment out for appendix experiment + 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 + } + // Barrier + barrier_wait(&my_barrier); + + dpu_results_t *result = &DPU_RESULTS[tasklet_id]; + + uint32_t input_size_dpu_bytes = DPU_INPUT_ARGUMENTS.size; // Input size per DPU in bytes + + // Address of the current processing block in MRAM + uint32_t base_tasklet = tasklet_id << BLOCK_SIZE_LOG2; + uint32_t mram_base_addr_A = (uint32_t)DPU_MRAM_HEAP_POINTER; + uint32_t mram_base_addr_B = (uint32_t)(DPU_MRAM_HEAP_POINTER + input_size_dpu_bytes); + + // 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); + + // Initialize shared variable + if(tasklet_id == NR_TASKLETS - 1) + message_partial_count = DPU_INPUT_ARGUMENTS.t_count; + // Barrier + barrier_wait(&my_barrier); + + for(unsigned int byte_index = base_tasklet; byte_index < input_size_dpu_bytes; byte_index += BLOCK_SIZE * NR_TASKLETS){ + + // Load cache with current MRAM block + mram_read((const __mram_ptr void*)(mram_base_addr_A + byte_index), cache_A, BLOCK_SIZE); + + // Scan in each tasklet + T l_count = scan(cache_B, cache_A); + + // Sync with adjacent tasklets + T p_count = handshake_sync(l_count, tasklet_id); + + // Barrier + barrier_wait(&my_barrier); + + // Add in each tasklet + add(cache_B, message_partial_count + p_count); + + // Write cache to current MRAM block + mram_write(cache_B, (__mram_ptr void*)(mram_base_addr_B + byte_index), BLOCK_SIZE); + + // Total count in this DPU + if(tasklet_id == NR_TASKLETS - 1){ + result->t_count = message_partial_count + p_count + l_count; + message_partial_count = result->t_count; + } + } + +#endif + return 0; +} + +// Add +int main_kernel2() { + 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 + } + // Barrier + barrier_wait(&my_barrier); + + uint32_t input_size_dpu_bytes = DPU_INPUT_ARGUMENTS.size; // Input size per DPU in bytes + + // Address of the current processing block in MRAM + uint32_t base_tasklet = tasklet_id << BLOCK_SIZE_LOG2; + uint32_t mram_base_addr_B = (uint32_t)(DPU_MRAM_HEAP_POINTER + input_size_dpu_bytes); + + // Initialize a local cache to store the MRAM block + T *cache_A = (T *) mem_alloc(BLOCK_SIZE); + + T t_count = DPU_INPUT_ARGUMENTS.t_count; + + for(unsigned int byte_index = base_tasklet; byte_index < input_size_dpu_bytes; byte_index += BLOCK_SIZE * NR_TASKLETS){ + + // Load cache with current MRAM block + mram_read((__mram_ptr void const*)(mram_base_addr_B + byte_index), cache_A, BLOCK_SIZE); + + // Add in each tasklet + add(cache_A, t_count); + + // Write cache to current MRAM block + mram_write(cache_A, (__mram_ptr void*)(mram_base_addr_B + byte_index), BLOCK_SIZE); + + } + + return 0; +} diff --git a/SCAN-SSA/host/app.c b/SCAN-SSA/host/app.c new file mode 100644 index 0000000..2dfe32c --- /dev/null +++ b/SCAN-SSA/host/app.c @@ -0,0 +1,294 @@ +/** +* app.c +* SCAN-SSA Host Application Source File +* +*/ +#include <stdio.h> +#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 "../support/common.h" +#include "../support/timer.h" +#include "../support/params.h" + +// Define the DPU Binary path as DPU_BINARY here +#ifndef DPU_BINARY +#define DPU_BINARY "./bin/dpu_code" +#endif + +#if ENERGY +#include <dpu_probe.h> +#endif + +// Pointer declaration +static T* A; +static T* C; +static T* C2; + +// Create input arrays +static void read_input(T* A, unsigned int nr_elements, unsigned int nr_elements_round) { + srand(0); + printf("nr_elements\t%u\t", nr_elements); + for (unsigned int i = 0; i < nr_elements; i++) { + A[i] = (T) (rand()); + } + for (unsigned int i = nr_elements; i < nr_elements_round; i++) { + A[i] = 0; + } +} + +// Compute output in the host +static void scan_host(T* C, T* A, unsigned int nr_elements) { + C[0] = A[0]; + for (unsigned int i = 1; i < nr_elements; i++) { + C[i] = C[i - 1] + A[i]; + } +} + +// Main of the Host Application +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; + +#if ENERGY + struct dpu_probe_t probe; + DPU_ASSERT(dpu_probe_init("energy_probe", &probe)); +#endif + + // Allocate DPUs and load binary + DPU_ASSERT(dpu_alloc(NR_DPUS, NULL, &dpu_set)); + DPU_ASSERT(dpu_load(dpu_set, DPU_BINARY, NULL)); + DPU_ASSERT(dpu_get_nr_dpus(dpu_set, &nr_of_dpus)); + printf("Allocated %d DPU(s)\n", nr_of_dpus); + + unsigned int i = 0; + T accum = 0; + + const unsigned int input_size = p.exp == 0 ? p.input_size * nr_of_dpus : p.input_size; // Total input size (weak or strong scaling) + const unsigned int input_size_dpu_ = divceil(input_size, nr_of_dpus); // Input size per DPU (max.) + const unsigned int input_size_dpu_round = + (input_size_dpu_ % (NR_TASKLETS * REGS) != 0) ? roundup(input_size_dpu_, (NR_TASKLETS * REGS)) : input_size_dpu_; // Input size per DPU (max.), 8-byte aligned + + // Input/output allocation + A = malloc(input_size_dpu_round * nr_of_dpus * sizeof(T)); + C = malloc(input_size_dpu_round * nr_of_dpus * sizeof(T)); + C2 = malloc(input_size_dpu_round * nr_of_dpus * sizeof(T)); + T *bufferA = A; + T *bufferC = C2; + + // Create an input file with arbitrary data + read_input(A, input_size, input_size_dpu_round * nr_of_dpus); + + // Timer declaration + Timer timer; + + printf("NR_TASKLETS\t%d\tBL\t%d\n", NR_TASKLETS, BL); + + // Loop over main kernel + for(int rep = 0; rep < p.n_warmup + p.n_reps; rep++) { + + // Compute output on CPU (performance comparison and verification purposes) + if(rep >= p.n_warmup) + start(&timer, 0, rep - p.n_warmup); + scan_host(C, A, input_size); + if(rep >= p.n_warmup) + stop(&timer, 0); + + printf("Load input data\n"); + if(rep >= p.n_warmup) + start(&timer, 1, rep - p.n_warmup); + // Input arguments + const unsigned int input_size_dpu = input_size_dpu_round; + unsigned int kernel = 0; + dpu_arguments_t input_arguments = {input_size_dpu * sizeof(T), kernel, 0}; + // Copy input arrays + i = 0; + 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_FOREACH(dpu_set, dpu, i) { + DPU_ASSERT(dpu_prepare_xfer(dpu, bufferA + input_size_dpu * i)); + } + DPU_ASSERT(dpu_push_xfer(dpu_set, DPU_XFER_TO_DPU, DPU_MRAM_HEAP_POINTER_NAME, 0, input_size_dpu * sizeof(T), DPU_XFER_DEFAULT)); + if(rep >= p.n_warmup) + stop(&timer, 1); + + printf("Run program on DPU(s) \n"); + // Run DPU kernel + if(rep >= p.n_warmup) { + start(&timer, 2, rep - p.n_warmup); + #if ENERGY + DPU_ASSERT(dpu_probe_start(&probe)); + #endif + } + + DPU_ASSERT(dpu_launch(dpu_set, DPU_SYNCHRONOUS)); + if(rep >= p.n_warmup) { + stop(&timer, 2); + #if ENERGY + DPU_ASSERT(dpu_probe_stop(&probe)); + #endif + } + +#if PRINT + { + unsigned int each_dpu = 0; + printf("Display DPU Logs\n"); + DPU_FOREACH (dpu_set, dpu) { + printf("DPU#%d:\n", each_dpu); + DPU_ASSERT(dpulog_read_for_dpu(dpu.dpu, stdout)); + each_dpu++; + } + } +#endif + + printf("Retrieve results\n"); + dpu_results_t results[nr_of_dpus]; + T* results_scan = malloc(nr_of_dpus * sizeof(T)); + i = 0; + accum = 0; + + if(rep >= p.n_warmup) + start(&timer, 3, rep - p.n_warmup); + // PARALLEL RETRIEVE TRANSFER + dpu_results_t* results_retrieve[nr_of_dpus]; + + if(rep >= p.n_warmup) + start(&timer, 3, rep - p.n_warmup); + + 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) { + // Retrieve tasklet timings + for (unsigned int each_tasklet = 0; each_tasklet < NR_TASKLETS; each_tasklet++) { + if(each_tasklet == NR_TASKLETS - 1) + results[i].t_count = results_retrieve[i][each_tasklet].t_count; + } + free(results_retrieve[i]); + // Sequential scan + T temp = results[i].t_count; + results_scan[i] = accum; + accum += temp; +#if PRINT + printf("i=%d -- %lu, %lu, %lu\n", i, results_scan[i], accum, temp); +#endif + } + + // Arguments for add kernel (2nd kernel) + kernel = 1; + dpu_arguments_t input_arguments_2[NR_DPUS]; + for(i=0; i<nr_of_dpus; i++) { + input_arguments_2[i].size=input_size_dpu * sizeof(T); + input_arguments_2[i].kernel=kernel; + input_arguments_2[i].t_count=results_scan[i]; + } + DPU_FOREACH(dpu_set, dpu, i) { + DPU_ASSERT(dpu_prepare_xfer(dpu, &input_arguments_2[i])); + } + DPU_ASSERT(dpu_push_xfer(dpu_set, DPU_XFER_TO_DPU, "DPU_INPUT_ARGUMENTS", 0, sizeof(input_arguments_2[0]), DPU_XFER_DEFAULT)); + if(rep >= p.n_warmup) + stop(&timer, 3); + + printf("Run program on DPU(s) \n"); + // Run DPU kernel + if(rep >= p.n_warmup) { + start(&timer, 4, rep - p.n_warmup); + #if ENERGY + DPU_ASSERT(dpu_probe_start(&probe)); + #endif + } + DPU_ASSERT(dpu_launch(dpu_set, DPU_SYNCHRONOUS)); + if(rep >= p.n_warmup) { + stop(&timer, 4); + #if ENERGY + DPU_ASSERT(dpu_probe_stop(&probe)); + #endif + } + +#if PRINT + { + unsigned int each_dpu = 0; + printf("Display DPU Logs\n"); + DPU_FOREACH (dpu_set, dpu) { + printf("DPU#%d:\n", each_dpu); + DPU_ASSERT(dpulog_read_for_dpu(dpu.dpu, stdout)); + each_dpu++; + } + } +#endif + + printf("Retrieve results\n"); + if(rep >= p.n_warmup) + start(&timer, 5, rep - p.n_warmup); + i = 0; + // PARALLEL RETRIEVE TRANSFER + DPU_FOREACH(dpu_set, dpu, i) { + DPU_ASSERT(dpu_prepare_xfer(dpu, bufferC + input_size_dpu * i)); + } + DPU_ASSERT(dpu_push_xfer(dpu_set, DPU_XFER_FROM_DPU, DPU_MRAM_HEAP_POINTER_NAME, input_size_dpu * sizeof(T), input_size_dpu * sizeof(T), DPU_XFER_DEFAULT)); + if(rep >= p.n_warmup) + stop(&timer, 5); + + // Free memory + free(results_scan); + } + + // Print timing results + printf("CPU "); + print(&timer, 0, p.n_reps); + printf("CPU-DPU "); + print(&timer, 1, p.n_reps); + printf("DPU Kernel Scan "); + print(&timer, 2, p.n_reps); + printf("Inter-DPU (Scan) "); + print(&timer, 3, p.n_reps); + printf("DPU Kernel Add "); + print(&timer, 4, p.n_reps); + printf("DPU-CPU "); + print(&timer, 5, 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); + #endif + + + // Check output + bool status = true; + for (i = 0; i < input_size; i++) { + if(C[i] != bufferC[i]){ + status = false; +#if PRINT + printf("%d: %lu -- %lu\n", i, C[i], bufferC[i]); +#endif + } + } + if (status) { + printf("[" ANSI_COLOR_GREEN "OK" ANSI_COLOR_RESET "] Outputs are equal\n"); + } else { + printf("[" ANSI_COLOR_RED "ERROR" ANSI_COLOR_RESET "] Outputs differ!\n"); + } + + // Deallocation + free(A); + free(C); + free(C2); + DPU_ASSERT(dpu_free(dpu_set)); + + return status ? 0 : -1; +} diff --git a/SCAN-SSA/run.sh b/SCAN-SSA/run.sh new file mode 100755 index 0000000..8ea8457 --- /dev/null +++ b/SCAN-SSA/run.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +for i in 2048 4096 8192 16384 65536 262144 1048576 3932160 +do + NR_DPUS=1 NR_TASKLETS=16 BL=10 make all + wait + ./bin/host_code -w 10 -e 100 -i ${i} > profile/out${i}_tl16_bl10_dpu11 + wait + make clean + wait +done diff --git a/SCAN-SSA/support/common.h b/SCAN-SSA/support/common.h new file mode 100755 index 0000000..1c419da --- /dev/null +++ b/SCAN-SSA/support/common.h @@ -0,0 +1,69 @@ +#ifndef _COMMON_H_ +#define _COMMON_H_ + +// Transfer size between MRAM and WRAM +#ifdef BL +#define BLOCK_SIZE_LOG2 BL +#define BLOCK_SIZE (1 << BLOCK_SIZE_LOG2) +#else +#define BLOCK_SIZE_LOG2 8 +#define BLOCK_SIZE (1 << BLOCK_SIZE_LOG2) +#define BL BLOCK_SIZE_LOG2 +#endif + +// Data type +#ifdef UINT32 +#define T uint32_t +#define DIV 2 // Shift right to divide by sizeof(T) +#elif UINT64 +#define T uint64_t +#define DIV 3 // Shift right to divide by sizeof(T) +#elif INT32 +#define T int32_t +#define DIV 2 // Shift right to divide by sizeof(T) +#elif INT64 +#define T int64_t +#define DIV 3 // Shift right to divide by sizeof(T) +#elif FLOAT +#define T float +#define DIV 2 // Shift right to divide by sizeof(T) +#elif DOUBLE +#define T double +#define DIV 3 // Shift right to divide by sizeof(T) +#elif CHAR +#define T char +#define DIV 0 // Shift right to divide by sizeof(T) +#elif SHORT +#define T short +#define DIV 1 // Shift right to divide by sizeof(T) +#endif + +#define REGS (BLOCK_SIZE >> DIV) + +// Structures used by both the host and the dpu to communicate information +typedef struct { + uint32_t size; + enum kernels { + kernel1 = 0, + kernel2 = 1, + nr_kernels = 2, + } kernel; + T t_count; +} dpu_arguments_t; + +typedef struct { + T t_count; +} dpu_results_t; + +#ifndef ENERGY +#define ENERGY 0 +#endif +#define PRINT 0 + +#define ANSI_COLOR_RED "\x1b[31m" +#define ANSI_COLOR_GREEN "\x1b[32m" +#define ANSI_COLOR_RESET "\x1b[0m" + +#define divceil(n, m) (((n)-1) / (m) + 1) +#define roundup(n, m) ((n / m) * m + m) +#endif diff --git a/SCAN-SSA/support/params.h b/SCAN-SSA/support/params.h new file mode 100644 index 0000000..bb86211 --- /dev/null +++ b/SCAN-SSA/support/params.h @@ -0,0 +1,56 @@ +#ifndef _PARAMS_H_ +#define _PARAMS_H_ + +#include "common.h" + +typedef struct Params { + unsigned int input_size; + int n_warmup; + int n_reps; + int exp; +}Params; + +static 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 -x <X> Weak (0) or strong (1) scaling (default=0)" + "\n" + "\nBenchmark-specific options:" + "\n -i <I> input size (default=3932160 elements)" + "\n"); +} + +struct Params input_params(int argc, char **argv) { + struct Params p; + p.input_size = 3932160; + p.n_warmup = 1; + p.n_reps = 3; + p.exp = 0; + + int opt; + while((opt = getopt(argc, argv, "hi:w:e:x:")) >= 0) { + switch(opt) { + case 'h': + usage(); + exit(0); + break; + case 'i': p.input_size = atoi(optarg); break; + case 'w': p.n_warmup = atoi(optarg); break; + case 'e': p.n_reps = atoi(optarg); break; + case 'x': p.exp = 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/SCAN-SSA/support/timer.h b/SCAN-SSA/support/timer.h new file mode 100755 index 0000000..b53d95f --- /dev/null +++ b/SCAN-SSA/support/timer.h @@ -0,0 +1,59 @@ +/*
+ * 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("Time (ms): %f\t", timer->time[i] / (1000 * REP)); }
|