aboutsummaryrefslogtreecommitdiff
path: root/benchmarks/median
diff options
context:
space:
mode:
authorYunsup Lee <yunsup@cs.berkeley.edu>2013-04-29 18:44:21 -0700
committerYunsup Lee <yunsup@cs.berkeley.edu>2013-04-29 18:44:21 -0700
commit23507d668862dff15a898f20e109a46c6e95780d (patch)
treea3b620e117c1ded337e9508042e353c62a1a97a8 /benchmarks/median
parentf8ea498f79ab4d6495f2966d1e5c3dd42f567752 (diff)
downloadriscv-tests-23507d668862dff15a898f20e109a46c6e95780d.zip
riscv-tests-23507d668862dff15a898f20e109a46c6e95780d.tar.gz
riscv-tests-23507d668862dff15a898f20e109a46c6e95780d.tar.bz2
benchmarks initial commit
Diffstat (limited to 'benchmarks/median')
-rw-r--r--benchmarks/median/bmark.mk30
-rw-r--r--benchmarks/median/dataset1.h51
-rw-r--r--benchmarks/median/median.c40
-rw-r--r--benchmarks/median/median.h9
-rwxr-xr-xbenchmarks/median/median_gendata.pl140
-rw-r--r--benchmarks/median/median_main.c131
6 files changed, 401 insertions, 0 deletions
diff --git a/benchmarks/median/bmark.mk b/benchmarks/median/bmark.mk
new file mode 100644
index 0000000..31c853a
--- /dev/null
+++ b/benchmarks/median/bmark.mk
@@ -0,0 +1,30 @@
+#=======================================================================
+# UCB CS250 Makefile fragment for benchmarks
+#-----------------------------------------------------------------------
+#
+# Each benchmark directory should have its own fragment which
+# essentially lists what the source files are and how to link them
+# into an riscv and/or host executable. All variables should include
+# the benchmark name as a prefix so that they are unique.
+#
+
+median_c_src = \
+ median_main.c \
+ median.c \
+
+median_riscv_src = \
+ crt.S \
+
+median_c_objs = $(patsubst %.c, %.o, $(median_c_src))
+median_riscv_objs = $(patsubst %.S, %.o, $(median_riscv_src))
+
+median_host_bin = median.host
+$(median_host_bin): $(median_c_src)
+ $(HOST_COMP) $^ -o $(median_host_bin)
+
+median_riscv_bin = median.riscv
+$(median_riscv_bin): $(median_c_objs) $(median_riscv_objs)
+ $(RISCV_LINK) $(median_c_objs) $(median_riscv_objs) -o $(median_riscv_bin)
+
+junk += $(median_c_objs) $(median_riscv_objs) \
+ $(median_host_bin) $(median_riscv_bin)
diff --git a/benchmarks/median/dataset1.h b/benchmarks/median/dataset1.h
new file mode 100644
index 0000000..a7bc568
--- /dev/null
+++ b/benchmarks/median/dataset1.h
@@ -0,0 +1,51 @@
+
+#define DATA_SIZE 400
+
+int input_data[DATA_SIZE] =
+{
+ 41, 454, 833, 335, 564, 1, 187, 989, 749, 365, 350, 572, 132, 64, 949, 153, 584, 216, 805, 140,
+ 621, 210, 6, 572, 931, 339, 890, 593, 392, 898, 694, 228, 961, 12, 110, 883, 116, 750, 296, 646,
+ 426, 500, 314, 436, 659, 701, 774, 812, 319, 981, 678, 150, 875, 696, 376, 564, 474, 272, 938, 258,
+ 539, 647, 569, 509, 203, 88, 280, 703, 759, 669, 606, 375, 511, 551, 657, 936, 195, 592, 81, 569,
+ 267, 952, 229, 800, 337, 584, 944, 643, 902, 368, 241, 489, 913, 328, 826, 313, 933, 592, 985, 388,
+ 195, 543, 960, 649, 566, 979, 350, 997, 649, 814, 657, 79, 181, 208, 111, 998, 859, 629, 65, 847,
+ 288, 704, 349, 997, 141, 253, 905, 715, 886, 430, 264, 415, 576, 538, 979, 700, 761, 4, 241, 494,
+ 478, 100, 499, 864, 403, 693, 222, 416, 444, 296, 721, 285, 676, 620, 317, 78, 224, 351, 937, 540,
+ 288, 646, 119, 169, 615, 527, 606, 289, 389, 796, 351, 801, 455, 720, 278, 758, 367, 745, 358, 92,
+ 584, 989, 62, 271, 985, 853, 403, 788, 346, 531, 517, 222, 559, 461, 908, 241, 775, 358, 255, 332,
+ 778, 684, 598, 740, 143, 446, 33, 311, 125, 743, 941, 557, 933, 479, 799, 557, 553, 925, 431, 796,
+ 648, 357, 952, 891, 287, 666, 19, 514, 49, 557, 86, 870, 95, 853, 441, 440, 587, 61, 614, 678,
+ 382, 396, 280, 9, 808, 17, 971, 170, 819, 291, 344, 380, 450, 536, 512, 185, 965, 917, 347, 539,
+ 808, 983, 882, 887, 537, 54, 946, 612, 701, 951, 356, 479, 567, 151, 891, 7, 22, 641, 568, 335,
+ 665, 730, 423, 95, 434, 728, 158, 280, 2, 395, 84, 688, 247, 911, 49, 476, 435, 815, 792, 729,
+ 869, 265, 486, 127, 414, 236, 369, 214, 548, 180, 518, 6, 888, 503, 682, 596, 284, 173, 264, 643,
+ 499, 346, 290, 599, 897, 68, 215, 849, 731, 658, 688, 619, 251, 121, 786, 131, 555, 828, 302, 667,
+ 528, 433, 544, 487, 322, 753, 947, 125, 287, 626, 824, 14, 304, 10, 788, 403, 733, 106, 959, 703,
+ 366, 818, 722, 964, 294, 406, 975, 874, 653, 856, 748, 86, 91, 60, 378, 660, 105, 667, 102, 153,
+ 381, 121, 651, 98, 825, 412, 840, 236, 356, 12, 148, 423, 54, 965, 140, 216, 955, 621, 343, 361
+};
+
+int verify_data[DATA_SIZE] =
+{
+ 0, 454, 454, 564, 335, 187, 187, 749, 749, 365, 365, 350, 132, 132, 153, 584, 216, 584, 216, 621,
+ 210, 210, 210, 572, 572, 890, 593, 593, 593, 694, 694, 694, 228, 110, 110, 116, 750, 296, 646, 426,
+ 500, 426, 436, 436, 659, 701, 774, 774, 812, 678, 678, 678, 696, 696, 564, 474, 474, 474, 272, 539,
+ 539, 569, 569, 509, 203, 203, 280, 703, 703, 669, 606, 511, 511, 551, 657, 657, 592, 195, 569, 267,
+ 569, 267, 800, 337, 584, 584, 643, 902, 643, 368, 368, 489, 489, 826, 328, 826, 592, 933, 592, 388,
+ 388, 543, 649, 649, 649, 566, 979, 649, 814, 657, 657, 181, 181, 181, 208, 859, 859, 629, 629, 288,
+ 704, 349, 704, 349, 253, 253, 715, 886, 715, 430, 415, 415, 538, 576, 700, 761, 700, 241, 241, 478,
+ 478, 478, 499, 499, 693, 403, 416, 416, 416, 444, 296, 676, 620, 620, 317, 224, 224, 351, 540, 540,
+ 540, 288, 169, 169, 527, 606, 527, 389, 389, 389, 796, 455, 720, 455, 720, 367, 745, 367, 358, 358,
+ 584, 584, 271, 271, 853, 853, 788, 403, 531, 517, 517, 517, 461, 559, 461, 775, 358, 358, 332, 332,
+ 684, 684, 684, 598, 446, 143, 311, 125, 311, 743, 743, 933, 557, 799, 557, 557, 557, 553, 796, 648,
+ 648, 648, 891, 891, 666, 287, 514, 49, 514, 86, 557, 95, 853, 441, 441, 441, 440, 587, 614, 614,
+ 396, 382, 280, 280, 17, 808, 170, 819, 291, 344, 344, 380, 450, 512, 512, 512, 917, 917, 539, 539,
+ 808, 882, 887, 882, 537, 537, 612, 701, 701, 701, 479, 479, 479, 567, 151, 22, 22, 568, 568, 568,
+ 665, 665, 423, 423, 434, 434, 280, 158, 280, 84, 395, 247, 688, 247, 476, 435, 476, 792, 792, 792,
+ 729, 486, 265, 414, 236, 369, 236, 369, 214, 518, 180, 518, 503, 682, 596, 596, 284, 264, 264, 499,
+ 499, 346, 346, 599, 599, 215, 215, 731, 731, 688, 658, 619, 251, 251, 131, 555, 555, 555, 667, 528,
+ 528, 528, 487, 487, 487, 753, 753, 287, 287, 626, 626, 304, 14, 304, 403, 733, 403, 733, 703, 703,
+ 703, 722, 818, 722, 406, 406, 874, 874, 856, 748, 748, 91, 86, 91, 378, 378, 660, 105, 153, 153,
+ 153, 381, 121, 651, 412, 825, 412, 356, 236, 148, 148, 148, 423, 140, 216, 216, 621, 621, 361, 0
+};
+
diff --git a/benchmarks/median/median.c b/benchmarks/median/median.c
new file mode 100644
index 0000000..3c509cc
--- /dev/null
+++ b/benchmarks/median/median.c
@@ -0,0 +1,40 @@
+//**************************************************************************
+// Median filter (c version)
+//--------------------------------------------------------------------------
+
+void median( int n, int input[], int results[] )
+{
+ int A, B, C, i;
+
+ // Zero the ends
+ results[0] = 0;
+ results[n-1] = 0;
+
+ // Do the filter
+ for ( i = 1; i < (n-1); i++ ) {
+
+ A = input[i-1];
+ B = input[i];
+ C = input[i+1];
+
+ if ( A < B ) {
+ if ( B < C )
+ results[i] = B;
+ else if ( C < A )
+ results[i] = A;
+ else
+ results[i] = C;
+ }
+
+ else {
+ if ( A < C )
+ results[i] = A;
+ else if ( C < B )
+ results[i] = B;
+ else
+ results[i] = C;
+ }
+
+ }
+
+}
diff --git a/benchmarks/median/median.h b/benchmarks/median/median.h
new file mode 100644
index 0000000..b8b9a94
--- /dev/null
+++ b/benchmarks/median/median.h
@@ -0,0 +1,9 @@
+//**************************************************************************
+// Median filters
+//--------------------------------------------------------------------------
+
+// Simple C version
+void median( int n, int input[], int results[] );
+
+// Simple assembly version
+void median_asm( int n, int input[], int results[] );
diff --git a/benchmarks/median/median_gendata.pl b/benchmarks/median/median_gendata.pl
new file mode 100755
index 0000000..373904e
--- /dev/null
+++ b/benchmarks/median/median_gendata.pl
@@ -0,0 +1,140 @@
+#!/usr/bin/perl -w
+#==========================================================================
+# median_gendata.pl
+#
+# Author : Christopher Batten (cbatten@mit.edu)
+# Date : May 9, 2005
+#
+(our $usageMsg = <<'ENDMSG') =~ s/^\#//gm;
+#
+# Simple script which creates an input data set and the reference data
+# for the median benchmark.
+#
+ENDMSG
+
+use strict "vars";
+use warnings;
+no warnings("once");
+use Getopt::Long;
+
+#--------------------------------------------------------------------------
+# Command line processing
+#--------------------------------------------------------------------------
+
+our %opts;
+
+sub usage()
+{
+
+ print "\n";
+ print " Usage: median_gendata.pl [options] \n";
+ print "\n";
+ print " Options:\n";
+ print " --help print this message\n";
+ print " --size size of input data [750]\n";
+ print " --seed random seed [1]\n";
+ print "$usageMsg";
+
+ exit();
+}
+
+sub processCommandLine()
+{
+
+ $opts{"help"} = 0;
+ $opts{"size"} = 750;
+ $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 "int ".$arrayName."[DATA_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";
+}
+
+#--------------------------------------------------------------------------
+# Main
+#--------------------------------------------------------------------------
+
+sub main()
+{
+
+ processCommandLine();
+ srand($opts{"seed"});
+
+ my @values;
+ for ( my $i = 0; $i < $opts{"size"}; $i++ ) {
+ push( @values, int(rand(999)) );
+ }
+
+ my @median;
+ $median[0] = 0;
+ $median[$opts{"size"}-1] = 0;
+ for ( my $i = 1; $i < $opts{"size"}-1; $i++ ) {
+ my @tempList = ( $values[$i-1], $values[$i], $values[$i+1] );
+ my @sorted = sort { $a <=> $b } @tempList;
+ $median[$i] = $sorted[1];
+ }
+
+ print "\n\#define DATA_SIZE ".$opts{"size"}." \n\n";
+ printArray( "input_data", \@values );
+ printArray( "verify_data", \@median );
+
+}
+
+main();
+
diff --git a/benchmarks/median/median_main.c b/benchmarks/median/median_main.c
new file mode 100644
index 0000000..6decd3d
--- /dev/null
+++ b/benchmarks/median/median_main.c
@@ -0,0 +1,131 @@
+//**************************************************************************
+// Median filter bencmark
+//--------------------------------------------------------------------------
+//
+// This benchmark performs a 1D three element median filter. The
+// input data (and reference data) should be generated using the
+// median_gendata.pl perl script and dumped to a file named
+// dataset1.h You should not change anything except the
+// HOST_DEBUG and PREALLOCATE macros for your timing run.
+
+#include "median.h"
+
+//--------------------------------------------------------------------------
+// Macros
+
+// Set HOST_DEBUG to 1 if you are going to compile this for a host
+// machine (ie Athena/Linux) for debug purposes and set HOST_DEBUG
+// to 0 if you are compiling with the smips-gcc toolchain.
+
+#ifndef HOST_DEBUG
+#define HOST_DEBUG 0
+#endif
+
+// Set PREALLOCATE to 1 if you want to preallocate the benchmark
+// function before starting stats. If you have instruction/data
+// caches and you don't want to count the overhead of misses, then
+// you will need to use preallocation.
+
+#ifndef PREALLOCATE
+#define PREALLOCATE 0
+#endif
+
+// Set SET_STATS to 1 if you want to carve out the piece that actually
+// does the computation.
+
+#ifndef SET_STATS
+#define SET_STATS 0
+#endif
+
+//--------------------------------------------------------------------------
+// Input/Reference Data
+
+#include "dataset1.h"
+
+//--------------------------------------------------------------------------
+// Helper functions
+
+int verify( int n, int test[], int correct[] )
+{
+ int i;
+ for ( i = 0; i < n; i++ ) {
+ if ( test[i] != correct[i] ) {
+ return 2;
+ }
+ }
+ return 1;
+}
+
+#if HOST_DEBUG
+void printArray( char name[], int n, int arr[] )
+{
+ int i;
+ printf( " %10s :", name );
+ for ( i = 0; i < n; i++ )
+ printf( " %3d ", arr[i] );
+ printf( "\n" );
+}
+#endif
+
+void finishTest( int toHostValue )
+{
+#if HOST_DEBUG
+ if ( toHostValue == 1 )
+ printf( "*** PASSED ***\n" );
+ else
+ printf( "*** FAILED *** (tohost = %d)\n", toHostValue );
+ exit(0);
+#else
+ asm( "mtpcr %0, cr30" : : "r" (toHostValue) );
+ while ( 1 ) { }
+#endif
+}
+
+void setStats( int enable )
+{
+#if ( !HOST_DEBUG && SET_STATS )
+ asm( "mtpcr %0, cr10" : : "r" (enable) );
+#endif
+}
+
+//--------------------------------------------------------------------------
+// Main
+
+int main( int argc, char* argv[] )
+{
+ int results_data[DATA_SIZE];
+
+ // Output the input array
+
+#if HOST_DEBUG
+ printArray( "input", DATA_SIZE, input_data );
+ printArray( "verify", DATA_SIZE, verify_data );
+#endif
+
+ // If needed we preallocate everything in the caches
+
+#if ( !HOST_DEBUG && PREALLOCATE )
+ median( DATA_SIZE, input_data, results_data );
+#endif
+
+ // Do the filter
+
+#if HOST_DEBUG
+ median( DATA_SIZE, input_data, results_data );
+#else
+ setStats(1);
+ median( DATA_SIZE, input_data, results_data );
+ setStats(0);
+#endif
+
+ // Print out the results
+
+#if HOST_DEBUG
+ printArray( "results", DATA_SIZE, results_data );
+#endif
+
+ // Check the results
+
+ finishTest(verify( DATA_SIZE, results_data, verify_data ));
+
+}