--- /dev/null
+#=======================================================================
+# UCB VLSI FLOW: Makefile for riscv-bmarks/mt
+#-----------------------------------------------------------------------
+# Henry Cook (hcook@cs.berkeley.edu)
+#
+
+default: all
+
+bmarkdir = .
+
+instname = riscv-bmarks-mt
+instbasedir = $(UCB_VLSI_HOME)/install
+
+#--------------------------------------------------------------------
+# Sources
+#--------------------------------------------------------------------
+
+bmarks = \
+ab_matmul\
+ab_vvadd\
+ad_matmul\
+ad_vvadd\
+ae_matmul\
+ae_vvadd\
+af_matmul\
+af_vvadd\
+ag_matmul\
+ag_vvadd\
+ai_matmul\
+ai_vvadd\
+aj_vvadd\
+ak_matmul\
+ak_vvadd\
+al_matmul\
+al_vvadd\
+am_matmul\
+am_vvadd\
+an_matmul\
+an_vvadd\
+ap_matmul\
+ap_vvadd\
+aq_matmul\
+aq_vvadd\
+ar_matmul\
+ar_vvadd\
+as_matmul\
+as_vvadd\
+at_matmul\
+at_vvadd\
+av_matmul\
+av_vvadd\
+ay_matmul\
+ay_vvadd\
+az_matmul\
+az_vvadd\
+ba_matmul\
+ba_vvadd\
+bb_matmul\
+bb_vvadd\
+bc_matmul\
+bc_vvadd\
+be_matmul\
+be_vvadd\
+bf_matmul\
+bf_vvadd\
+bh_matmul\
+bh_vvadd\
+bj_matmul\
+bj_vvadd\
+bk_matmul\
+bk_vvadd\
+bm_matmul\
+bm_vvadd\
+bn_matmul\
+bn_vvadd\
+bo_matmul\
+bo_vvadd\
+bp_matmul\
+bp_vvadd\
+br_matmul\
+br_vvadd\
+bs_matmul\
+bs_vvadd\
+bt_matmul\
+bt_vvadd\
+
+#--------------------------------------------------------------------
+# Build rules
+#--------------------------------------------------------------------
+
+RISCV_GCC = riscv-gcc
+RISCV_GCC_OPTS = -std=gnu99 -T common/test.ld -O3 -nostdlib -nostartfiles -funroll-all-loops
+RISCV_LINK = riscv-gcc -T $(bmarkdir)/common/test.ld
+RISCV_LINK_MT = riscv-gcc -T $(bmarkdir)/common/test-mt.ld
+RISCV_LINK_OPTS = -lc
+RISCV_LINK_SYSCALL = $(bmarkdir)/common/syscalls.c -lc
+RISCV_OBJDUMP = riscv-objdump --disassemble-all --disassemble-zeroes --section=.text --section=.text.startup --section=.data
+RISCV_SIM = spike -p2
+
+VPATH += $(addprefix $(bmarkdir)/, $(bmarks))
+VPATH += $(bmarkdir)/common
+
+incs += -I. -I./common $(addprefix -I$(bmarkdir)/, $(bmarks))
+objs :=
+
+#include $(patsubst %, $(bmarkdir)/%/bmark.mk, $(bmarks))
+
+#------------------------------------------------------------
+# Build and run benchmarks on riscv simulator
+#------------------------------------------------------------
+
+bmarks_riscv_obj = $(addsuffix .o, $(bmarks))
+bmarks_riscv_bin = $(addsuffix .riscv, $(bmarks))
+bmarks_riscv_dump = $(addsuffix .riscv.dump, $(bmarks))
+bmarks_riscv_hex = $(addsuffix .riscv.hex, $(bmarks))
+bmarks_riscv_out = $(addsuffix .riscv.out, $(bmarks))
+
+bmarks_defs = -DPREALLOCATE=1 -DHOST_DEBUG=0
+bmarks_cycles = 80000
+
+%.hex: %
+ elf2hex 16 32768 $< > $@
+
+$(bmarks_riscv_bin): %.riscv: %.o crt-mt.o
+ $(RISCV_LINK_MT) crt-mt.o $< $(RISCV_LINK_SYSCALL) -o $@
+
+$(bmarks_riscv_dump): %.riscv.dump: %.riscv
+ $(RISCV_OBJDUMP) $< > $@
+
+$(bmarks_riscv_out): %.riscv.out: %.riscv
+ $(RISCV_SIM) $< > $@
+
+%.o: %.c
+ $(RISCV_GCC) $(RISCV_GCC_OPTS) $(bmarks_defs) \
+ -c $(incs) $< -o $@
+
+%.o: %.S
+ $(RISCV_GCC) $(RISCV_GCC_OPTS) $(bmarks_defs) \
+ -c $(incs) $< -o $@
+
+riscv: $(bmarks_riscv_dump) $(bmarks_riscv_hex)
+run-riscv: $(bmarks_riscv_out)
+ echo; perl -ne 'print " [$$1] $$ARGV \t$$2\n" if /\*{3}(.{8})\*{3}(.*)/' \
+
+junk += $(bmarks_riscv_bin) $(bmarks_riscv_dump) $(bmarks_riscv_hex) $(bmarks_riscv_out)
+
+
+#------------------------------------------------------------
+# Default
+
+all: riscv
+
+#------------------------------------------------------------
+# Install
+
+date_suffix = $(shell date +%Y-%m-%d_%H-%M)
+install_dir = $(instbasedir)/$(instname)-$(date_suffix)
+latest_install = $(shell ls -1 -d $(instbasedir)/$(instname)* | tail -n 1)
+
+install:
+ mkdir $(install_dir)
+ cp -r $(bmarks_riscv_bin) $(bmarks_riscv_dump) $(install_dir)
+
+install-link:
+ rm -rf $(instbasedir)/$(instname)
+ ln -s $(latest_install) $(instbasedir)/$(instname)
+
+#------------------------------------------------------------
+# Clean up
+
+clean:
+ rm -rf $(objs) $(junk)
--- /dev/null
+//**************************************************************************
+// Multi-threaded Matrix Multiply benchmark
+//--------------------------------------------------------------------------
+// TA : Christopher Celio
+// Student:
+//
+//
+// This benchmark multiplies two 2-D arrays together and writes the results to
+// a third vector. The input data (and reference data) should be generated
+// using the matmul_gendata.pl perl script and dumped to a file named
+// dataset.h.
+
+
+// print out arrays, etc.
+//#define DEBUG
+
+//--------------------------------------------------------------------------
+// Includes
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+//--------------------------------------------------------------------------
+// Input/Reference Data
+
+typedef float data_t;
+#include "dataset.h"
+
+
+//--------------------------------------------------------------------------
+// Basic Utilities and Multi-thread Support
+
+__thread unsigned long coreid;
+unsigned long ncores;
+
+#include "util.h"
+
+#define stringify_1(s) #s
+#define stringify(s) stringify_1(s)
+#define stats(code) do { \
+ unsigned long _c = -rdcycle(), _i = -rdinstret(); \
+ code; \
+ _c += rdcycle(), _i += rdinstret(); \
+ if (coreid == 0) \
+ printf("%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
+ stringify(code), _c, _c/DIM_SIZE/DIM_SIZE/DIM_SIZE, 10*_c/DIM_SIZE/DIM_SIZE/DIM_SIZE%10, _c/_i, 10*_c/_i%10); \
+ } while(0)
+
+
+//--------------------------------------------------------------------------
+// Helper functions
+
+void printArray( char name[], int n, data_t arr[] )
+{
+ int i;
+ if (coreid != 0)
+ return;
+
+ printf( " %10s :", name );
+ for ( i = 0; i < n; i++ )
+ printf( " %3ld ", (long) arr[i] );
+ printf( "\n" );
+}
+
+void __attribute__((noinline)) verify(size_t n, const data_t* test, const data_t* correct)
+{
+ if (coreid != 0)
+ return;
+
+ size_t i;
+ for (i = 0; i < n; i++)
+ {
+ if (test[i] != correct[i])
+ {
+ printf("FAILED test[%d]= %3ld, correct[%d]= %3ld\n",
+ i, (long)test[i], i, (long)correct[i]);
+ exit(-1);
+ }
+ }
+
+ return;
+}
+
+//--------------------------------------------------------------------------
+// matmul function
+
+// single-thread, naive version
+void __attribute__((noinline)) matmul_naive(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ int i, j, k;
+
+ if (coreid > 0)
+ return;
+
+ for ( i = 0; i < lda; i++ )
+ for ( j = 0; j < lda; j++ )
+ {
+ for ( k = 0; k < lda; k++ )
+ {
+ C[i + j*lda] += A[j*lda + k] * B[k*lda + i];
+ }
+ }
+
+}
+
+
+
+void __attribute__((noinline)) matmul(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+
+ // ***************************** //
+ // **** ADD YOUR CODE HERE ***** //
+ // ***************************** //
+ //
+ // feel free to make a separate function for MI and MSI versions.
+
+ // I think I've got a way for this to not need the "shared" state to work nicely, so no MSI version
+ int i, j, k, lda_over_2;
+ lda_over_2 = lda/2;
+
+ if(coreid > 1)
+ return;
+ // left side of c
+ if(coreid == 0)
+ {
+ // first half of topleft corner
+ for(i = 0; i < lda_over_2; i++) {
+ for(j = 0; j < lda_over_2; j++) {
+ for(k = 0; k < lda_over_2; k++) {
+ C[i*lda + j] += A[i*lda + k]*B[k*lda + j];
+ }
+ }
+ }
+ // second half of topleft corner
+ for(i = 0; i < lda_over_2; i++) {
+ for(j = 0; j < lda_over_2; j++) {
+ for(k = lda_over_2; k < lda; k++) {
+ C[i*lda + j] += A[i*lda + k]*B[k*lda + j];
+ }
+ }
+ }
+ // second half of bottomleft corner
+ for(i = lda_over_2; i < lda; i++) {
+ for(j = 0; j < lda_over_2; j++) {
+ for(k = lda_over_2; k < lda; k++) {
+ C[i*lda + j] += A[i*lda + k]*B[k*lda + j];
+ }
+ }
+ }
+ // first half of bottomleft corner
+ for(i = lda_over_2; i < lda; i++) {
+ for(j = 0; j < lda_over_2; j++) {
+ for(k = 0; k < lda_over_2; k++) {
+ C[i*lda + j] += A[i*lda + k]*B[k*lda + j];
+ }
+ }
+ }
+ }
+ else // coreid == 1
+ {
+ // first half of bottomright corner
+ for(i = lda_over_2; i < lda; i++) {
+ for(j = lda_over_2; j < lda; j++) {
+ for(k = 0; k < lda_over_2; k++) {
+ C[i*lda + j] += A[i*lda + k]*B[k*lda + j];
+ }
+ }
+ }
+ // second half of bottomright corner
+ for(i = lda_over_2; i < lda; i++) {
+ for(j = lda_over_2; j < lda; j++) {
+ for(k = lda_over_2; k < lda; k++) {
+ C[i*lda + j] += A[i*lda + k]*B[k*lda + j];
+ }
+ }
+ }
+ // second half of topright corner
+ for(i = 0; i < lda_over_2; i++) {
+ for(j = lda_over_2; j < lda; j++) {
+ for(k = lda_over_2; k < lda; k++) {
+ C[i*lda + j] += A[i*lda + k]*B[k*lda + j];
+ }
+ }
+ }
+ // first half of topright corner
+ for(i = 0; i < lda_over_2; i++) {
+ for(j = lda_over_2; j < lda; j++) {
+ for(k = 0; k < lda_over_2; k++) {
+ C[i*lda + j] += A[i*lda + k]*B[k*lda + j];
+ }
+ }
+ }
+ }
+
+ return;
+}
+
+//--------------------------------------------------------------------------
+// Main
+//
+// all threads start executing thread_entry(). Use their "coreid" to
+// differentiate between threads (each thread is running on a separate core).
+
+void thread_entry(int cid, int nc)
+{
+ coreid = cid;
+ ncores = nc;
+
+ // static allocates data in the binary, which is visible to both threads
+ static data_t results_data[ARRAY_SIZE];
+
+
+// // Execute the provided, naive matmul
+// barrier();
+// stats(matmul_naive(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+//
+//
+// // verify
+// verify(ARRAY_SIZE, results_data, verify_data);
+//
+// // clear results from the first trial
+// size_t i;
+// if (coreid == 0)
+// for (i=0; i < ARRAY_SIZE; i++)
+// results_data[i] = 0;
+// barrier();
+
+
+ // Execute your faster matmul
+ barrier();
+ stats(matmul(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+#ifdef DEBUG
+ printArray("results:", ARRAY_SIZE, results_data);
+ printArray("verify :", ARRAY_SIZE, verify_data);
+#endif
+
+ // verify
+ verify(ARRAY_SIZE, results_data, verify_data);
+ barrier();
+
+ exit(0);
+}
+
--- /dev/null
+
+#define ARRAY_SIZE 1024
+
+
+#define DIM_SIZE 32
+
+static data_t input1_data[ARRAY_SIZE] =
+{
+ 0, 3, 2, 0, 3, 1, 0, 3, 2, 3, 2, 0, 3, 3, 1, 2, 3, 0, 0, 1,
+ 1, 1, 2, 3, 1, 2, 3, 1, 1, 3, 2, 2, 0, 1, 3, 2, 2, 2, 0, 0,
+ 1, 0, 1, 3, 3, 0, 3, 3, 3, 3, 0, 3, 2, 1, 2, 2, 0, 0, 3, 0,
+ 1, 1, 0, 3, 3, 1, 2, 3, 3, 0, 1, 2, 1, 0, 1, 2, 2, 1, 0, 3,
+ 1, 0, 2, 2, 1, 1, 1, 1, 1, 1, 2, 0, 3, 1, 1, 2, 2, 3, 3, 1,
+ 3, 2, 0, 0, 0, 3, 3, 3, 2, 1, 2, 3, 1, 0, 0, 0, 0, 1, 2, 2,
+ 1, 1, 3, 3, 3, 1, 1, 2, 3, 1, 3, 3, 2, 3, 2, 1, 2, 3, 0, 2,
+ 2, 1, 1, 0, 0, 0, 0, 0, 1, 3, 3, 1, 1, 1, 2, 2, 3, 2, 1, 1,
+ 1, 1, 3, 0, 2, 2, 1, 3, 2, 1, 2, 2, 1, 3, 1, 3, 1, 3, 2, 3,
+ 1, 2, 1, 3, 2, 2, 0, 1, 0, 0, 1, 2, 3, 3, 1, 0, 0, 0, 3, 1,
+ 2, 3, 2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, 60, 66, 63, 70, 62, 65, 50, 53, 66, 70, 72, 75, 78, 85, 95,
+ 71, 89, 70, 68, 86, 88, 58, 77, 84, 70, 65, 68, 73, 75, 91, 96, 105, 92, 76, 68,
+ 86, 69, 80, 59, 73, 83, 88, 75, 64, 63, 71, 99, 77, 77, 69, 55, 80, 73, 54, 73,
+ 87, 78, 60, 69, 65, 78, 86, 89, 95, 92, 63, 69, 89, 61, 80, 65, 70, 77, 89, 77,
+ 79, 79, 73, 92, 64, 81, 60, 78, 81, 80, 61, 63, 89, 65, 56, 83, 77, 65, 102, 70,
+ 98, 86, 96, 68, 72, 89, 73, 73, 70, 89, 84, 76, 48, 61, 63, 70, 70, 79, 50, 53,
+ 64, 63, 43, 51, 59, 62, 43, 63, 55, 77, 79, 74, 75, 74, 64, 44, 65, 69, 72, 66,
+ 54, 71, 74, 72, 69, 76, 68, 89, 94, 75, 65, 53, 85, 79, 65, 74, 82, 73, 58, 70,
+ 84, 77, 99, 72, 92, 84, 78, 62, 59, 83, 71, 74, 63, 85, 80, 78, 71, 72, 79, 83,
+ 73, 82, 60, 85, 76, 82, 60, 70, 82, 68, 54, 85, 84, 70, 86, 74, 100, 88, 98, 68,
+ 67, 87, 69, 73, 68, 88, 76, 71, 47, 43, 47, 80, 54, 65, 40, 37, 59, 53, 33, 48,
+ 62, 40, 36, 55, 36, 62, 53, 57, 70, 69, 45, 43, 53, 61, 42, 57, 56, 63, 51, 47,
+ 59, 75, 64, 89, 83, 75, 59, 75, 91, 92, 58, 64, 83, 74, 58, 60, 76, 66, 97, 69,
+ 90, 95, 92, 64, 78, 75, 77, 73, 65, 78, 82, 75, 47, 54, 59, 71, 59, 56, 53, 42,
+ 60, 55, 40, 51, 60, 46, 36, 59, 46, 57, 67, 43, 51, 53, 53, 38, 54, 56, 55, 48,
+ 41, 46, 63, 63, 80, 77, 89, 102, 89, 98, 74, 86, 98, 93, 63, 76, 98, 77, 48, 101,
+ 86, 88, 100, 82, 102, 90, 95, 75, 86, 103, 83, 98, 80, 104, 98, 86, 71, 74, 80, 90,
+ 86, 87, 73, 70, 81, 83, 55, 66, 90, 66, 58, 84, 77, 84, 93, 72, 99, 75, 85, 65,
+ 70, 89, 71, 82, 64, 79, 82, 80, 67, 73, 86, 101, 78, 97, 66, 64, 84, 80, 55, 64,
+ 79, 73, 51, 79, 89, 68, 94, 77, 109, 102, 82, 61, 66, 93, 88, 70, 82, 82, 85, 69,
+ 69, 72, 66, 97, 85, 90, 70, 59, 76, 89, 53, 56, 90, 79, 71, 64, 70, 67, 100, 92,
+ 106, 89, 83, 78, 73, 80, 70, 72, 65, 70, 92, 88, 57, 76, 55, 85, 66, 80, 61, 63,
+ 63, 78, 54, 58, 71, 73, 54, 63, 63, 62, 89, 76, 86, 81, 83, 54, 70, 81, 78, 64,
+ 56, 72, 74, 81, 75, 63, 68, 89, 65, 77, 58, 68, 75, 83, 52, 62, 82, 63, 55, 75,
+ 51, 70, 95, 66, 83, 77, 86, 61, 64, 77, 48, 70, 66, 82, 72, 75, 79, 71, 72, 89,
+ 78, 78, 66, 59, 91, 80, 55, 64, 79, 68, 54, 71, 67, 75, 87, 84, 100, 101, 76, 58,
+ 74, 82, 61, 74, 75, 97, 85, 79, 61, 55, 69, 68, 72, 65, 52, 64, 80, 73, 48, 54,
+ 71, 66, 42, 61, 66, 63, 92, 64, 85, 77, 73, 54, 74, 73, 76, 66, 62, 79, 85, 70,
+ 71, 84, 87, 81, 88, 86, 77, 77, 93, 88, 78, 71, 101, 89, 58, 84, 95, 81, 89, 97,
+ 104, 79, 83, 76, 90, 81, 91, 74, 70, 76, 91, 80, 51, 48, 56, 69, 47, 63, 54, 42,
+ 63, 63, 42, 52, 66, 56, 39, 59, 61, 52, 59, 63, 62, 68, 57, 35, 67, 58, 56, 52,
+ 61, 63, 60, 47, 85, 75, 89, 106, 88, 95, 74, 82, 107, 107, 64, 78, 98, 90, 62, 91,
+ 79, 87, 111, 84, 104, 106, 96, 68, 94, 99, 81, 89, 79, 105, 95, 86, 65, 63, 77, 89,
+ 66, 88, 56, 73, 82, 92, 41, 62, 85, 66, 50, 81, 57, 71, 77, 78, 86, 89, 77, 53,
+ 67, 78, 61, 63, 72, 82, 69, 66, 59, 46, 55, 70, 56, 64, 45, 50, 65, 64, 42, 56,
+ 78, 49, 51, 52, 38, 56, 72, 55, 73, 72, 61, 50, 63, 60, 47, 57, 55, 73, 53, 68,
+ 85, 88, 91, 96, 82, 89, 73, 76, 87, 86, 67, 69, 96, 84, 57, 89, 87, 89, 99, 88,
+ 104, 90, 85, 75, 88, 92, 85, 75, 74, 87, 103, 94, 55, 48, 56, 65, 72, 50, 45, 51,
+ 63, 62, 47, 57, 79, 53, 36, 63, 54, 68, 71, 59, 63, 61, 63, 41, 50, 73, 57, 59,
+ 56, 76, 73, 65, 61, 64, 61, 79, 53, 73, 57, 44, 61, 59, 59, 56, 81, 59, 49, 62,
+ 65, 55, 69, 72, 79, 70, 58, 57, 68, 61, 62, 50, 57, 60, 66, 66, 63, 77, 81, 89,
+ 85, 81, 76, 73, 78, 95, 59, 70, 81, 77, 46, 79, 78, 79, 83, 81, 84, 82, 85, 48,
+ 74, 85, 85, 74, 74, 80, 80, 74, 60, 76, 80, 97, 88, 93, 66, 66, 73, 84, 56, 70,
+ 90, 63, 58, 78, 73, 93, 90, 78, 94, 88, 82, 67, 85, 70, 81, 86, 74, 82, 88, 82,
+ 68, 73, 75, 91, 78, 97, 71, 66, 74, 85, 50, 59, 86, 77, 70, 74, 75, 74, 99, 82,
+ 99, 91, 86, 65, 80, 77, 72, 69, 60, 78, 90, 87, 79, 69, 74, 98, 70, 86, 81, 67,
+ 69, 78, 48, 65, 88, 70, 70, 70, 69, 72, 96, 90, 99, 82, 81, 76, 98, 73, 74, 71,
+ 69, 73, 94, 89
+};
+
--- /dev/null
+#!/usr/bin/perl -w
+#==========================================================================
+# matmul_gendata.pl
+#
+# Author : Christopher Batten (cbatten@mit.edu)
+# Date : April 29, 2005
+#
+(our $usageMsg = <<'ENDMSG') =~ s/^\#//gm;
+#
+# Simple script which creates an input data set and the reference data
+# for the matmul benchmark.
+#
+ENDMSG
+
+use strict "vars";
+use warnings;
+no warnings("once");
+use Getopt::Long;
+
+#--------------------------------------------------------------------------
+# Command line processing
+#--------------------------------------------------------------------------
+
+our %opts;
+
+sub usage()
+{
+
+ print "\n";
+ print " Usage: matmul_gendata.pl [options] \n";
+ print "\n";
+ print " Options:\n";
+ print " --help print this message\n";
+ print " --size size of input data [1000]\n";
+ print " --seed random seed [1]\n";
+ print "$usageMsg";
+
+ exit();
+}
+
+sub processCommandLine()
+{
+
+ $opts{"help"} = 0;
+ $opts{"size"} = 1000;
+ $opts{"seed"} = 1;
+ Getopt::Long::GetOptions( \%opts, 'help|?', 'size:i', 'seed:i' ) or usage();
+ $opts{"help"} and usage();
+
+}
+
+#--------------------------------------------------------------------------
+# Helper Functions
+#--------------------------------------------------------------------------
+
+sub printArray
+{
+ my $arrayName = $_[0];
+ my $arrayRef = $_[1];
+
+ my $numCols = 20;
+ my $arrayLen = scalar(@{$arrayRef});
+
+ print "static data_t ".$arrayName."[ARRAY_SIZE] = \n";
+ print "{\n";
+
+ if ( $arrayLen <= $numCols ) {
+ print " ";
+ for ( my $i = 0; $i < $arrayLen; $i++ ) {
+ print sprintf("%3d",$arrayRef->[$i]);
+ if ( $i != $arrayLen-1 ) {
+ print ", ";
+ }
+ }
+ print "\n";
+ }
+
+ else {
+ my $numRows = int($arrayLen/$numCols);
+ for ( my $j = 0; $j < $numRows; $j++ ) {
+ print " ";
+ for ( my $i = 0; $i < $numCols; $i++ ) {
+ my $index = $j*$numCols + $i;
+ print sprintf("%3d",$arrayRef->[$index]);
+ if ( $index != $arrayLen-1 ) {
+ print ", ";
+ }
+ }
+ print "\n";
+ }
+
+ if ( $arrayLen > ($numRows*$numCols) ) {
+ print " ";
+ for ( my $i = 0; $i < ($arrayLen-($numRows*$numCols)); $i++ ) {
+ my $index = $numCols*$numRows + $i;
+ print sprintf("%3d",$arrayRef->[$index]);
+ if ( $index != $arrayLen-1 ) {
+ print ", ";
+ }
+ }
+ print "\n";
+ }
+
+ }
+
+ print "};\n\n";
+}
+
+
+
+#--------------------------------------------------------------------------
+# Matmul
+#--------------------------------------------------------------------------
+
+# http://answers.oreilly.com/topic/418-how-to-multiply-matrices-in-perl/
+
+sub mmult {
+ my ($m1,$m2) = @_;
+ my ($m1rows,$m1cols) = matdim($m1);
+ my ($m2rows,$m2cols) = matdim($m2);
+
+ my $result = [ ];
+ my ($i, $j, $k);
+
+ for $i (range($m1rows)) {
+ for $j (range($m2cols)) {
+ for $k (range($m1cols)) {
+ $result->[$i][$j] += $m1->[$i][$k] * $m2->[$k][$j];
+ }
+ }
+ }
+ return $result;
+}
+
+sub range { 0 .. ($_[0] - 1) }
+
+
+sub veclen {
+ my $ary_ref = $_[0];
+ my $type = ref $ary_ref;
+ if ($type ne "ARRAY") { die "$type is bad array ref for $ary_ref" }
+ return scalar(@$ary_ref);
+}
+
+sub matdim {
+ my $matrix = $_[0];
+ my $rows = veclen($matrix);
+ my $cols = veclen($matrix->[0]);
+ return ($rows, $cols);
+}
+
+#--------------------------------------------------------------------------
+# Main
+#--------------------------------------------------------------------------
+
+sub main()
+{
+
+ processCommandLine();
+ srand($opts{"seed"});
+
+ # create random input arrays
+ my $mat_values1;
+ my $mat_values2;
+ for ( my $i = 0; $i < $opts{"size"}; $i++ ) {
+ for ( my $j = 0; $j < $opts{"size"}; $j++ ) {
+ $mat_values1->[$i][$j] = int(rand(4));
+ $mat_values2->[$i][$j] = int(rand(4));
+ }
+ }
+
+ # perform matmul
+ my $mat_results = mmult( $mat_values1, $mat_values2 );
+
+ # translate 2d arrays to 1d-somethings (I don't know how to code in perl - Chris)
+ my @values1;
+ my @values2;
+ my @results;
+ for ( my $i = 0; $i < $opts{"size"}; $i++ ) {
+ for ( my $j = 0; $j < $opts{"size"}; $j++ ) {
+ my $value1 = $mat_values1->[$i][$j];
+ my $value2 = $mat_values2->[$i][$j];
+ my $result = $mat_results->[$i][$j];
+ push( @values1, $value1 );
+ push( @values2, $value2 );
+ push( @results, $result );
+ }
+ }
+
+ print "\n\#define ARRAY_SIZE ".($opts{"size"}*$opts{"size"})." \n\n";
+ print "\n\#define DIM_SIZE ".$opts{"size"}." \n\n";
+
+ printArray( "input1_data", \@values1 );
+ printArray( "input2_data", \@values2 );
+ printArray( "verify_data", \@results);
+
+}
+
+main();
+
--- /dev/null
+//**************************************************************************
+// Multi-threaded Matrix Multiply benchmark
+//--------------------------------------------------------------------------
+// TA : Christopher Celio
+// Student:
+//
+//
+// This benchmark multiplies two 2-D arrays together and writes the results to
+// a third vector. The input data (and reference data) should be generated
+// using the matmul_gendata.pl perl script and dumped to a file named
+// dataset.h.
+
+
+// print out arrays, etc.
+//#define DEBUG
+
+//--------------------------------------------------------------------------
+// Includes
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+//--------------------------------------------------------------------------
+// Input/Reference Data
+
+typedef float data_t;
+#include "dataset.h"
+
+
+//--------------------------------------------------------------------------
+// Basic Utilities and Multi-thread Support
+
+__thread unsigned long coreid;
+unsigned long ncores;
+
+#include "util.h"
+
+#define stringify_1(s) #s
+#define stringify(s) stringify_1(s)
+#define stats(code) do { \
+ unsigned long _c = -rdcycle(), _i = -rdinstret(); \
+ code; \
+ _c += rdcycle(), _i += rdinstret(); \
+ if (coreid == 0) \
+ printf("%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
+ stringify(code), _c, _c/DIM_SIZE/DIM_SIZE/DIM_SIZE, 10*_c/DIM_SIZE/DIM_SIZE/DIM_SIZE%10, _c/_i, 10*_c/_i%10); \
+ } while(0)
+
+
+//--------------------------------------------------------------------------
+// Helper functions
+
+void printArray( char name[], int n, data_t arr[] )
+{
+ int i;
+ if (coreid != 0)
+ return;
+
+ printf( " %10s :", name );
+ for ( i = 0; i < n; i++ )
+ printf( " %3ld ", (long) arr[i] );
+ printf( "\n" );
+}
+
+void __attribute__((noinline)) verify(size_t n, const data_t* test, const data_t* correct)
+{
+ if (coreid != 0)
+ return;
+
+ size_t i;
+ for (i = 0; i < n; i++)
+ {
+ if (test[i] != correct[i])
+ {
+ printf("FAILED test[%d]= %3ld, correct[%d]= %3ld\n",
+ i, (long)test[i], i, (long)correct[i]);
+ exit(-1);
+ }
+ }
+
+ return;
+}
+
+//--------------------------------------------------------------------------
+// matmul function
+
+// single-thread, naive version
+void __attribute__((noinline)) matmul_naive(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ int i, j, k;
+
+ if (coreid > 0)
+ return;
+
+ for ( i = 0; i < lda; i++ )
+ for ( j = 0; j < lda; j++ )
+ {
+ for ( k = 0; k < lda; k++ )
+ {
+ C[i + j*lda] += A[j*lda + k] * B[k*lda + i];
+ }
+ }
+
+}
+
+
+
+void __attribute__((noinline)) matmul(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+
+ // ***************************** //
+ // **** ADD YOUR CODE HERE ***** //
+ // ***************************** //
+ //
+ // feel free to make a separate function for MI and MSI versions.
+
+ // I think I've got a way for this to not need the "shared" state to work nicely, so no MSI version
+ int i, j, k, lda_over_2;
+ lda_over_2 = lda/2;
+
+ if(coreid > 1)
+ return;
+ // left side of c
+ if(coreid == 0)
+ {
+ // first half of topleft corner
+ for(i = 0; i < lda_over_2; i++) {
+ for(j = 0; j < lda_over_2; j++) {
+ for(k = 0; k < lda_over_2; k++) {
+ C[i*lda + j] += A[i*lda + k]*B[k*lda + j];
+ }
+ }
+ }
+ // second half of topleft corner
+ for(i = 0; i < lda_over_2; i++) {
+ for(j = 0; j < lda_over_2; j++) {
+ for(k = lda_over_2; k < lda; k++) {
+ C[i*lda + j] += A[i*lda + k]*B[k*lda + j];
+ }
+ }
+ }
+ // second half of bottomleft corner
+ for(i = lda_over_2; i < lda; i++) {
+ for(j = 0; j < lda_over_2; j++) {
+ for(k = lda_over_2; k < lda; k++) {
+ C[i*lda + j] += A[i*lda + k]*B[k*lda + j];
+ }
+ }
+ }
+ // first half of bottomleft corner
+ for(i = lda_over_2; i < lda; i++) {
+ for(j = 0; j < lda_over_2; j++) {
+ for(k = 0; k < lda_over_2; k++) {
+ C[i*lda + j] += A[i*lda + k]*B[k*lda + j];
+ }
+ }
+ }
+ }
+ else // coreid == 1
+ {
+ // first half of bottomright corner
+ for(i = lda_over_2; i < lda; i++) {
+ for(j = lda_over_2; j < lda; j++) {
+ for(k = 0; k < lda_over_2; k++) {
+ C[i*lda + j] += A[i*lda + k]*B[k*lda + j];
+ }
+ }
+ }
+ // second half of bottomright corner
+ for(i = lda_over_2; i < lda; i++) {
+ for(j = lda_over_2; j < lda; j++) {
+ for(k = lda_over_2; k < lda; k++) {
+ C[i*lda + j] += A[i*lda + k]*B[k*lda + j];
+ }
+ }
+ }
+ // second half of topright corner
+ for(i = 0; i < lda_over_2; i++) {
+ for(j = lda_over_2; j < lda; j++) {
+ for(k = lda_over_2; k < lda; k++) {
+ C[i*lda + j] += A[i*lda + k]*B[k*lda + j];
+ }
+ }
+ }
+ // first half of topright corner
+ for(i = 0; i < lda_over_2; i++) {
+ for(j = lda_over_2; j < lda; j++) {
+ for(k = 0; k < lda_over_2; k++) {
+ C[i*lda + j] += A[i*lda + k]*B[k*lda + j];
+ }
+ }
+ }
+ }
+
+ return;
+}
+
+//--------------------------------------------------------------------------
+// Main
+//
+// all threads start executing thread_entry(). Use their "coreid" to
+// differentiate between threads (each thread is running on a separate core).
+
+void thread_entry(int cid, int nc)
+{
+ coreid = cid;
+ ncores = nc;
+
+ // static allocates data in the binary, which is visible to both threads
+ static data_t results_data[ARRAY_SIZE];
+
+
+// // Execute the provided, naive matmul
+// barrier();
+// stats(matmul_naive(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+//
+//
+// // verify
+// verify(ARRAY_SIZE, results_data, verify_data);
+//
+// // clear results from the first trial
+// size_t i;
+// if (coreid == 0)
+// for (i=0; i < ARRAY_SIZE; i++)
+// results_data[i] = 0;
+// barrier();
+
+
+ // Execute your faster matmul
+ barrier();
+ stats(matmul(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+#ifdef DEBUG
+ printArray("results:", ARRAY_SIZE, results_data);
+ printArray("verify :", ARRAY_SIZE, verify_data);
+#endif
+
+ // verify
+ verify(ARRAY_SIZE, results_data, verify_data);
+ barrier();
+
+ exit(0);
+}
+
--- /dev/null
+//**************************************************************************
+// Vector-vector add benchmark
+//--------------------------------------------------------------------------
+// Author : Andrew Waterman
+// TA : Christopher Celio
+// Student :
+//
+// This benchmark adds two vectors and writes the results to a
+// third vector. The input data (and reference data) should be
+// generated using the vvadd_gendata.pl perl script and dumped
+// to a file named dataset.h
+
+// to print out arrays, etc.
+//#define DEBUG
+
+//--------------------------------------------------------------------------
+// Includes
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+//--------------------------------------------------------------------------
+// Input/Reference Data
+
+typedef float data_t;
+#include "dataset.h"
+
+
+//--------------------------------------------------------------------------
+// Basic Utilities and Multi-thread Support
+
+__thread unsigned long coreid;
+unsigned long ncores;
+
+#include "util.h"
+
+#define stringify_1(s) #s
+#define stringify(s) stringify_1(s)
+#define stats(code) do { \
+ unsigned long _c = -rdcycle(), _i = -rdinstret(); \
+ code; \
+ _c += rdcycle(), _i += rdinstret(); \
+ if (coreid == 0) \
+ printf("%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
+ stringify(code), _c, _c/DATA_SIZE, 10*_c/DATA_SIZE%10, _c/_i, 10*_c/_i%10); \
+ } while(0)
+
+
+//--------------------------------------------------------------------------
+// Helper functions
+
+void printArray( char name[], int n, data_t arr[] )
+{
+ int i;
+ if (coreid != 0)
+ return;
+
+ printf( " %10s :", name );
+ for ( i = 0; i < n; i++ )
+ printf( " %4ld ", (long) arr[i] );
+ printf( "\n" );
+}
+
+void __attribute__((noinline)) verify(size_t n, const data_t* test, const data_t* correct)
+{
+ if (coreid != 0)
+ return;
+
+ size_t i;
+ for (i = 0; i < n; i++)
+ {
+ if (test[i] != correct[i])
+ {
+ printf("FAILED test[%d]= %4ld, correct[%d]= %4ld\n",
+ i, (long) test[i], i, (long)correct[i]);
+ exit(-1);
+ }
+ }
+
+ return;
+}
+
+//--------------------------------------------------------------------------
+// vvadd function
+
+//perform in-place vvadd
+void __attribute__((noinline)) vvadd(size_t n, data_t* __restrict__ x, const data_t* __restrict__ y)
+{
+ size_t i;
+
+ // interleave accesses
+ for (i = coreid; i < n; i+=ncores)
+ {
+ x[i] = x[i] + y[i];
+ }
+}
+
+void __attribute__((noinline)) vvadd_opt(size_t n, data_t* __restrict__ x, const data_t* __restrict__ y)
+{
+ // ***************************** //
+ // **** ADD YOUR CODE HERE ***** //
+ // ***************************** //
+
+ size_t i, j;
+ j = (coreid+1)*n/ncores;
+ for (i = coreid*n/ncores; i < j; i++)
+ {
+ x[i] = x[i] + y[i];
+ }
+}
+
+//--------------------------------------------------------------------------
+// Main
+//
+// all threads start executing thread_entry(). Use their "coreid" to
+// differentiate between threads (each thread is running on a separate core).
+
+void thread_entry(int cid, int nc)
+{
+ coreid = cid;
+ ncores = nc;
+
+ // static allocates data in the binary, which is visible to both threads
+ static data_t results_data[DATA_SIZE];
+
+ // because we're going to perform an in-place vvadd (and we're going to run
+ // it a couple of times) let's copy the input data to a temporary results
+ // array
+
+ size_t i;
+ if (coreid == 0)
+ {
+ for (i = 0; i < DATA_SIZE; i++)
+ results_data[i] = input1_data[i];
+ }
+
+
+ // Execute the provided, terrible vvadd
+ barrier();
+ stats(vvadd(DATA_SIZE, results_data, input2_data); barrier());
+
+
+ // verify
+ verify(DATA_SIZE, results_data, verify_data);
+
+ // reset results from the first trial
+ if (coreid == 0)
+ {
+ for (i=0; i < DATA_SIZE; i++)
+ results_data[i] = input1_data[i];
+ }
+ barrier();
+
+
+ // Execute your faster vvadd
+ barrier();
+ stats(vvadd_opt(DATA_SIZE, results_data, input2_data); barrier());
+
+#ifdef DEBUG
+ printArray("results: ", DATA_SIZE, results_data);
+ printArray("verify : ", DATA_SIZE, verify_data);
+#endif
+
+ // verify
+ verify(DATA_SIZE, results_data, verify_data);
+ barrier();
+
+ exit(0);
+}
+
--- /dev/null
+
+#define DATA_SIZE 1000
+
+static data_t input1_data[DATA_SIZE] =
+{
+ 0.00, 15.00, 10.00, 3.00, 14.00, 6.00, 2.00, 18.00, 11.00, 15.00, 11.00, 0.00, 17.00, 16.00, 7.00, 13.00, 18.00, 2.00, 2.00, 5.00,
+ 8.00, 5.00, 12.00, 14.00, 6.00, 12.00, 16.00, 7.00, 9.00, 17.00, 10.00, 10.00, 3.00, 5.00, 14.00, 11.00, 9.00, 12.00, 3.00, 1.00,
+ 5.00, 4.00, 6.00, 17.00, 17.00, 4.00, 17.00, 15.00, 17.00, 18.00, 3.00, 18.00, 10.00, 6.00, 12.00, 12.00, 3.00, 2.00, 16.00, 1.00,
+ 5.00, 6.00, 2.00, 17.00, 16.00, 5.00, 10.00, 18.00, 14.00, 4.00, 9.00, 9.00, 7.00, 4.00, 8.00, 13.00, 12.00, 6.00, 4.00, 17.00,
+ 5.00, 2.00, 11.00, 11.00, 7.00, 6.00, 8.00, 5.00, 6.00, 6.00, 11.00, 1.00, 18.00, 7.00, 6.00, 9.00, 10.00, 17.00, 14.00, 4.00,
+ 14.00, 11.00, 2.00, 0.00, 2.00, 17.00, 17.00, 15.00, 10.00, 8.00, 12.00, 18.00, 5.00, 0.00, 0.00, 1.00, 1.00, 8.00, 11.00, 11.00,
+ 7.00, 5.00, 15.00, 18.00, 15.00, 6.00, 8.00, 9.00, 18.00, 6.00, 15.00, 16.00, 10.00, 18.00, 13.00, 6.00, 10.00, 16.00, 0.00, 10.00,
+ 12.00, 8.00, 8.00, 3.00, 0.00, 1.00, 4.00, 0.00, 8.00, 15.00, 16.00, 9.00, 7.00, 7.00, 10.00, 9.00, 16.00, 12.00, 5.00, 5.00,
+ 9.00, 5.00, 17.00, 4.00, 13.00, 13.00, 4.00, 14.00, 10.00, 5.00, 10.00, 10.00, 6.00, 18.00, 5.00, 15.00, 5.00, 15.00, 13.00, 18.00,
+ 6.00, 13.00, 5.00, 18.00, 12.00, 14.00, 1.00, 7.00, 2.00, 1.00, 7.00, 12.00, 15.00, 15.00, 6.00, 2.00, 1.00, 2.00, 18.00, 6.00,
+ 10.00, 14.00, 9.00, 15.00, 11.00, 0.00, 3.00, 1.00, 2.00, 2.00, 14.00, 7.00, 18.00, 0.00, 2.00, 2.00, 16.00, 8.00, 4.00, 5.00,
+ 7.00, 11.00, 7.00, 10.00, 14.00, 10.00, 3.00, 0.00, 13.00, 9.00, 14.00, 0.00, 14.00, 1.00, 3.00, 16.00, 2.00, 14.00, 6.00, 17.00,
+ 17.00, 6.00, 9.00, 8.00, 9.00, 12.00, 5.00, 14.00, 2.00, 16.00, 17.00, 5.00, 4.00, 0.00, 14.00, 10.00, 6.00, 15.00, 15.00, 14.00,
+ 5.00, 1.00, 8.00, 8.00, 13.00, 8.00, 0.00, 4.00, 7.00, 9.00, 13.00, 16.00, 9.00, 14.00, 9.00, 13.00, 0.00, 7.00, 16.00, 17.00,
+ 18.00, 10.00, 13.00, 8.00, 4.00, 9.00, 13.00, 0.00, 6.00, 4.00, 6.00, 4.00, 10.00, 14.00, 14.00, 9.00, 15.00, 15.00, 3.00, 3.00,
+ 12.00, 0.00, 3.00, 2.00, 16.00, 1.00, 7.00, 2.00, 16.00, 2.00, 2.00, 0.00, 14.00, 3.00, 3.00, 10.00, 4.00, 10.00, 3.00, 4.00,
+ 13.00, 14.00, 13.00, 0.00, 1.00, 15.00, 16.00, 9.00, 7.00, 9.00, 0.00, 11.00, 1.00, 1.00, 15.00, 17.00, 12.00, 16.00, 15.00, 4.00,
+ 8.00, 2.00, 10.00, 10.00, 0.00, 18.00, 17.00, 7.00, 7.00, 2.00, 10.00, 17.00, 9.00, 7.00, 5.00, 3.00, 8.00, 11.00, 6.00, 9.00,
+ 13.00, 0.00, 3.00, 5.00, 2.00, 5.00, 7.00, 4.00, 9.00, 2.00, 13.00, 17.00, 14.00, 12.00, 1.00, 3.00, 7.00, 17.00, 0.00, 14.00,
+ 16.00, 2.00, 2.00, 1.00, 2.00, 15.00, 16.00, 8.00, 2.00, 4.00, 15.00, 15.00, 10.00, 6.00, 11.00, 9.00, 15.00, 17.00, 3.00, 8.00,
+ 15.00, 3.00, 10.00, 15.00, 8.00, 14.00, 16.00, 15.00, 15.00, 14.00, 1.00, 7.00, 4.00, 18.00, 2.00, 13.00, 11.00, 15.00, 7.00, 10.00,
+ 13.00, 10.00, 7.00, 14.00, 18.00, 4.00, 18.00, 4.00, 3.00, 9.00, 1.00, 13.00, 15.00, 2.00, 5.00, 15.00, 12.00, 10.00, 2.00, 0.00,
+ 10.00, 15.00, 0.00, 11.00, 14.00, 11.00, 14.00, 9.00, 1.00, 18.00, 14.00, 18.00, 15.00, 5.00, 1.00, 15.00, 18.00, 14.00, 3.00, 15.00,
+ 11.00, 2.00, 15.00, 0.00, 13.00, 1.00, 4.00, 14.00, 14.00, 5.00, 2.00, 13.00, 17.00, 8.00, 7.00, 6.00, 5.00, 10.00, 14.00, 14.00,
+ 17.00, 0.00, 0.00, 17.00, 18.00, 15.00, 10.00, 16.00, 18.00, 5.00, 9.00, 10.00, 18.00, 7.00, 11.00, 5.00, 4.00, 16.00, 2.00, 8.00,
+ 13.00, 1.00, 12.00, 3.00, 4.00, 6.00, 15.00, 12.00, 0.00, 6.00, 18.00, 12.00, 14.00, 18.00, 3.00, 2.00, 3.00, 5.00, 3.00, 14.00,
+ 18.00, 12.00, 10.00, 11.00, 8.00, 4.00, 10.00, 10.00, 9.00, 18.00, 14.00, 3.00, 7.00, 17.00, 12.00, 0.00, 10.00, 9.00, 17.00, 3.00,
+ 0.00, 4.00, 6.00, 16.00, 14.00, 12.00, 13.00, 13.00, 18.00, 7.00, 0.00, 1.00, 9.00, 7.00, 12.00, 6.00, 18.00, 8.00, 9.00, 13.00,
+ 13.00, 17.00, 10.00, 16.00, 1.00, 10.00, 17.00, 16.00, 2.00, 18.00, 4.00, 2.00, 6.00, 1.00, 1.00, 1.00, 8.00, 14.00, 6.00, 6.00,
+ 13.00, 14.00, 13.00, 6.00, 5.00, 10.00, 11.00, 11.00, 16.00, 1.00, 5.00, 9.00, 13.00, 8.00, 10.00, 2.00, 12.00, 15.00, 5.00, 14.00,
+ 3.00, 7.00, 9.00, 18.00, 2.00, 11.00, 16.00, 4.00, 5.00, 10.00, 17.00, 10.00, 3.00, 4.00, 14.00, 18.00, 13.00, 6.00, 8.00, 11.00,
+ 14.00, 3.00, 5.00, 6.00, 6.00, 5.00, 13.00, 0.00, 9.00, 9.00, 1.00, 7.00, 5.00, 5.00, 1.00, 6.00, 18.00, 11.00, 17.00, 7.00,
+ 1.00, 10.00, 5.00, 12.00, 6.00, 16.00, 16.00, 5.00, 1.00, 10.00, 10.00, 15.00, 7.00, 18.00, 8.00, 17.00, 3.00, 5.00, 3.00, 14.00,
+ 0.00, 16.00, 12.00, 0.00, 14.00, 17.00, 16.00, 2.00, 18.00, 13.00, 10.00, 13.00, 4.00, 14.00, 2.00, 3.00, 4.00, 8.00, 17.00, 0.00,
+ 6.00, 11.00, 5.00, 3.00, 3.00, 2.00, 15.00, 13.00, 10.00, 4.00, 1.00, 11.00, 6.00, 17.00, 1.00, 0.00, 18.00, 3.00, 3.00, 11.00,
+ 7.00, 7.00, 11.00, 14.00, 7.00, 16.00, 11.00, 10.00, 8.00, 6.00, 11.00, 5.00, 17.00, 10.00, 7.00, 8.00, 14.00, 2.00, 9.00, 17.00,
+ 15.00, 13.00, 10.00, 6.00, 0.00, 15.00, 11.00, 10.00, 11.00, 18.00, 2.00, 5.00, 17.00, 18.00, 11.00, 15.00, 3.00, 17.00, 9.00, 17.00,
+ 8.00, 6.00, 2.00, 4.00, 2.00, 11.00, 15.00, 2.00, 18.00, 3.00, 9.00, 7.00, 15.00, 9.00, 14.00, 10.00, 9.00, 6.00, 13.00, 8.00,
+ 15.00, 14.00, 0.00, 11.00, 5.00, 2.00, 12.00, 14.00, 10.00, 16.00, 9.00, 7.00, 9.00, 17.00, 4.00, 4.00, 7.00, 8.00, 4.00, 4.00,
+ 9.00, 7.00, 3.00, 5.00, 11.00, 11.00, 10.00, 13.00, 3.00, 14.00, 15.00, 8.00, 1.00, 1.00, 3.00, 0.00, 16.00, 9.00, 6.00, 1.00,
+ 0.00, 2.00, 0.00, 6.00, 13.00, 12.00, 5.00, 18.00, 1.00, 11.00, 17.00, 11.00, 16.00, 14.00, 14.00, 9.00, 11.00, 9.00, 17.00, 15.00,
+ 5.00, 18.00, 2.00, 11.00, 10.00, 16.00, 18.00, 5.00, 11.00, 12.00, 11.00, 18.00, 7.00, 6.00, 8.00, 3.00, 4.00, 3.00, 16.00, 4.00,
+ 6.00, 2.00, 15.00, 6.00, 7.00, 16.00, 0.00, 7.00, 11.00, 10.00, 3.00, 0.00, 14.00, 16.00, 15.00, 15.00, 12.00, 7.00, 1.00, 4.00,
+ 8.00, 4.00, 12.00, 0.00, 7.00, 8.00, 1.00, 1.00, 14.00, 15.00, 9.00, 8.00, 6.00, 6.00, 4.00, 7.00, 8.00, 13.00, 10.00, 5.00,
+ 8.00, 11.00, 2.00, 16.00, 7.00, 17.00, 5.00, 2.00, 17.00, 0.00, 18.00, 6.00, 7.00, 4.00, 4.00, 12.00, 0.00, 18.00, 8.00, 4.00,
+ 7.00, 0.00, 11.00, 1.00, 11.00, 17.00, 18.00, 15.00, 8.00, 11.00, 15.00, 9.00, 12.00, 1.00, 5.00, 6.00, 1.00, 18.00, 14.00, 7.00,
+ 16.00, 16.00, 10.00, 3.00, 13.00, 0.00, 12.00, 9.00, 18.00, 14.00, 15.00, 4.00, 11.00, 15.00, 15.00, 8.00, 16.00, 11.00, 13.00, 12.00,
+ 1.00, 13.00, 14.00, 2.00, 11.00, 0.00, 17.00, 11.00, 12.00, 6.00, 4.00, 4.00, 11.00, 13.00, 10.00, 2.00, 10.00, 14.00, 0.00, 6.00,
+ 18.00, 10.00, 7.00, 14.00, 12.00, 9.00, 4.00, 16.00, 17.00, 8.00, 14.00, 9.00, 0.00, 4.00, 15.00, 13.00, 8.00, 13.00, 13.00, 8.00,
+ 15.00, 6.00, 11.00, 4.00, 2.00, 6.00, 5.00, 14.00, 5.00, 17.00, 12.00, 11.00, 17.00, 4.00, 13.00, 7.00, 16.00, 12.00, 7.00, 18.00
+};
+
+static data_t input2_data[DATA_SIZE] =
+{
+ 8.00, 6.00, 0.00, 18.00, 6.00, 10.00, 1.00, 2.00, 4.00, 2.00, 4.00, 10.00, 6.00, 11.00, 17.00, 4.00, 0.00, 16.00, 14.00, 12.00,
+ 9.00, 8.00, 13.00, 15.00, 18.00, 2.00, 13.00, 10.00, 5.00, 4.00, 12.00, 9.00, 1.00, 13.00, 12.00, 7.00, 10.00, 17.00, 11.00, 10.00,
+ 18.00, 15.00, 11.00, 12.00, 7.00, 9.00, 6.00, 5.00, 11.00, 7.00, 10.00, 12.00, 18.00, 18.00, 15.00, 1.00, 3.00, 18.00, 11.00, 16.00,
+ 13.00, 18.00, 4.00, 13.00, 8.00, 7.00, 10.00, 13.00, 0.00, 9.00, 1.00, 16.00, 13.00, 7.00, 5.00, 5.00, 11.00, 1.00, 6.00, 10.00,
+ 12.00, 3.00, 10.00, 5.00, 15.00, 15.00, 13.00, 14.00, 14.00, 1.00, 18.00, 5.00, 16.00, 14.00, 10.00, 4.00, 8.00, 4.00, 6.00, 6.00,
+ 13.00, 14.00, 8.00, 5.00, 14.00, 10.00, 9.00, 10.00, 17.00, 15.00, 6.00, 16.00, 12.00, 9.00, 10.00, 16.00, 16.00, 8.00, 1.00, 12.00,
+ 7.00, 0.00, 0.00, 3.00, 5.00, 7.00, 10.00, 3.00, 17.00, 10.00, 18.00, 16.00, 1.00, 11.00, 18.00, 9.00, 2.00, 0.00, 12.00, 6.00,
+ 13.00, 1.00, 13.00, 5.00, 7.00, 13.00, 17.00, 9.00, 15.00, 13.00, 5.00, 2.00, 4.00, 4.00, 3.00, 0.00, 9.00, 11.00, 3.00, 12.00,
+ 6.00, 11.00, 1.00, 16.00, 12.00, 11.00, 2.00, 2.00, 15.00, 12.00, 8.00, 9.00, 14.00, 2.00, 11.00, 0.00, 0.00, 7.00, 2.00, 13.00,
+ 15.00, 18.00, 7.00, 16.00, 16.00, 1.00, 1.00, 12.00, 12.00, 2.00, 2.00, 1.00, 7.00, 4.00, 0.00, 8.00, 18.00, 4.00, 11.00, 6.00,
+ 17.00, 13.00, 12.00, 5.00, 16.00, 12.00, 0.00, 9.00, 10.00, 10.00, 18.00, 12.00, 8.00, 7.00, 5.00, 8.00, 16.00, 3.00, 9.00, 18.00,
+ 12.00, 13.00, 18.00, 6.00, 8.00, 12.00, 2.00, 12.00, 8.00, 8.00, 9.00, 18.00, 8.00, 0.00, 9.00, 2.00, 6.00, 7.00, 0.00, 3.00,
+ 11.00, 2.00, 18.00, 2.00, 16.00, 1.00, 16.00, 11.00, 11.00, 16.00, 16.00, 11.00, 7.00, 4.00, 14.00, 10.00, 5.00, 8.00, 4.00, 14.00,
+ 17.00, 13.00, 13.00, 3.00, 1.00, 14.00, 1.00, 7.00, 0.00, 2.00, 7.00, 14.00, 4.00, 9.00, 14.00, 3.00, 9.00, 13.00, 13.00, 3.00,
+ 3.00, 17.00, 0.00, 18.00, 4.00, 8.00, 6.00, 9.00, 4.00, 2.00, 0.00, 14.00, 3.00, 3.00, 14.00, 8.00, 6.00, 7.00, 2.00, 12.00,
+ 5.00, 14.00, 6.00, 12.00, 2.00, 16.00, 1.00, 15.00, 7.00, 18.00, 0.00, 0.00, 13.00, 13.00, 12.00, 11.00, 16.00, 15.00, 14.00, 8.00,
+ 9.00, 10.00, 8.00, 8.00, 13.00, 13.00, 13.00, 10.00, 1.00, 15.00, 4.00, 0.00, 12.00, 1.00, 8.00, 12.00, 1.00, 18.00, 12.00, 18.00,
+ 9.00, 1.00, 11.00, 5.00, 13.00, 7.00, 1.00, 13.00, 5.00, 8.00, 17.00, 11.00, 13.00, 15.00, 9.00, 3.00, 17.00, 18.00, 9.00, 3.00,
+ 15.00, 11.00, 12.00, 0.00, 2.00, 15.00, 3.00, 0.00, 13.00, 1.00, 14.00, 14.00, 15.00, 8.00, 6.00, 0.00, 0.00, 11.00, 17.00, 0.00,
+ 1.00, 8.00, 6.00, 6.00, 10.00, 6.00, 18.00, 12.00, 7.00, 18.00, 4.00, 6.00, 15.00, 18.00, 7.00, 5.00, 8.00, 6.00, 6.00, 7.00,
+ 4.00, 4.00, 10.00, 17.00, 12.00, 13.00, 11.00, 15.00, 12.00, 18.00, 7.00, 12.00, 17.00, 10.00, 14.00, 12.00, 2.00, 7.00, 17.00, 3.00,
+ 8.00, 6.00, 3.00, 9.00, 3.00, 7.00, 7.00, 15.00, 18.00, 5.00, 13.00, 13.00, 15.00, 10.00, 0.00, 11.00, 10.00, 1.00, 5.00, 16.00,
+ 2.00, 7.00, 14.00, 12.00, 7.00, 17.00, 17.00, 11.00, 0.00, 5.00, 16.00, 14.00, 1.00, 9.00, 8.00, 8.00, 3.00, 17.00, 0.00, 8.00,
+ 6.00, 5.00, 7.00, 6.00, 17.00, 3.00, 3.00, 8.00, 3.00, 12.00, 17.00, 5.00, 14.00, 3.00, 11.00, 5.00, 17.00, 2.00, 15.00, 1.00,
+ 18.00, 11.00, 12.00, 0.00, 0.00, 14.00, 7.00, 17.00, 15.00, 10.00, 18.00, 10.00, 11.00, 7.00, 12.00, 10.00, 17.00, 2.00, 18.00, 9.00,
+ 11.00, 4.00, 17.00, 10.00, 15.00, 12.00, 4.00, 1.00, 5.00, 10.00, 4.00, 2.00, 11.00, 3.00, 4.00, 15.00, 16.00, 10.00, 2.00, 2.00,
+ 15.00, 16.00, 0.00, 13.00, 16.00, 9.00, 1.00, 7.00, 3.00, 10.00, 7.00, 2.00, 12.00, 8.00, 1.00, 5.00, 0.00, 16.00, 4.00, 14.00,
+ 13.00, 16.00, 3.00, 0.00, 10.00, 6.00, 3.00, 9.00, 1.00, 3.00, 0.00, 13.00, 12.00, 17.00, 11.00, 4.00, 15.00, 15.00, 12.00, 4.00,
+ 4.00, 2.00, 16.00, 6.00, 11.00, 17.00, 14.00, 7.00, 4.00, 14.00, 8.00, 8.00, 3.00, 18.00, 17.00, 17.00, 12.00, 10.00, 11.00, 1.00,
+ 8.00, 13.00, 1.00, 14.00, 0.00, 9.00, 0.00, 7.00, 9.00, 0.00, 7.00, 12.00, 0.00, 18.00, 10.00, 1.00, 5.00, 13.00, 13.00, 2.00,
+ 10.00, 4.00, 2.00, 6.00, 0.00, 16.00, 2.00, 15.00, 13.00, 6.00, 8.00, 5.00, 6.00, 15.00, 12.00, 6.00, 6.00, 7.00, 8.00, 1.00,
+ 11.00, 9.00, 7.00, 18.00, 14.00, 4.00, 9.00, 6.00, 4.00, 2.00, 10.00, 13.00, 6.00, 17.00, 2.00, 11.00, 7.00, 3.00, 8.00, 9.00,
+ 2.00, 6.00, 18.00, 12.00, 18.00, 13.00, 8.00, 1.00, 11.00, 4.00, 13.00, 14.00, 16.00, 8.00, 6.00, 18.00, 14.00, 15.00, 9.00, 11.00,
+ 2.00, 13.00, 4.00, 3.00, 3.00, 15.00, 14.00, 3.00, 13.00, 12.00, 14.00, 16.00, 18.00, 12.00, 5.00, 11.00, 2.00, 3.00, 15.00, 1.00,
+ 12.00, 1.00, 15.00, 13.00, 12.00, 18.00, 4.00, 17.00, 13.00, 7.00, 11.00, 13.00, 7.00, 10.00, 1.00, 3.00, 18.00, 6.00, 10.00, 3.00,
+ 9.00, 16.00, 12.00, 10.00, 6.00, 6.00, 7.00, 16.00, 16.00, 16.00, 17.00, 18.00, 8.00, 18.00, 0.00, 6.00, 17.00, 13.00, 14.00, 8.00,
+ 0.00, 7.00, 5.00, 13.00, 8.00, 12.00, 14.00, 9.00, 10.00, 10.00, 9.00, 9.00, 8.00, 6.00, 0.00, 14.00, 16.00, 8.00, 7.00, 16.00,
+ 10.00, 3.00, 1.00, 9.00, 11.00, 2.00, 6.00, 18.00, 5.00, 4.00, 2.00, 11.00, 10.00, 17.00, 16.00, 2.00, 12.00, 15.00, 14.00, 6.00,
+ 6.00, 17.00, 3.00, 10.00, 9.00, 18.00, 18.00, 6.00, 11.00, 16.00, 18.00, 17.00, 7.00, 14.00, 1.00, 16.00, 7.00, 9.00, 11.00, 12.00,
+ 10.00, 6.00, 1.00, 16.00, 9.00, 18.00, 0.00, 9.00, 16.00, 10.00, 14.00, 6.00, 9.00, 14.00, 15.00, 7.00, 12.00, 8.00, 1.00, 1.00,
+ 1.00, 17.00, 17.00, 17.00, 18.00, 1.00, 15.00, 18.00, 16.00, 16.00, 11.00, 7.00, 4.00, 15.00, 3.00, 14.00, 13.00, 14.00, 9.00, 2.00,
+ 4.00, 8.00, 14.00, 7.00, 0.00, 12.00, 14.00, 15.00, 8.00, 2.00, 11.00, 5.00, 6.00, 16.00, 6.00, 4.00, 16.00, 7.00, 9.00, 5.00,
+ 1.00, 0.00, 16.00, 10.00, 9.00, 6.00, 5.00, 8.00, 15.00, 13.00, 7.00, 18.00, 18.00, 8.00, 0.00, 15.00, 4.00, 6.00, 14.00, 3.00,
+ 3.00, 2.00, 9.00, 14.00, 18.00, 13.00, 10.00, 15.00, 0.00, 11.00, 16.00, 7.00, 16.00, 18.00, 0.00, 12.00, 6.00, 13.00, 12.00, 12.00,
+ 5.00, 3.00, 5.00, 16.00, 13.00, 16.00, 8.00, 5.00, 12.00, 8.00, 8.00, 0.00, 2.00, 9.00, 18.00, 11.00, 8.00, 4.00, 14.00, 6.00,
+ 17.00, 2.00, 6.00, 8.00, 11.00, 13.00, 6.00, 18.00, 17.00, 6.00, 8.00, 0.00, 1.00, 14.00, 18.00, 4.00, 0.00, 4.00, 3.00, 3.00,
+ 16.00, 8.00, 16.00, 1.00, 2.00, 0.00, 15.00, 14.00, 10.00, 9.00, 15.00, 3.00, 5.00, 18.00, 5.00, 6.00, 7.00, 3.00, 7.00, 2.00,
+ 6.00, 12.00, 10.00, 10.00, 18.00, 16.00, 0.00, 9.00, 17.00, 10.00, 9.00, 14.00, 15.00, 5.00, 8.00, 15.00, 3.00, 15.00, 14.00, 11.00,
+ 6.00, 6.00, 14.00, 0.00, 14.00, 0.00, 7.00, 12.00, 8.00, 7.00, 1.00, 3.00, 6.00, 10.00, 12.00, 1.00, 16.00, 5.00, 5.00, 6.00,
+ 17.00, 15.00, 15.00, 9.00, 4.00, 18.00, 17.00, 13.00, 12.00, 9.00, 7.00, 10.00, 2.00, 5.00, 8.00, 18.00, 1.00, 15.00, 8.00, 0.00
+};
+
+static data_t verify_data[DATA_SIZE] =
+{
+ 8.00, 21.00, 10.00, 21.00, 20.00, 16.00, 3.00, 20.00, 15.00, 17.00, 15.00, 10.00, 23.00, 27.00, 24.00, 17.00, 18.00, 18.00, 16.00, 17.00,
+ 17.00, 13.00, 25.00, 29.00, 24.00, 14.00, 29.00, 17.00, 14.00, 21.00, 22.00, 19.00, 4.00, 18.00, 26.00, 18.00, 19.00, 29.00, 14.00, 11.00,
+ 23.00, 19.00, 17.00, 29.00, 24.00, 13.00, 23.00, 20.00, 28.00, 25.00, 13.00, 30.00, 28.00, 24.00, 27.00, 13.00, 6.00, 20.00, 27.00, 17.00,
+ 18.00, 24.00, 6.00, 30.00, 24.00, 12.00, 20.00, 31.00, 14.00, 13.00, 10.00, 25.00, 20.00, 11.00, 13.00, 18.00, 23.00, 7.00, 10.00, 27.00,
+ 17.00, 5.00, 21.00, 16.00, 22.00, 21.00, 21.00, 19.00, 20.00, 7.00, 29.00, 6.00, 34.00, 21.00, 16.00, 13.00, 18.00, 21.00, 20.00, 10.00,
+ 27.00, 25.00, 10.00, 5.00, 16.00, 27.00, 26.00, 25.00, 27.00, 23.00, 18.00, 34.00, 17.00, 9.00, 10.00, 17.00, 17.00, 16.00, 12.00, 23.00,
+ 14.00, 5.00, 15.00, 21.00, 20.00, 13.00, 18.00, 12.00, 35.00, 16.00, 33.00, 32.00, 11.00, 29.00, 31.00, 15.00, 12.00, 16.00, 12.00, 16.00,
+ 25.00, 9.00, 21.00, 8.00, 7.00, 14.00, 21.00, 9.00, 23.00, 28.00, 21.00, 11.00, 11.00, 11.00, 13.00, 9.00, 25.00, 23.00, 8.00, 17.00,
+ 15.00, 16.00, 18.00, 20.00, 25.00, 24.00, 6.00, 16.00, 25.00, 17.00, 18.00, 19.00, 20.00, 20.00, 16.00, 15.00, 5.00, 22.00, 15.00, 31.00,
+ 21.00, 31.00, 12.00, 34.00, 28.00, 15.00, 2.00, 19.00, 14.00, 3.00, 9.00, 13.00, 22.00, 19.00, 6.00, 10.00, 19.00, 6.00, 29.00, 12.00,
+ 27.00, 27.00, 21.00, 20.00, 27.00, 12.00, 3.00, 10.00, 12.00, 12.00, 32.00, 19.00, 26.00, 7.00, 7.00, 10.00, 32.00, 11.00, 13.00, 23.00,
+ 19.00, 24.00, 25.00, 16.00, 22.00, 22.00, 5.00, 12.00, 21.00, 17.00, 23.00, 18.00, 22.00, 1.00, 12.00, 18.00, 8.00, 21.00, 6.00, 20.00,
+ 28.00, 8.00, 27.00, 10.00, 25.00, 13.00, 21.00, 25.00, 13.00, 32.00, 33.00, 16.00, 11.00, 4.00, 28.00, 20.00, 11.00, 23.00, 19.00, 28.00,
+ 22.00, 14.00, 21.00, 11.00, 14.00, 22.00, 1.00, 11.00, 7.00, 11.00, 20.00, 30.00, 13.00, 23.00, 23.00, 16.00, 9.00, 20.00, 29.00, 20.00,
+ 21.00, 27.00, 13.00, 26.00, 8.00, 17.00, 19.00, 9.00, 10.00, 6.00, 6.00, 18.00, 13.00, 17.00, 28.00, 17.00, 21.00, 22.00, 5.00, 15.00,
+ 17.00, 14.00, 9.00, 14.00, 18.00, 17.00, 8.00, 17.00, 23.00, 20.00, 2.00, 0.00, 27.00, 16.00, 15.00, 21.00, 20.00, 25.00, 17.00, 12.00,
+ 22.00, 24.00, 21.00, 8.00, 14.00, 28.00, 29.00, 19.00, 8.00, 24.00, 4.00, 11.00, 13.00, 2.00, 23.00, 29.00, 13.00, 34.00, 27.00, 22.00,
+ 17.00, 3.00, 21.00, 15.00, 13.00, 25.00, 18.00, 20.00, 12.00, 10.00, 27.00, 28.00, 22.00, 22.00, 14.00, 6.00, 25.00, 29.00, 15.00, 12.00,
+ 28.00, 11.00, 15.00, 5.00, 4.00, 20.00, 10.00, 4.00, 22.00, 3.00, 27.00, 31.00, 29.00, 20.00, 7.00, 3.00, 7.00, 28.00, 17.00, 14.00,
+ 17.00, 10.00, 8.00, 7.00, 12.00, 21.00, 34.00, 20.00, 9.00, 22.00, 19.00, 21.00, 25.00, 24.00, 18.00, 14.00, 23.00, 23.00, 9.00, 15.00,
+ 19.00, 7.00, 20.00, 32.00, 20.00, 27.00, 27.00, 30.00, 27.00, 32.00, 8.00, 19.00, 21.00, 28.00, 16.00, 25.00, 13.00, 22.00, 24.00, 13.00,
+ 21.00, 16.00, 10.00, 23.00, 21.00, 11.00, 25.00, 19.00, 21.00, 14.00, 14.00, 26.00, 30.00, 12.00, 5.00, 26.00, 22.00, 11.00, 7.00, 16.00,
+ 12.00, 22.00, 14.00, 23.00, 21.00, 28.00, 31.00, 20.00, 1.00, 23.00, 30.00, 32.00, 16.00, 14.00, 9.00, 23.00, 21.00, 31.00, 3.00, 23.00,
+ 17.00, 7.00, 22.00, 6.00, 30.00, 4.00, 7.00, 22.00, 17.00, 17.00, 19.00, 18.00, 31.00, 11.00, 18.00, 11.00, 22.00, 12.00, 29.00, 15.00,
+ 35.00, 11.00, 12.00, 17.00, 18.00, 29.00, 17.00, 33.00, 33.00, 15.00, 27.00, 20.00, 29.00, 14.00, 23.00, 15.00, 21.00, 18.00, 20.00, 17.00,
+ 24.00, 5.00, 29.00, 13.00, 19.00, 18.00, 19.00, 13.00, 5.00, 16.00, 22.00, 14.00, 25.00, 21.00, 7.00, 17.00, 19.00, 15.00, 5.00, 16.00,
+ 33.00, 28.00, 10.00, 24.00, 24.00, 13.00, 11.00, 17.00, 12.00, 28.00, 21.00, 5.00, 19.00, 25.00, 13.00, 5.00, 10.00, 25.00, 21.00, 17.00,
+ 13.00, 20.00, 9.00, 16.00, 24.00, 18.00, 16.00, 22.00, 19.00, 10.00, 0.00, 14.00, 21.00, 24.00, 23.00, 10.00, 33.00, 23.00, 21.00, 17.00,
+ 17.00, 19.00, 26.00, 22.00, 12.00, 27.00, 31.00, 23.00, 6.00, 32.00, 12.00, 10.00, 9.00, 19.00, 18.00, 18.00, 20.00, 24.00, 17.00, 7.00,
+ 21.00, 27.00, 14.00, 20.00, 5.00, 19.00, 11.00, 18.00, 25.00, 1.00, 12.00, 21.00, 13.00, 26.00, 20.00, 3.00, 17.00, 28.00, 18.00, 16.00,
+ 13.00, 11.00, 11.00, 24.00, 2.00, 27.00, 18.00, 19.00, 18.00, 16.00, 25.00, 15.00, 9.00, 19.00, 26.00, 24.00, 19.00, 13.00, 16.00, 12.00,
+ 25.00, 12.00, 12.00, 24.00, 20.00, 9.00, 22.00, 6.00, 13.00, 11.00, 11.00, 20.00, 11.00, 22.00, 3.00, 17.00, 25.00, 14.00, 25.00, 16.00,
+ 3.00, 16.00, 23.00, 24.00, 24.00, 29.00, 24.00, 6.00, 12.00, 14.00, 23.00, 29.00, 23.00, 26.00, 14.00, 35.00, 17.00, 20.00, 12.00, 25.00,
+ 2.00, 29.00, 16.00, 3.00, 17.00, 32.00, 30.00, 5.00, 31.00, 25.00, 24.00, 29.00, 22.00, 26.00, 7.00, 14.00, 6.00, 11.00, 32.00, 1.00,
+ 18.00, 12.00, 20.00, 16.00, 15.00, 20.00, 19.00, 30.00, 23.00, 11.00, 12.00, 24.00, 13.00, 27.00, 2.00, 3.00, 36.00, 9.00, 13.00, 14.00,
+ 16.00, 23.00, 23.00, 24.00, 13.00, 22.00, 18.00, 26.00, 24.00, 22.00, 28.00, 23.00, 25.00, 28.00, 7.00, 14.00, 31.00, 15.00, 23.00, 25.00,
+ 15.00, 20.00, 15.00, 19.00, 8.00, 27.00, 25.00, 19.00, 21.00, 28.00, 11.00, 14.00, 25.00, 24.00, 11.00, 29.00, 19.00, 25.00, 16.00, 33.00,
+ 18.00, 9.00, 3.00, 13.00, 13.00, 13.00, 21.00, 20.00, 23.00, 7.00, 11.00, 18.00, 25.00, 26.00, 30.00, 12.00, 21.00, 21.00, 27.00, 14.00,
+ 21.00, 31.00, 3.00, 21.00, 14.00, 20.00, 30.00, 20.00, 21.00, 32.00, 27.00, 24.00, 16.00, 31.00, 5.00, 20.00, 14.00, 17.00, 15.00, 16.00,
+ 19.00, 13.00, 4.00, 21.00, 20.00, 29.00, 10.00, 22.00, 19.00, 24.00, 29.00, 14.00, 10.00, 15.00, 18.00, 7.00, 28.00, 17.00, 7.00, 2.00,
+ 1.00, 19.00, 17.00, 23.00, 31.00, 13.00, 20.00, 36.00, 17.00, 27.00, 28.00, 18.00, 20.00, 29.00, 17.00, 23.00, 24.00, 23.00, 26.00, 17.00,
+ 9.00, 26.00, 16.00, 18.00, 10.00, 28.00, 32.00, 20.00, 19.00, 14.00, 22.00, 23.00, 13.00, 22.00, 14.00, 7.00, 20.00, 10.00, 25.00, 9.00,
+ 7.00, 2.00, 31.00, 16.00, 16.00, 22.00, 5.00, 15.00, 26.00, 23.00, 10.00, 18.00, 32.00, 24.00, 15.00, 30.00, 16.00, 13.00, 15.00, 7.00,
+ 11.00, 6.00, 21.00, 14.00, 25.00, 21.00, 11.00, 16.00, 14.00, 26.00, 25.00, 15.00, 22.00, 24.00, 4.00, 19.00, 14.00, 26.00, 22.00, 17.00,
+ 13.00, 14.00, 7.00, 32.00, 20.00, 33.00, 13.00, 7.00, 29.00, 8.00, 26.00, 6.00, 9.00, 13.00, 22.00, 23.00, 8.00, 22.00, 22.00, 10.00,
+ 24.00, 2.00, 17.00, 9.00, 22.00, 30.00, 24.00, 33.00, 25.00, 17.00, 23.00, 9.00, 13.00, 15.00, 23.00, 10.00, 1.00, 22.00, 17.00, 10.00,
+ 32.00, 24.00, 26.00, 4.00, 15.00, 0.00, 27.00, 23.00, 28.00, 23.00, 30.00, 7.00, 16.00, 33.00, 20.00, 14.00, 23.00, 14.00, 20.00, 14.00,
+ 7.00, 25.00, 24.00, 12.00, 29.00, 16.00, 17.00, 20.00, 29.00, 16.00, 13.00, 18.00, 26.00, 18.00, 18.00, 17.00, 13.00, 29.00, 14.00, 17.00,
+ 24.00, 16.00, 21.00, 14.00, 26.00, 9.00, 11.00, 28.00, 25.00, 15.00, 15.00, 12.00, 6.00, 14.00, 27.00, 14.00, 24.00, 18.00, 18.00, 14.00,
+ 32.00, 21.00, 26.00, 13.00, 6.00, 24.00, 22.00, 27.00, 17.00, 26.00, 19.00, 21.00, 19.00, 9.00, 21.00, 25.00, 17.00, 27.00, 15.00, 18.00
+};
+
--- /dev/null
+#!/usr/bin/perl -w
+#==========================================================================
+# vvadd_gendata.pl
+#
+# Author : Christopher Batten (cbatten@mit.edu)
+# Date : April 29, 2005
+#
+(our $usageMsg = <<'ENDMSG') =~ s/^\#//gm;
+#
+# Simple script which creates an input data set and the reference data
+# for the vvadd benchmark.
+#
+ENDMSG
+
+use strict "vars";
+use warnings;
+no warnings("once");
+use Getopt::Long;
+
+#--------------------------------------------------------------------------
+# Command line processing
+#--------------------------------------------------------------------------
+
+our %opts;
+
+sub usage()
+{
+
+ print "\n";
+ print " Usage: vvadd_gendata.pl [options] \n";
+ print "\n";
+ print " Options:\n";
+ print " --help print this message\n";
+ print " --size size of input data [1000]\n";
+ print " --seed random seed [1]\n";
+ print "$usageMsg";
+
+ exit();
+}
+
+sub processCommandLine()
+{
+
+ $opts{"help"} = 0;
+ $opts{"size"} = 1000;
+ $opts{"seed"} = 1;
+ Getopt::Long::GetOptions( \%opts, 'help|?', 'size:i', 'seed:i' ) or usage();
+ $opts{"help"} and usage();
+
+}
+
+#--------------------------------------------------------------------------
+# Helper Functions
+#--------------------------------------------------------------------------
+
+sub printArray
+{
+ my $arrayName = $_[0];
+ my $arrayRef = $_[1];
+
+ my $numCols = 20;
+ my $arrayLen = scalar(@{$arrayRef});
+
+ print "static data_t ".$arrayName."[DATA_SIZE] = \n";
+ print "{\n";
+
+ if ( $arrayLen <= $numCols ) {
+ print " ";
+ for ( my $i = 0; $i < $arrayLen; $i++ ) {
+ print sprintf("%3.2f",$arrayRef->[$i]);
+ if ( $i != $arrayLen-1 ) {
+ print ", ";
+ }
+ }
+ print "\n";
+ }
+
+ else {
+ my $numRows = int($arrayLen/$numCols);
+ for ( my $j = 0; $j < $numRows; $j++ ) {
+ print " ";
+ for ( my $i = 0; $i < $numCols; $i++ ) {
+ my $index = $j*$numCols + $i;
+ print sprintf("%3.2f",$arrayRef->[$index]);
+ if ( $index != $arrayLen-1 ) {
+ print ", ";
+ }
+ }
+ print "\n";
+ }
+
+ if ( $arrayLen > ($numRows*$numCols) ) {
+ print " ";
+ for ( my $i = 0; $i < ($arrayLen-($numRows*$numCols)); $i++ ) {
+ my $index = $numCols*$numRows + $i;
+ print sprintf("%3.2f",$arrayRef->[$index]);
+ if ( $index != $arrayLen-1 ) {
+ print ", ";
+ }
+ }
+ print "\n";
+ }
+
+ }
+
+ print "};\n\n";
+}
+
+#--------------------------------------------------------------------------
+# Main
+#--------------------------------------------------------------------------
+
+sub main()
+{
+
+ processCommandLine();
+ srand($opts{"seed"});
+
+ my @values1;
+ my @values2;
+ my @sum;
+ for ( my $i = 0; $i < $opts{"size"}; $i++ ) {
+ my $value1 = int(rand(19));
+ my $value2 = int(rand(19));
+ push( @values1, $value1 );
+ push( @values2, $value2 );
+ push( @sum, $value1 + $value2 );
+ }
+
+
+ print "\n\#define DATA_SIZE ".$opts{"size"}." \n\n";
+ printArray( "input1_data", \@values1 );
+ printArray( "input2_data", \@values2 );
+ printArray( "verify_data", \@sum );
+
+}
+
+main();
+
--- /dev/null
+//**************************************************************************
+// Multi-threaded Matrix Multiply benchmark
+//--------------------------------------------------------------------------
+// TA : Christopher Celio
+// Student:
+//
+//
+// This benchmark multiplies two 2-D arrays together and writes the results to
+// a third vector. The input data (and reference data) should be generated
+// using the matmul_gendata.pl perl script and dumped to a file named
+// dataset.h.
+
+
+// print out arrays, etc.
+//#define DEBUG
+
+//--------------------------------------------------------------------------
+// Includes
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+//--------------------------------------------------------------------------
+// Input/Reference Data
+
+typedef float data_t;
+#include "dataset.h"
+
+
+//--------------------------------------------------------------------------
+// Basic Utilities and Multi-thread Support
+
+__thread unsigned long coreid;
+unsigned long ncores;
+
+#include "util.h"
+
+#define stringify_1(s) #s
+#define stringify(s) stringify_1(s)
+#define stats(code) do { \
+ unsigned long _c = -rdcycle(), _i = -rdinstret(); \
+ code; \
+ _c += rdcycle(), _i += rdinstret(); \
+ if (coreid == 0) \
+ printf("%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
+ stringify(code), _c, _c/DIM_SIZE/DIM_SIZE/DIM_SIZE, 10*_c/DIM_SIZE/DIM_SIZE/DIM_SIZE%10, _c/_i, 10*_c/_i%10); \
+ } while(0)
+
+
+//--------------------------------------------------------------------------
+// Helper functions
+
+void printArray( char name[], int n, data_t arr[] )
+{
+ int i;
+ if (coreid != 0)
+ return;
+
+ printf( " %10s :", name );
+ for ( i = 0; i < n; i++ )
+ printf( " %3ld ", (long) arr[i] );
+ printf( "\n" );
+}
+
+void __attribute__((noinline)) verify(size_t n, const data_t* test, const data_t* correct)
+{
+ if (coreid != 0)
+ return;
+
+ size_t i;
+ for (i = 0; i < n; i++)
+ {
+ if (test[i] != correct[i])
+ {
+ printf("FAILED test[%d]= %3ld, correct[%d]= %3ld\n",
+ i, (long)test[i], i, (long)correct[i]);
+ exit(-1);
+ }
+ }
+
+ return;
+}
+
+//--------------------------------------------------------------------------
+// matmul function
+
+// single-thread, naive version
+void __attribute__((noinline)) matmul_naive(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ int i, j, k;
+
+ if (coreid > 0)
+ return;
+
+ for ( i = 0; i < lda; i++ )
+ for ( j = 0; j < lda; j++ )
+ {
+ for ( k = 0; k < lda; k++ )
+ {
+ C[i + j*lda] += A[j*lda + k] * B[k*lda + i];
+ }
+ }
+
+}
+
+
+
+void __attribute__((noinline)) matmul(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+
+ // ***************************** //
+ // **** ADD YOUR CODE HERE ***** //
+ // ***************************** //
+ //
+ // feel free to make a separate function for MI and MSI versions.
+ int i, j=0, k, jend=16;
+ if (coreid != 0) {
+ j = jend;
+ jend = jend << 1;
+ }
+ for ( ; j < jend; j++ )
+ {
+ int j32 = j << 5;
+ data_t* Cj32 = C + j32;
+ for ( k = 0; k < 32; k+=2 )
+ {
+ data_t Aj32k = A[k + j32];
+ data_t Aj32k2 = A[k + 1 + j32];
+ data_t* Bk32 = B + (k << 5);
+ data_t* Bk322 = Bk32 + 32;
+ for ( i = 0; i < 32; i+=4 )
+ {
+ Cj32[i] += Aj32k * Bk32 [i];
+ Cj32[i] += Aj32k2 * Bk322 [i];
+ Cj32[i+1] += Aj32k * Bk32 [i+1];
+ Cj32[i+1] += Aj32k2 * Bk322[i+1];
+ Cj32[i+2] += Aj32k * Bk32 [i+2];
+ Cj32[i+2] += Aj32k2 * Bk322[i+2];
+ Cj32[i+3] += Aj32k * Bk32 [i+3];
+ Cj32[i+3] += Aj32k2 * Bk322[i+3];
+ }
+ }
+ }
+
+
+}
+
+//--------------------------------------------------------------------------
+// Main
+//
+// all threads start executing thread_entry(). Use their "coreid" to
+// differentiate between threads (each thread is running on a separate core).
+
+void thread_entry(int cid, int nc)
+{
+ coreid = cid;
+ ncores = nc;
+
+ // static allocates data in the binary, which is visible to both threads
+ static data_t results_data[ARRAY_SIZE];
+
+
+// // Execute the provided, naive matmul
+// barrier();
+// stats(matmul_naive(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+//
+//
+// // verify
+// verify(ARRAY_SIZE, results_data, verify_data);
+//
+// // clear results from the first trial
+// size_t i;
+// if (coreid == 0)
+// for (i=0; i < ARRAY_SIZE; i++)
+// results_data[i] = 0;
+// barrier();
+
+
+ // Execute your faster matmul
+ barrier();
+ stats(matmul(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+#ifdef DEBUG
+ printArray("results:", ARRAY_SIZE, results_data);
+ printArray("verify :", ARRAY_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 3, 1, 3, 3, 0, 2, 1, 2, 2, 2,
+ 1, 0, 1, 3, 2, 3, 1, 1, 2, 1, 1, 0, 0, 2, 3, 2, 1, 0, 3, 1,
+ 3, 0, 1, 1, 2, 2, 1, 3, 3, 1, 1, 0, 0, 3, 3, 0, 0, 0, 0, 0,
+ 3, 1, 3, 0, 0, 0, 3, 3, 2, 1, 3, 0, 1, 3, 1, 1, 1, 0, 1, 0,
+ 1, 2, 2, 2, 3, 3, 0, 2, 3, 2, 1, 3, 3, 1, 1, 3, 0, 3, 3, 2,
+ 1, 1, 2, 0, 3, 0, 1, 2, 1, 1, 0, 0, 1, 2, 2, 0, 3, 1, 1, 1,
+ 3, 3, 3, 1, 0, 3, 3, 2, 2, 2, 1, 2, 0, 1, 1, 3, 0, 3, 1, 0,
+ 2, 2, 0, 1, 2, 3, 2, 1, 2, 0, 3, 2, 1, 3, 0, 1, 2, 0, 3, 0,
+ 1, 1, 2, 1
+};
+
+static data_t verify_data[ARRAY_SIZE] =
+{
+ 72, 75, 88, 101, 80, 88, 73, 75, 80, 81, 58, 75, 86, 65, 60, 80, 84, 83, 87, 83,
+ 108, 93, 85, 76, 72, 98, 79, 86, 80, 96, 91, 85, 72, 64, 70, 83, 68, 92, 51, 54,
+ 85, 85, 60, 58, 90, 64, 55, 69, 72, 48, 94, 77, 91, 83, 70, 69, 67, 77, 59, 50,
+ 67, 74, 77, 67, 67, 62, 72, 71, 68, 79, 54, 61, 67, 61, 55, 62, 78, 60, 53, 64,
+ 67, 69, 99, 68, 88, 60, 66, 63, 70, 62, 65, 50, 53, 66, 70, 72, 75, 78, 85, 95,
+ 71, 89, 70, 68, 86, 88, 58, 77, 84, 70, 65, 68, 73, 75, 91, 96, 105, 92, 76, 68,
+ 86, 69, 80, 59, 73, 83, 88, 75, 64, 63, 71, 99, 77, 77, 69, 55, 80, 73, 54, 73,
+ 87, 78, 60, 69, 65, 78, 86, 89, 95, 92, 63, 69, 89, 61, 80, 65, 70, 77, 89, 77,
+ 79, 79, 73, 92, 64, 81, 60, 78, 81, 80, 61, 63, 89, 65, 56, 83, 77, 65, 102, 70,
+ 98, 86, 96, 68, 72, 89, 73, 73, 70, 89, 84, 76, 48, 61, 63, 70, 70, 79, 50, 53,
+ 64, 63, 43, 51, 59, 62, 43, 63, 55, 77, 79, 74, 75, 74, 64, 44, 65, 69, 72, 66,
+ 54, 71, 74, 72, 69, 76, 68, 89, 94, 75, 65, 53, 85, 79, 65, 74, 82, 73, 58, 70,
+ 84, 77, 99, 72, 92, 84, 78, 62, 59, 83, 71, 74, 63, 85, 80, 78, 71, 72, 79, 83,
+ 73, 82, 60, 85, 76, 82, 60, 70, 82, 68, 54, 85, 84, 70, 86, 74, 100, 88, 98, 68,
+ 67, 87, 69, 73, 68, 88, 76, 71, 47, 43, 47, 80, 54, 65, 40, 37, 59, 53, 33, 48,
+ 62, 40, 36, 55, 36, 62, 53, 57, 70, 69, 45, 43, 53, 61, 42, 57, 56, 63, 51, 47,
+ 59, 75, 64, 89, 83, 75, 59, 75, 91, 92, 58, 64, 83, 74, 58, 60, 76, 66, 97, 69,
+ 90, 95, 92, 64, 78, 75, 77, 73, 65, 78, 82, 75, 47, 54, 59, 71, 59, 56, 53, 42,
+ 60, 55, 40, 51, 60, 46, 36, 59, 46, 57, 67, 43, 51, 53, 53, 38, 54, 56, 55, 48,
+ 41, 46, 63, 63, 80, 77, 89, 102, 89, 98, 74, 86, 98, 93, 63, 76, 98, 77, 48, 101,
+ 86, 88, 100, 82, 102, 90, 95, 75, 86, 103, 83, 98, 80, 104, 98, 86, 71, 74, 80, 90,
+ 86, 87, 73, 70, 81, 83, 55, 66, 90, 66, 58, 84, 77, 84, 93, 72, 99, 75, 85, 65,
+ 70, 89, 71, 82, 64, 79, 82, 80, 67, 73, 86, 101, 78, 97, 66, 64, 84, 80, 55, 64,
+ 79, 73, 51, 79, 89, 68, 94, 77, 109, 102, 82, 61, 66, 93, 88, 70, 82, 82, 85, 69,
+ 69, 72, 66, 97, 85, 90, 70, 59, 76, 89, 53, 56, 90, 79, 71, 64, 70, 67, 100, 92,
+ 106, 89, 83, 78, 73, 80, 70, 72, 65, 70, 92, 88, 57, 76, 55, 85, 66, 80, 61, 63,
+ 63, 78, 54, 58, 71, 73, 54, 63, 63, 62, 89, 76, 86, 81, 83, 54, 70, 81, 78, 64,
+ 56, 72, 74, 81, 75, 63, 68, 89, 65, 77, 58, 68, 75, 83, 52, 62, 82, 63, 55, 75,
+ 51, 70, 95, 66, 83, 77, 86, 61, 64, 77, 48, 70, 66, 82, 72, 75, 79, 71, 72, 89,
+ 78, 78, 66, 59, 91, 80, 55, 64, 79, 68, 54, 71, 67, 75, 87, 84, 100, 101, 76, 58,
+ 74, 82, 61, 74, 75, 97, 85, 79, 61, 55, 69, 68, 72, 65, 52, 64, 80, 73, 48, 54,
+ 71, 66, 42, 61, 66, 63, 92, 64, 85, 77, 73, 54, 74, 73, 76, 66, 62, 79, 85, 70,
+ 71, 84, 87, 81, 88, 86, 77, 77, 93, 88, 78, 71, 101, 89, 58, 84, 95, 81, 89, 97,
+ 104, 79, 83, 76, 90, 81, 91, 74, 70, 76, 91, 80, 51, 48, 56, 69, 47, 63, 54, 42,
+ 63, 63, 42, 52, 66, 56, 39, 59, 61, 52, 59, 63, 62, 68, 57, 35, 67, 58, 56, 52,
+ 61, 63, 60, 47, 85, 75, 89, 106, 88, 95, 74, 82, 107, 107, 64, 78, 98, 90, 62, 91,
+ 79, 87, 111, 84, 104, 106, 96, 68, 94, 99, 81, 89, 79, 105, 95, 86, 65, 63, 77, 89,
+ 66, 88, 56, 73, 82, 92, 41, 62, 85, 66, 50, 81, 57, 71, 77, 78, 86, 89, 77, 53,
+ 67, 78, 61, 63, 72, 82, 69, 66, 59, 46, 55, 70, 56, 64, 45, 50, 65, 64, 42, 56,
+ 78, 49, 51, 52, 38, 56, 72, 55, 73, 72, 61, 50, 63, 60, 47, 57, 55, 73, 53, 68,
+ 85, 88, 91, 96, 82, 89, 73, 76, 87, 86, 67, 69, 96, 84, 57, 89, 87, 89, 99, 88,
+ 104, 90, 85, 75, 88, 92, 85, 75, 74, 87, 103, 94, 55, 48, 56, 65, 72, 50, 45, 51,
+ 63, 62, 47, 57, 79, 53, 36, 63, 54, 68, 71, 59, 63, 61, 63, 41, 50, 73, 57, 59,
+ 56, 76, 73, 65, 61, 64, 61, 79, 53, 73, 57, 44, 61, 59, 59, 56, 81, 59, 49, 62,
+ 65, 55, 69, 72, 79, 70, 58, 57, 68, 61, 62, 50, 57, 60, 66, 66, 63, 77, 81, 89,
+ 85, 81, 76, 73, 78, 95, 59, 70, 81, 77, 46, 79, 78, 79, 83, 81, 84, 82, 85, 48,
+ 74, 85, 85, 74, 74, 80, 80, 74, 60, 76, 80, 97, 88, 93, 66, 66, 73, 84, 56, 70,
+ 90, 63, 58, 78, 73, 93, 90, 78, 94, 88, 82, 67, 85, 70, 81, 86, 74, 82, 88, 82,
+ 68, 73, 75, 91, 78, 97, 71, 66, 74, 85, 50, 59, 86, 77, 70, 74, 75, 74, 99, 82,
+ 99, 91, 86, 65, 80, 77, 72, 69, 60, 78, 90, 87, 79, 69, 74, 98, 70, 86, 81, 67,
+ 69, 78, 48, 65, 88, 70, 70, 70, 69, 72, 96, 90, 99, 82, 81, 76, 98, 73, 74, 71,
+ 69, 73, 94, 89
+};
+
--- /dev/null
+#!/usr/bin/perl -w
+#==========================================================================
+# matmul_gendata.pl
+#
+# Author : Christopher Batten (cbatten@mit.edu)
+# Date : April 29, 2005
+#
+(our $usageMsg = <<'ENDMSG') =~ s/^\#//gm;
+#
+# Simple script which creates an input data set and the reference data
+# for the matmul benchmark.
+#
+ENDMSG
+
+use strict "vars";
+use warnings;
+no warnings("once");
+use Getopt::Long;
+
+#--------------------------------------------------------------------------
+# Command line processing
+#--------------------------------------------------------------------------
+
+our %opts;
+
+sub usage()
+{
+
+ print "\n";
+ print " Usage: matmul_gendata.pl [options] \n";
+ print "\n";
+ print " Options:\n";
+ print " --help print this message\n";
+ print " --size size of input data [1000]\n";
+ print " --seed random seed [1]\n";
+ print "$usageMsg";
+
+ exit();
+}
+
+sub processCommandLine()
+{
+
+ $opts{"help"} = 0;
+ $opts{"size"} = 1000;
+ $opts{"seed"} = 1;
+ Getopt::Long::GetOptions( \%opts, 'help|?', 'size:i', 'seed:i' ) or usage();
+ $opts{"help"} and usage();
+
+}
+
+#--------------------------------------------------------------------------
+# Helper Functions
+#--------------------------------------------------------------------------
+
+sub printArray
+{
+ my $arrayName = $_[0];
+ my $arrayRef = $_[1];
+
+ my $numCols = 20;
+ my $arrayLen = scalar(@{$arrayRef});
+
+ print "static data_t ".$arrayName."[ARRAY_SIZE] = \n";
+ print "{\n";
+
+ if ( $arrayLen <= $numCols ) {
+ print " ";
+ for ( my $i = 0; $i < $arrayLen; $i++ ) {
+ print sprintf("%3d",$arrayRef->[$i]);
+ if ( $i != $arrayLen-1 ) {
+ print ", ";
+ }
+ }
+ print "\n";
+ }
+
+ else {
+ my $numRows = int($arrayLen/$numCols);
+ for ( my $j = 0; $j < $numRows; $j++ ) {
+ print " ";
+ for ( my $i = 0; $i < $numCols; $i++ ) {
+ my $index = $j*$numCols + $i;
+ print sprintf("%3d",$arrayRef->[$index]);
+ if ( $index != $arrayLen-1 ) {
+ print ", ";
+ }
+ }
+ print "\n";
+ }
+
+ if ( $arrayLen > ($numRows*$numCols) ) {
+ print " ";
+ for ( my $i = 0; $i < ($arrayLen-($numRows*$numCols)); $i++ ) {
+ my $index = $numCols*$numRows + $i;
+ print sprintf("%3d",$arrayRef->[$index]);
+ if ( $index != $arrayLen-1 ) {
+ print ", ";
+ }
+ }
+ print "\n";
+ }
+
+ }
+
+ print "};\n\n";
+}
+
+
+
+#--------------------------------------------------------------------------
+# Matmul
+#--------------------------------------------------------------------------
+
+# http://answers.oreilly.com/topic/418-how-to-multiply-matrices-in-perl/
+
+sub mmult {
+ my ($m1,$m2) = @_;
+ my ($m1rows,$m1cols) = matdim($m1);
+ my ($m2rows,$m2cols) = matdim($m2);
+
+ my $result = [ ];
+ my ($i, $j, $k);
+
+ for $i (range($m1rows)) {
+ for $j (range($m2cols)) {
+ for $k (range($m1cols)) {
+ $result->[$i][$j] += $m1->[$i][$k] * $m2->[$k][$j];
+ }
+ }
+ }
+ return $result;
+}
+
+sub range { 0 .. ($_[0] - 1) }
+
+
+sub veclen {
+ my $ary_ref = $_[0];
+ my $type = ref $ary_ref;
+ if ($type ne "ARRAY") { die "$type is bad array ref for $ary_ref" }
+ return scalar(@$ary_ref);
+}
+
+sub matdim {
+ my $matrix = $_[0];
+ my $rows = veclen($matrix);
+ my $cols = veclen($matrix->[0]);
+ return ($rows, $cols);
+}
+
+#--------------------------------------------------------------------------
+# Main
+#--------------------------------------------------------------------------
+
+sub main()
+{
+
+ processCommandLine();
+ srand($opts{"seed"});
+
+ # create random input arrays
+ my $mat_values1;
+ my $mat_values2;
+ for ( my $i = 0; $i < $opts{"size"}; $i++ ) {
+ for ( my $j = 0; $j < $opts{"size"}; $j++ ) {
+ $mat_values1->[$i][$j] = int(rand(4));
+ $mat_values2->[$i][$j] = int(rand(4));
+ }
+ }
+
+ # perform matmul
+ my $mat_results = mmult( $mat_values1, $mat_values2 );
+
+ # translate 2d arrays to 1d-somethings (I don't know how to code in perl - Chris)
+ my @values1;
+ my @values2;
+ my @results;
+ for ( my $i = 0; $i < $opts{"size"}; $i++ ) {
+ for ( my $j = 0; $j < $opts{"size"}; $j++ ) {
+ my $value1 = $mat_values1->[$i][$j];
+ my $value2 = $mat_values2->[$i][$j];
+ my $result = $mat_results->[$i][$j];
+ push( @values1, $value1 );
+ push( @values2, $value2 );
+ push( @results, $result );
+ }
+ }
+
+ print "\n\#define ARRAY_SIZE ".($opts{"size"}*$opts{"size"})." \n\n";
+ print "\n\#define DIM_SIZE ".$opts{"size"}." \n\n";
+
+ printArray( "input1_data", \@values1 );
+ printArray( "input2_data", \@values2 );
+ printArray( "verify_data", \@results);
+
+}
+
+main();
+
--- /dev/null
+//**************************************************************************
+// Multi-threaded Matrix Multiply benchmark
+//--------------------------------------------------------------------------
+// TA : Christopher Celio
+// Student:
+//
+//
+// This benchmark multiplies two 2-D arrays together and writes the results to
+// a third vector. The input data (and reference data) should be generated
+// using the matmul_gendata.pl perl script and dumped to a file named
+// dataset.h.
+
+
+// print out arrays, etc.
+//#define DEBUG
+
+//--------------------------------------------------------------------------
+// Includes
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+//--------------------------------------------------------------------------
+// Input/Reference Data
+
+typedef float data_t;
+#include "dataset.h"
+
+
+//--------------------------------------------------------------------------
+// Basic Utilities and Multi-thread Support
+
+__thread unsigned long coreid;
+unsigned long ncores;
+
+#include "util.h"
+
+#define stringify_1(s) #s
+#define stringify(s) stringify_1(s)
+#define stats(code) do { \
+ unsigned long _c = -rdcycle(), _i = -rdinstret(); \
+ code; \
+ _c += rdcycle(), _i += rdinstret(); \
+ if (coreid == 0) \
+ printf("%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
+ stringify(code), _c, _c/DIM_SIZE/DIM_SIZE/DIM_SIZE, 10*_c/DIM_SIZE/DIM_SIZE/DIM_SIZE%10, _c/_i, 10*_c/_i%10); \
+ } while(0)
+
+
+//--------------------------------------------------------------------------
+// Helper functions
+
+void printArray( char name[], int n, data_t arr[] )
+{
+ int i;
+ if (coreid != 0)
+ return;
+
+ printf( " %10s :", name );
+ for ( i = 0; i < n; i++ )
+ printf( " %3ld ", (long) arr[i] );
+ printf( "\n" );
+}
+
+void __attribute__((noinline)) verify(size_t n, const data_t* test, const data_t* correct)
+{
+ if (coreid != 0)
+ return;
+
+ size_t i;
+ for (i = 0; i < n; i++)
+ {
+ if (test[i] != correct[i])
+ {
+ printf("FAILED test[%d]= %3ld, correct[%d]= %3ld\n",
+ i, (long)test[i], i, (long)correct[i]);
+ exit(-1);
+ }
+ }
+
+ return;
+}
+
+//--------------------------------------------------------------------------
+// matmul function
+
+// single-thread, naive version
+void __attribute__((noinline)) matmul_naive(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ int i, j, k;
+
+ if (coreid > 0)
+ return;
+
+ for ( i = 0; i < lda; i++ )
+ for ( j = 0; j < lda; j++ )
+ {
+ for ( k = 0; k < lda; k++ )
+ {
+ C[i + j*lda] += A[j*lda + k] * B[k*lda + i];
+ }
+ }
+
+}
+
+
+
+void __attribute__((noinline)) matmul(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+
+ // ***************************** //
+ // **** ADD YOUR CODE HERE ***** //
+ // ***************************** //
+ //
+ // feel free to make a separate function for MI and MSI versions.
+ int i, j=0, k, jend=16;
+ if (coreid != 0) {
+ j = jend;
+ jend = jend << 1;
+ }
+ for ( ; j < jend; j++ )
+ {
+ int j32 = j << 5;
+ data_t* Cj32 = C + j32;
+ for ( k = 0; k < 32; k+=2 )
+ {
+ data_t Aj32k = A[k + j32];
+ data_t Aj32k2 = A[k + 1 + j32];
+ data_t* Bk32 = B + (k << 5);
+ data_t* Bk322 = Bk32 + 32;
+ for ( i = 0; i < 32; i+=4 )
+ {
+ Cj32[i] += Aj32k * Bk32 [i];
+ Cj32[i] += Aj32k2 * Bk322 [i];
+ Cj32[i+1] += Aj32k * Bk32 [i+1];
+ Cj32[i+1] += Aj32k2 * Bk322[i+1];
+ Cj32[i+2] += Aj32k * Bk32 [i+2];
+ Cj32[i+2] += Aj32k2 * Bk322[i+2];
+ Cj32[i+3] += Aj32k * Bk32 [i+3];
+ Cj32[i+3] += Aj32k2 * Bk322[i+3];
+ }
+ }
+ }
+
+
+}
+
+//--------------------------------------------------------------------------
+// Main
+//
+// all threads start executing thread_entry(). Use their "coreid" to
+// differentiate between threads (each thread is running on a separate core).
+
+void thread_entry(int cid, int nc)
+{
+ coreid = cid;
+ ncores = nc;
+
+ // static allocates data in the binary, which is visible to both threads
+ static data_t results_data[ARRAY_SIZE];
+
+
+// // Execute the provided, naive matmul
+// barrier();
+// stats(matmul_naive(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+//
+//
+// // verify
+// verify(ARRAY_SIZE, results_data, verify_data);
+//
+// // clear results from the first trial
+// size_t i;
+// if (coreid == 0)
+// for (i=0; i < ARRAY_SIZE; i++)
+// results_data[i] = 0;
+// barrier();
+
+
+ // Execute your faster matmul
+ barrier();
+ stats(matmul(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+#ifdef DEBUG
+ printArray("results:", ARRAY_SIZE, results_data);
+ printArray("verify :", ARRAY_SIZE, verify_data);
+#endif
+
+ // verify
+ verify(ARRAY_SIZE, results_data, verify_data);
+ barrier();
+
+ exit(0);
+}
+
--- /dev/null
+//**************************************************************************
+// Vector-vector add benchmark
+//--------------------------------------------------------------------------
+// Author : Andrew Waterman
+// TA : Christopher Celio
+// Student :
+//
+// This benchmark adds two vectors and writes the results to a
+// third vector. The input data (and reference data) should be
+// generated using the vvadd_gendata.pl perl script and dumped
+// to a file named dataset.h
+
+// to print out arrays, etc.
+//#define DEBUG
+
+//--------------------------------------------------------------------------
+// Includes
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+//--------------------------------------------------------------------------
+// Input/Reference Data
+
+typedef float data_t;
+#include "dataset.h"
+
+
+//--------------------------------------------------------------------------
+// Basic Utilities and Multi-thread Support
+
+__thread unsigned long coreid;
+unsigned long ncores;
+
+#include "util.h"
+
+#define stringify_1(s) #s
+#define stringify(s) stringify_1(s)
+#define stats(code) do { \
+ unsigned long _c = -rdcycle(), _i = -rdinstret(); \
+ code; \
+ _c += rdcycle(), _i += rdinstret(); \
+ if (coreid == 0) \
+ printf("%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
+ stringify(code), _c, _c/DATA_SIZE, 10*_c/DATA_SIZE%10, _c/_i, 10*_c/_i%10); \
+ } while(0)
+
+
+//--------------------------------------------------------------------------
+// Helper functions
+
+void printArray( char name[], int n, data_t arr[] )
+{
+ int i;
+ if (coreid != 0)
+ return;
+
+ printf( " %10s :", name );
+ for ( i = 0; i < n; i++ )
+ printf( " %4ld ", (long) arr[i] );
+ printf( "\n" );
+}
+
+void __attribute__((noinline)) verify(size_t n, const data_t* test, const data_t* correct)
+{
+ if (coreid != 0)
+ return;
+
+ size_t i;
+ for (i = 0; i < n; i++)
+ {
+ if (test[i] != correct[i])
+ {
+ printf("FAILED test[%d]= %4ld, correct[%d]= %4ld\n",
+ i, (long) test[i], i, (long)correct[i]);
+ exit(-1);
+ }
+ }
+
+ return;
+}
+
+//--------------------------------------------------------------------------
+// vvadd function
+
+//perform in-place vvadd
+void __attribute__((noinline)) vvadd(size_t n, data_t* __restrict__ x, const data_t* __restrict__ y)
+{
+ size_t i;
+
+ // interleave accesses
+ for (i = coreid; i < n; i+=ncores)
+ {
+ x[i] = x[i] + y[i];
+ }
+}
+
+void __attribute__((noinline)) vvadd_opt(size_t n, data_t* __restrict__ x, const data_t* __restrict__ y)
+{
+ // ***************************** //
+ // **** ADD YOUR CODE HERE ***** //
+ // ***************************** //
+ size_t i;
+ size_t m = n/2;
+ if (coreid == 0) {
+ for (i = 0; i < m; i++) {
+ x[i] = x[i] + y[i];
+ }
+ } else {
+ for (i = m; i < n; i++) {
+ x[i] = x[i] + y[i];
+ }
+ }
+}
+
+//--------------------------------------------------------------------------
+// Main
+//
+// all threads start executing thread_entry(). Use their "coreid" to
+// differentiate between threads (each thread is running on a separate core).
+
+void thread_entry(int cid, int nc)
+{
+ coreid = cid;
+ ncores = nc;
+
+ // static allocates data in the binary, which is visible to both threads
+ static data_t results_data[DATA_SIZE];
+
+ // because we're going to perform an in-place vvadd (and we're going to run
+ // it a couple of times) let's copy the input data to a temporary results
+ // array
+
+ size_t i;
+ if (coreid == 0)
+ {
+ for (i = 0; i < DATA_SIZE; i++)
+ results_data[i] = input1_data[i];
+ }
+
+
+ // Execute the provided, terrible vvadd
+ barrier();
+ stats(vvadd(DATA_SIZE, results_data, input2_data); barrier());
+
+
+ // verify
+ verify(DATA_SIZE, results_data, verify_data);
+
+ // reset results from the first trial
+ if (coreid == 0)
+ {
+ for (i=0; i < DATA_SIZE; i++)
+ results_data[i] = input1_data[i];
+ }
+ barrier();
+
+
+ // Execute your faster vvadd
+ barrier();
+ stats(vvadd_opt(DATA_SIZE, results_data, input2_data); barrier());
+
+#ifdef DEBUG
+ printArray("results: ", DATA_SIZE, results_data);
+ printArray("verify : ", DATA_SIZE, verify_data);
+#endif
+
+ // verify
+ verify(DATA_SIZE, results_data, verify_data);
+ barrier();
+
+ exit(0);
+}
+
--- /dev/null
+
+#define DATA_SIZE 1000
+
+static data_t input1_data[DATA_SIZE] =
+{
+ 0.00, 15.00, 10.00, 3.00, 14.00, 6.00, 2.00, 18.00, 11.00, 15.00, 11.00, 0.00, 17.00, 16.00, 7.00, 13.00, 18.00, 2.00, 2.00, 5.00,
+ 8.00, 5.00, 12.00, 14.00, 6.00, 12.00, 16.00, 7.00, 9.00, 17.00, 10.00, 10.00, 3.00, 5.00, 14.00, 11.00, 9.00, 12.00, 3.00, 1.00,
+ 5.00, 4.00, 6.00, 17.00, 17.00, 4.00, 17.00, 15.00, 17.00, 18.00, 3.00, 18.00, 10.00, 6.00, 12.00, 12.00, 3.00, 2.00, 16.00, 1.00,
+ 5.00, 6.00, 2.00, 17.00, 16.00, 5.00, 10.00, 18.00, 14.00, 4.00, 9.00, 9.00, 7.00, 4.00, 8.00, 13.00, 12.00, 6.00, 4.00, 17.00,
+ 5.00, 2.00, 11.00, 11.00, 7.00, 6.00, 8.00, 5.00, 6.00, 6.00, 11.00, 1.00, 18.00, 7.00, 6.00, 9.00, 10.00, 17.00, 14.00, 4.00,
+ 14.00, 11.00, 2.00, 0.00, 2.00, 17.00, 17.00, 15.00, 10.00, 8.00, 12.00, 18.00, 5.00, 0.00, 0.00, 1.00, 1.00, 8.00, 11.00, 11.00,
+ 7.00, 5.00, 15.00, 18.00, 15.00, 6.00, 8.00, 9.00, 18.00, 6.00, 15.00, 16.00, 10.00, 18.00, 13.00, 6.00, 10.00, 16.00, 0.00, 10.00,
+ 12.00, 8.00, 8.00, 3.00, 0.00, 1.00, 4.00, 0.00, 8.00, 15.00, 16.00, 9.00, 7.00, 7.00, 10.00, 9.00, 16.00, 12.00, 5.00, 5.00,
+ 9.00, 5.00, 17.00, 4.00, 13.00, 13.00, 4.00, 14.00, 10.00, 5.00, 10.00, 10.00, 6.00, 18.00, 5.00, 15.00, 5.00, 15.00, 13.00, 18.00,
+ 6.00, 13.00, 5.00, 18.00, 12.00, 14.00, 1.00, 7.00, 2.00, 1.00, 7.00, 12.00, 15.00, 15.00, 6.00, 2.00, 1.00, 2.00, 18.00, 6.00,
+ 10.00, 14.00, 9.00, 15.00, 11.00, 0.00, 3.00, 1.00, 2.00, 2.00, 14.00, 7.00, 18.00, 0.00, 2.00, 2.00, 16.00, 8.00, 4.00, 5.00,
+ 7.00, 11.00, 7.00, 10.00, 14.00, 10.00, 3.00, 0.00, 13.00, 9.00, 14.00, 0.00, 14.00, 1.00, 3.00, 16.00, 2.00, 14.00, 6.00, 17.00,
+ 17.00, 6.00, 9.00, 8.00, 9.00, 12.00, 5.00, 14.00, 2.00, 16.00, 17.00, 5.00, 4.00, 0.00, 14.00, 10.00, 6.00, 15.00, 15.00, 14.00,
+ 5.00, 1.00, 8.00, 8.00, 13.00, 8.00, 0.00, 4.00, 7.00, 9.00, 13.00, 16.00, 9.00, 14.00, 9.00, 13.00, 0.00, 7.00, 16.00, 17.00,
+ 18.00, 10.00, 13.00, 8.00, 4.00, 9.00, 13.00, 0.00, 6.00, 4.00, 6.00, 4.00, 10.00, 14.00, 14.00, 9.00, 15.00, 15.00, 3.00, 3.00,
+ 12.00, 0.00, 3.00, 2.00, 16.00, 1.00, 7.00, 2.00, 16.00, 2.00, 2.00, 0.00, 14.00, 3.00, 3.00, 10.00, 4.00, 10.00, 3.00, 4.00,
+ 13.00, 14.00, 13.00, 0.00, 1.00, 15.00, 16.00, 9.00, 7.00, 9.00, 0.00, 11.00, 1.00, 1.00, 15.00, 17.00, 12.00, 16.00, 15.00, 4.00,
+ 8.00, 2.00, 10.00, 10.00, 0.00, 18.00, 17.00, 7.00, 7.00, 2.00, 10.00, 17.00, 9.00, 7.00, 5.00, 3.00, 8.00, 11.00, 6.00, 9.00,
+ 13.00, 0.00, 3.00, 5.00, 2.00, 5.00, 7.00, 4.00, 9.00, 2.00, 13.00, 17.00, 14.00, 12.00, 1.00, 3.00, 7.00, 17.00, 0.00, 14.00,
+ 16.00, 2.00, 2.00, 1.00, 2.00, 15.00, 16.00, 8.00, 2.00, 4.00, 15.00, 15.00, 10.00, 6.00, 11.00, 9.00, 15.00, 17.00, 3.00, 8.00,
+ 15.00, 3.00, 10.00, 15.00, 8.00, 14.00, 16.00, 15.00, 15.00, 14.00, 1.00, 7.00, 4.00, 18.00, 2.00, 13.00, 11.00, 15.00, 7.00, 10.00,
+ 13.00, 10.00, 7.00, 14.00, 18.00, 4.00, 18.00, 4.00, 3.00, 9.00, 1.00, 13.00, 15.00, 2.00, 5.00, 15.00, 12.00, 10.00, 2.00, 0.00,
+ 10.00, 15.00, 0.00, 11.00, 14.00, 11.00, 14.00, 9.00, 1.00, 18.00, 14.00, 18.00, 15.00, 5.00, 1.00, 15.00, 18.00, 14.00, 3.00, 15.00,
+ 11.00, 2.00, 15.00, 0.00, 13.00, 1.00, 4.00, 14.00, 14.00, 5.00, 2.00, 13.00, 17.00, 8.00, 7.00, 6.00, 5.00, 10.00, 14.00, 14.00,
+ 17.00, 0.00, 0.00, 17.00, 18.00, 15.00, 10.00, 16.00, 18.00, 5.00, 9.00, 10.00, 18.00, 7.00, 11.00, 5.00, 4.00, 16.00, 2.00, 8.00,
+ 13.00, 1.00, 12.00, 3.00, 4.00, 6.00, 15.00, 12.00, 0.00, 6.00, 18.00, 12.00, 14.00, 18.00, 3.00, 2.00, 3.00, 5.00, 3.00, 14.00,
+ 18.00, 12.00, 10.00, 11.00, 8.00, 4.00, 10.00, 10.00, 9.00, 18.00, 14.00, 3.00, 7.00, 17.00, 12.00, 0.00, 10.00, 9.00, 17.00, 3.00,
+ 0.00, 4.00, 6.00, 16.00, 14.00, 12.00, 13.00, 13.00, 18.00, 7.00, 0.00, 1.00, 9.00, 7.00, 12.00, 6.00, 18.00, 8.00, 9.00, 13.00,
+ 13.00, 17.00, 10.00, 16.00, 1.00, 10.00, 17.00, 16.00, 2.00, 18.00, 4.00, 2.00, 6.00, 1.00, 1.00, 1.00, 8.00, 14.00, 6.00, 6.00,
+ 13.00, 14.00, 13.00, 6.00, 5.00, 10.00, 11.00, 11.00, 16.00, 1.00, 5.00, 9.00, 13.00, 8.00, 10.00, 2.00, 12.00, 15.00, 5.00, 14.00,
+ 3.00, 7.00, 9.00, 18.00, 2.00, 11.00, 16.00, 4.00, 5.00, 10.00, 17.00, 10.00, 3.00, 4.00, 14.00, 18.00, 13.00, 6.00, 8.00, 11.00,
+ 14.00, 3.00, 5.00, 6.00, 6.00, 5.00, 13.00, 0.00, 9.00, 9.00, 1.00, 7.00, 5.00, 5.00, 1.00, 6.00, 18.00, 11.00, 17.00, 7.00,
+ 1.00, 10.00, 5.00, 12.00, 6.00, 16.00, 16.00, 5.00, 1.00, 10.00, 10.00, 15.00, 7.00, 18.00, 8.00, 17.00, 3.00, 5.00, 3.00, 14.00,
+ 0.00, 16.00, 12.00, 0.00, 14.00, 17.00, 16.00, 2.00, 18.00, 13.00, 10.00, 13.00, 4.00, 14.00, 2.00, 3.00, 4.00, 8.00, 17.00, 0.00,
+ 6.00, 11.00, 5.00, 3.00, 3.00, 2.00, 15.00, 13.00, 10.00, 4.00, 1.00, 11.00, 6.00, 17.00, 1.00, 0.00, 18.00, 3.00, 3.00, 11.00,
+ 7.00, 7.00, 11.00, 14.00, 7.00, 16.00, 11.00, 10.00, 8.00, 6.00, 11.00, 5.00, 17.00, 10.00, 7.00, 8.00, 14.00, 2.00, 9.00, 17.00,
+ 15.00, 13.00, 10.00, 6.00, 0.00, 15.00, 11.00, 10.00, 11.00, 18.00, 2.00, 5.00, 17.00, 18.00, 11.00, 15.00, 3.00, 17.00, 9.00, 17.00,
+ 8.00, 6.00, 2.00, 4.00, 2.00, 11.00, 15.00, 2.00, 18.00, 3.00, 9.00, 7.00, 15.00, 9.00, 14.00, 10.00, 9.00, 6.00, 13.00, 8.00,
+ 15.00, 14.00, 0.00, 11.00, 5.00, 2.00, 12.00, 14.00, 10.00, 16.00, 9.00, 7.00, 9.00, 17.00, 4.00, 4.00, 7.00, 8.00, 4.00, 4.00,
+ 9.00, 7.00, 3.00, 5.00, 11.00, 11.00, 10.00, 13.00, 3.00, 14.00, 15.00, 8.00, 1.00, 1.00, 3.00, 0.00, 16.00, 9.00, 6.00, 1.00,
+ 0.00, 2.00, 0.00, 6.00, 13.00, 12.00, 5.00, 18.00, 1.00, 11.00, 17.00, 11.00, 16.00, 14.00, 14.00, 9.00, 11.00, 9.00, 17.00, 15.00,
+ 5.00, 18.00, 2.00, 11.00, 10.00, 16.00, 18.00, 5.00, 11.00, 12.00, 11.00, 18.00, 7.00, 6.00, 8.00, 3.00, 4.00, 3.00, 16.00, 4.00,
+ 6.00, 2.00, 15.00, 6.00, 7.00, 16.00, 0.00, 7.00, 11.00, 10.00, 3.00, 0.00, 14.00, 16.00, 15.00, 15.00, 12.00, 7.00, 1.00, 4.00,
+ 8.00, 4.00, 12.00, 0.00, 7.00, 8.00, 1.00, 1.00, 14.00, 15.00, 9.00, 8.00, 6.00, 6.00, 4.00, 7.00, 8.00, 13.00, 10.00, 5.00,
+ 8.00, 11.00, 2.00, 16.00, 7.00, 17.00, 5.00, 2.00, 17.00, 0.00, 18.00, 6.00, 7.00, 4.00, 4.00, 12.00, 0.00, 18.00, 8.00, 4.00,
+ 7.00, 0.00, 11.00, 1.00, 11.00, 17.00, 18.00, 15.00, 8.00, 11.00, 15.00, 9.00, 12.00, 1.00, 5.00, 6.00, 1.00, 18.00, 14.00, 7.00,
+ 16.00, 16.00, 10.00, 3.00, 13.00, 0.00, 12.00, 9.00, 18.00, 14.00, 15.00, 4.00, 11.00, 15.00, 15.00, 8.00, 16.00, 11.00, 13.00, 12.00,
+ 1.00, 13.00, 14.00, 2.00, 11.00, 0.00, 17.00, 11.00, 12.00, 6.00, 4.00, 4.00, 11.00, 13.00, 10.00, 2.00, 10.00, 14.00, 0.00, 6.00,
+ 18.00, 10.00, 7.00, 14.00, 12.00, 9.00, 4.00, 16.00, 17.00, 8.00, 14.00, 9.00, 0.00, 4.00, 15.00, 13.00, 8.00, 13.00, 13.00, 8.00,
+ 15.00, 6.00, 11.00, 4.00, 2.00, 6.00, 5.00, 14.00, 5.00, 17.00, 12.00, 11.00, 17.00, 4.00, 13.00, 7.00, 16.00, 12.00, 7.00, 18.00
+};
+
+static data_t input2_data[DATA_SIZE] =
+{
+ 8.00, 6.00, 0.00, 18.00, 6.00, 10.00, 1.00, 2.00, 4.00, 2.00, 4.00, 10.00, 6.00, 11.00, 17.00, 4.00, 0.00, 16.00, 14.00, 12.00,
+ 9.00, 8.00, 13.00, 15.00, 18.00, 2.00, 13.00, 10.00, 5.00, 4.00, 12.00, 9.00, 1.00, 13.00, 12.00, 7.00, 10.00, 17.00, 11.00, 10.00,
+ 18.00, 15.00, 11.00, 12.00, 7.00, 9.00, 6.00, 5.00, 11.00, 7.00, 10.00, 12.00, 18.00, 18.00, 15.00, 1.00, 3.00, 18.00, 11.00, 16.00,
+ 13.00, 18.00, 4.00, 13.00, 8.00, 7.00, 10.00, 13.00, 0.00, 9.00, 1.00, 16.00, 13.00, 7.00, 5.00, 5.00, 11.00, 1.00, 6.00, 10.00,
+ 12.00, 3.00, 10.00, 5.00, 15.00, 15.00, 13.00, 14.00, 14.00, 1.00, 18.00, 5.00, 16.00, 14.00, 10.00, 4.00, 8.00, 4.00, 6.00, 6.00,
+ 13.00, 14.00, 8.00, 5.00, 14.00, 10.00, 9.00, 10.00, 17.00, 15.00, 6.00, 16.00, 12.00, 9.00, 10.00, 16.00, 16.00, 8.00, 1.00, 12.00,
+ 7.00, 0.00, 0.00, 3.00, 5.00, 7.00, 10.00, 3.00, 17.00, 10.00, 18.00, 16.00, 1.00, 11.00, 18.00, 9.00, 2.00, 0.00, 12.00, 6.00,
+ 13.00, 1.00, 13.00, 5.00, 7.00, 13.00, 17.00, 9.00, 15.00, 13.00, 5.00, 2.00, 4.00, 4.00, 3.00, 0.00, 9.00, 11.00, 3.00, 12.00,
+ 6.00, 11.00, 1.00, 16.00, 12.00, 11.00, 2.00, 2.00, 15.00, 12.00, 8.00, 9.00, 14.00, 2.00, 11.00, 0.00, 0.00, 7.00, 2.00, 13.00,
+ 15.00, 18.00, 7.00, 16.00, 16.00, 1.00, 1.00, 12.00, 12.00, 2.00, 2.00, 1.00, 7.00, 4.00, 0.00, 8.00, 18.00, 4.00, 11.00, 6.00,
+ 17.00, 13.00, 12.00, 5.00, 16.00, 12.00, 0.00, 9.00, 10.00, 10.00, 18.00, 12.00, 8.00, 7.00, 5.00, 8.00, 16.00, 3.00, 9.00, 18.00,
+ 12.00, 13.00, 18.00, 6.00, 8.00, 12.00, 2.00, 12.00, 8.00, 8.00, 9.00, 18.00, 8.00, 0.00, 9.00, 2.00, 6.00, 7.00, 0.00, 3.00,
+ 11.00, 2.00, 18.00, 2.00, 16.00, 1.00, 16.00, 11.00, 11.00, 16.00, 16.00, 11.00, 7.00, 4.00, 14.00, 10.00, 5.00, 8.00, 4.00, 14.00,
+ 17.00, 13.00, 13.00, 3.00, 1.00, 14.00, 1.00, 7.00, 0.00, 2.00, 7.00, 14.00, 4.00, 9.00, 14.00, 3.00, 9.00, 13.00, 13.00, 3.00,
+ 3.00, 17.00, 0.00, 18.00, 4.00, 8.00, 6.00, 9.00, 4.00, 2.00, 0.00, 14.00, 3.00, 3.00, 14.00, 8.00, 6.00, 7.00, 2.00, 12.00,
+ 5.00, 14.00, 6.00, 12.00, 2.00, 16.00, 1.00, 15.00, 7.00, 18.00, 0.00, 0.00, 13.00, 13.00, 12.00, 11.00, 16.00, 15.00, 14.00, 8.00,
+ 9.00, 10.00, 8.00, 8.00, 13.00, 13.00, 13.00, 10.00, 1.00, 15.00, 4.00, 0.00, 12.00, 1.00, 8.00, 12.00, 1.00, 18.00, 12.00, 18.00,
+ 9.00, 1.00, 11.00, 5.00, 13.00, 7.00, 1.00, 13.00, 5.00, 8.00, 17.00, 11.00, 13.00, 15.00, 9.00, 3.00, 17.00, 18.00, 9.00, 3.00,
+ 15.00, 11.00, 12.00, 0.00, 2.00, 15.00, 3.00, 0.00, 13.00, 1.00, 14.00, 14.00, 15.00, 8.00, 6.00, 0.00, 0.00, 11.00, 17.00, 0.00,
+ 1.00, 8.00, 6.00, 6.00, 10.00, 6.00, 18.00, 12.00, 7.00, 18.00, 4.00, 6.00, 15.00, 18.00, 7.00, 5.00, 8.00, 6.00, 6.00, 7.00,
+ 4.00, 4.00, 10.00, 17.00, 12.00, 13.00, 11.00, 15.00, 12.00, 18.00, 7.00, 12.00, 17.00, 10.00, 14.00, 12.00, 2.00, 7.00, 17.00, 3.00,
+ 8.00, 6.00, 3.00, 9.00, 3.00, 7.00, 7.00, 15.00, 18.00, 5.00, 13.00, 13.00, 15.00, 10.00, 0.00, 11.00, 10.00, 1.00, 5.00, 16.00,
+ 2.00, 7.00, 14.00, 12.00, 7.00, 17.00, 17.00, 11.00, 0.00, 5.00, 16.00, 14.00, 1.00, 9.00, 8.00, 8.00, 3.00, 17.00, 0.00, 8.00,
+ 6.00, 5.00, 7.00, 6.00, 17.00, 3.00, 3.00, 8.00, 3.00, 12.00, 17.00, 5.00, 14.00, 3.00, 11.00, 5.00, 17.00, 2.00, 15.00, 1.00,
+ 18.00, 11.00, 12.00, 0.00, 0.00, 14.00, 7.00, 17.00, 15.00, 10.00, 18.00, 10.00, 11.00, 7.00, 12.00, 10.00, 17.00, 2.00, 18.00, 9.00,
+ 11.00, 4.00, 17.00, 10.00, 15.00, 12.00, 4.00, 1.00, 5.00, 10.00, 4.00, 2.00, 11.00, 3.00, 4.00, 15.00, 16.00, 10.00, 2.00, 2.00,
+ 15.00, 16.00, 0.00, 13.00, 16.00, 9.00, 1.00, 7.00, 3.00, 10.00, 7.00, 2.00, 12.00, 8.00, 1.00, 5.00, 0.00, 16.00, 4.00, 14.00,
+ 13.00, 16.00, 3.00, 0.00, 10.00, 6.00, 3.00, 9.00, 1.00, 3.00, 0.00, 13.00, 12.00, 17.00, 11.00, 4.00, 15.00, 15.00, 12.00, 4.00,
+ 4.00, 2.00, 16.00, 6.00, 11.00, 17.00, 14.00, 7.00, 4.00, 14.00, 8.00, 8.00, 3.00, 18.00, 17.00, 17.00, 12.00, 10.00, 11.00, 1.00,
+ 8.00, 13.00, 1.00, 14.00, 0.00, 9.00, 0.00, 7.00, 9.00, 0.00, 7.00, 12.00, 0.00, 18.00, 10.00, 1.00, 5.00, 13.00, 13.00, 2.00,
+ 10.00, 4.00, 2.00, 6.00, 0.00, 16.00, 2.00, 15.00, 13.00, 6.00, 8.00, 5.00, 6.00, 15.00, 12.00, 6.00, 6.00, 7.00, 8.00, 1.00,
+ 11.00, 9.00, 7.00, 18.00, 14.00, 4.00, 9.00, 6.00, 4.00, 2.00, 10.00, 13.00, 6.00, 17.00, 2.00, 11.00, 7.00, 3.00, 8.00, 9.00,
+ 2.00, 6.00, 18.00, 12.00, 18.00, 13.00, 8.00, 1.00, 11.00, 4.00, 13.00, 14.00, 16.00, 8.00, 6.00, 18.00, 14.00, 15.00, 9.00, 11.00,
+ 2.00, 13.00, 4.00, 3.00, 3.00, 15.00, 14.00, 3.00, 13.00, 12.00, 14.00, 16.00, 18.00, 12.00, 5.00, 11.00, 2.00, 3.00, 15.00, 1.00,
+ 12.00, 1.00, 15.00, 13.00, 12.00, 18.00, 4.00, 17.00, 13.00, 7.00, 11.00, 13.00, 7.00, 10.00, 1.00, 3.00, 18.00, 6.00, 10.00, 3.00,
+ 9.00, 16.00, 12.00, 10.00, 6.00, 6.00, 7.00, 16.00, 16.00, 16.00, 17.00, 18.00, 8.00, 18.00, 0.00, 6.00, 17.00, 13.00, 14.00, 8.00,
+ 0.00, 7.00, 5.00, 13.00, 8.00, 12.00, 14.00, 9.00, 10.00, 10.00, 9.00, 9.00, 8.00, 6.00, 0.00, 14.00, 16.00, 8.00, 7.00, 16.00,
+ 10.00, 3.00, 1.00, 9.00, 11.00, 2.00, 6.00, 18.00, 5.00, 4.00, 2.00, 11.00, 10.00, 17.00, 16.00, 2.00, 12.00, 15.00, 14.00, 6.00,
+ 6.00, 17.00, 3.00, 10.00, 9.00, 18.00, 18.00, 6.00, 11.00, 16.00, 18.00, 17.00, 7.00, 14.00, 1.00, 16.00, 7.00, 9.00, 11.00, 12.00,
+ 10.00, 6.00, 1.00, 16.00, 9.00, 18.00, 0.00, 9.00, 16.00, 10.00, 14.00, 6.00, 9.00, 14.00, 15.00, 7.00, 12.00, 8.00, 1.00, 1.00,
+ 1.00, 17.00, 17.00, 17.00, 18.00, 1.00, 15.00, 18.00, 16.00, 16.00, 11.00, 7.00, 4.00, 15.00, 3.00, 14.00, 13.00, 14.00, 9.00, 2.00,
+ 4.00, 8.00, 14.00, 7.00, 0.00, 12.00, 14.00, 15.00, 8.00, 2.00, 11.00, 5.00, 6.00, 16.00, 6.00, 4.00, 16.00, 7.00, 9.00, 5.00,
+ 1.00, 0.00, 16.00, 10.00, 9.00, 6.00, 5.00, 8.00, 15.00, 13.00, 7.00, 18.00, 18.00, 8.00, 0.00, 15.00, 4.00, 6.00, 14.00, 3.00,
+ 3.00, 2.00, 9.00, 14.00, 18.00, 13.00, 10.00, 15.00, 0.00, 11.00, 16.00, 7.00, 16.00, 18.00, 0.00, 12.00, 6.00, 13.00, 12.00, 12.00,
+ 5.00, 3.00, 5.00, 16.00, 13.00, 16.00, 8.00, 5.00, 12.00, 8.00, 8.00, 0.00, 2.00, 9.00, 18.00, 11.00, 8.00, 4.00, 14.00, 6.00,
+ 17.00, 2.00, 6.00, 8.00, 11.00, 13.00, 6.00, 18.00, 17.00, 6.00, 8.00, 0.00, 1.00, 14.00, 18.00, 4.00, 0.00, 4.00, 3.00, 3.00,
+ 16.00, 8.00, 16.00, 1.00, 2.00, 0.00, 15.00, 14.00, 10.00, 9.00, 15.00, 3.00, 5.00, 18.00, 5.00, 6.00, 7.00, 3.00, 7.00, 2.00,
+ 6.00, 12.00, 10.00, 10.00, 18.00, 16.00, 0.00, 9.00, 17.00, 10.00, 9.00, 14.00, 15.00, 5.00, 8.00, 15.00, 3.00, 15.00, 14.00, 11.00,
+ 6.00, 6.00, 14.00, 0.00, 14.00, 0.00, 7.00, 12.00, 8.00, 7.00, 1.00, 3.00, 6.00, 10.00, 12.00, 1.00, 16.00, 5.00, 5.00, 6.00,
+ 17.00, 15.00, 15.00, 9.00, 4.00, 18.00, 17.00, 13.00, 12.00, 9.00, 7.00, 10.00, 2.00, 5.00, 8.00, 18.00, 1.00, 15.00, 8.00, 0.00
+};
+
+static data_t verify_data[DATA_SIZE] =
+{
+ 8.00, 21.00, 10.00, 21.00, 20.00, 16.00, 3.00, 20.00, 15.00, 17.00, 15.00, 10.00, 23.00, 27.00, 24.00, 17.00, 18.00, 18.00, 16.00, 17.00,
+ 17.00, 13.00, 25.00, 29.00, 24.00, 14.00, 29.00, 17.00, 14.00, 21.00, 22.00, 19.00, 4.00, 18.00, 26.00, 18.00, 19.00, 29.00, 14.00, 11.00,
+ 23.00, 19.00, 17.00, 29.00, 24.00, 13.00, 23.00, 20.00, 28.00, 25.00, 13.00, 30.00, 28.00, 24.00, 27.00, 13.00, 6.00, 20.00, 27.00, 17.00,
+ 18.00, 24.00, 6.00, 30.00, 24.00, 12.00, 20.00, 31.00, 14.00, 13.00, 10.00, 25.00, 20.00, 11.00, 13.00, 18.00, 23.00, 7.00, 10.00, 27.00,
+ 17.00, 5.00, 21.00, 16.00, 22.00, 21.00, 21.00, 19.00, 20.00, 7.00, 29.00, 6.00, 34.00, 21.00, 16.00, 13.00, 18.00, 21.00, 20.00, 10.00,
+ 27.00, 25.00, 10.00, 5.00, 16.00, 27.00, 26.00, 25.00, 27.00, 23.00, 18.00, 34.00, 17.00, 9.00, 10.00, 17.00, 17.00, 16.00, 12.00, 23.00,
+ 14.00, 5.00, 15.00, 21.00, 20.00, 13.00, 18.00, 12.00, 35.00, 16.00, 33.00, 32.00, 11.00, 29.00, 31.00, 15.00, 12.00, 16.00, 12.00, 16.00,
+ 25.00, 9.00, 21.00, 8.00, 7.00, 14.00, 21.00, 9.00, 23.00, 28.00, 21.00, 11.00, 11.00, 11.00, 13.00, 9.00, 25.00, 23.00, 8.00, 17.00,
+ 15.00, 16.00, 18.00, 20.00, 25.00, 24.00, 6.00, 16.00, 25.00, 17.00, 18.00, 19.00, 20.00, 20.00, 16.00, 15.00, 5.00, 22.00, 15.00, 31.00,
+ 21.00, 31.00, 12.00, 34.00, 28.00, 15.00, 2.00, 19.00, 14.00, 3.00, 9.00, 13.00, 22.00, 19.00, 6.00, 10.00, 19.00, 6.00, 29.00, 12.00,
+ 27.00, 27.00, 21.00, 20.00, 27.00, 12.00, 3.00, 10.00, 12.00, 12.00, 32.00, 19.00, 26.00, 7.00, 7.00, 10.00, 32.00, 11.00, 13.00, 23.00,
+ 19.00, 24.00, 25.00, 16.00, 22.00, 22.00, 5.00, 12.00, 21.00, 17.00, 23.00, 18.00, 22.00, 1.00, 12.00, 18.00, 8.00, 21.00, 6.00, 20.00,
+ 28.00, 8.00, 27.00, 10.00, 25.00, 13.00, 21.00, 25.00, 13.00, 32.00, 33.00, 16.00, 11.00, 4.00, 28.00, 20.00, 11.00, 23.00, 19.00, 28.00,
+ 22.00, 14.00, 21.00, 11.00, 14.00, 22.00, 1.00, 11.00, 7.00, 11.00, 20.00, 30.00, 13.00, 23.00, 23.00, 16.00, 9.00, 20.00, 29.00, 20.00,
+ 21.00, 27.00, 13.00, 26.00, 8.00, 17.00, 19.00, 9.00, 10.00, 6.00, 6.00, 18.00, 13.00, 17.00, 28.00, 17.00, 21.00, 22.00, 5.00, 15.00,
+ 17.00, 14.00, 9.00, 14.00, 18.00, 17.00, 8.00, 17.00, 23.00, 20.00, 2.00, 0.00, 27.00, 16.00, 15.00, 21.00, 20.00, 25.00, 17.00, 12.00,
+ 22.00, 24.00, 21.00, 8.00, 14.00, 28.00, 29.00, 19.00, 8.00, 24.00, 4.00, 11.00, 13.00, 2.00, 23.00, 29.00, 13.00, 34.00, 27.00, 22.00,
+ 17.00, 3.00, 21.00, 15.00, 13.00, 25.00, 18.00, 20.00, 12.00, 10.00, 27.00, 28.00, 22.00, 22.00, 14.00, 6.00, 25.00, 29.00, 15.00, 12.00,
+ 28.00, 11.00, 15.00, 5.00, 4.00, 20.00, 10.00, 4.00, 22.00, 3.00, 27.00, 31.00, 29.00, 20.00, 7.00, 3.00, 7.00, 28.00, 17.00, 14.00,
+ 17.00, 10.00, 8.00, 7.00, 12.00, 21.00, 34.00, 20.00, 9.00, 22.00, 19.00, 21.00, 25.00, 24.00, 18.00, 14.00, 23.00, 23.00, 9.00, 15.00,
+ 19.00, 7.00, 20.00, 32.00, 20.00, 27.00, 27.00, 30.00, 27.00, 32.00, 8.00, 19.00, 21.00, 28.00, 16.00, 25.00, 13.00, 22.00, 24.00, 13.00,
+ 21.00, 16.00, 10.00, 23.00, 21.00, 11.00, 25.00, 19.00, 21.00, 14.00, 14.00, 26.00, 30.00, 12.00, 5.00, 26.00, 22.00, 11.00, 7.00, 16.00,
+ 12.00, 22.00, 14.00, 23.00, 21.00, 28.00, 31.00, 20.00, 1.00, 23.00, 30.00, 32.00, 16.00, 14.00, 9.00, 23.00, 21.00, 31.00, 3.00, 23.00,
+ 17.00, 7.00, 22.00, 6.00, 30.00, 4.00, 7.00, 22.00, 17.00, 17.00, 19.00, 18.00, 31.00, 11.00, 18.00, 11.00, 22.00, 12.00, 29.00, 15.00,
+ 35.00, 11.00, 12.00, 17.00, 18.00, 29.00, 17.00, 33.00, 33.00, 15.00, 27.00, 20.00, 29.00, 14.00, 23.00, 15.00, 21.00, 18.00, 20.00, 17.00,
+ 24.00, 5.00, 29.00, 13.00, 19.00, 18.00, 19.00, 13.00, 5.00, 16.00, 22.00, 14.00, 25.00, 21.00, 7.00, 17.00, 19.00, 15.00, 5.00, 16.00,
+ 33.00, 28.00, 10.00, 24.00, 24.00, 13.00, 11.00, 17.00, 12.00, 28.00, 21.00, 5.00, 19.00, 25.00, 13.00, 5.00, 10.00, 25.00, 21.00, 17.00,
+ 13.00, 20.00, 9.00, 16.00, 24.00, 18.00, 16.00, 22.00, 19.00, 10.00, 0.00, 14.00, 21.00, 24.00, 23.00, 10.00, 33.00, 23.00, 21.00, 17.00,
+ 17.00, 19.00, 26.00, 22.00, 12.00, 27.00, 31.00, 23.00, 6.00, 32.00, 12.00, 10.00, 9.00, 19.00, 18.00, 18.00, 20.00, 24.00, 17.00, 7.00,
+ 21.00, 27.00, 14.00, 20.00, 5.00, 19.00, 11.00, 18.00, 25.00, 1.00, 12.00, 21.00, 13.00, 26.00, 20.00, 3.00, 17.00, 28.00, 18.00, 16.00,
+ 13.00, 11.00, 11.00, 24.00, 2.00, 27.00, 18.00, 19.00, 18.00, 16.00, 25.00, 15.00, 9.00, 19.00, 26.00, 24.00, 19.00, 13.00, 16.00, 12.00,
+ 25.00, 12.00, 12.00, 24.00, 20.00, 9.00, 22.00, 6.00, 13.00, 11.00, 11.00, 20.00, 11.00, 22.00, 3.00, 17.00, 25.00, 14.00, 25.00, 16.00,
+ 3.00, 16.00, 23.00, 24.00, 24.00, 29.00, 24.00, 6.00, 12.00, 14.00, 23.00, 29.00, 23.00, 26.00, 14.00, 35.00, 17.00, 20.00, 12.00, 25.00,
+ 2.00, 29.00, 16.00, 3.00, 17.00, 32.00, 30.00, 5.00, 31.00, 25.00, 24.00, 29.00, 22.00, 26.00, 7.00, 14.00, 6.00, 11.00, 32.00, 1.00,
+ 18.00, 12.00, 20.00, 16.00, 15.00, 20.00, 19.00, 30.00, 23.00, 11.00, 12.00, 24.00, 13.00, 27.00, 2.00, 3.00, 36.00, 9.00, 13.00, 14.00,
+ 16.00, 23.00, 23.00, 24.00, 13.00, 22.00, 18.00, 26.00, 24.00, 22.00, 28.00, 23.00, 25.00, 28.00, 7.00, 14.00, 31.00, 15.00, 23.00, 25.00,
+ 15.00, 20.00, 15.00, 19.00, 8.00, 27.00, 25.00, 19.00, 21.00, 28.00, 11.00, 14.00, 25.00, 24.00, 11.00, 29.00, 19.00, 25.00, 16.00, 33.00,
+ 18.00, 9.00, 3.00, 13.00, 13.00, 13.00, 21.00, 20.00, 23.00, 7.00, 11.00, 18.00, 25.00, 26.00, 30.00, 12.00, 21.00, 21.00, 27.00, 14.00,
+ 21.00, 31.00, 3.00, 21.00, 14.00, 20.00, 30.00, 20.00, 21.00, 32.00, 27.00, 24.00, 16.00, 31.00, 5.00, 20.00, 14.00, 17.00, 15.00, 16.00,
+ 19.00, 13.00, 4.00, 21.00, 20.00, 29.00, 10.00, 22.00, 19.00, 24.00, 29.00, 14.00, 10.00, 15.00, 18.00, 7.00, 28.00, 17.00, 7.00, 2.00,
+ 1.00, 19.00, 17.00, 23.00, 31.00, 13.00, 20.00, 36.00, 17.00, 27.00, 28.00, 18.00, 20.00, 29.00, 17.00, 23.00, 24.00, 23.00, 26.00, 17.00,
+ 9.00, 26.00, 16.00, 18.00, 10.00, 28.00, 32.00, 20.00, 19.00, 14.00, 22.00, 23.00, 13.00, 22.00, 14.00, 7.00, 20.00, 10.00, 25.00, 9.00,
+ 7.00, 2.00, 31.00, 16.00, 16.00, 22.00, 5.00, 15.00, 26.00, 23.00, 10.00, 18.00, 32.00, 24.00, 15.00, 30.00, 16.00, 13.00, 15.00, 7.00,
+ 11.00, 6.00, 21.00, 14.00, 25.00, 21.00, 11.00, 16.00, 14.00, 26.00, 25.00, 15.00, 22.00, 24.00, 4.00, 19.00, 14.00, 26.00, 22.00, 17.00,
+ 13.00, 14.00, 7.00, 32.00, 20.00, 33.00, 13.00, 7.00, 29.00, 8.00, 26.00, 6.00, 9.00, 13.00, 22.00, 23.00, 8.00, 22.00, 22.00, 10.00,
+ 24.00, 2.00, 17.00, 9.00, 22.00, 30.00, 24.00, 33.00, 25.00, 17.00, 23.00, 9.00, 13.00, 15.00, 23.00, 10.00, 1.00, 22.00, 17.00, 10.00,
+ 32.00, 24.00, 26.00, 4.00, 15.00, 0.00, 27.00, 23.00, 28.00, 23.00, 30.00, 7.00, 16.00, 33.00, 20.00, 14.00, 23.00, 14.00, 20.00, 14.00,
+ 7.00, 25.00, 24.00, 12.00, 29.00, 16.00, 17.00, 20.00, 29.00, 16.00, 13.00, 18.00, 26.00, 18.00, 18.00, 17.00, 13.00, 29.00, 14.00, 17.00,
+ 24.00, 16.00, 21.00, 14.00, 26.00, 9.00, 11.00, 28.00, 25.00, 15.00, 15.00, 12.00, 6.00, 14.00, 27.00, 14.00, 24.00, 18.00, 18.00, 14.00,
+ 32.00, 21.00, 26.00, 13.00, 6.00, 24.00, 22.00, 27.00, 17.00, 26.00, 19.00, 21.00, 19.00, 9.00, 21.00, 25.00, 17.00, 27.00, 15.00, 18.00
+};
+
--- /dev/null
+#!/usr/bin/perl -w
+#==========================================================================
+# vvadd_gendata.pl
+#
+# Author : Christopher Batten (cbatten@mit.edu)
+# Date : April 29, 2005
+#
+(our $usageMsg = <<'ENDMSG') =~ s/^\#//gm;
+#
+# Simple script which creates an input data set and the reference data
+# for the vvadd benchmark.
+#
+ENDMSG
+
+use strict "vars";
+use warnings;
+no warnings("once");
+use Getopt::Long;
+
+#--------------------------------------------------------------------------
+# Command line processing
+#--------------------------------------------------------------------------
+
+our %opts;
+
+sub usage()
+{
+
+ print "\n";
+ print " Usage: vvadd_gendata.pl [options] \n";
+ print "\n";
+ print " Options:\n";
+ print " --help print this message\n";
+ print " --size size of input data [1000]\n";
+ print " --seed random seed [1]\n";
+ print "$usageMsg";
+
+ exit();
+}
+
+sub processCommandLine()
+{
+
+ $opts{"help"} = 0;
+ $opts{"size"} = 1000;
+ $opts{"seed"} = 1;
+ Getopt::Long::GetOptions( \%opts, 'help|?', 'size:i', 'seed:i' ) or usage();
+ $opts{"help"} and usage();
+
+}
+
+#--------------------------------------------------------------------------
+# Helper Functions
+#--------------------------------------------------------------------------
+
+sub printArray
+{
+ my $arrayName = $_[0];
+ my $arrayRef = $_[1];
+
+ my $numCols = 20;
+ my $arrayLen = scalar(@{$arrayRef});
+
+ print "static data_t ".$arrayName."[DATA_SIZE] = \n";
+ print "{\n";
+
+ if ( $arrayLen <= $numCols ) {
+ print " ";
+ for ( my $i = 0; $i < $arrayLen; $i++ ) {
+ print sprintf("%3.2f",$arrayRef->[$i]);
+ if ( $i != $arrayLen-1 ) {
+ print ", ";
+ }
+ }
+ print "\n";
+ }
+
+ else {
+ my $numRows = int($arrayLen/$numCols);
+ for ( my $j = 0; $j < $numRows; $j++ ) {
+ print " ";
+ for ( my $i = 0; $i < $numCols; $i++ ) {
+ my $index = $j*$numCols + $i;
+ print sprintf("%3.2f",$arrayRef->[$index]);
+ if ( $index != $arrayLen-1 ) {
+ print ", ";
+ }
+ }
+ print "\n";
+ }
+
+ if ( $arrayLen > ($numRows*$numCols) ) {
+ print " ";
+ for ( my $i = 0; $i < ($arrayLen-($numRows*$numCols)); $i++ ) {
+ my $index = $numCols*$numRows + $i;
+ print sprintf("%3.2f",$arrayRef->[$index]);
+ if ( $index != $arrayLen-1 ) {
+ print ", ";
+ }
+ }
+ print "\n";
+ }
+
+ }
+
+ print "};\n\n";
+}
+
+#--------------------------------------------------------------------------
+# Main
+#--------------------------------------------------------------------------
+
+sub main()
+{
+
+ processCommandLine();
+ srand($opts{"seed"});
+
+ my @values1;
+ my @values2;
+ my @sum;
+ for ( my $i = 0; $i < $opts{"size"}; $i++ ) {
+ my $value1 = int(rand(19));
+ my $value2 = int(rand(19));
+ push( @values1, $value1 );
+ push( @values2, $value2 );
+ push( @sum, $value1 + $value2 );
+ }
+
+
+ print "\n\#define DATA_SIZE ".$opts{"size"}." \n\n";
+ printArray( "input1_data", \@values1 );
+ printArray( "input2_data", \@values2 );
+ printArray( "verify_data", \@sum );
+
+}
+
+main();
+
--- /dev/null
+//**************************************************************************
+// Multi-threaded Matrix Multiply benchmark
+//--------------------------------------------------------------------------
+// TA : Christopher Celio
+// Student:
+//
+//
+// This benchmark multiplies two 2-D arrays together and writes the results to
+// a third vector. The input data (and reference data) should be generated
+// using the matmul_gendata.pl perl script and dumped to a file named
+// dataset.h.
+
+
+// print out arrays, etc.
+//#define DEBUG
+
+//--------------------------------------------------------------------------
+// Includes
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+//--------------------------------------------------------------------------
+// Input/Reference Data
+
+typedef float data_t;
+#include "dataset.h"
+
+
+//--------------------------------------------------------------------------
+// Basic Utilities and Multi-thread Support
+
+__thread unsigned long coreid;
+unsigned long ncores;
+
+#include "util.h"
+
+#define stringify_1(s) #s
+#define stringify(s) stringify_1(s)
+#define stats(code) do { \
+ unsigned long _c = -rdcycle(), _i = -rdinstret(); \
+ code; \
+ _c += rdcycle(), _i += rdinstret(); \
+ if (coreid == 0) \
+ printf("%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
+ stringify(code), _c, _c/DIM_SIZE/DIM_SIZE/DIM_SIZE, 10*_c/DIM_SIZE/DIM_SIZE/DIM_SIZE%10, _c/_i, 10*_c/_i%10); \
+ } while(0)
+
+
+//--------------------------------------------------------------------------
+// Helper functions
+
+void printArray( char name[], int n, data_t arr[] )
+{
+ int i;
+ if (coreid != 0)
+ return;
+
+ printf( " %10s :", name );
+ for ( i = 0; i < n; i++ )
+ printf( " %3ld ", (long) arr[i] );
+ printf( "\n" );
+}
+
+void __attribute__((noinline)) verify(size_t n, const data_t* test, const data_t* correct)
+{
+ if (coreid != 0)
+ return;
+
+ size_t i;
+ for (i = 0; i < n; i++)
+ {
+ if (test[i] != correct[i])
+ {
+ printf("FAILED test[%d]= %3ld, correct[%d]= %3ld\n",
+ i, (long)test[i], i, (long)correct[i]);
+ exit(-1);
+ }
+ }
+
+ return;
+}
+
+//--------------------------------------------------------------------------
+// matmul function
+
+// single-thread, naive version
+void __attribute__((noinline)) matmul_naive(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ int i, j, k;
+
+ if (coreid > 0)
+ return;
+
+ for ( i = 0; i < lda; i++ )
+ for ( j = 0; j < lda; j++ )
+ {
+ for ( k = 0; k < lda; k++ )
+ {
+ C[i + j*lda] += A[j*lda + k] * B[k*lda + i];
+ }
+ }
+
+}
+
+
+void __attribute__((noinline)) matmul(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+
+ // ***************************** //
+ // **** ADD YOUR CODE HERE ***** //
+ // ***************************** //
+ //
+ // feel free to make a separate function for MI and MSI versions.
+
+
+
+ data_t *b1;
+ data_t *b2;
+ data_t *b3;
+ data_t *b4;
+ data_t c1;
+ data_t c2;
+ data_t c3;
+ data_t c4;
+ data_t a1;
+ data_t a2;
+ data_t a3;
+ data_t a4;
+ data_t a5;
+ data_t a6;
+ data_t a7;
+ data_t a8;
+ int i, j, k;
+ static data_t BB[1024];
+
+
+
+ //transpose B
+ if (coreid == 0 | coreid == 1) {
+ for ( k = 0; k < lda; k++) {
+ for ( i = coreid*(lda/2); i < (coreid+1)*(lda/2); i++ ) {
+ BB[i*lda + k] = B[k*lda + i];
+ }
+ }
+ }
+ barrier();
+
+ for ( i = 0; i < lda; i+=4 ) {
+ for ( j = coreid*(lda/ncores); j < (coreid+1)*(lda/ncores); j++ ) {
+ c1 = 0; c2 = 0; c3 = 0; c4 = 0;
+ b1 = &BB[(i+0)*lda];
+ b2 = &BB[(i+1)*lda];
+ b3 = &BB[(i+2)*lda];
+ b4 = &BB[(i+3)*lda];
+ for ( k = 0; k < lda; k+=8 ) {
+
+ a1 = A[j*lda + k+0];
+ a2 = A[j*lda + k+1];
+ a3 = A[j*lda + k+2];
+ a4 = A[j*lda + k+3];
+ a5 = A[j*lda + k+4];
+ a6 = A[j*lda + k+5];
+ a7 = A[j*lda + k+6];
+ a8 = A[j*lda + k+7];
+
+ c1 += a1 * b1[k+0];
+ c1 += a2 * b1[k+1];
+ c1 += a3 * b1[k+2];
+ c1 += a4 * b1[k+3];
+ c1 += a5 * b1[k+4];
+ c1 += a6 * b1[k+5];
+ c1 += a7 * b1[k+6];
+ c1 += a8 * b1[k+7];
+
+ c2 += a1 * b2[k+0];
+ c2 += a2 * b2[k+1];
+ c2 += a3 * b2[k+2];
+ c2 += a4 * b2[k+3];
+ c2 += a5 * b2[k+4];
+ c2 += a6 * b2[k+5];
+ c2 += a7 * b2[k+6];
+ c2 += a8 * b2[k+7];
+
+ c3 += a1 * b3[k+0];
+ c3 += a2 * b3[k+1];
+ c3 += a3 * b3[k+2];
+ c3 += a4 * b3[k+3];
+ c3 += a5 * b3[k+4];
+ c3 += a6 * b3[k+5];
+ c3 += a7 * b3[k+6];
+ c3 += a8 * b3[k+7];
+
+ c4 += a1 * b4[k+0];
+ c4 += a2 * b4[k+1];
+ c4 += a3 * b4[k+2];
+ c4 += a4 * b4[k+3];
+ c4 += a5 * b4[k+4];
+ c4 += a6 * b4[k+5];
+ c4 += a7 * b4[k+6];
+ c4 += a8 * b4[k+7];
+
+
+ }
+ C[i+0 + j*lda] = c1;
+ C[i+1 + j*lda] = c2;
+ C[i+2 + j*lda] = c3;
+ C[i+3 + j*lda] = c4;
+ }
+ }
+
+}
+
+//--------------------------------------------------------------------------
+// Main
+//
+// all threads start executing thread_entry(). Use their "coreid" to
+// differentiate between threads (each thread is running on a separate core).
+
+void thread_entry(int cid, int nc)
+{
+ coreid = cid;
+ ncores = nc;
+
+ // static allocates data in the binary, which is visible to both threads
+ static data_t results_data[ARRAY_SIZE];
+
+/*
+ // Execute the provided, naive matmul
+ barrier();
+ stats(matmul_naive(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+
+ // verify
+ verify(ARRAY_SIZE, results_data, verify_data);
+
+ // clear results from the first trial
+ size_t i;
+ if (coreid == 0)
+ for (i=0; i < ARRAY_SIZE; i++)
+ results_data[i] = 0;
+ barrier();
+*/
+
+
+ // Execute your faster matmul
+ barrier();
+ stats(matmul(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+#ifdef DEBUG
+ printArray("results:", ARRAY_SIZE, results_data);
+ printArray("verify :", ARRAY_S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3, 1, 3, 3, 0, 2, 1, 2, 2, 2,
+ 1, 0, 1, 3, 2, 3, 1, 1, 2, 1, 1, 0, 0, 2, 3, 2, 1, 0, 3, 1,
+ 3, 0, 1, 1, 2, 2, 1, 3, 3, 1, 1, 0, 0, 3, 3, 0, 0, 0, 0, 0,
+ 3, 1, 3, 0, 0, 0, 3, 3, 2, 1, 3, 0, 1, 3, 1, 1, 1, 0, 1, 0,
+ 1, 2, 2, 2, 3, 3, 0, 2, 3, 2, 1, 3, 3, 1, 1, 3, 0, 3, 3, 2,
+ 1, 1, 2, 0, 3, 0, 1, 2, 1, 1, 0, 0, 1, 2, 2, 0, 3, 1, 1, 1,
+ 3, 3, 3, 1, 0, 3, 3, 2, 2, 2, 1, 2, 0, 1, 1, 3, 0, 3, 1, 0,
+ 2, 2, 0, 1, 2, 3, 2, 1, 2, 0, 3, 2, 1, 3, 0, 1, 2, 0, 3, 0,
+ 1, 1, 2, 1
+};
+
+static data_t verify_data[ARRAY_SIZE] =
+{
+ 72, 75, 88, 101, 80, 88, 73, 75, 80, 81, 58, 75, 86, 65, 60, 80, 84, 83, 87, 83,
+ 108, 93, 85, 76, 72, 98, 79, 86, 80, 96, 91, 85, 72, 64, 70, 83, 68, 92, 51, 54,
+ 85, 85, 60, 58, 90, 64, 55, 69, 72, 48, 94, 77, 91, 83, 70, 69, 67, 77, 59, 50,
+ 67, 74, 77, 67, 67, 62, 72, 71, 68, 79, 54, 61, 67, 61, 55, 62, 78, 60, 53, 64,
+ 67, 69, 99, 68, 88, 60, 66, 63, 70, 62, 65, 50, 53, 66, 70, 72, 75, 78, 85, 95,
+ 71, 89, 70, 68, 86, 88, 58, 77, 84, 70, 65, 68, 73, 75, 91, 96, 105, 92, 76, 68,
+ 86, 69, 80, 59, 73, 83, 88, 75, 64, 63, 71, 99, 77, 77, 69, 55, 80, 73, 54, 73,
+ 87, 78, 60, 69, 65, 78, 86, 89, 95, 92, 63, 69, 89, 61, 80, 65, 70, 77, 89, 77,
+ 79, 79, 73, 92, 64, 81, 60, 78, 81, 80, 61, 63, 89, 65, 56, 83, 77, 65, 102, 70,
+ 98, 86, 96, 68, 72, 89, 73, 73, 70, 89, 84, 76, 48, 61, 63, 70, 70, 79, 50, 53,
+ 64, 63, 43, 51, 59, 62, 43, 63, 55, 77, 79, 74, 75, 74, 64, 44, 65, 69, 72, 66,
+ 54, 71, 74, 72, 69, 76, 68, 89, 94, 75, 65, 53, 85, 79, 65, 74, 82, 73, 58, 70,
+ 84, 77, 99, 72, 92, 84, 78, 62, 59, 83, 71, 74, 63, 85, 80, 78, 71, 72, 79, 83,
+ 73, 82, 60, 85, 76, 82, 60, 70, 82, 68, 54, 85, 84, 70, 86, 74, 100, 88, 98, 68,
+ 67, 87, 69, 73, 68, 88, 76, 71, 47, 43, 47, 80, 54, 65, 40, 37, 59, 53, 33, 48,
+ 62, 40, 36, 55, 36, 62, 53, 57, 70, 69, 45, 43, 53, 61, 42, 57, 56, 63, 51, 47,
+ 59, 75, 64, 89, 83, 75, 59, 75, 91, 92, 58, 64, 83, 74, 58, 60, 76, 66, 97, 69,
+ 90, 95, 92, 64, 78, 75, 77, 73, 65, 78, 82, 75, 47, 54, 59, 71, 59, 56, 53, 42,
+ 60, 55, 40, 51, 60, 46, 36, 59, 46, 57, 67, 43, 51, 53, 53, 38, 54, 56, 55, 48,
+ 41, 46, 63, 63, 80, 77, 89, 102, 89, 98, 74, 86, 98, 93, 63, 76, 98, 77, 48, 101,
+ 86, 88, 100, 82, 102, 90, 95, 75, 86, 103, 83, 98, 80, 104, 98, 86, 71, 74, 80, 90,
+ 86, 87, 73, 70, 81, 83, 55, 66, 90, 66, 58, 84, 77, 84, 93, 72, 99, 75, 85, 65,
+ 70, 89, 71, 82, 64, 79, 82, 80, 67, 73, 86, 101, 78, 97, 66, 64, 84, 80, 55, 64,
+ 79, 73, 51, 79, 89, 68, 94, 77, 109, 102, 82, 61, 66, 93, 88, 70, 82, 82, 85, 69,
+ 69, 72, 66, 97, 85, 90, 70, 59, 76, 89, 53, 56, 90, 79, 71, 64, 70, 67, 100, 92,
+ 106, 89, 83, 78, 73, 80, 70, 72, 65, 70, 92, 88, 57, 76, 55, 85, 66, 80, 61, 63,
+ 63, 78, 54, 58, 71, 73, 54, 63, 63, 62, 89, 76, 86, 81, 83, 54, 70, 81, 78, 64,
+ 56, 72, 74, 81, 75, 63, 68, 89, 65, 77, 58, 68, 75, 83, 52, 62, 82, 63, 55, 75,
+ 51, 70, 95, 66, 83, 77, 86, 61, 64, 77, 48, 70, 66, 82, 72, 75, 79, 71, 72, 89,
+ 78, 78, 66, 59, 91, 80, 55, 64, 79, 68, 54, 71, 67, 75, 87, 84, 100, 101, 76, 58,
+ 74, 82, 61, 74, 75, 97, 85, 79, 61, 55, 69, 68, 72, 65, 52, 64, 80, 73, 48, 54,
+ 71, 66, 42, 61, 66, 63, 92, 64, 85, 77, 73, 54, 74, 73, 76, 66, 62, 79, 85, 70,
+ 71, 84, 87, 81, 88, 86, 77, 77, 93, 88, 78, 71, 101, 89, 58, 84, 95, 81, 89, 97,
+ 104, 79, 83, 76, 90, 81, 91, 74, 70, 76, 91, 80, 51, 48, 56, 69, 47, 63, 54, 42,
+ 63, 63, 42, 52, 66, 56, 39, 59, 61, 52, 59, 63, 62, 68, 57, 35, 67, 58, 56, 52,
+ 61, 63, 60, 47, 85, 75, 89, 106, 88, 95, 74, 82, 107, 107, 64, 78, 98, 90, 62, 91,
+ 79, 87, 111, 84, 104, 106, 96, 68, 94, 99, 81, 89, 79, 105, 95, 86, 65, 63, 77, 89,
+ 66, 88, 56, 73, 82, 92, 41, 62, 85, 66, 50, 81, 57, 71, 77, 78, 86, 89, 77, 53,
+ 67, 78, 61, 63, 72, 82, 69, 66, 59, 46, 55, 70, 56, 64, 45, 50, 65, 64, 42, 56,
+ 78, 49, 51, 52, 38, 56, 72, 55, 73, 72, 61, 50, 63, 60, 47, 57, 55, 73, 53, 68,
+ 85, 88, 91, 96, 82, 89, 73, 76, 87, 86, 67, 69, 96, 84, 57, 89, 87, 89, 99, 88,
+ 104, 90, 85, 75, 88, 92, 85, 75, 74, 87, 103, 94, 55, 48, 56, 65, 72, 50, 45, 51,
+ 63, 62, 47, 57, 79, 53, 36, 63, 54, 68, 71, 59, 63, 61, 63, 41, 50, 73, 57, 59,
+ 56, 76, 73, 65, 61, 64, 61, 79, 53, 73, 57, 44, 61, 59, 59, 56, 81, 59, 49, 62,
+ 65, 55, 69, 72, 79, 70, 58, 57, 68, 61, 62, 50, 57, 60, 66, 66, 63, 77, 81, 89,
+ 85, 81, 76, 73, 78, 95, 59, 70, 81, 77, 46, 79, 78, 79, 83, 81, 84, 82, 85, 48,
+ 74, 85, 85, 74, 74, 80, 80, 74, 60, 76, 80, 97, 88, 93, 66, 66, 73, 84, 56, 70,
+ 90, 63, 58, 78, 73, 93, 90, 78, 94, 88, 82, 67, 85, 70, 81, 86, 74, 82, 88, 82,
+ 68, 73, 75, 91, 78, 97, 71, 66, 74, 85, 50, 59, 86, 77, 70, 74, 75, 74, 99, 82,
+ 99, 91, 86, 65, 80, 77, 72, 69, 60, 78, 90, 87, 79, 69, 74, 98, 70, 86, 81, 67,
+ 69, 78, 48, 65, 88, 70, 70, 70, 69, 72, 96, 90, 99, 82, 81, 76, 98, 73, 74, 71,
+ 69, 73, 94, 89
+};
+
--- /dev/null
+#!/usr/bin/perl -w
+#==========================================================================
+# matmul_gendata.pl
+#
+# Author : Christopher Batten (cbatten@mit.edu)
+# Date : April 29, 2005
+#
+(our $usageMsg = <<'ENDMSG') =~ s/^\#//gm;
+#
+# Simple script which creates an input data set and the reference data
+# for the matmul benchmark.
+#
+ENDMSG
+
+use strict "vars";
+use warnings;
+no warnings("once");
+use Getopt::Long;
+
+#--------------------------------------------------------------------------
+# Command line processing
+#--------------------------------------------------------------------------
+
+our %opts;
+
+sub usage()
+{
+
+ print "\n";
+ print " Usage: matmul_gendata.pl [options] \n";
+ print "\n";
+ print " Options:\n";
+ print " --help print this message\n";
+ print " --size size of input data [1000]\n";
+ print " --seed random seed [1]\n";
+ print "$usageMsg";
+
+ exit();
+}
+
+sub processCommandLine()
+{
+
+ $opts{"help"} = 0;
+ $opts{"size"} = 1000;
+ $opts{"seed"} = 1;
+ Getopt::Long::GetOptions( \%opts, 'help|?', 'size:i', 'seed:i' ) or usage();
+ $opts{"help"} and usage();
+
+}
+
+#--------------------------------------------------------------------------
+# Helper Functions
+#--------------------------------------------------------------------------
+
+sub printArray
+{
+ my $arrayName = $_[0];
+ my $arrayRef = $_[1];
+
+ my $numCols = 20;
+ my $arrayLen = scalar(@{$arrayRef});
+
+ print "static data_t ".$arrayName."[ARRAY_SIZE] = \n";
+ print "{\n";
+
+ if ( $arrayLen <= $numCols ) {
+ print " ";
+ for ( my $i = 0; $i < $arrayLen; $i++ ) {
+ print sprintf("%3d",$arrayRef->[$i]);
+ if ( $i != $arrayLen-1 ) {
+ print ", ";
+ }
+ }
+ print "\n";
+ }
+
+ else {
+ my $numRows = int($arrayLen/$numCols);
+ for ( my $j = 0; $j < $numRows; $j++ ) {
+ print " ";
+ for ( my $i = 0; $i < $numCols; $i++ ) {
+ my $index = $j*$numCols + $i;
+ print sprintf("%3d",$arrayRef->[$index]);
+ if ( $index != $arrayLen-1 ) {
+ print ", ";
+ }
+ }
+ print "\n";
+ }
+
+ if ( $arrayLen > ($numRows*$numCols) ) {
+ print " ";
+ for ( my $i = 0; $i < ($arrayLen-($numRows*$numCols)); $i++ ) {
+ my $index = $numCols*$numRows + $i;
+ print sprintf("%3d",$arrayRef->[$index]);
+ if ( $index != $arrayLen-1 ) {
+ print ", ";
+ }
+ }
+ print "\n";
+ }
+
+ }
+
+ print "};\n\n";
+}
+
+
+
+#--------------------------------------------------------------------------
+# Matmul
+#--------------------------------------------------------------------------
+
+# http://answers.oreilly.com/topic/418-how-to-multiply-matrices-in-perl/
+
+sub mmult {
+ my ($m1,$m2) = @_;
+ my ($m1rows,$m1cols) = matdim($m1);
+ my ($m2rows,$m2cols) = matdim($m2);
+
+ my $result = [ ];
+ my ($i, $j, $k);
+
+ for $i (range($m1rows)) {
+ for $j (range($m2cols)) {
+ for $k (range($m1cols)) {
+ $result->[$i][$j] += $m1->[$i][$k] * $m2->[$k][$j];
+ }
+ }
+ }
+ return $result;
+}
+
+sub range { 0 .. ($_[0] - 1) }
+
+
+sub veclen {
+ my $ary_ref = $_[0];
+ my $type = ref $ary_ref;
+ if ($type ne "ARRAY") { die "$type is bad array ref for $ary_ref" }
+ return scalar(@$ary_ref);
+}
+
+sub matdim {
+ my $matrix = $_[0];
+ my $rows = veclen($matrix);
+ my $cols = veclen($matrix->[0]);
+ return ($rows, $cols);
+}
+
+#--------------------------------------------------------------------------
+# Main
+#--------------------------------------------------------------------------
+
+sub main()
+{
+
+ processCommandLine();
+ srand($opts{"seed"});
+
+ # create random input arrays
+ my $mat_values1;
+ my $mat_values2;
+ for ( my $i = 0; $i < $opts{"size"}; $i++ ) {
+ for ( my $j = 0; $j < $opts{"size"}; $j++ ) {
+ $mat_values1->[$i][$j] = int(rand(4));
+ $mat_values2->[$i][$j] = int(rand(4));
+ }
+ }
+
+ # perform matmul
+ my $mat_results = mmult( $mat_values1, $mat_values2 );
+
+ # translate 2d arrays to 1d-somethings (I don't know how to code in perl - Chris)
+ my @values1;
+ my @values2;
+ my @results;
+ for ( my $i = 0; $i < $opts{"size"}; $i++ ) {
+ for ( my $j = 0; $j < $opts{"size"}; $j++ ) {
+ my $value1 = $mat_values1->[$i][$j];
+ my $value2 = $mat_values2->[$i][$j];
+ my $result = $mat_results->[$i][$j];
+ push( @values1, $value1 );
+ push( @values2, $value2 );
+ push( @results, $result );
+ }
+ }
+
+ print "\n\#define ARRAY_SIZE ".($opts{"size"}*$opts{"size"})." \n\n";
+ print "\n\#define DIM_SIZE ".$opts{"size"}." \n\n";
+
+ printArray( "input1_data", \@values1 );
+ printArray( "input2_data", \@values2 );
+ printArray( "verify_data", \@results);
+
+}
+
+main();
+
--- /dev/null
+//**************************************************************************
+// Multi-threaded Matrix Multiply benchmark
+//--------------------------------------------------------------------------
+// TA : Christopher Celio
+// Student:
+//
+//
+// This benchmark multiplies two 2-D arrays together and writes the results to
+// a third vector. The input data (and reference data) should be generated
+// using the matmul_gendata.pl perl script and dumped to a file named
+// dataset.h.
+
+
+// print out arrays, etc.
+//#define DEBUG
+
+//--------------------------------------------------------------------------
+// Includes
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+//--------------------------------------------------------------------------
+// Input/Reference Data
+
+typedef float data_t;
+#include "dataset.h"
+
+
+//--------------------------------------------------------------------------
+// Basic Utilities and Multi-thread Support
+
+__thread unsigned long coreid;
+unsigned long ncores;
+
+#include "util.h"
+
+#define stringify_1(s) #s
+#define stringify(s) stringify_1(s)
+#define stats(code) do { \
+ unsigned long _c = -rdcycle(), _i = -rdinstret(); \
+ code; \
+ _c += rdcycle(), _i += rdinstret(); \
+ if (coreid == 0) \
+ printf("%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
+ stringify(code), _c, _c/DIM_SIZE/DIM_SIZE/DIM_SIZE, 10*_c/DIM_SIZE/DIM_SIZE/DIM_SIZE%10, _c/_i, 10*_c/_i%10); \
+ } while(0)
+
+
+//--------------------------------------------------------------------------
+// Helper functions
+
+void printArray( char name[], int n, data_t arr[] )
+{
+ int i;
+ if (coreid != 0)
+ return;
+
+ printf( " %10s :", name );
+ for ( i = 0; i < n; i++ )
+ printf( " %3ld ", (long) arr[i] );
+ printf( "\n" );
+}
+
+void __attribute__((noinline)) verify(size_t n, const data_t* test, const data_t* correct)
+{
+ if (coreid != 0)
+ return;
+
+ size_t i;
+ for (i = 0; i < n; i++)
+ {
+ if (test[i] != correct[i])
+ {
+ printf("FAILED test[%d]= %3ld, correct[%d]= %3ld\n",
+ i, (long)test[i], i, (long)correct[i]);
+ exit(-1);
+ }
+ }
+
+ return;
+}
+
+//--------------------------------------------------------------------------
+// matmul function
+
+// single-thread, naive version
+void __attribute__((noinline)) matmul_naive(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ int i, j, k;
+
+ if (coreid > 0)
+ return;
+
+ for ( i = 0; i < lda; i++ )
+ for ( j = 0; j < lda; j++ )
+ {
+ for ( k = 0; k < lda; k++ )
+ {
+ C[i + j*lda] += A[j*lda + k] * B[k*lda + i];
+ }
+ }
+
+}
+
+
+void __attribute__((noinline)) matmul(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+
+ data_t a1;
+ data_t a2;
+ data_t a3;
+ data_t a4;
+ data_t a5;
+ data_t a6;
+ data_t a7;
+ data_t a8;
+ data_t *b1;
+ data_t *b2;
+ data_t *b3;
+ data_t *b4;
+ data_t *b5;
+ data_t *b6;
+ data_t *b7;
+ data_t *b8;
+ data_t c1;
+ data_t c2;
+ data_t c3;
+ data_t c4;
+ data_t c5;
+ data_t c6;
+ data_t c7;
+ data_t c8;
+ int i, j, k;
+ int start, end;
+ static data_t BB[1024];
+
+
+ //transpose B
+ if (coreid == 0 | coreid == 1 ) {
+ for ( k = 0; k < lda; k++) {
+ for ( i = coreid*(lda/2); i < (coreid+1)*(lda/2); i++ ) {
+ BB[i*lda + k] = B[k*lda + i];
+ }
+ }
+ }
+ barrier();
+
+ for ( int x = 0; x < ncores; x++) {
+ //split the i values into two chunks so the threads don't interfere on the B loads
+ //this could be generalized if needed, but I won't bother since it would be tricky
+ //and we already know the size and numthreads
+ start = coreid == x ? 0 : 16;
+ end = coreid == x ? 16 : 32;
+ for ( i = start; i < end; i+=8 ) {
+ for ( j = coreid*(lda/ncores); j < (coreid+1)*(lda/ncores); j++ ) {
+ c1=0;c2=0;c3=0;c4=0;c5=0;c6=0;c7=0;c8=0;
+ b1 = &BB[(i+0)*lda];
+ b2 = &BB[(i+1)*lda];
+ b3 = &BB[(i+2)*lda];
+ b4 = &BB[(i+3)*lda];
+ b5 = &BB[(i+4)*lda];
+ b6 = &BB[(i+5)*lda];
+ b7 = &BB[(i+6)*lda];
+ b8 = &BB[(i+7)*lda];
+
+ for ( k = 0; k < lda; k+=8 ) {
+ a1 = A[j*lda + k+0];
+ a2 = A[j*lda + k+1];
+ a3 = A[j*lda + k+2];
+ a4 = A[j*lda + k+3];
+ a5 = A[j*lda + k+4];
+ a6 = A[j*lda + k+5];
+ a7 = A[j*lda + k+6];
+ a8 = A[j*lda + k+7];
+
+ c1 += a1 * b1[k+0];
+ c1 += a2 * b1[k+1];
+ c1 += a3 * b1[k+2];
+ c1 += a4 * b1[k+3];
+ c1 += a5 * b1[k+4];
+ c1 += a6 * b1[k+5];
+ c1 += a7 * b1[k+6];
+ c1 += a8 * b1[k+7];
+
+ c2 += a1 * b2[k+0];
+ c2 += a2 * b2[k+1];
+ c2 += a3 * b2[k+2];
+ c2 += a4 * b2[k+3];
+ c2 += a5 * b2[k+4];
+ c2 += a6 * b2[k+5];
+ c2 += a7 * b2[k+6];
+ c2 += a8 * b2[k+7];
+
+ c3 += a1 * b3[k+0];
+ c3 += a2 * b3[k+1];
+ c3 += a3 * b3[k+2];
+ c3 += a4 * b3[k+3];
+ c3 += a5 * b3[k+4];
+ c3 += a6 * b3[k+5];
+ c3 += a7 * b3[k+6];
+ c3 += a8 * b3[k+7];
+
+ c4 += a1 * b4[k+0];
+ c4 += a2 * b4[k+1];
+ c4 += a3 * b4[k+2];
+ c4 += a4 * b4[k+3];
+ c4 += a5 * b4[k+4];
+ c4 += a6 * b4[k+5];
+ c4 += a7 * b4[k+6];
+ c4 += a8 * b4[k+7];
+
+ c5 += a1 * b5[k+0];
+ c5 += a2 * b5[k+1];
+ c5 += a3 * b5[k+2];
+ c5 += a4 * b5[k+3];
+ c5 += a5 * b5[k+4];
+ c5 += a6 * b5[k+5];
+ c5 += a7 * b5[k+6];
+ c5 += a8 * b5[k+7];
+
+ c6 += a1 * b6[k+0];
+ c6 += a2 * b6[k+1];
+ c6 += a3 * b6[k+2];
+ c6 += a4 * b6[k+3];
+ c6 += a5 * b6[k+4];
+ c6 += a6 * b6[k+5];
+ c6 += a7 * b6[k+6];
+ c6 += a8 * b6[k+7];
+
+ c7 += a1 * b7[k+0];
+ c7 += a2 * b7[k+1];
+ c7 += a3 * b7[k+2];
+ c7 += a4 * b7[k+3];
+ c7 += a5 * b7[k+4];
+ c7 += a6 * b7[k+5];
+ c7 += a7 * b7[k+6];
+ c7 += a8 * b7[k+7];
+
+ c8 += a1 * b8[k+0];
+ c8 += a2 * b8[k+1];
+ c8 += a3 * b8[k+2];
+ c8 += a4 * b8[k+3];
+ c8 += a5 * b8[k+4];
+ c8 += a6 * b8[k+5];
+ c8 += a7 * b8[k+6];
+ c8 += a8 * b8[k+7];
+ }
+ C[i+0 + j*lda] += c1;
+ C[i+1 + j*lda] += c2;
+ C[i+2 + j*lda] += c3;
+ C[i+3 + j*lda] += c4;
+ C[i+4 + j*lda] += c5;
+ C[i+5 + j*lda] += c6;
+ C[i+6 + j*lda] += c7;
+ C[i+7 + j*lda] += c8;
+ }
+ }
+ }
+}
+
+//--------------------------------------------------------------------------
+// Main
+//
+// all threads start executing thread_entry(). Use their "coreid" to
+// differentiate between threads (each thread is running on a separate core).
+
+void thread_entry(int cid, int nc)
+{
+ coreid = cid;
+ ncores = nc;
+
+ // static allocates data in the binary, which is visible to both threads
+ static data_t results_data[ARRAY_SIZE];
+
+/*
+ // Execute the provided, naive matmul
+ barrier();
+ stats(matmul_naive(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+
+ // verify
+ verify(ARRAY_SIZE, results_data, verify_data);
+
+ // clear results from the first trial
+ size_t i;
+ if (coreid == 0)
+ for (i=0; i < ARRAY_SIZE; i++)
+ results_data[i] = 0;
+ barrier();
+*/
+
+
+ // Execute your faster matmul
+ barrier();
+ stats(matmul(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+#ifdef DEBUG
+ printArray("results:", ARRAY_SIZE, results_data);
+ printArray("verify :", ARRAY_SIZE, verify_data);
+#endif
+
+ // verify
+ verify(ARRAY_SIZE, results_data, verify_data);
+ barrier();
+
+ exit(0);
+}
+
--- /dev/null
+//**************************************************************************
+// Vector-vector add benchmark
+//--------------------------------------------------------------------------
+// Author : Andrew Waterman
+// TA : Christopher Celio
+// Student :
+//
+// This benchmark adds two vectors and writes the results to a
+// third vector. The input data (and reference data) should be
+// generated using the vvadd_gendata.pl perl script and dumped
+// to a file named dataset.h
+
+// to print out arrays, etc.
+//#define DEBUG
+
+//--------------------------------------------------------------------------
+// Includes
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+//--------------------------------------------------------------------------
+// Input/Reference Data
+
+typedef float data_t;
+#include "dataset.h"
+
+
+//--------------------------------------------------------------------------
+// Basic Utilities and Multi-thread Support
+
+__thread unsigned long coreid;
+unsigned long ncores;
+
+#include "util.h"
+
+#define stringify_1(s) #s
+#define stringify(s) stringify_1(s)
+#define stats(code) do { \
+ unsigned long _c = -rdcycle(), _i = -rdinstret(); \
+ code; \
+ _c += rdcycle(), _i += rdinstret(); \
+ if (coreid == 0) \
+ printf("%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
+ stringify(code), _c, _c/DATA_SIZE, 10*_c/DATA_SIZE%10, _c/_i, 10*_c/_i%10); \
+ } while(0)
+
+
+//--------------------------------------------------------------------------
+// Helper functions
+
+void printArray( char name[], int n, data_t arr[] )
+{
+ int i;
+ if (coreid != 0)
+ return;
+
+ printf( " %10s :", name );
+ for ( i = 0; i < n; i++ )
+ printf( " %4ld ", (long) arr[i] );
+ printf( "\n" );
+}
+
+void __attribute__((noinline)) verify(size_t n, const data_t* test, const data_t* correct)
+{
+ if (coreid != 0)
+ return;
+
+ size_t i;
+ for (i = 0; i < n; i++)
+ {
+ if (test[i] != correct[i])
+ {
+ printf("FAILED test[%d]= %4ld, correct[%d]= %4ld\n",
+ i, (long) test[i], i, (long)correct[i]);
+ exit(-1);
+ }
+ }
+
+ return;
+}
+
+//--------------------------------------------------------------------------
+// vvadd function
+
+//perform in-place vvadd
+void __attribute__((noinline)) vvadd(size_t n, data_t* __restrict__ x, const data_t* __restrict__ y)
+{
+ size_t i;
+
+ // interleave accesses
+ for (i = coreid; i < n; i+=ncores)
+ {
+ x[i] = x[i] + y[i];
+ }
+}
+
+void __attribute__((noinline)) vvadd_opt(size_t n, data_t* __restrict__ x, const data_t* __restrict__ y)
+{
+ // ***************************** //
+ // **** ADD YOUR CODE HERE ***** //
+ // ***************************** //
+
+ size_t i;
+
+ size_t sizepercore = n / ncores;
+ size_t start = coreid * sizepercore;
+ size_t end = (coreid + 1) * sizepercore;
+ for (i = start; i < end; i++)
+ {
+ x[i] = x[i] + y[i];
+ }
+
+
+
+}
+
+//--------------------------------------------------------------------------
+// Main
+//
+// all threads start executing thread_entry(). Use their "coreid" to
+// differentiate between threads (each thread is running on a separate core).
+
+void thread_entry(int cid, int nc)
+{
+ coreid = cid;
+ ncores = nc;
+
+ // static allocates data in the binary, which is visible to both threads
+ static data_t results_data[DATA_SIZE];
+
+ // because we're going to perform an in-place vvadd (and we're going to run
+ // it a couple of times) let's copy the input data to a temporary results
+ // array
+
+ size_t i;
+ if (coreid == 0)
+ {
+ for (i = 0; i < DATA_SIZE; i++)
+ results_data[i] = input1_data[i];
+ }
+
+
+ // Execute the provided, terrible vvadd
+ barrier();
+ stats(vvadd(DATA_SIZE, results_data, input2_data); barrier());
+
+
+ // verify
+ verify(DATA_SIZE, results_data, verify_data);
+
+ // reset results from the first trial
+ if (coreid == 0)
+ {
+ for (i=0; i < DATA_SIZE; i++)
+ results_data[i] = input1_data[i];
+ }
+ barrier();
+
+
+ // Execute your faster vvadd
+ barrier();
+ stats(vvadd_opt(DATA_SIZE, results_data, input2_data); barrier());
+
+#ifdef DEBUG
+ printArray("results: ", DATA_SIZE, results_data);
+ printArray("verify : ", DATA_SIZE, verify_data);
+#endif
+
+ // verify
+ verify(DATA_SIZE, results_data, verify_data);
+ barrier();
+
+ exit(0);
+}
+
--- /dev/null
+
+#define DATA_SIZE 1000
+
+static data_t input1_data[DATA_SIZE] =
+{
+ 0.00, 15.00, 10.00, 3.00, 14.00, 6.00, 2.00, 18.00, 11.00, 15.00, 11.00, 0.00, 17.00, 16.00, 7.00, 13.00, 18.00, 2.00, 2.00, 5.00,
+ 8.00, 5.00, 12.00, 14.00, 6.00, 12.00, 16.00, 7.00, 9.00, 17.00, 10.00, 10.00, 3.00, 5.00, 14.00, 11.00, 9.00, 12.00, 3.00, 1.00,
+ 5.00, 4.00, 6.00, 17.00, 17.00, 4.00, 17.00, 15.00, 17.00, 18.00, 3.00, 18.00, 10.00, 6.00, 12.00, 12.00, 3.00, 2.00, 16.00, 1.00,
+ 5.00, 6.00, 2.00, 17.00, 16.00, 5.00, 10.00, 18.00, 14.00, 4.00, 9.00, 9.00, 7.00, 4.00, 8.00, 13.00, 12.00, 6.00, 4.00, 17.00,
+ 5.00, 2.00, 11.00, 11.00, 7.00, 6.00, 8.00, 5.00, 6.00, 6.00, 11.00, 1.00, 18.00, 7.00, 6.00, 9.00, 10.00, 17.00, 14.00, 4.00,
+ 14.00, 11.00, 2.00, 0.00, 2.00, 17.00, 17.00, 15.00, 10.00, 8.00, 12.00, 18.00, 5.00, 0.00, 0.00, 1.00, 1.00, 8.00, 11.00, 11.00,
+ 7.00, 5.00, 15.00, 18.00, 15.00, 6.00, 8.00, 9.00, 18.00, 6.00, 15.00, 16.00, 10.00, 18.00, 13.00, 6.00, 10.00, 16.00, 0.00, 10.00,
+ 12.00, 8.00, 8.00, 3.00, 0.00, 1.00, 4.00, 0.00, 8.00, 15.00, 16.00, 9.00, 7.00, 7.00, 10.00, 9.00, 16.00, 12.00, 5.00, 5.00,
+ 9.00, 5.00, 17.00, 4.00, 13.00, 13.00, 4.00, 14.00, 10.00, 5.00, 10.00, 10.00, 6.00, 18.00, 5.00, 15.00, 5.00, 15.00, 13.00, 18.00,
+ 6.00, 13.00, 5.00, 18.00, 12.00, 14.00, 1.00, 7.00, 2.00, 1.00, 7.00, 12.00, 15.00, 15.00, 6.00, 2.00, 1.00, 2.00, 18.00, 6.00,
+ 10.00, 14.00, 9.00, 15.00, 11.00, 0.00, 3.00, 1.00, 2.00, 2.00, 14.00, 7.00, 18.00, 0.00, 2.00, 2.00, 16.00, 8.00, 4.00, 5.00,
+ 7.00, 11.00, 7.00, 10.00, 14.00, 10.00, 3.00, 0.00, 13.00, 9.00, 14.00, 0.00, 14.00, 1.00, 3.00, 16.00, 2.00, 14.00, 6.00, 17.00,
+ 17.00, 6.00, 9.00, 8.00, 9.00, 12.00, 5.00, 14.00, 2.00, 16.00, 17.00, 5.00, 4.00, 0.00, 14.00, 10.00, 6.00, 15.00, 15.00, 14.00,
+ 5.00, 1.00, 8.00, 8.00, 13.00, 8.00, 0.00, 4.00, 7.00, 9.00, 13.00, 16.00, 9.00, 14.00, 9.00, 13.00, 0.00, 7.00, 16.00, 17.00,
+ 18.00, 10.00, 13.00, 8.00, 4.00, 9.00, 13.00, 0.00, 6.00, 4.00, 6.00, 4.00, 10.00, 14.00, 14.00, 9.00, 15.00, 15.00, 3.00, 3.00,
+ 12.00, 0.00, 3.00, 2.00, 16.00, 1.00, 7.00, 2.00, 16.00, 2.00, 2.00, 0.00, 14.00, 3.00, 3.00, 10.00, 4.00, 10.00, 3.00, 4.00,
+ 13.00, 14.00, 13.00, 0.00, 1.00, 15.00, 16.00, 9.00, 7.00, 9.00, 0.00, 11.00, 1.00, 1.00, 15.00, 17.00, 12.00, 16.00, 15.00, 4.00,
+ 8.00, 2.00, 10.00, 10.00, 0.00, 18.00, 17.00, 7.00, 7.00, 2.00, 10.00, 17.00, 9.00, 7.00, 5.00, 3.00, 8.00, 11.00, 6.00, 9.00,
+ 13.00, 0.00, 3.00, 5.00, 2.00, 5.00, 7.00, 4.00, 9.00, 2.00, 13.00, 17.00, 14.00, 12.00, 1.00, 3.00, 7.00, 17.00, 0.00, 14.00,
+ 16.00, 2.00, 2.00, 1.00, 2.00, 15.00, 16.00, 8.00, 2.00, 4.00, 15.00, 15.00, 10.00, 6.00, 11.00, 9.00, 15.00, 17.00, 3.00, 8.00,
+ 15.00, 3.00, 10.00, 15.00, 8.00, 14.00, 16.00, 15.00, 15.00, 14.00, 1.00, 7.00, 4.00, 18.00, 2.00, 13.00, 11.00, 15.00, 7.00, 10.00,
+ 13.00, 10.00, 7.00, 14.00, 18.00, 4.00, 18.00, 4.00, 3.00, 9.00, 1.00, 13.00, 15.00, 2.00, 5.00, 15.00, 12.00, 10.00, 2.00, 0.00,
+ 10.00, 15.00, 0.00, 11.00, 14.00, 11.00, 14.00, 9.00, 1.00, 18.00, 14.00, 18.00, 15.00, 5.00, 1.00, 15.00, 18.00, 14.00, 3.00, 15.00,
+ 11.00, 2.00, 15.00, 0.00, 13.00, 1.00, 4.00, 14.00, 14.00, 5.00, 2.00, 13.00, 17.00, 8.00, 7.00, 6.00, 5.00, 10.00, 14.00, 14.00,
+ 17.00, 0.00, 0.00, 17.00, 18.00, 15.00, 10.00, 16.00, 18.00, 5.00, 9.00, 10.00, 18.00, 7.00, 11.00, 5.00, 4.00, 16.00, 2.00, 8.00,
+ 13.00, 1.00, 12.00, 3.00, 4.00, 6.00, 15.00, 12.00, 0.00, 6.00, 18.00, 12.00, 14.00, 18.00, 3.00, 2.00, 3.00, 5.00, 3.00, 14.00,
+ 18.00, 12.00, 10.00, 11.00, 8.00, 4.00, 10.00, 10.00, 9.00, 18.00, 14.00, 3.00, 7.00, 17.00, 12.00, 0.00, 10.00, 9.00, 17.00, 3.00,
+ 0.00, 4.00, 6.00, 16.00, 14.00, 12.00, 13.00, 13.00, 18.00, 7.00, 0.00, 1.00, 9.00, 7.00, 12.00, 6.00, 18.00, 8.00, 9.00, 13.00,
+ 13.00, 17.00, 10.00, 16.00, 1.00, 10.00, 17.00, 16.00, 2.00, 18.00, 4.00, 2.00, 6.00, 1.00, 1.00, 1.00, 8.00, 14.00, 6.00, 6.00,
+ 13.00, 14.00, 13.00, 6.00, 5.00, 10.00, 11.00, 11.00, 16.00, 1.00, 5.00, 9.00, 13.00, 8.00, 10.00, 2.00, 12.00, 15.00, 5.00, 14.00,
+ 3.00, 7.00, 9.00, 18.00, 2.00, 11.00, 16.00, 4.00, 5.00, 10.00, 17.00, 10.00, 3.00, 4.00, 14.00, 18.00, 13.00, 6.00, 8.00, 11.00,
+ 14.00, 3.00, 5.00, 6.00, 6.00, 5.00, 13.00, 0.00, 9.00, 9.00, 1.00, 7.00, 5.00, 5.00, 1.00, 6.00, 18.00, 11.00, 17.00, 7.00,
+ 1.00, 10.00, 5.00, 12.00, 6.00, 16.00, 16.00, 5.00, 1.00, 10.00, 10.00, 15.00, 7.00, 18.00, 8.00, 17.00, 3.00, 5.00, 3.00, 14.00,
+ 0.00, 16.00, 12.00, 0.00, 14.00, 17.00, 16.00, 2.00, 18.00, 13.00, 10.00, 13.00, 4.00, 14.00, 2.00, 3.00, 4.00, 8.00, 17.00, 0.00,
+ 6.00, 11.00, 5.00, 3.00, 3.00, 2.00, 15.00, 13.00, 10.00, 4.00, 1.00, 11.00, 6.00, 17.00, 1.00, 0.00, 18.00, 3.00, 3.00, 11.00,
+ 7.00, 7.00, 11.00, 14.00, 7.00, 16.00, 11.00, 10.00, 8.00, 6.00, 11.00, 5.00, 17.00, 10.00, 7.00, 8.00, 14.00, 2.00, 9.00, 17.00,
+ 15.00, 13.00, 10.00, 6.00, 0.00, 15.00, 11.00, 10.00, 11.00, 18.00, 2.00, 5.00, 17.00, 18.00, 11.00, 15.00, 3.00, 17.00, 9.00, 17.00,
+ 8.00, 6.00, 2.00, 4.00, 2.00, 11.00, 15.00, 2.00, 18.00, 3.00, 9.00, 7.00, 15.00, 9.00, 14.00, 10.00, 9.00, 6.00, 13.00, 8.00,
+ 15.00, 14.00, 0.00, 11.00, 5.00, 2.00, 12.00, 14.00, 10.00, 16.00, 9.00, 7.00, 9.00, 17.00, 4.00, 4.00, 7.00, 8.00, 4.00, 4.00,
+ 9.00, 7.00, 3.00, 5.00, 11.00, 11.00, 10.00, 13.00, 3.00, 14.00, 15.00, 8.00, 1.00, 1.00, 3.00, 0.00, 16.00, 9.00, 6.00, 1.00,
+ 0.00, 2.00, 0.00, 6.00, 13.00, 12.00, 5.00, 18.00, 1.00, 11.00, 17.00, 11.00, 16.00, 14.00, 14.00, 9.00, 11.00, 9.00, 17.00, 15.00,
+ 5.00, 18.00, 2.00, 11.00, 10.00, 16.00, 18.00, 5.00, 11.00, 12.00, 11.00, 18.00, 7.00, 6.00, 8.00, 3.00, 4.00, 3.00, 16.00, 4.00,
+ 6.00, 2.00, 15.00, 6.00, 7.00, 16.00, 0.00, 7.00, 11.00, 10.00, 3.00, 0.00, 14.00, 16.00, 15.00, 15.00, 12.00, 7.00, 1.00, 4.00,
+ 8.00, 4.00, 12.00, 0.00, 7.00, 8.00, 1.00, 1.00, 14.00, 15.00, 9.00, 8.00, 6.00, 6.00, 4.00, 7.00, 8.00, 13.00, 10.00, 5.00,
+ 8.00, 11.00, 2.00, 16.00, 7.00, 17.00, 5.00, 2.00, 17.00, 0.00, 18.00, 6.00, 7.00, 4.00, 4.00, 12.00, 0.00, 18.00, 8.00, 4.00,
+ 7.00, 0.00, 11.00, 1.00, 11.00, 17.00, 18.00, 15.00, 8.00, 11.00, 15.00, 9.00, 12.00, 1.00, 5.00, 6.00, 1.00, 18.00, 14.00, 7.00,
+ 16.00, 16.00, 10.00, 3.00, 13.00, 0.00, 12.00, 9.00, 18.00, 14.00, 15.00, 4.00, 11.00, 15.00, 15.00, 8.00, 16.00, 11.00, 13.00, 12.00,
+ 1.00, 13.00, 14.00, 2.00, 11.00, 0.00, 17.00, 11.00, 12.00, 6.00, 4.00, 4.00, 11.00, 13.00, 10.00, 2.00, 10.00, 14.00, 0.00, 6.00,
+ 18.00, 10.00, 7.00, 14.00, 12.00, 9.00, 4.00, 16.00, 17.00, 8.00, 14.00, 9.00, 0.00, 4.00, 15.00, 13.00, 8.00, 13.00, 13.00, 8.00,
+ 15.00, 6.00, 11.00, 4.00, 2.00, 6.00, 5.00, 14.00, 5.00, 17.00, 12.00, 11.00, 17.00, 4.00, 13.00, 7.00, 16.00, 12.00, 7.00, 18.00
+};
+
+static data_t input2_data[DATA_SIZE] =
+{
+ 8.00, 6.00, 0.00, 18.00, 6.00, 10.00, 1.00, 2.00, 4.00, 2.00, 4.00, 10.00, 6.00, 11.00, 17.00, 4.00, 0.00, 16.00, 14.00, 12.00,
+ 9.00, 8.00, 13.00, 15.00, 18.00, 2.00, 13.00, 10.00, 5.00, 4.00, 12.00, 9.00, 1.00, 13.00, 12.00, 7.00, 10.00, 17.00, 11.00, 10.00,
+ 18.00, 15.00, 11.00, 12.00, 7.00, 9.00, 6.00, 5.00, 11.00, 7.00, 10.00, 12.00, 18.00, 18.00, 15.00, 1.00, 3.00, 18.00, 11.00, 16.00,
+ 13.00, 18.00, 4.00, 13.00, 8.00, 7.00, 10.00, 13.00, 0.00, 9.00, 1.00, 16.00, 13.00, 7.00, 5.00, 5.00, 11.00, 1.00, 6.00, 10.00,
+ 12.00, 3.00, 10.00, 5.00, 15.00, 15.00, 13.00, 14.00, 14.00, 1.00, 18.00, 5.00, 16.00, 14.00, 10.00, 4.00, 8.00, 4.00, 6.00, 6.00,
+ 13.00, 14.00, 8.00, 5.00, 14.00, 10.00, 9.00, 10.00, 17.00, 15.00, 6.00, 16.00, 12.00, 9.00, 10.00, 16.00, 16.00, 8.00, 1.00, 12.00,
+ 7.00, 0.00, 0.00, 3.00, 5.00, 7.00, 10.00, 3.00, 17.00, 10.00, 18.00, 16.00, 1.00, 11.00, 18.00, 9.00, 2.00, 0.00, 12.00, 6.00,
+ 13.00, 1.00, 13.00, 5.00, 7.00, 13.00, 17.00, 9.00, 15.00, 13.00, 5.00, 2.00, 4.00, 4.00, 3.00, 0.00, 9.00, 11.00, 3.00, 12.00,
+ 6.00, 11.00, 1.00, 16.00, 12.00, 11.00, 2.00, 2.00, 15.00, 12.00, 8.00, 9.00, 14.00, 2.00, 11.00, 0.00, 0.00, 7.00, 2.00, 13.00,
+ 15.00, 18.00, 7.00, 16.00, 16.00, 1.00, 1.00, 12.00, 12.00, 2.00, 2.00, 1.00, 7.00, 4.00, 0.00, 8.00, 18.00, 4.00, 11.00, 6.00,
+ 17.00, 13.00, 12.00, 5.00, 16.00, 12.00, 0.00, 9.00, 10.00, 10.00, 18.00, 12.00, 8.00, 7.00, 5.00, 8.00, 16.00, 3.00, 9.00, 18.00,
+ 12.00, 13.00, 18.00, 6.00, 8.00, 12.00, 2.00, 12.00, 8.00, 8.00, 9.00, 18.00, 8.00, 0.00, 9.00, 2.00, 6.00, 7.00, 0.00, 3.00,
+ 11.00, 2.00, 18.00, 2.00, 16.00, 1.00, 16.00, 11.00, 11.00, 16.00, 16.00, 11.00, 7.00, 4.00, 14.00, 10.00, 5.00, 8.00, 4.00, 14.00,
+ 17.00, 13.00, 13.00, 3.00, 1.00, 14.00, 1.00, 7.00, 0.00, 2.00, 7.00, 14.00, 4.00, 9.00, 14.00, 3.00, 9.00, 13.00, 13.00, 3.00,
+ 3.00, 17.00, 0.00, 18.00, 4.00, 8.00, 6.00, 9.00, 4.00, 2.00, 0.00, 14.00, 3.00, 3.00, 14.00, 8.00, 6.00, 7.00, 2.00, 12.00,
+ 5.00, 14.00, 6.00, 12.00, 2.00, 16.00, 1.00, 15.00, 7.00, 18.00, 0.00, 0.00, 13.00, 13.00, 12.00, 11.00, 16.00, 15.00, 14.00, 8.00,
+ 9.00, 10.00, 8.00, 8.00, 13.00, 13.00, 13.00, 10.00, 1.00, 15.00, 4.00, 0.00, 12.00, 1.00, 8.00, 12.00, 1.00, 18.00, 12.00, 18.00,
+ 9.00, 1.00, 11.00, 5.00, 13.00, 7.00, 1.00, 13.00, 5.00, 8.00, 17.00, 11.00, 13.00, 15.00, 9.00, 3.00, 17.00, 18.00, 9.00, 3.00,
+ 15.00, 11.00, 12.00, 0.00, 2.00, 15.00, 3.00, 0.00, 13.00, 1.00, 14.00, 14.00, 15.00, 8.00, 6.00, 0.00, 0.00, 11.00, 17.00, 0.00,
+ 1.00, 8.00, 6.00, 6.00, 10.00, 6.00, 18.00, 12.00, 7.00, 18.00, 4.00, 6.00, 15.00, 18.00, 7.00, 5.00, 8.00, 6.00, 6.00, 7.00,
+ 4.00, 4.00, 10.00, 17.00, 12.00, 13.00, 11.00, 15.00, 12.00, 18.00, 7.00, 12.00, 17.00, 10.00, 14.00, 12.00, 2.00, 7.00, 17.00, 3.00,
+ 8.00, 6.00, 3.00, 9.00, 3.00, 7.00, 7.00, 15.00, 18.00, 5.00, 13.00, 13.00, 15.00, 10.00, 0.00, 11.00, 10.00, 1.00, 5.00, 16.00,
+ 2.00, 7.00, 14.00, 12.00, 7.00, 17.00, 17.00, 11.00, 0.00, 5.00, 16.00, 14.00, 1.00, 9.00, 8.00, 8.00, 3.00, 17.00, 0.00, 8.00,
+ 6.00, 5.00, 7.00, 6.00, 17.00, 3.00, 3.00, 8.00, 3.00, 12.00, 17.00, 5.00, 14.00, 3.00, 11.00, 5.00, 17.00, 2.00, 15.00, 1.00,
+ 18.00, 11.00, 12.00, 0.00, 0.00, 14.00, 7.00, 17.00, 15.00, 10.00, 18.00, 10.00, 11.00, 7.00, 12.00, 10.00, 17.00, 2.00, 18.00, 9.00,
+ 11.00, 4.00, 17.00, 10.00, 15.00, 12.00, 4.00, 1.00, 5.00, 10.00, 4.00, 2.00, 11.00, 3.00, 4.00, 15.00, 16.00, 10.00, 2.00, 2.00,
+ 15.00, 16.00, 0.00, 13.00, 16.00, 9.00, 1.00, 7.00, 3.00, 10.00, 7.00, 2.00, 12.00, 8.00, 1.00, 5.00, 0.00, 16.00, 4.00, 14.00,
+ 13.00, 16.00, 3.00, 0.00, 10.00, 6.00, 3.00, 9.00, 1.00, 3.00, 0.00, 13.00, 12.00, 17.00, 11.00, 4.00, 15.00, 15.00, 12.00, 4.00,
+ 4.00, 2.00, 16.00, 6.00, 11.00, 17.00, 14.00, 7.00, 4.00, 14.00, 8.00, 8.00, 3.00, 18.00, 17.00, 17.00, 12.00, 10.00, 11.00, 1.00,
+ 8.00, 13.00, 1.00, 14.00, 0.00, 9.00, 0.00, 7.00, 9.00, 0.00, 7.00, 12.00, 0.00, 18.00, 10.00, 1.00, 5.00, 13.00, 13.00, 2.00,
+ 10.00, 4.00, 2.00, 6.00, 0.00, 16.00, 2.00, 15.00, 13.00, 6.00, 8.00, 5.00, 6.00, 15.00, 12.00, 6.00, 6.00, 7.00, 8.00, 1.00,
+ 11.00, 9.00, 7.00, 18.00, 14.00, 4.00, 9.00, 6.00, 4.00, 2.00, 10.00, 13.00, 6.00, 17.00, 2.00, 11.00, 7.00, 3.00, 8.00, 9.00,
+ 2.00, 6.00, 18.00, 12.00, 18.00, 13.00, 8.00, 1.00, 11.00, 4.00, 13.00, 14.00, 16.00, 8.00, 6.00, 18.00, 14.00, 15.00, 9.00, 11.00,
+ 2.00, 13.00, 4.00, 3.00, 3.00, 15.00, 14.00, 3.00, 13.00, 12.00, 14.00, 16.00, 18.00, 12.00, 5.00, 11.00, 2.00, 3.00, 15.00, 1.00,
+ 12.00, 1.00, 15.00, 13.00, 12.00, 18.00, 4.00, 17.00, 13.00, 7.00, 11.00, 13.00, 7.00, 10.00, 1.00, 3.00, 18.00, 6.00, 10.00, 3.00,
+ 9.00, 16.00, 12.00, 10.00, 6.00, 6.00, 7.00, 16.00, 16.00, 16.00, 17.00, 18.00, 8.00, 18.00, 0.00, 6.00, 17.00, 13.00, 14.00, 8.00,
+ 0.00, 7.00, 5.00, 13.00, 8.00, 12.00, 14.00, 9.00, 10.00, 10.00, 9.00, 9.00, 8.00, 6.00, 0.00, 14.00, 16.00, 8.00, 7.00, 16.00,
+ 10.00, 3.00, 1.00, 9.00, 11.00, 2.00, 6.00, 18.00, 5.00, 4.00, 2.00, 11.00, 10.00, 17.00, 16.00, 2.00, 12.00, 15.00, 14.00, 6.00,
+ 6.00, 17.00, 3.00, 10.00, 9.00, 18.00, 18.00, 6.00, 11.00, 16.00, 18.00, 17.00, 7.00, 14.00, 1.00, 16.00, 7.00, 9.00, 11.00, 12.00,
+ 10.00, 6.00, 1.00, 16.00, 9.00, 18.00, 0.00, 9.00, 16.00, 10.00, 14.00, 6.00, 9.00, 14.00, 15.00, 7.00, 12.00, 8.00, 1.00, 1.00,
+ 1.00, 17.00, 17.00, 17.00, 18.00, 1.00, 15.00, 18.00, 16.00, 16.00, 11.00, 7.00, 4.00, 15.00, 3.00, 14.00, 13.00, 14.00, 9.00, 2.00,
+ 4.00, 8.00, 14.00, 7.00, 0.00, 12.00, 14.00, 15.00, 8.00, 2.00, 11.00, 5.00, 6.00, 16.00, 6.00, 4.00, 16.00, 7.00, 9.00, 5.00,
+ 1.00, 0.00, 16.00, 10.00, 9.00, 6.00, 5.00, 8.00, 15.00, 13.00, 7.00, 18.00, 18.00, 8.00, 0.00, 15.00, 4.00, 6.00, 14.00, 3.00,
+ 3.00, 2.00, 9.00, 14.00, 18.00, 13.00, 10.00, 15.00, 0.00, 11.00, 16.00, 7.00, 16.00, 18.00, 0.00, 12.00, 6.00, 13.00, 12.00, 12.00,
+ 5.00, 3.00, 5.00, 16.00, 13.00, 16.00, 8.00, 5.00, 12.00, 8.00, 8.00, 0.00, 2.00, 9.00, 18.00, 11.00, 8.00, 4.00, 14.00, 6.00,
+ 17.00, 2.00, 6.00, 8.00, 11.00, 13.00, 6.00, 18.00, 17.00, 6.00, 8.00, 0.00, 1.00, 14.00, 18.00, 4.00, 0.00, 4.00, 3.00, 3.00,
+ 16.00, 8.00, 16.00, 1.00, 2.00, 0.00, 15.00, 14.00, 10.00, 9.00, 15.00, 3.00, 5.00, 18.00, 5.00, 6.00, 7.00, 3.00, 7.00, 2.00,
+ 6.00, 12.00, 10.00, 10.00, 18.00, 16.00, 0.00, 9.00, 17.00, 10.00, 9.00, 14.00, 15.00, 5.00, 8.00, 15.00, 3.00, 15.00, 14.00, 11.00,
+ 6.00, 6.00, 14.00, 0.00, 14.00, 0.00, 7.00, 12.00, 8.00, 7.00, 1.00, 3.00, 6.00, 10.00, 12.00, 1.00, 16.00, 5.00, 5.00, 6.00,
+ 17.00, 15.00, 15.00, 9.00, 4.00, 18.00, 17.00, 13.00, 12.00, 9.00, 7.00, 10.00, 2.00, 5.00, 8.00, 18.00, 1.00, 15.00, 8.00, 0.00
+};
+
+static data_t verify_data[DATA_SIZE] =
+{
+ 8.00, 21.00, 10.00, 21.00, 20.00, 16.00, 3.00, 20.00, 15.00, 17.00, 15.00, 10.00, 23.00, 27.00, 24.00, 17.00, 18.00, 18.00, 16.00, 17.00,
+ 17.00, 13.00, 25.00, 29.00, 24.00, 14.00, 29.00, 17.00, 14.00, 21.00, 22.00, 19.00, 4.00, 18.00, 26.00, 18.00, 19.00, 29.00, 14.00, 11.00,
+ 23.00, 19.00, 17.00, 29.00, 24.00, 13.00, 23.00, 20.00, 28.00, 25.00, 13.00, 30.00, 28.00, 24.00, 27.00, 13.00, 6.00, 20.00, 27.00, 17.00,
+ 18.00, 24.00, 6.00, 30.00, 24.00, 12.00, 20.00, 31.00, 14.00, 13.00, 10.00, 25.00, 20.00, 11.00, 13.00, 18.00, 23.00, 7.00, 10.00, 27.00,
+ 17.00, 5.00, 21.00, 16.00, 22.00, 21.00, 21.00, 19.00, 20.00, 7.00, 29.00, 6.00, 34.00, 21.00, 16.00, 13.00, 18.00, 21.00, 20.00, 10.00,
+ 27.00, 25.00, 10.00, 5.00, 16.00, 27.00, 26.00, 25.00, 27.00, 23.00, 18.00, 34.00, 17.00, 9.00, 10.00, 17.00, 17.00, 16.00, 12.00, 23.00,
+ 14.00, 5.00, 15.00, 21.00, 20.00, 13.00, 18.00, 12.00, 35.00, 16.00, 33.00, 32.00, 11.00, 29.00, 31.00, 15.00, 12.00, 16.00, 12.00, 16.00,
+ 25.00, 9.00, 21.00, 8.00, 7.00, 14.00, 21.00, 9.00, 23.00, 28.00, 21.00, 11.00, 11.00, 11.00, 13.00, 9.00, 25.00, 23.00, 8.00, 17.00,
+ 15.00, 16.00, 18.00, 20.00, 25.00, 24.00, 6.00, 16.00, 25.00, 17.00, 18.00, 19.00, 20.00, 20.00, 16.00, 15.00, 5.00, 22.00, 15.00, 31.00,
+ 21.00, 31.00, 12.00, 34.00, 28.00, 15.00, 2.00, 19.00, 14.00, 3.00, 9.00, 13.00, 22.00, 19.00, 6.00, 10.00, 19.00, 6.00, 29.00, 12.00,
+ 27.00, 27.00, 21.00, 20.00, 27.00, 12.00, 3.00, 10.00, 12.00, 12.00, 32.00, 19.00, 26.00, 7.00, 7.00, 10.00, 32.00, 11.00, 13.00, 23.00,
+ 19.00, 24.00, 25.00, 16.00, 22.00, 22.00, 5.00, 12.00, 21.00, 17.00, 23.00, 18.00, 22.00, 1.00, 12.00, 18.00, 8.00, 21.00, 6.00, 20.00,
+ 28.00, 8.00, 27.00, 10.00, 25.00, 13.00, 21.00, 25.00, 13.00, 32.00, 33.00, 16.00, 11.00, 4.00, 28.00, 20.00, 11.00, 23.00, 19.00, 28.00,
+ 22.00, 14.00, 21.00, 11.00, 14.00, 22.00, 1.00, 11.00, 7.00, 11.00, 20.00, 30.00, 13.00, 23.00, 23.00, 16.00, 9.00, 20.00, 29.00, 20.00,
+ 21.00, 27.00, 13.00, 26.00, 8.00, 17.00, 19.00, 9.00, 10.00, 6.00, 6.00, 18.00, 13.00, 17.00, 28.00, 17.00, 21.00, 22.00, 5.00, 15.00,
+ 17.00, 14.00, 9.00, 14.00, 18.00, 17.00, 8.00, 17.00, 23.00, 20.00, 2.00, 0.00, 27.00, 16.00, 15.00, 21.00, 20.00, 25.00, 17.00, 12.00,
+ 22.00, 24.00, 21.00, 8.00, 14.00, 28.00, 29.00, 19.00, 8.00, 24.00, 4.00, 11.00, 13.00, 2.00, 23.00, 29.00, 13.00, 34.00, 27.00, 22.00,
+ 17.00, 3.00, 21.00, 15.00, 13.00, 25.00, 18.00, 20.00, 12.00, 10.00, 27.00, 28.00, 22.00, 22.00, 14.00, 6.00, 25.00, 29.00, 15.00, 12.00,
+ 28.00, 11.00, 15.00, 5.00, 4.00, 20.00, 10.00, 4.00, 22.00, 3.00, 27.00, 31.00, 29.00, 20.00, 7.00, 3.00, 7.00, 28.00, 17.00, 14.00,
+ 17.00, 10.00, 8.00, 7.00, 12.00, 21.00, 34.00, 20.00, 9.00, 22.00, 19.00, 21.00, 25.00, 24.00, 18.00, 14.00, 23.00, 23.00, 9.00, 15.00,
+ 19.00, 7.00, 20.00, 32.00, 20.00, 27.00, 27.00, 30.00, 27.00, 32.00, 8.00, 19.00, 21.00, 28.00, 16.00, 25.00, 13.00, 22.00, 24.00, 13.00,
+ 21.00, 16.00, 10.00, 23.00, 21.00, 11.00, 25.00, 19.00, 21.00, 14.00, 14.00, 26.00, 30.00, 12.00, 5.00, 26.00, 22.00, 11.00, 7.00, 16.00,
+ 12.00, 22.00, 14.00, 23.00, 21.00, 28.00, 31.00, 20.00, 1.00, 23.00, 30.00, 32.00, 16.00, 14.00, 9.00, 23.00, 21.00, 31.00, 3.00, 23.00,
+ 17.00, 7.00, 22.00, 6.00, 30.00, 4.00, 7.00, 22.00, 17.00, 17.00, 19.00, 18.00, 31.00, 11.00, 18.00, 11.00, 22.00, 12.00, 29.00, 15.00,
+ 35.00, 11.00, 12.00, 17.00, 18.00, 29.00, 17.00, 33.00, 33.00, 15.00, 27.00, 20.00, 29.00, 14.00, 23.00, 15.00, 21.00, 18.00, 20.00, 17.00,
+ 24.00, 5.00, 29.00, 13.00, 19.00, 18.00, 19.00, 13.00, 5.00, 16.00, 22.00, 14.00, 25.00, 21.00, 7.00, 17.00, 19.00, 15.00, 5.00, 16.00,
+ 33.00, 28.00, 10.00, 24.00, 24.00, 13.00, 11.00, 17.00, 12.00, 28.00, 21.00, 5.00, 19.00, 25.00, 13.00, 5.00, 10.00, 25.00, 21.00, 17.00,
+ 13.00, 20.00, 9.00, 16.00, 24.00, 18.00, 16.00, 22.00, 19.00, 10.00, 0.00, 14.00, 21.00, 24.00, 23.00, 10.00, 33.00, 23.00, 21.00, 17.00,
+ 17.00, 19.00, 26.00, 22.00, 12.00, 27.00, 31.00, 23.00, 6.00, 32.00, 12.00, 10.00, 9.00, 19.00, 18.00, 18.00, 20.00, 24.00, 17.00, 7.00,
+ 21.00, 27.00, 14.00, 20.00, 5.00, 19.00, 11.00, 18.00, 25.00, 1.00, 12.00, 21.00, 13.00, 26.00, 20.00, 3.00, 17.00, 28.00, 18.00, 16.00,
+ 13.00, 11.00, 11.00, 24.00, 2.00, 27.00, 18.00, 19.00, 18.00, 16.00, 25.00, 15.00, 9.00, 19.00, 26.00, 24.00, 19.00, 13.00, 16.00, 12.00,
+ 25.00, 12.00, 12.00, 24.00, 20.00, 9.00, 22.00, 6.00, 13.00, 11.00, 11.00, 20.00, 11.00, 22.00, 3.00, 17.00, 25.00, 14.00, 25.00, 16.00,
+ 3.00, 16.00, 23.00, 24.00, 24.00, 29.00, 24.00, 6.00, 12.00, 14.00, 23.00, 29.00, 23.00, 26.00, 14.00, 35.00, 17.00, 20.00, 12.00, 25.00,
+ 2.00, 29.00, 16.00, 3.00, 17.00, 32.00, 30.00, 5.00, 31.00, 25.00, 24.00, 29.00, 22.00, 26.00, 7.00, 14.00, 6.00, 11.00, 32.00, 1.00,
+ 18.00, 12.00, 20.00, 16.00, 15.00, 20.00, 19.00, 30.00, 23.00, 11.00, 12.00, 24.00, 13.00, 27.00, 2.00, 3.00, 36.00, 9.00, 13.00, 14.00,
+ 16.00, 23.00, 23.00, 24.00, 13.00, 22.00, 18.00, 26.00, 24.00, 22.00, 28.00, 23.00, 25.00, 28.00, 7.00, 14.00, 31.00, 15.00, 23.00, 25.00,
+ 15.00, 20.00, 15.00, 19.00, 8.00, 27.00, 25.00, 19.00, 21.00, 28.00, 11.00, 14.00, 25.00, 24.00, 11.00, 29.00, 19.00, 25.00, 16.00, 33.00,
+ 18.00, 9.00, 3.00, 13.00, 13.00, 13.00, 21.00, 20.00, 23.00, 7.00, 11.00, 18.00, 25.00, 26.00, 30.00, 12.00, 21.00, 21.00, 27.00, 14.00,
+ 21.00, 31.00, 3.00, 21.00, 14.00, 20.00, 30.00, 20.00, 21.00, 32.00, 27.00, 24.00, 16.00, 31.00, 5.00, 20.00, 14.00, 17.00, 15.00, 16.00,
+ 19.00, 13.00, 4.00, 21.00, 20.00, 29.00, 10.00, 22.00, 19.00, 24.00, 29.00, 14.00, 10.00, 15.00, 18.00, 7.00, 28.00, 17.00, 7.00, 2.00,
+ 1.00, 19.00, 17.00, 23.00, 31.00, 13.00, 20.00, 36.00, 17.00, 27.00, 28.00, 18.00, 20.00, 29.00, 17.00, 23.00, 24.00, 23.00, 26.00, 17.00,
+ 9.00, 26.00, 16.00, 18.00, 10.00, 28.00, 32.00, 20.00, 19.00, 14.00, 22.00, 23.00, 13.00, 22.00, 14.00, 7.00, 20.00, 10.00, 25.00, 9.00,
+ 7.00, 2.00, 31.00, 16.00, 16.00, 22.00, 5.00, 15.00, 26.00, 23.00, 10.00, 18.00, 32.00, 24.00, 15.00, 30.00, 16.00, 13.00, 15.00, 7.00,
+ 11.00, 6.00, 21.00, 14.00, 25.00, 21.00, 11.00, 16.00, 14.00, 26.00, 25.00, 15.00, 22.00, 24.00, 4.00, 19.00, 14.00, 26.00, 22.00, 17.00,
+ 13.00, 14.00, 7.00, 32.00, 20.00, 33.00, 13.00, 7.00, 29.00, 8.00, 26.00, 6.00, 9.00, 13.00, 22.00, 23.00, 8.00, 22.00, 22.00, 10.00,
+ 24.00, 2.00, 17.00, 9.00, 22.00, 30.00, 24.00, 33.00, 25.00, 17.00, 23.00, 9.00, 13.00, 15.00, 23.00, 10.00, 1.00, 22.00, 17.00, 10.00,
+ 32.00, 24.00, 26.00, 4.00, 15.00, 0.00, 27.00, 23.00, 28.00, 23.00, 30.00, 7.00, 16.00, 33.00, 20.00, 14.00, 23.00, 14.00, 20.00, 14.00,
+ 7.00, 25.00, 24.00, 12.00, 29.00, 16.00, 17.00, 20.00, 29.00, 16.00, 13.00, 18.00, 26.00, 18.00, 18.00, 17.00, 13.00, 29.00, 14.00, 17.00,
+ 24.00, 16.00, 21.00, 14.00, 26.00, 9.00, 11.00, 28.00, 25.00, 15.00, 15.00, 12.00, 6.00, 14.00, 27.00, 14.00, 24.00, 18.00, 18.00, 14.00,
+ 32.00, 21.00, 26.00, 13.00, 6.00, 24.00, 22.00, 27.00, 17.00, 26.00, 19.00, 21.00, 19.00, 9.00, 21.00, 25.00, 17.00, 27.00, 15.00, 18.00
+};
+
--- /dev/null
+#!/usr/bin/perl -w
+#==========================================================================
+# vvadd_gendata.pl
+#
+# Author : Christopher Batten (cbatten@mit.edu)
+# Date : April 29, 2005
+#
+(our $usageMsg = <<'ENDMSG') =~ s/^\#//gm;
+#
+# Simple script which creates an input data set and the reference data
+# for the vvadd benchmark.
+#
+ENDMSG
+
+use strict "vars";
+use warnings;
+no warnings("once");
+use Getopt::Long;
+
+#--------------------------------------------------------------------------
+# Command line processing
+#--------------------------------------------------------------------------
+
+our %opts;
+
+sub usage()
+{
+
+ print "\n";
+ print " Usage: vvadd_gendata.pl [options] \n";
+ print "\n";
+ print " Options:\n";
+ print " --help print this message\n";
+ print " --size size of input data [1000]\n";
+ print " --seed random seed [1]\n";
+ print "$usageMsg";
+
+ exit();
+}
+
+sub processCommandLine()
+{
+
+ $opts{"help"} = 0;
+ $opts{"size"} = 1000;
+ $opts{"seed"} = 1;
+ Getopt::Long::GetOptions( \%opts, 'help|?', 'size:i', 'seed:i' ) or usage();
+ $opts{"help"} and usage();
+
+}
+
+#--------------------------------------------------------------------------
+# Helper Functions
+#--------------------------------------------------------------------------
+
+sub printArray
+{
+ my $arrayName = $_[0];
+ my $arrayRef = $_[1];
+
+ my $numCols = 20;
+ my $arrayLen = scalar(@{$arrayRef});
+
+ print "static data_t ".$arrayName."[DATA_SIZE] = \n";
+ print "{\n";
+
+ if ( $arrayLen <= $numCols ) {
+ print " ";
+ for ( my $i = 0; $i < $arrayLen; $i++ ) {
+ print sprintf("%3.2f",$arrayRef->[$i]);
+ if ( $i != $arrayLen-1 ) {
+ print ", ";
+ }
+ }
+ print "\n";
+ }
+
+ else {
+ my $numRows = int($arrayLen/$numCols);
+ for ( my $j = 0; $j < $numRows; $j++ ) {
+ print " ";
+ for ( my $i = 0; $i < $numCols; $i++ ) {
+ my $index = $j*$numCols + $i;
+ print sprintf("%3.2f",$arrayRef->[$index]);
+ if ( $index != $arrayLen-1 ) {
+ print ", ";
+ }
+ }
+ print "\n";
+ }
+
+ if ( $arrayLen > ($numRows*$numCols) ) {
+ print " ";
+ for ( my $i = 0; $i < ($arrayLen-($numRows*$numCols)); $i++ ) {
+ my $index = $numCols*$numRows + $i;
+ print sprintf("%3.2f",$arrayRef->[$index]);
+ if ( $index != $arrayLen-1 ) {
+ print ", ";
+ }
+ }
+ print "\n";
+ }
+
+ }
+
+ print "};\n\n";
+}
+
+#--------------------------------------------------------------------------
+# Main
+#--------------------------------------------------------------------------
+
+sub main()
+{
+
+ processCommandLine();
+ srand($opts{"seed"});
+
+ my @values1;
+ my @values2;
+ my @sum;
+ for ( my $i = 0; $i < $opts{"size"}; $i++ ) {
+ my $value1 = int(rand(19));
+ my $value2 = int(rand(19));
+ push( @values1, $value1 );
+ push( @values2, $value2 );
+ push( @sum, $value1 + $value2 );
+ }
+
+
+ print "\n\#define DATA_SIZE ".$opts{"size"}." \n\n";
+ printArray( "input1_data", \@values1 );
+ printArray( "input2_data", \@values2 );
+ printArray( "verify_data", \@sum );
+
+}
+
+main();
+
--- /dev/null
+//**************************************************************************
+// Multi-threaded Matrix Multiply benchmark
+//--------------------------------------------------------------------------
+// TA : Christopher Celio
+// Student:
+//
+//
+// This benchmark multiplies two 2-D arrays together and writes the results to
+// a third vector. The input data (and reference data) should be generated
+// using the matmul_gendata.pl perl script and dumped to a file named
+// dataset.h.
+
+
+// print out arrays, etc.
+//#define DEBUG
+
+//--------------------------------------------------------------------------
+// Includes
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+//--------------------------------------------------------------------------
+// Input/Reference Data
+
+typedef float data_t;
+#include "dataset.h"
+
+
+//--------------------------------------------------------------------------
+// Basic Utilities and Multi-thread Support
+
+__thread unsigned long coreid;
+unsigned long ncores;
+
+#include "util.h"
+
+#define stringify_1(s) #s
+#define stringify(s) stringify_1(s)
+#define stats(code) do { \
+ unsigned long _c = -rdcycle(), _i = -rdinstret(); \
+ code; \
+ _c += rdcycle(), _i += rdinstret(); \
+ if (coreid == 0) \
+ printf("%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
+ stringify(code), _c, _c/DIM_SIZE/DIM_SIZE/DIM_SIZE, 10*_c/DIM_SIZE/DIM_SIZE/DIM_SIZE%10, _c/_i, 10*_c/_i%10); \
+ } while(0)
+
+
+//--------------------------------------------------------------------------
+// Helper functions
+
+void printArray( char name[], int n, data_t arr[] )
+{
+ int i;
+ if (coreid != 0)
+ return;
+
+ printf( " %10s :", name );
+ for ( i = 0; i < n; i++ )
+ printf( " %3ld ", (long) arr[i] );
+ printf( "\n" );
+}
+
+void __attribute__((noinline)) verify(size_t n, const data_t* test, const data_t* correct)
+{
+ if (coreid != 0)
+ return;
+
+ size_t i;
+ for (i = 0; i < n; i++)
+ {
+ if (test[i] != correct[i])
+ {
+ printf("FAILED test[%d]= %3ld, correct[%d]= %3ld\n",
+ i, (long)test[i], i, (long)correct[i]);
+ exit(-1);
+ }
+ }
+
+ return;
+}
+
+//--------------------------------------------------------------------------
+// matmul function
+
+// single-thread, naive version
+void __attribute__((noinline)) matmul_naive(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ int i, j, k;
+
+ if (coreid > 0)
+ return;
+
+ for ( i = 0; i < lda; i++ )
+ for ( j = 0; j < lda; j++ )
+ {
+ for ( k = 0; k < lda; k++ )
+ {
+ C[i + j*lda] += A[j*lda + k] * B[k*lda + i];
+ }
+ }
+
+}
+
+
+void __attribute__((noinline)) matmul(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ int i,j,k,l;
+ data_t element1, element2, element3, element4, element5, element6, element7, element8;
+ int row, row2;
+ int column1, column2, column3, column4, column5, column6, column7, column8;
+ data_t temp[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+ data_t temp2[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+ if (coreid == 0){
+ for (i=0; i<32; i+=2){
+ row = i*32;
+ row2 = (i+1)*32;
+ for (j=0; j<16; j+=4){
+ element1 = A[row+j];
+ element2 = A[row+j+1];
+ element3 = A[row+j+2];
+ element4 = A[row+j+3];
+ column1 = j*32;
+ column2 = (j+1)*32;
+ column3 = (j+2)*32;
+ column4 = (j+3)*32;
+ element5 = A[row2+j];
+ element6 = A[row2+j+1];
+ element7 = A[row2+j+2];
+ element8 = A[row2+j+3];
+
+ for (k=0; k<32; k+=4){
+ temp[k]+=element1*B[column1+k]+element2*B[column2+k]+element3*B[column3+k]+element4*B[column4+k];
+ temp[k+1]+=element1*B[column1+k+1]+element2*B[column2+k+1]+element3*B[column3+k+1]+element4*B[column4+k+1];
+ temp[k+2]+=element1*B[column1+k+2]+element2*B[column2+k+2]+element3*B[column3+k+2]+element4*B[column4+k+2];
+ temp[k+3]+=element1*B[column1+k+3]+element2*B[column2+k+3]+element3*B[column3+k+3]+element4*B[column4+k+3];
+ temp2[k]+=element5*B[column1+k]+element6*B[column2+k]+element7*B[column3+k]+element8*B[column4+k];
+ temp2[k+1]+=element5*B[column1+k+1]+element6*B[column2+k+1]+element7*B[column3+k+1]+element8*B[column4+k+1];
+ temp2[k+2]+=element5*B[column1+k+2]+element6*B[column2+k+2]+element7*B[column3+k+2]+element8*B[column4+k+2];
+ temp2[k+3]+=element5*B[column1+k+3]+element6*B[column2+k+3]+element7*B[column3+k+3]+element8*B[column4+k+3];
+ }
+ if (j==12){
+ for (l=0; l<32; l++){
+ C[row+l]+=temp[l];
+ C[row2+l]+=temp2[l];
+ temp[l]=0;
+ temp2[l]=0;
+ }
+ }
+ }
+ }
+ }
+ else if (coreid==1){
+ for (i=0; i<32; i+=2){
+ row = (31-i)*32;
+ row2 = (31-i-1)*32;
+ for (j=16; j<32; j+=4){
+ element1 = A[row+j];
+ element2 = A[row+j+1];
+ element3 = A[row+j+2];
+ element4 = A[row+j+3];
+ element5 = A[row2+j];
+ element6 = A[row2+j+1];
+ element7 = A[row2+j+2];
+ element8 = A[row2+j+3];
+ column1 = j*32;
+ column2 = (j+1)*32;
+ column3 = (j+2)*32;
+ column4 = (j+3)*32;
+ for (k=0; k<32; k+=4){
+ temp[k]+=element1*B[column1+k]+element2*B[column2+k]+element3*B[column3+k]+element4*B[column4+k];
+ temp[k+1]+=element1*B[column1+k+1]+element2*B[column2+k+1]+element3*B[column3+k+1]+element4*B[column4+k+1];
+ temp[k+2]+=element1*B[column1+k+2]+element2*B[column2+k+2]+element3*B[column3+k+2]+element4*B[column4+k+2];
+ temp[k+3]+=element1*B[column1+k+3]+element2*B[column2+k+3]+element3*B[column3+k+3]+element4*B[column4+k+3];
+ temp2[k]+=element5*B[column1+k]+element6*B[column2+k]+element7*B[column3+k]+element8*B[column4+k];
+ temp2[k+1]+=element5*B[column1+k+1]+element6*B[column2+k+1]+element7*B[column3+k+1]+element8*B[column4+k+1];
+ temp2[k+2]+=element5*B[column1+k+2]+element6*B[column2+k+2]+element7*B[column3+k+2]+element8*B[column4+k+2];
+ temp2[k+3]+=element5*B[column1+k+3]+element6*B[column2+k+3]+element7*B[column3+k+3]+element8*B[column4+k+3];
+ }
+ if (j==28){
+ for (l=0; l<32; l++){
+ C[row+l]+=temp[l];
+ C[row2+l]+=temp2[l];
+ temp[l]=0;
+ temp2[l]=0;
+ }
+ }
+ }
+ }
+ }
+ // ***************************** //
+ // **** ADD YOUR CODE HERE ***** //
+ // ***************************** //
+ //
+ // feel free to make a separate function for MI and MSI versions.
+
+}
+//--------------------------------------------------------------------------
+// Main
+//
+// all threads start executing thread_entry(). Use their "coreid" to
+// differentiate between threads (each thread is running on a separate core).
+
+void thread_entry(int cid, int nc)
+{
+ coreid = cid;
+ ncores = nc;
+
+ // static allocates data in the binary, which is visible to both threads
+ static data_t results_data[ARRAY_SIZE];
+
+
+ // Execute the provided, naive matmul
+ barrier();
+ stats(matmul_naive(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+
+ // verify
+ verify(ARRAY_SIZE, results_data, verify_data);
+
+ // clear results from the first trial
+ size_t i;
+ if (coreid == 0)
+ for (i=0; i < ARRAY_SIZE; i++)
+ results_data[i] = 0;
+ barrier();
+
+
+ // Execute your faster matmul
+ barrier();
+ stats(matmul(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+#ifdef DEBUG
+ printArray("results:", ARRAY_SIZE, results_data);
+ printArray("verify :", ARRAY_SIZE, verify_data);
+#endif
+
+ // verify
+ verify(ARRAY_SIZE, results_data, verify_data);
+ barrier();
+
+ exit(0);
+}
--- /dev/null
+//**************************************************************************
+// Multi-threaded Matrix Multiply benchmark
+//--------------------------------------------------------------------------
+// TA : Christopher Celio
+// Student:
+//
+//
+// This benchmark multiplies two 2-D arrays together and writes the results to
+// a third vector. The input data (and reference data) should be generated
+// using the matmul_gendata.pl perl script and dumped to a file named
+// dataset.h.
+
+
+// print out arrays, etc.
+//#define DEBUG
+
+//--------------------------------------------------------------------------
+// Includes
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+//--------------------------------------------------------------------------
+// Input/Reference Data
+
+typedef float data_t;
+#include "dataset.h"
+
+
+//--------------------------------------------------------------------------
+// Basic Utilities and Multi-thread Support
+
+__thread unsigned long coreid;
+unsigned long ncores;
+
+#include "util.h"
+
+#define stringify_1(s) #s
+#define stringify(s) stringify_1(s)
+#define stats(code) do { \
+ unsigned long _c = -rdcycle(), _i = -rdinstret(); \
+ code; \
+ _c += rdcycle(), _i += rdinstret(); \
+ if (coreid == 0) \
+ printf("%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
+ stringify(code), _c, _c/DIM_SIZE/DIM_SIZE/DIM_SIZE, 10*_c/DIM_SIZE/DIM_SIZE/DIM_SIZE%10, _c/_i, 10*_c/_i%10); \
+ } while(0)
+
+
+//--------------------------------------------------------------------------
+// Helper functions
+
+void printArray( char name[], int n, data_t arr[] )
+{
+ int i;
+ if (coreid != 0)
+ return;
+
+ printf( " %10s :", name );
+ for ( i = 0; i < n; i++ )
+ printf( " %3ld ", (long) arr[i] );
+ printf( "\n" );
+}
+
+void __attribute__((noinline)) verify(size_t n, const data_t* test, const data_t* correct)
+{
+ if (coreid != 0)
+ return;
+
+ size_t i;
+ for (i = 0; i < n; i++)
+ {
+ if (test[i] != correct[i])
+ {
+ printf("FAILED test[%d]= %3ld, correct[%d]= %3ld\n",
+ i, (long)test[i], i, (long)correct[i]);
+ exit(-1);
+ }
+ }
+
+ return;
+}
+
+//--------------------------------------------------------------------------
+// matmul function
+
+// single-thread, naive version
+void __attribute__((noinline)) matmul_naive(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ int i, j, k;
+
+ if (coreid > 0)
+ return;
+
+ for ( i = 0; i < lda; i++ )
+ for ( j = 0; j < lda; j++ )
+ {
+ for ( k = 0; k < lda; k++ )
+ {
+ C[i + j*lda] += A[j*lda + k] * B[k*lda + i];
+ }
+ }
+
+}
+
+
+void __attribute__((noinline)) matmul(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ int i,j,k,l;
+ data_t element1, element2, element3, element4, element5, element6, element7, element8;
+ int row, row2;
+ int column1, column2, column3, column4, column5, column6, column7, column8;
+ data_t temp[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+ data_t temp2[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+ if (coreid == 0){
+ for (i=0; i<32; i+=2){
+ row = i*32;
+ row2 = (i+1)*32;
+ for (j=0; j<16; j+=4){
+ element1 = A[row+j];
+ element2 = A[row+j+1];
+ element3 = A[row+j+2];
+ element4 = A[row+j+3];
+ column1 = j*32;
+ column2 = (j+1)*32;
+ column3 = (j+2)*32;
+ column4 = (j+3)*32;
+ element5 = A[row2+j];
+ element6 = A[row2+j+1];
+ element7 = A[row2+j+2];
+ element8 = A[row2+j+3];
+
+ for (k=0; k<32; k+=4){
+ temp[k]+=element1*B[column1+k]+element2*B[column2+k]+element3*B[column3+k]+element4*B[column4+k];
+ temp[k+1]+=element1*B[column1+k+1]+element2*B[column2+k+1]+element3*B[column3+k+1]+element4*B[column4+k+1];
+ temp[k+2]+=element1*B[column1+k+2]+element2*B[column2+k+2]+element3*B[column3+k+2]+element4*B[column4+k+2];
+ temp[k+3]+=element1*B[column1+k+3]+element2*B[column2+k+3]+element3*B[column3+k+3]+element4*B[column4+k+3];
+ temp2[k]+=element5*B[column1+k]+element6*B[column2+k]+element7*B[column3+k]+element8*B[column4+k];
+ temp2[k+1]+=element5*B[column1+k+1]+element6*B[column2+k+1]+element7*B[column3+k+1]+element8*B[column4+k+1];
+ temp2[k+2]+=element5*B[column1+k+2]+element6*B[column2+k+2]+element7*B[column3+k+2]+element8*B[column4+k+2];
+ temp2[k+3]+=element5*B[column1+k+3]+element6*B[column2+k+3]+element7*B[column3+k+3]+element8*B[column4+k+3];
+ }
+ if (j==12){
+ for (l=0; l<32; l++){
+ C[row+l]+=temp[l];
+ C[row2+l]+=temp2[l];
+ temp[l]=0;
+ temp2[l]=0;
+ }
+ }
+ }
+ }
+ }
+ else if (coreid==1){
+ for (i=0; i<32; i+=2){
+ row = (31-i)*32;
+ row2 = (31-i-1)*32;
+ for (j=16; j<32; j+=4){
+ element1 = A[row+j];
+ element2 = A[row+j+1];
+ element3 = A[row+j+2];
+ element4 = A[row+j+3];
+ element5 = A[row2+j];
+ element6 = A[row2+j+1];
+ element7 = A[row2+j+2];
+ element8 = A[row2+j+3];
+ column1 = j*32;
+ column2 = (j+1)*32;
+ column3 = (j+2)*32;
+ column4 = (j+3)*32;
+ for (k=0; k<32; k+=4){
+ temp[k]+=element1*B[column1+k]+element2*B[column2+k]+element3*B[column3+k]+element4*B[column4+k];
+ temp[k+1]+=element1*B[column1+k+1]+element2*B[column2+k+1]+element3*B[column3+k+1]+element4*B[column4+k+1];
+ temp[k+2]+=element1*B[column1+k+2]+element2*B[column2+k+2]+element3*B[column3+k+2]+element4*B[column4+k+2];
+ temp[k+3]+=element1*B[column1+k+3]+element2*B[column2+k+3]+element3*B[column3+k+3]+element4*B[column4+k+3];
+ temp2[k]+=element5*B[column1+k]+element6*B[column2+k]+element7*B[column3+k]+element8*B[column4+k];
+ temp2[k+1]+=element5*B[column1+k+1]+element6*B[column2+k+1]+element7*B[column3+k+1]+element8*B[column4+k+1];
+ temp2[k+2]+=element5*B[column1+k+2]+element6*B[column2+k+2]+element7*B[column3+k+2]+element8*B[column4+k+2];
+ temp2[k+3]+=element5*B[column1+k+3]+element6*B[column2+k+3]+element7*B[column3+k+3]+element8*B[column4+k+3];
+ }
+ if (j==28){
+ for (l=0; l<32; l++){
+ C[row+l]+=temp[l];
+ C[row2+l]+=temp2[l];
+ temp[l]=0;
+ temp2[l]=0;
+ }
+ }
+ }
+ }
+ }
+ // ***************************** //
+ // **** ADD YOUR CODE HERE ***** //
+ // ***************************** //
+ //
+ // feel free to make a separate function for MI and MSI versions.
+
+}
+//--------------------------------------------------------------------------
+// Main
+//
+// all threads start executing thread_entry(). Use their "coreid" to
+// differentiate between threads (each thread is running on a separate core).
+
+void thread_entry(int cid, int nc)
+{
+ coreid = cid;
+ ncores = nc;
+
+ // static allocates data in the binary, which is visible to both threads
+ static data_t results_data[ARRAY_SIZE];
+
+
+ // Execute the provided, naive matmul
+ barrier();
+ stats(matmul_naive(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+
+ // verify
+ verify(ARRAY_SIZE, results_data, verify_data);
+
+ // clear results from the first trial
+ size_t i;
+ if (coreid == 0)
+ for (i=0; i < ARRAY_SIZE; i++)
+ results_data[i] = 0;
+ barrier();
+
+
+ // Execute your faster matmul
+ barrier();
+ stats(matmul(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+#ifdef DEBUG
+ printArray("results:", ARRAY_SIZE, results_data);
+ printArray("verify :", ARRAY_SIZE, verify_data);
+#endif
+
+ // verify
+ verify(ARRAY_SIZE, results_data, verify_data);
+ barrier();
+
+ exit(0);
+}
--- /dev/null
+//**************************************************************************
+// Multi-threaded Matrix Multiply benchmark
+//--------------------------------------------------------------------------
+// TA : Christopher Celio
+// Student:
+//
+//
+// This benchmark multiplies two 2-D arrays together and writes the results to
+// a third vector. The input data (and reference data) should be generated
+// using the matmul_gendata.pl perl script and dumped to a file named
+// dataset.h.
+
+
+// print out arrays, etc.
+//#define DEBUG
+
+//--------------------------------------------------------------------------
+// Includes
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+//--------------------------------------------------------------------------
+// Input/Reference Data
+
+typedef float data_t;
+#include "dataset.h"
+
+
+//--------------------------------------------------------------------------
+// Basic Utilities and Multi-thread Support
+
+__thread unsigned long coreid;
+unsigned long ncores;
+
+#include "util.h"
+
+#define stringify_1(s) #s
+#define stringify(s) stringify_1(s)
+#define stats(code) do { \
+ unsigned long _c = -rdcycle(), _i = -rdinstret(); \
+ code; \
+ _c += rdcycle(), _i += rdinstret(); \
+ if (coreid == 0) \
+ printf("%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
+ stringify(code), _c, _c/DIM_SIZE/DIM_SIZE/DIM_SIZE, 10*_c/DIM_SIZE/DIM_SIZE/DIM_SIZE%10, _c/_i, 10*_c/_i%10); \
+ } while(0)
+
+
+//--------------------------------------------------------------------------
+// Helper functions
+
+void printArray( char name[], int n, data_t arr[] )
+{
+ int i;
+ if (coreid != 0)
+ return;
+
+ printf( " %10s :", name );
+ for ( i = 0; i < n; i++ )
+ printf( " %3ld ", (long) arr[i] );
+ printf( "\n" );
+}
+
+void __attribute__((noinline)) verify(size_t n, const data_t* test, const data_t* correct)
+{
+ if (coreid != 0)
+ return;
+
+ size_t i;
+ for (i = 0; i < n; i++)
+ {
+ if (test[i] != correct[i])
+ {
+ printf("FAILED test[%d]= %3ld, correct[%d]= %3ld\n",
+ i, (long)test[i], i, (long)correct[i]);
+ exit(-1);
+ }
+ }
+
+ return;
+}
+
+data_t mult(data_t x, data_t y)
+{ data_t result = 0;
+ size_t i;
+ for (i=0; i < x; i++) {
+ result += y;
+ }
+ return result;
+}
+//--------------------------------------------------------------------------
+// matmul function
+
+// single-thread, naive version
+void __attribute__((noinline)) matmul_naive(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ int i, j, k;
+
+ if (coreid > 0)
+ return;
+
+ for ( i = 0; i < lda; i++ )
+ for ( j = 0; j < lda; j++ )
+ {
+ for ( k = 0; k < lda; k++ )
+ {
+ C[i + j*lda] += A[j*lda + k] * B[k*lda + i];
+ }
+ }
+
+}
+
+
+ void __attribute__((noinline)) matmul(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ size_t i, j, k, l;
+ int row,row2, column, column2, column3, column4, column5, column6, column7, column8;
+ data_t element, element2, element3, element4, element5, element6, element7, element8;
+ data_t B1, B2, B3, B4;
+ data_t temp_mat[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+ data_t temp_mat2[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+ int local_lda = lda;
+
+ for (l=coreid*local_lda/ncores; l<local_lda*(1+coreid)/ncores; l+=2){
+ row=l*32;
+ row2=(l+1)*32;
+ //element = A[row];
+ //element5 = A[row2];
+ for (i=0; i<local_lda; i+=4){
+ element = A[row+i];
+ element2 = A[row+i+1];
+ element3 = A[row+i+2];
+ element4 = A[row+i+3];
+
+ element5 = A[row2+i];
+ element6 = A[row2+i+1];
+ element7 = A[row2+i+2];
+ element8 = A[row2+i+3];
+
+ column=i*local_lda;
+ column2=(i+1)*local_lda;
+ column3=(i+2)*local_lda;
+ column4=(i+3)*local_lda;
+
+ B1 = B[column];
+ B2 = B[column2];
+ B3 = B[column3];
+ B4 = B[column4];
+
+ for (j=0; j<lda; j+=4){
+ temp_mat[j]+=element*B1+element2*B2+element3*B3+element4*B4;
+ temp_mat[j+1]+=element*B[column+j+1]+element2*B[column2+j+1]+element3*B[column3+j+1]+element4*B[column4+j+1];
+ temp_mat[j+2]+=element*B[column+j+2]+element2*B[column2+j+2]+element3*B[column3+j+2]+element4*B[column4+j+2];
+ temp_mat[j+3]+=element*B[column+j+3]+element2*B[column2+j+3]+element3*B[column3+j+3]+element4*B[column4+j+3];
+
+ temp_mat2[j]+=element5*B1+element6*B2+element7*B3+element8*B4;
+ temp_mat2[j+1]+=element5*B[column+j+1]+element6*B[column2+j+1]+element7*B[column3+j+1]+element8*B[column4+j+1];
+ temp_mat2[j+2]+=element5*B[column+j+2]+element6*B[column2+j+2]+element7*B[column3+j+2]+element8*B[column4+j+2];
+ temp_mat2[j+3]+=element5*B[column+j+3]+element6*B[column2+j+3]+element7*B[column3+j+3]+element8*B[column4+j+3];
+
+ B1 = B[column+j+4];
+ B2 = B[column2+j+4];
+ B3 = B[column3+j+4];
+ B4 = B[column4+j+4];
+
+ }
+ //element = A[row+i+4];
+ //element5 = A[row2+i+4];
+ }
+
+ for(k=0; k<local_lda; k++){
+ C[row+k]=temp_mat[k];
+ temp_mat[k]=0;
+ C[row2+k]=temp_mat2[k];
+ temp_mat2[k]=0;
+
+ }
+
+
+ }
+ // ***************************** //
+ // **** ADD YOUR CODE HERE ***** //
+ // ***************************** //
+ //
+ // feel free to make a separate function for MI and MSI versions.
+
+}
+
+//--------------------------------------------------------------------------
+// Main
+//
+// all threads start executing thread_entry(). Use their "coreid" to
+// differentiate between threads (each thread is running on a separate core).
+
+void thread_entry(int cid, int nc)
+{
+ coreid = cid;
+ ncores = nc;
+
+ // static allocates data in the binary, which is visible to both threads
+ static data_t results_data[ARRAY_SIZE];
+
+
+// // Execute the provided, naive matmul
+// barrier();
+// stats(matmul_naive(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+//
+//
+// // verify
+// verify(ARRAY_SIZE, results_data, verify_data);
+//
+// // clear results from the first trial
+// size_t i;
+// if (coreid == 0)
+// for (i=0; i < ARRAY_SIZE; i++)
+// results_data[i] = 0;
+// barrier();
+
+
+ // Execute your faster matmul
+ barrier();
+ stats(matmul(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+#ifdef DEBUG
+ printArray("results:", ARRAY_SIZE, results_data);
+ printArray("verify :", ARRAY_SIZE, verify_data);
+#endif
+
+ // verify
+ verify(ARRAY_SIZE, results_data, verify_data);
+ barrier();
+
+ exit(0);
+}
--- /dev/null
+//**************************************************************************
+// Multi-threaded Matrix Multiply benchmark
+//--------------------------------------------------------------------------
+// TA : Christopher Celio
+// Student:
+//
+//
+// This benchmark multiplies two 2-D arrays together and writes the results to
+// a third vector. The input data (and reference data) should be generated
+// using the matmul_gendata.pl perl script and dumped to a file named
+// dataset.h.
+
+
+// print out arrays, etc.
+//#define DEBUG
+
+//--------------------------------------------------------------------------
+// Includes
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+//--------------------------------------------------------------------------
+// Input/Reference Data
+
+typedef float data_t;
+#include "dataset.h"
+
+
+//--------------------------------------------------------------------------
+// Basic Utilities and Multi-thread Support
+
+__thread unsigned long coreid;
+unsigned long ncores;
+
+#include "util.h"
+
+#define stringify_1(s) #s
+#define stringify(s) stringify_1(s)
+#define stats(code) do { \
+ unsigned long _c = -rdcycle(), _i = -rdinstret(); \
+ code; \
+ _c += rdcycle(), _i += rdinstret(); \
+ if (coreid == 0) \
+ printf("%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
+ stringify(code), _c, _c/DIM_SIZE/DIM_SIZE/DIM_SIZE, 10*_c/DIM_SIZE/DIM_SIZE/DIM_SIZE%10, _c/_i, 10*_c/_i%10); \
+ } while(0)
+
+
+//--------------------------------------------------------------------------
+// Helper functions
+
+void printArray( char name[], int n, data_t arr[] )
+{
+ int i;
+ if (coreid != 0)
+ return;
+
+ printf( " %10s :", name );
+ for ( i = 0; i < n; i++ )
+ printf( " %3ld ", (long) arr[i] );
+ printf( "\n" );
+}
+
+void __attribute__((noinline)) verify(size_t n, const data_t* test, const data_t* correct)
+{
+ if (coreid != 0)
+ return;
+
+ size_t i;
+ for (i = 0; i < n; i++)
+ {
+ if (test[i] != correct[i])
+ {
+ printf("FAILED test[%d]= %3ld, correct[%d]= %3ld\n",
+ i, (long)test[i], i, (long)correct[i]);
+ exit(-1);
+ }
+ }
+
+ return;
+}
+
+//--------------------------------------------------------------------------
+// matmul function
+
+// single-thread, naive version
+void __attribute__((noinline)) matmul_naive(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ int i, j, k;
+
+ if (coreid > 0)
+ return;
+
+ for ( i = 0; i < lda; i++ )
+ for ( j = 0; j < lda; j++ )
+ {
+ for ( k = 0; k < lda; k++ )
+ {
+ C[i + j*lda] += A[j*lda + k] * B[k*lda + i];
+ }
+ }
+
+}
+
+
+void __attribute__((noinline)) matmul(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ size_t i, j, k, l;
+ int row,row2, column, column2, column3, column4, column5, column6, column7, column8;
+ data_t element, element2, element3, element4, element5, element6, element7, element8;
+ data_t temp_mat[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+ data_t temp_mat2[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+ //for (i=coreid*max_dim/ncores; i<(max_dim/ncores+coreid*max_dim/ncores); i+=8){
+ for (l=coreid*32/ncores; l<32*(1+coreid)/ncores; l+=2){
+ row=l*lda;
+ row2=(l+1)*lda;
+ for (i=0; i<lda; i+=4){
+ element = A[row+i];
+ element2 = A[row+i+1];
+ element3 = A[row+i+2];
+ element4 = A[row+i+3];
+
+ element5 = A[row2+i];
+ element6 = A[row2+i+1];
+ element7 = A[row2+i+2];
+ element8 = A[row2+i+3];
+
+ column=i*lda;
+ column2=(i+1)*lda;
+ column3=(i+2)*lda;
+ column4=(i+3)*lda;
+
+ for (j=0; j<lda; j+=4){
+ temp_mat[j]+=element*B[column+j]+element2*B[column2+j]+element3*B[column3+j]+element4*B[column4+j];
+ temp_mat[j+1]+=element*B[column+j+1]+element2*B[column2+j+1]+element3*B[column3+j+1]+element4*B[column4+j+1];
+ temp_mat[j+2]+=element*B[column+j+2]+element2*B[column2+j+2]+element3*B[column3+j+2]+element4*B[column4+j+2];
+ temp_mat[j+3]+=element*B[column+j+3]+element2*B[column2+j+3]+element3*B[column3+j+3]+element4*B[column4+j+3];
+
+ temp_mat2[j]+=element5*B[column+j]+element6*B[column2+j]+element7*B[column3+j]+element8*B[column4+j];
+ temp_mat2[j+1]+=element5*B[column+j+1]+element6*B[column2+j+1]+element7*B[column3+j+1]+element8*B[column4+j+1];
+ temp_mat2[j+2]+=element5*B[column+j+2]+element6*B[column2+j+2]+element7*B[column3+j+2]+element8*B[column4+j+2];
+ temp_mat2[j+3]+=element5*B[column+j+3]+element6*B[column2+j+3]+element7*B[column3+j+3]+element8*B[column4+j+3];
+ }
+
+ }
+
+ for(k=0; k<32; k++){
+ C[row+k]=temp_mat[k];
+ temp_mat[k]=0;
+ C[row2+k]=temp_mat2[k];
+ temp_mat2[k]=0;
+
+
+ }
+ }
+
+ // ***************************** //
+ // **** ADD YOUR CODE HERE ***** //
+ // ***************************** //
+ //
+ // feel free to make a separate function for MI and MSI versions.
+
+}
+//--------------------------------------------------------------------------
+// Main
+//
+// all threads start executing thread_entry(). Use their "coreid" to
+// differentiate between threads (each thread is running on a separate core).
+
+void thread_entry(int cid, int nc)
+{
+ coreid = cid;
+ ncores = nc;
+
+ // static allocates data in the binary, which is visible to both threads
+ static data_t results_data[ARRAY_SIZE];
+
+
+ // Execute the provided, naive matmul
+ barrier();
+ stats(matmul_naive(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+
+ // verify
+ verify(ARRAY_SIZE, results_data, verify_data);
+
+ // clear results from the first trial
+ size_t i;
+ if (coreid == 0)
+ for (i=0; i < ARRAY_SIZE; i++)
+ results_data[i] = 0;
+ barrier();
+
+
+ // Execute your faster matmul
+ barrier();
+ stats(matmul(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+#ifdef DEBUG
+ printArray("results:", ARRAY_SIZE, results_data);
+ printArray("verify :", ARRAY_SIZE, verify_data);
+#endif
+
+ // verify
+ verify(ARRAY_SIZE, results_data, verify_data);
+ barrier();
+
+ exit(0);
+}
--- /dev/null
+//**************************************************************************
+// Multi-threaded Matrix Multiply benchmark
+//--------------------------------------------------------------------------
+// TA : Christopher Celio
+// Student:
+//
+//
+// This benchmark multiplies two 2-D arrays together and writes the results to
+// a third vector. The input data (and reference data) should be generated
+// using the matmul_gendata.pl perl script and dumped to a file named
+// dataset.h.
+
+
+// print out arrays, etc.
+//#define DEBUG
+
+//--------------------------------------------------------------------------
+// Includes
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+//--------------------------------------------------------------------------
+// Input/Reference Data
+
+typedef float data_t;
+#include "dataset.h"
+
+
+//--------------------------------------------------------------------------
+// Basic Utilities and Multi-thread Support
+
+__thread unsigned long coreid;
+unsigned long ncores;
+
+#include "util.h"
+
+#define stringify_1(s) #s
+#define stringify(s) stringify_1(s)
+#define stats(code) do { \
+ unsigned long _c = -rdcycle(), _i = -rdinstret(); \
+ code; \
+ _c += rdcycle(), _i += rdinstret(); \
+ if (coreid == 0) \
+ printf("%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
+ stringify(code), _c, _c/DIM_SIZE/DIM_SIZE/DIM_SIZE, 10*_c/DIM_SIZE/DIM_SIZE/DIM_SIZE%10, _c/_i, 10*_c/_i%10); \
+ } while(0)
+
+
+//--------------------------------------------------------------------------
+// Helper functions
+
+void printArray( char name[], int n, data_t arr[] )
+{
+ int i;
+ if (coreid != 0)
+ return;
+
+ printf( " %10s :", name );
+ for ( i = 0; i < n; i++ )
+ printf( " %3ld ", (long) arr[i] );
+ printf( "\n" );
+}
+
+void __attribute__((noinline)) verify(size_t n, const data_t* test, const data_t* correct)
+{
+ if (coreid != 0)
+ return;
+
+ size_t i;
+ for (i = 0; i < n; i++)
+ {
+ if (test[i] != correct[i])
+ {
+ printf("FAILED test[%d]= %3ld, correct[%d]= %3ld\n",
+ i, (long)test[i], i, (long)correct[i]);
+ exit(-1);
+ }
+ }
+
+ return;
+}
+
+//--------------------------------------------------------------------------
+// matmul function
+
+// single-thread, naive version
+void __attribute__((noinline)) matmul_naive(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ int i, j, k;
+
+ if (coreid > 0)
+ return;
+
+ for ( i = 0; i < lda; i++ )
+ for ( j = 0; j < lda; j++ )
+ {
+ for ( k = 0; k < lda; k++ )
+ {
+ C[i + j*lda] += A[j*lda + k] * B[k*lda + i];
+ }
+ }
+
+}
+
+
+void __attribute__((noinline)) matmul(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ size_t i, j, k, l;
+ int row,row2, column, column2, column3, column4, column5, column6, column7, column8;
+ data_t element, element2, element3, element4, element5, element6, element7, element8;
+ data_t temp_mat[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+ data_t temp_mat2[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+ //for (i=coreid*max_dim/ncores; i<(max_dim/ncores+coreid*max_dim/ncores); i+=8){
+ for (l=coreid*32/ncores; l<32*(1+coreid)/ncores; l+=4){
+ row=l*lda;
+ row2=(l+1)*lda;
+ for (i=0; i<lda; i+=4){
+ element = A[row+i];
+ element2 = A[row+i+1];
+ element3 = A[row+i+2];
+ element4 = A[row+i+3];
+
+ element5 = A[row2+i];
+ element6 = A[row2+i+1];
+ element7 = A[row2+i+2];
+ element8 = A[row2+i+3];
+
+ column=i*lda;
+ column2=(i+1)*lda;
+ column3=(i+2)*lda;
+ column4=(i+3)*lda;
+
+ for (j=0; j<lda; j+=4){
+ temp_mat[j]+=element*B[column+j]+element2*B[column2+j]+element3*B[column3+j]+element4*B[column4+j];
+ temp_mat[j+1]+=element*B[column+j+1]+element2*B[column2+j+1]+element3*B[column3+j+1]+element4*B[column4+j+1];
+ temp_mat[j+2]+=element*B[column+j+2]+element2*B[column2+j+2]+element3*B[column3+j+2]+element4*B[column4+j+2];
+ temp_mat[j+3]+=element*B[column+j+3]+element2*B[column2+j+3]+element3*B[column3+j+3]+element4*B[column4+j+3];
+
+ temp_mat2[j]+=element5*B[column+j]+element6*B[column2+j]+element7*B[column3+j]+element8*B[column4+j];
+ temp_mat2[j+1]+=element5*B[column+j+1]+element6*B[column2+j+1]+element7*B[column3+j+1]+element8*B[column4+j+1];
+ temp_mat2[j+2]+=element5*B[column+j+2]+element6*B[column2+j+2]+element7*B[column3+j+2]+element8*B[column4+j+2];
+ temp_mat2[j+3]+=element5*B[column+j+3]+element6*B[column2+j+3]+element7*B[column3+j+3]+element8*B[column4+j+3];
+ }
+
+ }
+
+ for(k=0; k<32; k++){
+ C[row+k]=temp_mat[k];
+ temp_mat[k]=0;
+ C[row2+k]=temp_mat2[k];
+ temp_mat2[k]=0;
+
+
+ }
+ }
+
+ // ***************************** //
+ // **** ADD YOUR CODE HERE ***** //
+ // ***************************** //
+ //
+ // feel free to make a separate function for MI and MSI versions.
+
+}
+//--------------------------------------------------------------------------
+// Main
+//
+// all threads start executing thread_entry(). Use their "coreid" to
+// differentiate between threads (each thread is running on a separate core).
+
+void thread_entry(int cid, int nc)
+{
+ coreid = cid;
+ ncores = nc;
+
+ // static allocates data in the binary, which is visible to both threads
+ static data_t results_data[ARRAY_SIZE];
+
+
+ // Execute the provided, naive matmul
+ barrier();
+ stats(matmul_naive(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+
+ // verify
+ verify(ARRAY_SIZE, results_data, verify_data);
+
+ // clear results from the first trial
+ size_t i;
+ if (coreid == 0)
+ for (i=0; i < ARRAY_SIZE; i++)
+ results_data[i] = 0;
+ barrier();
+
+
+ // Execute your faster matmul
+ barrier();
+ stats(matmul(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+#ifdef DEBUG
+ printArray("results:", ARRAY_SIZE, results_data);
+ printArray("verify :", ARRAY_SIZE, verify_data);
+#endif
+
+ // verify
+ verify(ARRAY_SIZE, results_data, verify_data);
+ barrier();
+
+ exit(0);
+}
--- /dev/null
+//**************************************************************************
+// Multi-threaded Matrix Multiply benchmark
+//--------------------------------------------------------------------------
+// TA : Christopher Celio
+// Student:
+//
+//
+// This benchmark multiplies two 2-D arrays together and writes the results to
+// a third vector. The input data (and reference data) should be generated
+// using the matmul_gendata.pl perl script and dumped to a file named
+// dataset.h.
+
+
+// print out arrays, etc.
+//#define DEBUG
+
+//--------------------------------------------------------------------------
+// Includes
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+//--------------------------------------------------------------------------
+// Input/Reference Data
+
+typedef float data_t;
+#include "dataset.h"
+
+
+//--------------------------------------------------------------------------
+// Basic Utilities and Multi-thread Support
+
+__thread unsigned long coreid;
+unsigned long ncores;
+
+#include "util.h"
+
+#define stringify_1(s) #s
+#define stringify(s) stringify_1(s)
+#define stats(code) do { \
+ unsigned long _c = -rdcycle(), _i = -rdinstret(); \
+ code; \
+ _c += rdcycle(), _i += rdinstret(); \
+ if (coreid == 0) \
+ printf("%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
+ stringify(code), _c, _c/DIM_SIZE/DIM_SIZE/DIM_SIZE, 10*_c/DIM_SIZE/DIM_SIZE/DIM_SIZE%10, _c/_i, 10*_c/_i%10); \
+ } while(0)
+
+
+//--------------------------------------------------------------------------
+// Helper functions
+
+void printArray( char name[], int n, data_t arr[] )
+{
+ int i;
+ if (coreid != 0)
+ return;
+
+ printf( " %10s :", name );
+ for ( i = 0; i < n; i++ )
+ printf( " %3ld ", (long) arr[i] );
+ printf( "\n" );
+}
+
+void __attribute__((noinline)) verify(size_t n, const data_t* test, const data_t* correct)
+{
+ if (coreid != 0)
+ return;
+
+ size_t i;
+ for (i = 0; i < n; i++)
+ {
+ if (test[i] != correct[i])
+ {
+ printf("FAILED test[%d]= %3ld, correct[%d]= %3ld\n",
+ i, (long)test[i], i, (long)correct[i]);
+ exit(-1);
+ }
+ }
+
+ return;
+}
+
+data_t mult(data_t x, data_t y)
+{ data_t result = 0;
+ size_t i;
+ for (i=0; i < x; i++) {
+ result += y;
+ }
+ return result;
+}
+//--------------------------------------------------------------------------
+// matmul function
+
+// single-thread, naive version
+void __attribute__((noinline)) matmul_naive(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ int i, j, k;
+
+ if (coreid > 0)
+ return;
+
+ for ( i = 0; i < lda; i++ )
+ for ( j = 0; j < lda; j++ )
+ {
+ for ( k = 0; k < lda; k++ )
+ {
+ C[i + j*lda] += A[j*lda + k] * B[k*lda + i];
+ }
+ }
+
+}
+
+
+void __attribute__((noinline)) matmul(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+
+ size_t i, j, k, l;
+ int row,row2, column, column2, column3, column4, column5, column6, column7, column8;
+ data_t element, element2, element3, element4, element5, element6, element7, element8;
+ data_t B1, B2, B3, B4;
+ data_t temp_mat[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+ data_t temp_mat2[32]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+ int local_lda = lda;
+ //for (i=coreid*max_dim/ncores; i<(max_dim/ncores+coreid*max_dim/ncores); i+=8){
+ for (l=coreid*local_lda/ncores; l<local_lda*(1+coreid)/ncores; l+=2){
+ row=l*32;
+ row2=(l+1)*32;
+ //element = A[row];
+ //element5 = A[row2];
+ for (i=0; i<local_lda; i+=4){
+ element = A[row+i];
+ element2 = A[row+i+1];
+ element3 = A[row+i+2];
+ element4 = A[row+i+3];
+
+ element5 = A[row2+i];
+ element6 = A[row2+i+1];
+ element7 = A[row2+i+2];
+ element8 = A[row2+i+3];
+
+ column=i*local_lda;
+ column2=(i+1)*local_lda;
+ column3=(i+2)*local_lda;
+ column4=(i+3)*local_lda;
+
+ B1 = B[column];
+ B2 = B[column2];
+ B3 = B[column3];
+ B4 = B[column4];
+
+ for (j=0; j<lda; j+=4){
+ temp_mat[j]+=element*B1+element2*B2+element3*B3+element4*B4;
+ temp_mat[j+1]+=element*B[column+j+1]+element2*B[column2+j+1]+element3*B[column3+j+1]+element4*B[column4+j+1];
+ temp_mat[j+2]+=element*B[column+j+2]+element2*B[column2+j+2]+element3*B[column3+j+2]+element4*B[column4+j+2];
+ temp_mat[j+3]+=element*B[column+j+3]+element2*B[column2+j+3]+element3*B[column3+j+3]+element4*B[column4+j+3];
+
+ temp_mat2[j]+=element5*B1+element6*B2+element7*B3+element8*B4;
+ temp_mat2[j+1]+=element5*B[column+j+1]+element6*B[column2+j+1]+element7*B[column3+j+1]+element8*B[column4+j+1];
+ temp_mat2[j+2]+=element5*B[column+j+2]+element6*B[column2+j+2]+element7*B[column3+j+2]+element8*B[column4+j+2];
+ temp_mat2[j+3]+=element5*B[column+j+3]+element6*B[column2+j+3]+element7*B[column3+j+3]+element8*B[column4+j+3];
+
+ B1 = B[column+j+4];
+ B2 = B[column2+j+4];
+ B3 = B[column3+j+4];
+ B4 = B[column4+j+4];
+
+ }
+ //element = A[row+i+4];
+ //element5 = A[row2+i+4];
+ }
+
+ for(k=0; k<local_lda; k++){
+ C[row+k]=temp_mat[k];
+ temp_mat[k]=0;
+ C[row2+k]=temp_mat2[k];
+ temp_mat2[k]=0;
+
+ }
+
+
+ }
+
+ // ***************************** //
+ // **** ADD YOUR CODE HERE ***** //
+ // ***************************** //
+ //
+ // feel free to make a separate function for MI and MSI versions.
+
+}
+//--------------------------------------------------------------------------
+// Main
+//
+// all threads start executing thread_entry(). Use their "coreid" to
+// differentiate between threads (each thread is running on a separate core).
+
+void thread_entry(int cid, int nc)
+{
+ coreid = cid;
+ ncores = nc;
+
+ // static allocates data in the binary, which is visible to both threads
+ static data_t results_data[ARRAY_SIZE];
+
+
+ // Execute the provided, naive matmul
+ barrier();
+ stats(matmul_naive(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+
+ // verify
+ verify(ARRAY_SIZE, results_data, verify_data);
+
+ // clear results from the first trial
+ size_t i;
+ if (coreid == 0)
+ for (i=0; i < ARRAY_SIZE; i++)
+ results_data[i] = 0;
+ barrier();
+
+
+ // Execute your faster matmul
+ barrier();
+ stats(matmul(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+#ifdef DEBUG
+ printArray("results:", ARRAY_SIZE, results_data);
+ printArray("verify :", ARRAY_SIZE, verify_data);
+#endif
+
+ // verify
+ verify(ARRAY_SIZE, results_data, verify_data);
+ barrier();
+
+ exit(0);
+}
--- /dev/null
+
+#define ARRAY_SIZE 1024
+
+
+#define DIM_SIZE 32
+
+static data_t input1_data[ARRAY_SIZE] =
+{
+ 0, 3, 2, 0, 3, 1, 0, 3, 2, 3, 2, 0, 3, 3, 1, 2, 3, 0, 0, 1,
+ 1, 1, 2, 3, 1, 2, 3, 1, 1, 3, 2, 2, 0, 1, 3, 2, 2, 2, 0, 0,
+ 1, 0, 1, 3, 3, 0, 3, 3, 3, 3, 0, 3, 2, 1, 2, 2, 0, 0, 3, 0,
+ 1, 1, 0, 3, 3, 1, 2, 3, 3, 0, 1, 2, 1, 0, 1, 2, 2, 1, 0, 3,
+ 1, 0, 2, 2, 1, 1, 1, 1, 1, 1, 2, 0, 3, 1, 1, 2, 2, 3, 3, 1,
+ 3, 2, 0, 0, 0, 3, 3, 3, 2, 1, 2, 3, 1, 0, 0, 0, 0, 1, 2, 2,
+ 1, 1, 3, 3, 3, 1, 1, 2, 3, 1, 3, 3, 2, 3, 2, 1, 2, 3, 0, 2,
+ 2, 1, 1, 0, 0, 0, 0, 0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, 91, 85, 72, 64, 70, 83, 68, 92, 51, 54,
+ 85, 85, 60, 58, 90, 64, 55, 69, 72, 48, 94, 77, 91, 83, 70, 69, 67, 77, 59, 50,
+ 67, 74, 77, 67, 67, 62, 72, 71, 68, 79, 54, 61, 67, 61, 55, 62, 78, 60, 53, 64,
+ 67, 69, 99, 68, 88, 60, 66, 63, 70, 62, 65, 50, 53, 66, 70, 72, 75, 78, 85, 95,
+ 71, 89, 70, 68, 86, 88, 58, 77, 84, 70, 65, 68, 73, 75, 91, 96, 105, 92, 76, 68,
+ 86, 69, 80, 59, 73, 83, 88, 75, 64, 63, 71, 99, 77, 77, 69, 55, 80, 73, 54, 73,
+ 87, 78, 60, 69, 65, 78, 86, 89, 95, 92, 63, 69, 89, 61, 80, 65, 70, 77, 89, 77,
+ 79, 79, 73, 92, 64, 81, 60, 78, 81, 80, 61, 63, 89, 65, 56, 83, 77, 65, 102, 70,
+ 98, 86, 96, 68, 72, 89, 73, 73, 70, 89, 84, 76, 48, 61, 63, 70, 70, 79, 50, 53,
+ 64, 63, 43, 51, 59, 62, 43, 63, 55, 77, 79, 74, 75, 74, 64, 44, 65, 69, 72, 66,
+ 54, 71, 74, 72, 69, 76, 68, 89, 94, 75, 65, 53, 85, 79, 65, 74, 82, 73, 58, 70,
+ 84, 77, 99, 72, 92, 84, 78, 62, 59, 83, 71, 74, 63, 85, 80, 78, 71, 72, 79, 83,
+ 73, 82, 60, 85, 76, 82, 60, 70, 82, 68, 54, 85, 84, 70, 86, 74, 100, 88, 98, 68,
+ 67, 87, 69, 73, 68, 88, 76, 71, 47, 43, 47, 80, 54, 65, 40, 37, 59, 53, 33, 48,
+ 62, 40, 36, 55, 36, 62, 53, 57, 70, 69, 45, 43, 53, 61, 42, 57, 56, 63, 51, 47,
+ 59, 75, 64, 89, 83, 75, 59, 75, 91, 92, 58, 64, 83, 74, 58, 60, 76, 66, 97, 69,
+ 90, 95, 92, 64, 78, 75, 77, 73, 65, 78, 82, 75, 47, 54, 59, 71, 59, 56, 53, 42,
+ 60, 55, 40, 51, 60, 46, 36, 59, 46, 57, 67, 43, 51, 53, 53, 38, 54, 56, 55, 48,
+ 41, 46, 63, 63, 80, 77, 89, 102, 89, 98, 74, 86, 98, 93, 63, 76, 98, 77, 48, 101,
+ 86, 88, 100, 82, 102, 90, 95, 75, 86, 103, 83, 98, 80, 104, 98, 86, 71, 74, 80, 90,
+ 86, 87, 73, 70, 81, 83, 55, 66, 90, 66, 58, 84, 77, 84, 93, 72, 99, 75, 85, 65,
+ 70, 89, 71, 82, 64, 79, 82, 80, 67, 73, 86, 101, 78, 97, 66, 64, 84, 80, 55, 64,
+ 79, 73, 51, 79, 89, 68, 94, 77, 109, 102, 82, 61, 66, 93, 88, 70, 82, 82, 85, 69,
+ 69, 72, 66, 97, 85, 90, 70, 59, 76, 89, 53, 56, 90, 79, 71, 64, 70, 67, 100, 92,
+ 106, 89, 83, 78, 73, 80, 70, 72, 65, 70, 92, 88, 57, 76, 55, 85, 66, 80, 61, 63,
+ 63, 78, 54, 58, 71, 73, 54, 63, 63, 62, 89, 76, 86, 81, 83, 54, 70, 81, 78, 64,
+ 56, 72, 74, 81, 75, 63, 68, 89, 65, 77, 58, 68, 75, 83, 52, 62, 82, 63, 55, 75,
+ 51, 70, 95, 66, 83, 77, 86, 61, 64, 77, 48, 70, 66, 82, 72, 75, 79, 71, 72, 89,
+ 78, 78, 66, 59, 91, 80, 55, 64, 79, 68, 54, 71, 67, 75, 87, 84, 100, 101, 76, 58,
+ 74, 82, 61, 74, 75, 97, 85, 79, 61, 55, 69, 68, 72, 65, 52, 64, 80, 73, 48, 54,
+ 71, 66, 42, 61, 66, 63, 92, 64, 85, 77, 73, 54, 74, 73, 76, 66, 62, 79, 85, 70,
+ 71, 84, 87, 81, 88, 86, 77, 77, 93, 88, 78, 71, 101, 89, 58, 84, 95, 81, 89, 97,
+ 104, 79, 83, 76, 90, 81, 91, 74, 70, 76, 91, 80, 51, 48, 56, 69, 47, 63, 54, 42,
+ 63, 63, 42, 52, 66, 56, 39, 59, 61, 52, 59, 63, 62, 68, 57, 35, 67, 58, 56, 52,
+ 61, 63, 60, 47, 85, 75, 89, 106, 88, 95, 74, 82, 107, 107, 64, 78, 98, 90, 62, 91,
+ 79, 87, 111, 84, 104, 106, 96, 68, 94, 99, 81, 89, 79, 105, 95, 86, 65, 63, 77, 89,
+ 66, 88, 56, 73, 82, 92, 41, 62, 85, 66, 50, 81, 57, 71, 77, 78, 86, 89, 77, 53,
+ 67, 78, 61, 63, 72, 82, 69, 66, 59, 46, 55, 70, 56, 64, 45, 50, 65, 64, 42, 56,
+ 78, 49, 51, 52, 38, 56, 72, 55, 73, 72, 61, 50, 63, 60, 47, 57, 55, 73, 53, 68,
+ 85, 88, 91, 96, 82, 89, 73, 76, 87, 86, 67, 69, 96, 84, 57, 89, 87, 89, 99, 88,
+ 104, 90, 85, 75, 88, 92, 85, 75, 74, 87, 103, 94, 55, 48, 56, 65, 72, 50, 45, 51,
+ 63, 62, 47, 57, 79, 53, 36, 63, 54, 68, 71, 59, 63, 61, 63, 41, 50, 73, 57, 59,
+ 56, 76, 73, 65, 61, 64, 61, 79, 53, 73, 57, 44, 61, 59, 59, 56, 81, 59, 49, 62,
+ 65, 55, 69, 72, 79, 70, 58, 57, 68, 61, 62, 50, 57, 60, 66, 66, 63, 77, 81, 89,
+ 85, 81, 76, 73, 78, 95, 59, 70, 81, 77, 46, 79, 78, 79, 83, 81, 84, 82, 85, 48,
+ 74, 85, 85, 74, 74, 80, 80, 74, 60, 76, 80, 97, 88, 93, 66, 66, 73, 84, 56, 70,
+ 90, 63, 58, 78, 73, 93, 90, 78, 94, 88, 82, 67, 85, 70, 81, 86, 74, 82, 88, 82,
+ 68, 73, 75, 91, 78, 97, 71, 66, 74, 85, 50, 59, 86, 77, 70, 74, 75, 74, 99, 82,
+ 99, 91, 86, 65, 80, 77, 72, 69, 60, 78, 90, 87, 79, 69, 74, 98, 70, 86, 81, 67,
+ 69, 78, 48, 65, 88, 70, 70, 70, 69, 72, 96, 90, 99, 82, 81, 76, 98, 73, 74, 71,
+ 69, 73, 94, 89
+};
+
--- /dev/null
+//**************************************************************************
+// Multi-threaded Matrix Multiply benchmark
+//--------------------------------------------------------------------------
+// TA : Christopher Celio
+// Student:
+//
+//
+// This benchmark multiplies two 2-D arrays together and writes the results to
+// a third vector. The input data (and reference data) should be generated
+// using the matmul_gendata.pl perl script and dumped to a file named
+// dataset.h.
+
+
+// print out arrays, etc.
+//#define DEBUG
+
+//--------------------------------------------------------------------------
+// Includes
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+//--------------------------------------------------------------------------
+// Input/Reference Data
+
+typedef float data_t;
+#include "dataset.h"
+
+
+//--------------------------------------------------------------------------
+// Basic Utilities and Multi-thread Support
+
+__thread unsigned long coreid;
+unsigned long ncores;
+
+#include "util.h"
+
+#define stringify_1(s) #s
+#define stringify(s) stringify_1(s)
+#define stats(code) do { \
+ unsigned long _c = -rdcycle(), _i = -rdinstret(); \
+ code; \
+ _c += rdcycle(), _i += rdinstret(); \
+ if (coreid == 0) \
+ printf("%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
+ stringify(code), _c, _c/DIM_SIZE/DIM_SIZE/DIM_SIZE, 10*_c/DIM_SIZE/DIM_SIZE/DIM_SIZE%10, _c/_i, 10*_c/_i%10); \
+ } while(0)
+
+
+//--------------------------------------------------------------------------
+// Helper functions
+
+void printArray( char name[], int n, data_t arr[] )
+{
+ int i;
+ if (coreid != 0)
+ return;
+
+ printf( " %10s :", name );
+ for ( i = 0; i < n; i++ )
+ printf( " %3ld ", (long) arr[i] );
+ printf( "\n" );
+}
+
+void __attribute__((noinline)) verify(size_t n, const data_t* test, const data_t* correct)
+{
+ if (coreid != 0)
+ return;
+
+ size_t i;
+ for (i = 0; i < n; i++)
+ {
+ if (test[i] != correct[i])
+ {
+ printf("FAILED test[%d]= %3ld, correct[%d]= %3ld\n",
+ i, (long)test[i], i, (long)correct[i]);
+ exit(-1);
+ }
+ }
+
+ return;
+}
+
+//--------------------------------------------------------------------------
+// matmul function
+
+// single-thread, naive version
+void __attribute__((noinline)) matmul_naive(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ int i, j, k;
+
+ if (coreid > 0)
+ return;
+
+ for ( i = 0; i < lda; i++ )
+ for ( j = 0; j < lda; j++ )
+ {
+ for ( k = 0; k < lda; k++ )
+ {
+ C[i + j*lda] += A[j*lda + k] * B[k*lda + i];
+ }
+ }
+
+}
+
+
+
+void __attribute__((noinline)) matmul(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ size_t i;
+ size_t i2;
+ size_t j;
+ size_t j2;
+ size_t k;
+ size_t k2;
+ size_t max_dim = lda*lda;
+ size_t block_size = lda/2;
+ data_t temp_mat[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+ if (coreid == 0) {
+ //making a 16x16 block
+ //First block: Top 16x16 block left of A and top left of B = top left of C
+ //Second block: top right 16x16 right block of A and top right of B = top right of C
+ for (j2= 0; j2 < 2; j2++) {
+ for (i2 = 0; i2 < 2; i2++) {
+ //for (j2= 0; j2 < 2; j2++) {
+ //K represents which row of A and C
+ for (k = 0; k < block_size; k++) {
+ int rowIndex = k*32;
+ for (i = i2*block_size; i < i2*block_size+block_size; i++) {
+ int elementA = A[rowIndex+i];
+ int columnIndex = i%32*32;
+ for (j = 0; j < block_size; j++) {
+ temp_mat[j] += elementA*B[columnIndex+j+j2*block_size];
+ }
+ }
+ //Put temp_mat into actual result Matrix
+ for (k2 = 0; k2 < block_size; k2++) {
+ C[rowIndex+k2+j2*block_size] += temp_mat[k2];
+ temp_mat[k2] = 0;
+ }
+ }
+ }
+ }
+ } else {
+ for (j2= 0; j2 < 2; j2++) {
+ for (i2 = 0; i2 < 2; i2++) {
+ //for (j2= 0; j2 < 2; j2++) {
+ //K represents which row of A and C
+ for (k = block_size; k < lda; k++) {
+ int rowIndex = k*32;
+ for (i = i2*block_size; i < i2*block_size+block_size; i++) {
+ int elementA = A[rowIndex+i];
+ int columnIndex = i%32*32;
+ for (j = 0; j < block_size; j++) {
+ temp_mat[j] += elementA*B[columnIndex+j+j2*block_size];
+ }
+ }
+ //Put temp_mat into actual result Matrix
+ for (k2 = 0; k2 < block_size; k2++) {
+ C[rowIndex+k2+j2*block_size] += temp_mat[k2];
+ temp_mat[k2] = 0;
+ }
+ }
+ }
+ }
+ }
+
+
+ //size_t half_lda = lda/2;
+ // k = which pair of row we're on
+
+
+
+
+
+
+/*
+ for (k = coreid*lda/ncores; k < (lda/ncores + coreid*lda/ncores); k += 2) {
+ //printf("%d", k);
+ for (i = 0; i < lda ; i++) {
+ int elementA = A[32*k+i];
+ int elementA2 = A[i + 32*(k+1)];
+ int column = i%32*32;
+ for (j = 0; j < lda; j++) {
+ C[32*k + j] += elementA*B[column+j];
+ C[32*(k+1) + j] += elementA2*B[column+j];
+ }
+ }
+
+ }
+*/
+
+/*
+ data_t element=A[i];
+ data_t element2 = A[i+1];
+ data_t element3 = A[i+2];
+ data_t element4 = A[i+3];
+ data_t element5 = A[i+4];
+ data_t element6 = A[i+5];
+ data_t element7 = A[i+6];
+ data_t element8 = A[i+7];
+ int row= (int)(i/32)*32;
+ int row2 = (i+1)/32*32;
+ int row3 = (i+2)/32*32;
+ int row4 = (i+3)/32*32;
+ int row5 = (i+4)/32*32;
+ int row6 = (i+5)/32*32;
+ int row7 = (i+6)/32*32;
+ int row8 = (i+7)/32*32;
+ int column = i%32*32;
+ int column2 = (i+1)%32*32;
+ int column3 = (i+2)%32*32;
+ int column4 = (i+3)%32*32;
+ int column5 = (i+4)%32*32;
+ int column6 = (i+5)%32*32;
+ int column7 = (i+6)%32*32;
+
+ */
+
+ //int column8 = (i+7)%32*32;
+
+ /*
+ for (j=0; j < lda; j++) {
+ sum = B[
+ C[row+j]+=element*B[column+j];
+ C[row2+j]+=element2*B[column2+j];
+ C[row3+j]+=element3*B[column3+j];
+ C[row4+j]+=element4*B[column4+j];
+ C[row5+j]+=element5*B[column5+j];
+ C[row6+j]+=element6*B[column6+j];
+ C[row7+j]+=element7*B[column7+j];
+ C[row8+j]+=element8*B[column8+j];
+ C[row+j]+=element*B[column+j]+element2*B[column2+j]+element3*B[column3+j]+element4*B[column4+j]+element5*B[column5+j]+element6*B[column6+j]+element7*B[column7+j]+element8*B[column8+j];
+ }
+ }
+ */
+
+
+
+
+
+
+ // ***************************** //
+ // **** ADD YOUR CODE HERE ***** //
+ // ***************************** //
+ //
+ // feel free to make a separate function for MI and MSI versions.
+
+}
+
+//--------------------------------------------------------------------------
+// Main
+//
+// all threads start executing thread_entry(). Use their "coreid" to
+// differentiate between threads (each thread is running on a separate core).
+
+void thread_entry(int cid, int nc)
+{
+ coreid = cid;
+ ncores = nc;
+
+ // static allocates data in the binary, which is visible to both threads
+ static data_t results_data[ARRAY_SIZE];
+
+
+ // Execute the provided, naive matmul
+ barrier();
+ stats(matmul_naive(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+
+ // verify
+ verify(ARRAY_SIZE, results_data, verify_data);
+
+ // clear results from the first trial
+ size_t i;
+ if (coreid == 0)
+ for (i=0; i < ARRAY_SIZE; i++)
+ results_data[i] = 0;
+ barrier();
+
+
+ // Execute your faster matmul
+ barrier();
+ stats(matmul(DIM_SIZE, input1_data, input2_data, results_data); barrier());
+
+#ifdef DEBUG
+ printArray("results:", ARRAY_SIZE, results_data);
+ printArray("verify :", ARRAY_SIZE, verify_data);
+#endif
+
+ // verify
+ verify(ARRAY_SIZE, results_data, verify_data);
+ barrier();
+
+ exit(0);
+}
--- /dev/null
+//**************************************************************************
+// Multi-threaded Matrix Multiply benchmark
+//--------------------------------------------------------------------------
+// TA : Christopher Celio
+// Student:
+//
+//
+// This benchmark multiplies two 2-D arrays together and writes the results to
+// a third vector. The input data (and reference data) should be generated
+// using the matmul_gendata.pl perl script and dumped to a file named
+// dataset.h.
+
+
+// print out arrays, etc.
+//#define DEBUG
+
+//--------------------------------------------------------------------------
+// Includes
+
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+
+//--------------------------------------------------------------------------
+// Input/Reference Data
+
+typedef float data_t;
+#include "dataset.h"
+
+
+//--------------------------------------------------------------------------
+// Basic Utilities and Multi-thread Support
+
+__thread unsigned long coreid;
+unsigned long ncores;
+
+#include "util.h"
+
+#define stringify_1(s) #s
+#define stringify(s) stringify_1(s)
+#define stats(code) do { \
+ unsigned long _c = -rdcycle(), _i = -rdinstret(); \
+ code; \
+ _c += rdcycle(), _i += rdinstret(); \
+ if (coreid == 0) \
+ printf("%s: %ld cycles, %ld.%ld cycles/iter, %ld.%ld CPI\n", \
+ stringify(code), _c, _c/DIM_SIZE/DIM_SIZE/DIM_SIZE, 10*_c/DIM_SIZE/DIM_SIZE/DIM_SIZE%10, _c/_i, 10*_c/_i%10); \
+ } while(0)
+
+
+//--------------------------------------------------------------------------
+// Helper functions
+
+void printArray( char name[], int n, data_t arr[] )
+{
+ int i;
+ if (coreid != 0)
+ return;
+
+ printf( " %10s :", name );
+ for ( i = 0; i < n; i++ )
+ printf( " %3ld ", (long) arr[i] );
+ printf( "\n" );
+}
+
+void __attribute__((noinline)) verify(size_t n, const data_t* test, const data_t* correct)
+{
+ if (coreid != 0)
+ return;
+
+ size_t i;
+ for (i = 0; i < n; i++)
+ {
+ if (test[i] != correct[i])
+ {
+ printf("FAILED test[%d]= %3ld, correct[%d]= %3ld\n",
+ i, (long)test[i], i, (long)correct[i]);
+ exit(-1);
+ }
+ }
+
+ return;
+}
+
+//--------------------------------------------------------------------------
+// matmul function
+
+// single-thread, naive version
+void __attribute__((noinline)) matmul_naive(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ int i, j, k;
+
+ if (coreid > 0)
+ return;
+
+ for ( i = 0; i < lda; i++ )
+ for ( j = 0; j < lda; j++ )
+ {
+ for ( k = 0; k < lda; k++ )
+ {
+ C[i + j*lda] += A[j*lda + k] * B[k*lda + i];
+ }
+ }
+
+}
+
+
+
+void __attribute__((noinline)) matmul(const int lda, const data_t A[], const data_t B[], data_t C[] )
+{
+ size_t i;
+ size_t i2;
+ size_t j;
+ size_t j2;
+ size_t k;
+ size_t k2;
+ size_t max_dim = lda*lda;
+ size_t block_size = lda/2;
+ int result = 0;
+ data_t temp_mat1[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
+ if (coreid == 0) {
+ for (k = 0; k < lda/2; k++) {
+ int columnIndex = 32*k;
+
+ //temp_mat1 will store the kth column of B
+ for (i = 0; i < lda; i++) {
+ temp_mat1[i] = B[32*i + k];
+ }
+
+ for (j =0; j < lda; j++) {
+ int rowIndex = 32*j;
+ //iterate through each element of A in row J and accumulate result
+ for (i2 = 0; i2 <lda; i2 += 4) {
+ int elementA = A[rowIndex+i2];
+ int elementA2 = A[rowIndex+i2+1];
+ int elementA3 = A[rowIndex+i2+2];
+ int elementA4 = A[rowIndex+i2+3];
+ result += elementA*temp_mat1[i2] + elementA2*temp_mat1[i2+1] + elementA3*temp_mat1[i2+2] + elementA4*temp_mat1[i2+3] ;
+ }
+ &nb