Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dataset1.h filter=lfs diff=lfs merge=lfs -text
37 changes: 29 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,42 @@
cmake_minimum_required(VERSION 3.22 FATAL_ERROR)

project(prot_jit)
project(prot_jit LANGUAGES C CXX)

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set_property(CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "${CMAKE_BINARY_DIR}/install")
set_property(CACHE CMAKE_INSTALL_PREFIX
PROPERTY VALUE "${CMAKE_BINARY_DIR}/install")
endif()

option(PROT_ENABLE_WERROR "Enable -Werror option (CI)" OFF)

option(PROT_BUILD_BENCHMARKS
"Enable benchmarks build (requires riscv gnu toolchain)" OFF)
enable_testing()

include(cmake/CPM.cmake)
# Provide default CXX settings
include(cmake/defaults.cmake)
include(cmake/dependencies.cmake)
include(cmake/utils.cmake)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

include(CPM)
# Provide default CXX settings
include(defaults)
include(dependencies)
include(utils)

add_subdirectory(src)
add_subdirectory(tools)

if(PROT_BUILD_BENCHMARKS)
set(RISCV_TOOLCHAIN ${CMAKE_CURRENT_SOURCE_DIR}/cmake/toolchain/riscv.cmake)
set(DEFAULT_ARGS
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE:STRING=Release
-DCMAKE_TOOLCHAIN_FILE:PATH=${RISCV_TOOLCHAIN})
if (DEFINED RISCV_TOOLCHAIN_DIR)
list(APPEND DEFAULT_ARGS -DRISCV_TOOLCHAIN_DIR:PATH=${RISCV_TOOLCHAIN_DIR})
endif()
ExternalProject_Add(
benchmarks
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/benchmarks
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/benchmarks
CONFIGURE_HANDLED_BY_BUILD True
BUILD_ALWAYS True
CMAKE_ARGS ${DEFAULT_ARGS})
endif()
22 changes: 22 additions & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.22 FATAL_ERROR)
project(psim-benchmarks LANGUAGES C ASM)

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set_property(CACHE CMAKE_INSTALL_PREFIX PROPERTY VALUE "${CMAKE_BINARY_DIR}/install")
endif()

macro(prot_add_bench tar)
add_executable(${tar} ${ARGN})
target_link_libraries(${tar} PRIVATE bench_startup)
install(TARGETS ${tar} DESTINATION bench)
endmacro()

add_subdirectory(common)
add_subdirectory(qsort)
add_subdirectory(towers)
add_subdirectory(multiply)
add_subdirectory(rsort)
add_subdirectory(vvadd)
add_subdirectory(median)
add_subdirectory(nopbench)
add_subdirectory(fibrec)
2 changes: 2 additions & 0 deletions benchmarks/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_library(bench_startup OBJECT start.s)
target_include_directories(bench_startup PUBLIC include)
21 changes: 21 additions & 0 deletions benchmarks/common/include/bench/utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef UTILS_H_INCLUDED
#define UTILS_H_INCLUDED


static int verify(int n, const int *test, const int *verify) {
int i;
// Unrolled for faster verification
for (i = 0; i < n / 2 * 2; i += 2) {
int t0 = test[i], t1 = test[i + 1];
int v0 = verify[i], v1 = verify[i + 1];
if (t0 != v0)
return i + 1;
if (t1 != v1)
return i + 2;
}
if (n % 2 != 0 && test[n - 1] != verify[n - 1])
return n;
return 0;
}

#endif // UTILS_H_INCLUDED
39 changes: 39 additions & 0 deletions benchmarks/common/start.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.global _start
.section .text
_start:
li x1, 0
# li x2, 0 set via sim
li x3, 0
li x4, 0
li x5, 0
li x6, 0
li x7, 0
li x8, 0
li x9, 0
li x10,0
li x11,0
li x12,0
li x13,0
li x14,0
li x15,0
li x16,0
li x17,0
li x18,0
li x19,0
li x20,0
li x21,0
li x22,0
li x23,0
li x24,0
li x25,0
li x26,0
li x27,0
li x28,0
li x29,0
li x30,0
li x31,0

jal main

li a7, 93
ecall
2 changes: 2 additions & 0 deletions benchmarks/fibrec/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
prot_add_bench(fibrec fibrec.c)
target_compile_definitions(fibrec PRIVATE N=31)
31 changes: 31 additions & 0 deletions benchmarks/fibrec/fibrec.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef N
#error "N was not defined"
#endif

int verify(unsigned r, unsigned n) {
static const unsigned calculated[] = {
1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987,
1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393,
196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887,
9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141,
267914296, 433494437, 701408733, 1134903170, 1836311903, 2971215073, 512559680,
3483774753, 3996334433, 3185141890, 2886509027, 1776683621, 368225352, 2144908973,
2513134325, 363076002, 2876210327, 3239286329, 1820529360, 764848393, 2585377753,
3350226146, 1640636603,
};
if (r == calculated[n])
return 0;
return 1;
}

unsigned fib(unsigned n) {
if (n <= 1)
return 1;
return fib(n - 1) + fib(n - 2);
}

int main() {
unsigned r = fib(N);
return verify(r, N);
}

1 change: 1 addition & 0 deletions benchmarks/median/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
prot_add_bench(median median.c median_main.c)
3 changes: 3 additions & 0 deletions benchmarks/median/dataset1.h
Git LFS file not shown
42 changes: 42 additions & 0 deletions benchmarks/median/median.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// See LICENSE for license details.

//**************************************************************************
// 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;
}

}

}
11 changes: 11 additions & 0 deletions benchmarks/median/median.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// See LICENSE for license details.

//**************************************************************************
// 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[] );
140 changes: 140 additions & 0 deletions benchmarks/median/median_gendata.pl
Original file line number Diff line number Diff line change
@@ -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();

Loading