diff options
author | Henry Cook <hcook@eecs.berkeley.edu> | 2014-11-06 17:24:39 -0800 |
---|---|---|
committer | Henry Cook <hcook@eecs.berkeley.edu> | 2014-11-07 16:52:51 -0800 |
commit | d537de7deffa6036dab573ff174b7f8c8e470437 (patch) | |
tree | ddc921eb337cda4889570f0251bdba85059a2531 /mt/br_matmul | |
parent | 5afc6b9bc2e3685220cffb3da66ad9f5f1f7b14f (diff) | |
download | riscv-tests-d537de7deffa6036dab573ff174b7f8c8e470437.zip riscv-tests-d537de7deffa6036dab573ff174b7f8c8e470437.tar.gz riscv-tests-d537de7deffa6036dab573ff174b7f8c8e470437.tar.bz2 |
Clean up canonical mt benchmarks and reorganize extra versions in /mt. All versions support support at least 1/2/4 threads.
Diffstat (limited to 'mt/br_matmul')
-rwxr-xr-x | mt/br_matmul/br_matmul.c | 283 | ||||
-rwxr-xr-x | mt/br_matmul/dataset.h | 174 | ||||
-rwxr-xr-x | mt/br_matmul/matmul_gendata.pl | 200 | ||||
-rwxr-xr-x | mt/br_matmul/matmul_mi.c | 283 |
4 files changed, 0 insertions, 940 deletions
diff --git a/mt/br_matmul/br_matmul.c b/mt/br_matmul/br_matmul.c deleted file mode 100755 index f831ac2..0000000 --- a/mt/br_matmul/br_matmul.c +++ /dev/null @@ -1,283 +0,0 @@ -//************************************************************************** -// Multi-threaded Matrix Multiply benchmark -//-------------------------------------------------------------------------- -// TA : Christopher Celio -// Student: Benjamin Han -// -// -// 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 printArrayMT( 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)) verifyMT(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 j2, i2, k2, j, i, k; - int tmpC00, tmpC01, tmpC02, tmpC03, tmpC04, tmpC05, tmpC06, tmpC07; - int tmpC10, tmpC11, tmpC12, tmpC13, tmpC14, tmpC15, tmpC16, tmpC17; - int jBLOCK = 32; - int iBLOCK = 16; - int kBLOCK = 32; - static __thread int tB[4096]; //__thread - int startInd = 0; - int endInd = lda >> 1; - if (coreid == 1) { - startInd = lda >> 1; - endInd = lda; - } - - //tranpose B (block?) - for (i = 0; i < lda; i += 2) { - for (j = startInd; j < endInd; j += 2) { - tB[j*lda + i] = B[i*lda + j]; - tB[(j + 1)*lda + i] = B[i*lda + j + 1]; - tB[j*lda + i + 1] = B[(i + 1)*lda + j]; - tB[(j + 1)*lda + i + 1] = B[(i + 1)*lda + j + 1]; - } - } - barrier(ncores); - - // compute C[j*n + i] += A[j*n + k] + Btranspose[i*n + k] - for ( j2 = 0; j2 < lda; j2 += jBLOCK ) - for ( i2 = startInd; i2 < endInd; i2 += iBLOCK ) - for ( j = j2; j < j2 + jBLOCK; j += 2 ) - for ( k2 = 0; k2 < lda; k2 += kBLOCK ) - for ( i = i2; i < i2 + iBLOCK; i += 4) { - tmpC00 = C[j*lda + i + 0]; tmpC10 = C[(j + 1)*lda + i + 0]; - tmpC01 = C[j*lda + i + 1]; tmpC11 = C[(j + 1)*lda + i + 1]; - tmpC02 = C[j*lda + i + 2]; tmpC12 = C[(j + 1)*lda + i + 2]; - tmpC03 = C[j*lda + i + 3]; tmpC13 = C[(j + 1)*lda + i + 3]; - //tmpC04 = C[j*lda + i + 4]; tmpC14 = C[(j + 1)*lda + i + 4]; - //tmpC05 = C[j*lda + i + 5]; tmpC15 = C[(j + 1)*lda + i + 5]; - //tmpC06 = C[j*lda + i + 6]; tmpC16 = C[(j + 1)*lda + i + 6]; - //tmpC07 = C[j*lda + i + 7]; tmpC17 = C[(j + 1)*lda + i + 7]; - for ( k = k2; k < k2 + kBLOCK; k += 4) { - tmpC00 += A[j*lda + k] * tB[(i + 0)*lda + k]; - tmpC01 += A[j*lda + k] * tB[(i + 1)*lda + k]; - tmpC02 += A[j*lda + k] * tB[(i + 2)*lda + k]; - tmpC03 += A[j*lda + k] * tB[(i + 3)*lda + k]; - //tmpC04 += A[j*lda + k] * tB[(i + 4)*lda + k]; - //tmpC05 += A[j*lda + k] * tB[(i + 5)*lda + k]; - //tmpC06 += A[j*lda + k] * tB[(i + 6)*lda + k]; - //tmpC07 += A[j*lda + k] * tB[(i + 7)*lda + k]; - tmpC10 += A[(j + 1)*lda + k] * tB[(i + 0)*lda + k]; - tmpC11 += A[(j + 1)*lda + k] * tB[(i + 1)*lda + k]; - tmpC12 += A[(j + 1)*lda + k] * tB[(i + 2)*lda + k]; - tmpC13 += A[(j + 1)*lda + k] * tB[(i + 3)*lda + k]; - //tmpC14 += A[(j + 1)*lda + k] * tB[(i + 4)*lda + k]; - //tmpC15 += A[(j + 1)*lda + k] * tB[(i + 5)*lda + k]; - //tmpC16 += A[(j + 1)*lda + k] * tB[(i + 6)*lda + k]; - //tmpC17 += A[(j + 1)*lda + k] * tB[(i + 7)*lda + k]; - - tmpC00 += A[j*lda + k + 1] * tB[(i + 0)*lda + k + 1]; - tmpC01 += A[j*lda + k + 1] * tB[(i + 1)*lda + k + 1]; - tmpC02 += A[j*lda + k + 1] * tB[(i + 2)*lda + k + 1]; - tmpC03 += A[j*lda + k + 1] * tB[(i + 3)*lda + k + 1]; - //tmpC04 += A[j*lda + k + 1] * tB[(i + 4)*lda + k + 1]; - //tmpC05 += A[j*lda + k + 1] * tB[(i + 5)*lda + k + 1]; - //tmpC06 += A[j*lda + k + 1] * tB[(i + 6)*lda + k + 1]; - //tmpC07 += A[j*lda + k + 1] * tB[(i + 7)*lda + k + 1]; - tmpC10 += A[(j + 1)*lda + k + 1] * tB[(i + 0)*lda + k + 1]; - tmpC11 += A[(j + 1)*lda + k + 1] * tB[(i + 1)*lda + k + 1]; - tmpC12 += A[(j + 1)*lda + k + 1] * tB[(i + 2)*lda + k + 1]; - tmpC13 += A[(j + 1)*lda + k + 1] * tB[(i + 3)*lda + k + 1]; - //tmpC14 += A[(j + 1)*lda + k + 1] * tB[(i + 4)*lda + k + 1]; - //tmpC15 += A[(j + 1)*lda + k + 1] * tB[(i + 5)*lda + k + 1]; - //tmpC16 += A[(j + 1)*lda + k + 1] * tB[(i + 6)*lda + k + 1]; - //tmpC17 += A[(j + 1)*lda + k + 1] * tB[(i + 7)*lda + k + 1]; - - tmpC00 += A[j*lda + k + 2] * tB[(i + 0)*lda + k + 2]; - tmpC01 += A[j*lda + k + 2] * tB[(i + 1)*lda + k + 2]; - tmpC02 += A[j*lda + k + 2] * tB[(i + 2)*lda + k + 2]; - tmpC03 += A[j*lda + k + 2] * tB[(i + 3)*lda + k + 2]; - //tmpC04 += A[j*lda + k + 2] * tB[(i + 4)*lda + k + 2]; - //tmpC05 += A[j*lda + k + 2] * tB[(i + 5)*lda + k + 2]; - //tmpC06 += A[j*lda + k + 2] * tB[(i + 6)*lda + k + 2]; - //tmpC07 += A[j*lda + k + 2] * tB[(i + 7)*lda + k + 2]; - tmpC10 += A[(j + 1)*lda + k + 2] * tB[(i + 0)*lda + k + 2]; - tmpC11 += A[(j + 1)*lda + k + 2] * tB[(i + 1)*lda + k + 2]; - tmpC12 += A[(j + 1)*lda + k + 2] * tB[(i + 2)*lda + k + 2]; - tmpC13 += A[(j + 1)*lda + k + 2] * tB[(i + 3)*lda + k + 2]; - //tmpC14 += A[(j + 1)*lda + k + 2] * tB[(i + 4)*lda + k + 2]; - //tmpC15 += A[(j + 1)*lda + k + 2] * tB[(i + 5)*lda + k + 2]; - //tmpC16 += A[(j + 1)*lda + k + 2] * tB[(i + 6)*lda + k + 2]; - //tmpC17 += A[(j + 1)*lda + k + 2] * tB[(i + 7)*lda + k + 2]; - - tmpC00 += A[j*lda + k + 3] * tB[(i + 0)*lda + k + 3]; - tmpC01 += A[j*lda + k + 3] * tB[(i + 1)*lda + k + 3]; - tmpC02 += A[j*lda + k + 3] * tB[(i + 2)*lda + k + 3]; - tmpC03 += A[j*lda + k + 3] * tB[(i + 3)*lda + k + 3]; - //tmpC04 += A[j*lda + k + 3] * tB[(i + 4)*lda + k + 3]; - //tmpC05 += A[j*lda + k + 3] * tB[(i + 5)*lda + k + 3]; - //tmpC06 += A[j*lda + k + 3] * tB[(i + 6)*lda + k + 3]; - //tmpC07 += A[j*lda + k + 3] * tB[(i + 7)*lda + k + 3]; - tmpC10 += A[(j + 1)*lda + k + 3] * tB[(i + 0)*lda + k + 3]; - tmpC11 += A[(j + 1)*lda + k + 3] * tB[(i + 1)*lda + k + 3]; - tmpC12 += A[(j + 1)*lda + k + 3] * tB[(i + 2)*lda + k + 3]; - tmpC13 += A[(j + 1)*lda + k + 3] * tB[(i + 3)*lda + k + 3]; - //tmpC14 += A[(j + 1)*lda + k + 3] * tB[(i + 4)*lda + k + 3]; - //tmpC15 += A[(j + 1)*lda + k + 3] * tB[(i + 5)*lda + k + 3]; - //tmpC16 += A[(j + 1)*lda + k + 3] * tB[(i + 6)*lda + k + 3]; - //tmpC17 += A[(j + 1)*lda + k + 3] * tB[(i + 7)*lda + k + 3]; - } - C[j*lda + i + 0] = tmpC00; C[(j + 1)*lda + i + 0] = tmpC10; - C[j*lda + i + 1] = tmpC01; C[(j + 1)*lda + i + 1] = tmpC11; - C[j*lda + i + 2] = tmpC02; C[(j + 1)*lda + i + 2] = tmpC12; - C[j*lda + i + 3] = tmpC03; C[(j + 1)*lda + i + 3] = tmpC13; - //C[j*lda + i + 4] = tmpC04; C[(j + 1)*lda + i + 4] = tmpC14; - //C[j*lda + i + 5] = tmpC05; C[(j + 1)*lda + i + 5] = tmpC15; - //C[j*lda + i + 6] = tmpC06; C[(j + 1)*lda + i + 6] = tmpC16; - //C[j*lda + i + 7] = tmpC07; C[(j + 1)*lda + i + 7] = tmpC17; - } -} - -//-------------------------------------------------------------------------- -// 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(nc); -// stats(matmul_naive(DIM_SIZE, input1_data, input2_data, results_data); barrier(nc)); -// -// -// // verify -// verifyMT(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(nc); - - - // Execute your faster matmul - barrier(nc); - stats(matmul(DIM_SIZE, input1_data, input2_data, results_data); barrier(nc)); - -#ifdef DEBUG - printArrayMT("results:", ARRAY_SIZE, results_data); - printArrayMT("verify :", ARRAY_SIZE, verify_data); -#endif - - // verify - verifyMT(ARRAY_SIZE, results_data, verify_data); - barrier(nc); - - exit(0); -} - diff --git a/mt/br_matmul/dataset.h b/mt/br_matmul/dataset.h deleted file mode 100755 index dde3ee4..0000000 --- a/mt/br_matmul/dataset.h +++ /dev/null @@ -1,174 +0,0 @@ - -#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, 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 0, 0, 3, 2, 1, 1, 1, 1, 3, 2, 1, 3, 3, 1, 0, 3, 1, 1, 2, 0, - 0, 0, 2, 3, 3, 2, 2, 3, 0, 2, 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 -}; - diff --git a/mt/br_matmul/matmul_gendata.pl b/mt/br_matmul/matmul_gendata.pl deleted file mode 100755 index f21bb46..0000000 --- a/mt/br_matmul/matmul_gendata.pl +++ /dev/null @@ -1,200 +0,0 @@ -#!/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(); - diff --git a/mt/br_matmul/matmul_mi.c b/mt/br_matmul/matmul_mi.c deleted file mode 100755 index 14a0705..0000000 --- a/mt/br_matmul/matmul_mi.c +++ /dev/null @@ -1,283 +0,0 @@ -//************************************************************************** -// Multi-threaded Matrix Multiply benchmark -//-------------------------------------------------------------------------- -// TA : Christopher Celio -// Student: Benjamin Han -// -// -// 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 printArrayMT( 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)) verifyMT(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 j2, i2, k2, j, i, k; - int tmpC00, tmpC01, tmpC02, tmpC03, tmpC04, tmpC05, tmpC06, tmpC07; - int tmpC10, tmpC11, tmpC12, tmpC13, tmpC14, tmpC15, tmpC16, tmpC17; - int jBLOCK = 32; - int iBLOCK = 16; - int kBLOCK = 32; - static __thread int tB[4096]; //__thread - int startInd = 0; - int endInd = lda >> 1; - if (coreid == 1) { - startInd = lda >> 1; - endInd = lda; - } - - //tranpose B (block?) - for (i = 0; i < lda; i += 2) { - for (j = startInd; j < endInd; j += 2) { - tB[j*lda + i] = B[i*lda + j]; - tB[(j + 1)*lda + i] = B[i*lda + j + 1]; - tB[j*lda + i + 1] = B[(i + 1)*lda + j]; - tB[(j + 1)*lda + i + 1] = B[(i + 1)*lda + j + 1]; - } - } - barrier(nc); - - // compute C[j*n + i] += A[j*n + k] + Btranspose[i*n + k] - for ( j2 = 0; j2 < lda; j2 += jBLOCK ) - for ( i2 = startInd; i2 < endInd; i2 += iBLOCK ) - for ( j = j2; j < j2 + jBLOCK; j += 2 ) - for ( k2 = 0; k2 < lda; k2 += kBLOCK ) - for ( i = i2; i < i2 + iBLOCK; i += 4) { - tmpC00 = C[j*lda + i + 0]; tmpC10 = C[(j + 1)*lda + i + 0]; - tmpC01 = C[j*lda + i + 1]; tmpC11 = C[(j + 1)*lda + i + 1]; - tmpC02 = C[j*lda + i + 2]; tmpC12 = C[(j + 1)*lda + i + 2]; - tmpC03 = C[j*lda + i + 3]; tmpC13 = C[(j + 1)*lda + i + 3]; - //tmpC04 = C[j*lda + i + 4]; tmpC14 = C[(j + 1)*lda + i + 4]; - //tmpC05 = C[j*lda + i + 5]; tmpC15 = C[(j + 1)*lda + i + 5]; - //tmpC06 = C[j*lda + i + 6]; tmpC16 = C[(j + 1)*lda + i + 6]; - //tmpC07 = C[j*lda + i + 7]; tmpC17 = C[(j + 1)*lda + i + 7]; - for ( k = k2; k < k2 + kBLOCK; k += 4) { - tmpC00 += A[j*lda + k] * tB[(i + 0)*lda + k]; - tmpC01 += A[j*lda + k] * tB[(i + 1)*lda + k]; - tmpC02 += A[j*lda + k] * tB[(i + 2)*lda + k]; - tmpC03 += A[j*lda + k] * tB[(i + 3)*lda + k]; - //tmpC04 += A[j*lda + k] * tB[(i + 4)*lda + k]; - //tmpC05 += A[j*lda + k] * tB[(i + 5)*lda + k]; - //tmpC06 += A[j*lda + k] * tB[(i + 6)*lda + k]; - //tmpC07 += A[j*lda + k] * tB[(i + 7)*lda + k]; - tmpC10 += A[(j + 1)*lda + k] * tB[(i + 0)*lda + k]; - tmpC11 += A[(j + 1)*lda + k] * tB[(i + 1)*lda + k]; - tmpC12 += A[(j + 1)*lda + k] * tB[(i + 2)*lda + k]; - tmpC13 += A[(j + 1)*lda + k] * tB[(i + 3)*lda + k]; - //tmpC14 += A[(j + 1)*lda + k] * tB[(i + 4)*lda + k]; - //tmpC15 += A[(j + 1)*lda + k] * tB[(i + 5)*lda + k]; - //tmpC16 += A[(j + 1)*lda + k] * tB[(i + 6)*lda + k]; - //tmpC17 += A[(j + 1)*lda + k] * tB[(i + 7)*lda + k]; - - tmpC00 += A[j*lda + k + 1] * tB[(i + 0)*lda + k + 1]; - tmpC01 += A[j*lda + k + 1] * tB[(i + 1)*lda + k + 1]; - tmpC02 += A[j*lda + k + 1] * tB[(i + 2)*lda + k + 1]; - tmpC03 += A[j*lda + k + 1] * tB[(i + 3)*lda + k + 1]; - //tmpC04 += A[j*lda + k + 1] * tB[(i + 4)*lda + k + 1]; - //tmpC05 += A[j*lda + k + 1] * tB[(i + 5)*lda + k + 1]; - //tmpC06 += A[j*lda + k + 1] * tB[(i + 6)*lda + k + 1]; - //tmpC07 += A[j*lda + k + 1] * tB[(i + 7)*lda + k + 1]; - tmpC10 += A[(j + 1)*lda + k + 1] * tB[(i + 0)*lda + k + 1]; - tmpC11 += A[(j + 1)*lda + k + 1] * tB[(i + 1)*lda + k + 1]; - tmpC12 += A[(j + 1)*lda + k + 1] * tB[(i + 2)*lda + k + 1]; - tmpC13 += A[(j + 1)*lda + k + 1] * tB[(i + 3)*lda + k + 1]; - //tmpC14 += A[(j + 1)*lda + k + 1] * tB[(i + 4)*lda + k + 1]; - //tmpC15 += A[(j + 1)*lda + k + 1] * tB[(i + 5)*lda + k + 1]; - //tmpC16 += A[(j + 1)*lda + k + 1] * tB[(i + 6)*lda + k + 1]; - //tmpC17 += A[(j + 1)*lda + k + 1] * tB[(i + 7)*lda + k + 1]; - - tmpC00 += A[j*lda + k + 2] * tB[(i + 0)*lda + k + 2]; - tmpC01 += A[j*lda + k + 2] * tB[(i + 1)*lda + k + 2]; - tmpC02 += A[j*lda + k + 2] * tB[(i + 2)*lda + k + 2]; - tmpC03 += A[j*lda + k + 2] * tB[(i + 3)*lda + k + 2]; - //tmpC04 += A[j*lda + k + 2] * tB[(i + 4)*lda + k + 2]; - //tmpC05 += A[j*lda + k + 2] * tB[(i + 5)*lda + k + 2]; - //tmpC06 += A[j*lda + k + 2] * tB[(i + 6)*lda + k + 2]; - //tmpC07 += A[j*lda + k + 2] * tB[(i + 7)*lda + k + 2]; - tmpC10 += A[(j + 1)*lda + k + 2] * tB[(i + 0)*lda + k + 2]; - tmpC11 += A[(j + 1)*lda + k + 2] * tB[(i + 1)*lda + k + 2]; - tmpC12 += A[(j + 1)*lda + k + 2] * tB[(i + 2)*lda + k + 2]; - tmpC13 += A[(j + 1)*lda + k + 2] * tB[(i + 3)*lda + k + 2]; - //tmpC14 += A[(j + 1)*lda + k + 2] * tB[(i + 4)*lda + k + 2]; - //tmpC15 += A[(j + 1)*lda + k + 2] * tB[(i + 5)*lda + k + 2]; - //tmpC16 += A[(j + 1)*lda + k + 2] * tB[(i + 6)*lda + k + 2]; - //tmpC17 += A[(j + 1)*lda + k + 2] * tB[(i + 7)*lda + k + 2]; - - tmpC00 += A[j*lda + k + 3] * tB[(i + 0)*lda + k + 3]; - tmpC01 += A[j*lda + k + 3] * tB[(i + 1)*lda + k + 3]; - tmpC02 += A[j*lda + k + 3] * tB[(i + 2)*lda + k + 3]; - tmpC03 += A[j*lda + k + 3] * tB[(i + 3)*lda + k + 3]; - //tmpC04 += A[j*lda + k + 3] * tB[(i + 4)*lda + k + 3]; - //tmpC05 += A[j*lda + k + 3] * tB[(i + 5)*lda + k + 3]; - //tmpC06 += A[j*lda + k + 3] * tB[(i + 6)*lda + k + 3]; - //tmpC07 += A[j*lda + k + 3] * tB[(i + 7)*lda + k + 3]; - tmpC10 += A[(j + 1)*lda + k + 3] * tB[(i + 0)*lda + k + 3]; - tmpC11 += A[(j + 1)*lda + k + 3] * tB[(i + 1)*lda + k + 3]; - tmpC12 += A[(j + 1)*lda + k + 3] * tB[(i + 2)*lda + k + 3]; - tmpC13 += A[(j + 1)*lda + k + 3] * tB[(i + 3)*lda + k + 3]; - //tmpC14 += A[(j + 1)*lda + k + 3] * tB[(i + 4)*lda + k + 3]; - //tmpC15 += A[(j + 1)*lda + k + 3] * tB[(i + 5)*lda + k + 3]; - //tmpC16 += A[(j + 1)*lda + k + 3] * tB[(i + 6)*lda + k + 3]; - //tmpC17 += A[(j + 1)*lda + k + 3] * tB[(i + 7)*lda + k + 3]; - } - C[j*lda + i + 0] = tmpC00; C[(j + 1)*lda + i + 0] = tmpC10; - C[j*lda + i + 1] = tmpC01; C[(j + 1)*lda + i + 1] = tmpC11; - C[j*lda + i + 2] = tmpC02; C[(j + 1)*lda + i + 2] = tmpC12; - C[j*lda + i + 3] = tmpC03; C[(j + 1)*lda + i + 3] = tmpC13; - //C[j*lda + i + 4] = tmpC04; C[(j + 1)*lda + i + 4] = tmpC14; - //C[j*lda + i + 5] = tmpC05; C[(j + 1)*lda + i + 5] = tmpC15; - //C[j*lda + i + 6] = tmpC06; C[(j + 1)*lda + i + 6] = tmpC16; - //C[j*lda + i + 7] = tmpC07; C[(j + 1)*lda + i + 7] = tmpC17; - } -} - -//-------------------------------------------------------------------------- -// 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(nc); -// stats(matmul_naive(DIM_SIZE, input1_data, input2_data, results_data); barrier(nc)); -// -// -// // verify -// verifyMT(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(nc); - - - // Execute your faster matmul - barrier(nc); - stats(matmul(DIM_SIZE, input1_data, input2_data, results_data); barrier(nc)); - -#ifdef DEBUG - printArrayMT("results:", ARRAY_SIZE, results_data); - printArrayMT("verify :", ARRAY_SIZE, verify_data); -#endif - - // verify - verifyMT(ARRAY_SIZE, results_data, verify_data); - barrier(nc); - - exit(0); -} - |