Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
095f0ef72f | |||
adb66cfe6e | |||
13fdeb7c36 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -151,6 +151,3 @@ compile_commands.json
|
|||||||
CTestTestfile.cmake
|
CTestTestfile.cmake
|
||||||
*.dump
|
*.dump
|
||||||
|
|
||||||
.vscode/c_cpp_properties.json
|
|
||||||
semihosting_test/build/semihosting_test
|
|
||||||
semihosting_test/build/Makefile
|
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
if (NOT DEFINED BOARD)
|
||||||
|
set(BOARD iss)
|
||||||
|
endif()
|
||||||
|
if (NOT DEFINED ISA)
|
||||||
|
set(ISA imc)
|
||||||
|
endif()
|
||||||
|
message(STATUS "Building firmware using ${BOARD} board configuration")
|
||||||
|
add_custom_target(fw-hello-world ALL
|
||||||
|
COMMAND make -C ${riscvfw_SOURCE_DIR}/hello-world BOARD=${BOARD} ISA=${ISA}
|
||||||
|
USES_TERMINAL
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
add_custom_target(fw-dhrystone ALL
|
||||||
|
COMMAND make -C ${riscvfw_SOURCE_DIR}/benchmarks/dhrystone BOARD=${BOARD} ISA=${ISA}
|
||||||
|
USES_TERMINAL
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
add_custom_target(fw-coremark ALL
|
||||||
|
COMMAND make -C ${riscvfw_SOURCE_DIR}/benchmarks/coremark BOARD=${BOARD} ISA=${ISA}
|
||||||
|
USES_TERMINAL
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
Submodule bare-metal-bsp updated: 540397494a...87dc0ec230
@ -1,46 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.21)
|
|
||||||
project(coremark C)
|
|
||||||
set(TARGET coremark)
|
|
||||||
#set(CMAKE_BUILD_TYPE Release)
|
|
||||||
|
|
||||||
option(HAVE_NO_INIT_FINI "Enable NO_INIT_FINI" OFF)
|
|
||||||
|
|
||||||
if(HAVE_NO_INIT_FINI)
|
|
||||||
#if HAVE_NO_INIT_FINI is ON
|
|
||||||
add_definitions(-DHAVE_NO_INIT_FINI)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
# Source files
|
|
||||||
set(SOURCES
|
|
||||||
core_portme.c
|
|
||||||
cvt.c
|
|
||||||
ee_printf.c
|
|
||||||
cm/core_list_join.c
|
|
||||||
cm/core_main.c
|
|
||||||
cm/core_matrix.c
|
|
||||||
cm/core_state.c
|
|
||||||
cm/core_util.c
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# Create executable
|
|
||||||
add_executable(coremark ${SOURCES})
|
|
||||||
target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_LIST_DIR}/cm)
|
|
||||||
target_compile_options(${TARGET} PRIVATE -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -fno-builtin-strnlen -fno-common -funroll-loops -finline-functions -falign-functions=16 -falign-jumps=4 -falign-loops=4 -finline-limit=1000 -fno-if-conversion2 -fselective-scheduling -fno-crossjumping -freorder-blocks-and-partition -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -fno-common -funroll-loops -finline-functions -falign-functions=16 -falign-jumps=4 -falign-loops=4 -finline-limit=1000 -fno-if-conversion2 -fselective-scheduling -fno-crossjumping -freorder-blocks-and-partition )
|
|
||||||
target_compile_definitions(${TARGET} PRIVATE PERFORMANCE_RUN=1 CLOCKS_PER_SEC=10000000 FLAGS_STR="" PERFORMANCE_RUN=1 CLOCKS_PER_SEC=10000000 ITERATIONS=600)
|
|
||||||
|
|
||||||
set(BOARD "iss" CACHE STRING "Target board")
|
|
||||||
add_subdirectory(../../bare-metal-bsp bsp)
|
|
||||||
target_link_libraries(${TARGET} PRIVATE bsp)
|
|
||||||
target_link_options(${TARGET} PRIVATE -Wl,-Map=${TARGET}.map)
|
|
||||||
|
|
||||||
include(CMakePrintHelpers)
|
|
||||||
cmake_print_properties(TARGETS ${TARGET} PROPERTIES COMPILE_DEFINITIONS COMPILE_OPTIONS LINK_OPTIONS INTERFACE_LINK_OPTIONS)
|
|
||||||
|
|
||||||
#message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
|
|
||||||
#message(STATUS "CMAKE_C_FLAGS = ${CMAKE_C_FLAGS}")
|
|
||||||
|
|
||||||
add_custom_command(TARGET ${TARGET} POST_BUILD
|
|
||||||
COMMAND ${CMAKE_OBJDUMP} -S ${TARGET}.elf > ${TARGET}.dis
|
|
||||||
COMMENT "Creating disassembly for ${TARGET}")
|
|
@ -1,70 +0,0 @@
|
|||||||
{
|
|
||||||
"version": 3,
|
|
||||||
"vendor": {
|
|
||||||
"conan": {}
|
|
||||||
},
|
|
||||||
"cmakeMinimumRequired": {
|
|
||||||
"major": 3,
|
|
||||||
"minor": 24,
|
|
||||||
"patch": 0
|
|
||||||
},
|
|
||||||
"configurePresets": [
|
|
||||||
{
|
|
||||||
"name": "debug",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Debug",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "debug_moon",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Debug",
|
|
||||||
"BOARD": "moonlight",
|
|
||||||
"HAVE_NO_INIT_FINI": "ON",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "debug_tgc",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Debug",
|
|
||||||
"BOARD": "tgc_vp",
|
|
||||||
"HAVE_NO_INIT_FINI": "ON",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "debug_64",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Debug",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "debug_64_moon",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Debug",
|
|
||||||
"BOARD": "moonlight",
|
|
||||||
"HAVE_NO_INIT_FINI": "ON",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "debug_64_tgc",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Debug",
|
|
||||||
"BOARD": "tgc_vp",
|
|
||||||
"HAVE_NO_INIT_FINI": "ON",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "release",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Release",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -15,58 +15,55 @@ limitations under the License.
|
|||||||
|
|
||||||
Original Author: Shay Gal-on
|
Original Author: Shay Gal-on
|
||||||
*/
|
*/
|
||||||
#include "core_portme.h"
|
|
||||||
#include "coremark.h"
|
#include "coremark.h"
|
||||||
#include <unistd.h>
|
#include "core_portme.h"
|
||||||
// Read cycle CSR
|
//Read cycle CSR
|
||||||
unsigned long long _read_cycle() {
|
unsigned long long _read_cycle()
|
||||||
unsigned long long result;
|
{
|
||||||
unsigned long lower;
|
unsigned long long result;
|
||||||
unsigned long upper1;
|
unsigned long lower;
|
||||||
unsigned long upper2;
|
unsigned long upper1;
|
||||||
|
unsigned long upper2;
|
||||||
|
|
||||||
asm volatile("repeat_cycle_%=: csrr %0, cycleh;\n"
|
asm volatile (
|
||||||
" csrr %1, cycle;\n"
|
"repeat_cycle_%=: csrr %0, cycleh;\n"
|
||||||
" csrr %2, cycleh;\n"
|
" csrr %1, cycle;\n"
|
||||||
" bne %0, %2, repeat_cycle_%=;\n"
|
" csrr %2, cycleh;\n"
|
||||||
: "=r"(upper1), "=r"(lower),
|
" bne %0, %2, repeat_cycle_%=;\n"
|
||||||
"=r"(upper2) // Outputs : temp variable for load result
|
: "=r" (upper1),"=r" (lower),"=r" (upper2) // Outputs : temp variable for load result
|
||||||
:
|
:
|
||||||
:);
|
:
|
||||||
*(unsigned long *)(&result) = lower;
|
);
|
||||||
*((unsigned long *)(&result) + 1) = upper1;
|
*(unsigned long *)(&result) = lower;
|
||||||
|
*((unsigned long *)(&result)+1) = upper1;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// extern volatile int tohost;
|
volatile int tohost;
|
||||||
// extern volatile int fromhost;
|
volatile int fromhost;
|
||||||
|
|
||||||
void write_hex(int fd, uint32_t hex);
|
void exit(int n){
|
||||||
|
tohost = 0x1;
|
||||||
void exit(int n) {
|
for (;;);
|
||||||
write_hex(STDERR_FILENO, 1);
|
|
||||||
// tohost = 0x1;
|
|
||||||
for (;;)
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void __libc_init_array(void) {
|
void __libc_init_array (void) {
|
||||||
/*
|
/*
|
||||||
size_t count;
|
size_t count;
|
||||||
size_t i;
|
size_t i;
|
||||||
count = __preinit_array_end - __preinit_array_start;
|
count = __preinit_array_end - __preinit_array_start;
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
__preinit_array_start[i] ();
|
__preinit_array_start[i] ();
|
||||||
|
|
||||||
#ifdef HAVE_INIT_FINI
|
#ifdef HAVE_INIT_FINI
|
||||||
_init ();
|
_init ();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
count = __init_array_end - __init_array_start;
|
count = __init_array_end - __init_array_start;
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
__init_array_start[i] ();
|
__init_array_start[i] ();
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
#if VALIDATION_RUN
|
#if VALIDATION_RUN
|
||||||
volatile ee_s32 seed1_volatile = 0x3415;
|
volatile ee_s32 seed1_volatile = 0x3415;
|
||||||
@ -92,7 +89,10 @@ volatile ee_s32 seed5_volatile = 0;
|
|||||||
time.h and windows.h definitions included.
|
time.h and windows.h definitions included.
|
||||||
*/
|
*/
|
||||||
CORETIMETYPE
|
CORETIMETYPE
|
||||||
barebones_clock() { return (CORETIMETYPE)_read_cycle(); }
|
barebones_clock()
|
||||||
|
{
|
||||||
|
return (CORETIMETYPE)_read_cycle();
|
||||||
|
}
|
||||||
/* Define : TIMER_RES_DIVIDER
|
/* Define : TIMER_RES_DIVIDER
|
||||||
Divider to trade off timer resolution and total time that can be
|
Divider to trade off timer resolution and total time that can be
|
||||||
measured.
|
measured.
|
||||||
@ -101,11 +101,11 @@ barebones_clock() { return (CORETIMETYPE)_read_cycle(); }
|
|||||||
does not occur. If there are issues with the return value overflowing,
|
does not occur. If there are issues with the return value overflowing,
|
||||||
increase this value.
|
increase this value.
|
||||||
*/
|
*/
|
||||||
#define GETMYTIME(_t) (*_t = barebones_clock())
|
#define GETMYTIME(_t) (*_t = barebones_clock())
|
||||||
#define MYTIMEDIFF(fin, ini) ((fin) - (ini))
|
#define MYTIMEDIFF(fin, ini) ((fin) - (ini))
|
||||||
#define TIMER_RES_DIVIDER 1
|
#define TIMER_RES_DIVIDER 1
|
||||||
#define SAMPLE_TIME_IMPLEMENTATION 1
|
#define SAMPLE_TIME_IMPLEMENTATION 1
|
||||||
#define EE_TICKS_PER_SEC (CLOCKS_PER_SEC / TIMER_RES_DIVIDER)
|
#define EE_TICKS_PER_SEC (CLOCKS_PER_SEC / TIMER_RES_DIVIDER)
|
||||||
|
|
||||||
/** Define Host specific (POSIX), or target specific global time variables. */
|
/** Define Host specific (POSIX), or target specific global time variables. */
|
||||||
static CORETIMETYPE start_time_val, stop_time_val;
|
static CORETIMETYPE start_time_val, stop_time_val;
|
||||||
@ -118,7 +118,11 @@ static CORETIMETYPE start_time_val, stop_time_val;
|
|||||||
example code) or zeroing some system parameters - e.g. setting the cpu clocks
|
example code) or zeroing some system parameters - e.g. setting the cpu clocks
|
||||||
cycles to 0.
|
cycles to 0.
|
||||||
*/
|
*/
|
||||||
void start_time(void) { GETMYTIME(&start_time_val); }
|
void
|
||||||
|
start_time(void)
|
||||||
|
{
|
||||||
|
GETMYTIME(&start_time_val);
|
||||||
|
}
|
||||||
/* Function : stop_time
|
/* Function : stop_time
|
||||||
This function will be called right after ending the timed portion of the
|
This function will be called right after ending the timed portion of the
|
||||||
benchmark.
|
benchmark.
|
||||||
@ -127,7 +131,11 @@ void start_time(void) { GETMYTIME(&start_time_val); }
|
|||||||
example code) or other system parameters - e.g. reading the current value of
|
example code) or other system parameters - e.g. reading the current value of
|
||||||
cpu cycles counter.
|
cpu cycles counter.
|
||||||
*/
|
*/
|
||||||
void stop_time(void) { GETMYTIME(&stop_time_val); }
|
void
|
||||||
|
stop_time(void)
|
||||||
|
{
|
||||||
|
GETMYTIME(&stop_time_val);
|
||||||
|
}
|
||||||
/* Function : get_time
|
/* Function : get_time
|
||||||
Return an abstract "ticks" number that signifies time on the system.
|
Return an abstract "ticks" number that signifies time on the system.
|
||||||
|
|
||||||
@ -138,9 +146,11 @@ void stop_time(void) { GETMYTIME(&stop_time_val); }
|
|||||||
controlled by <TIMER_RES_DIVIDER>
|
controlled by <TIMER_RES_DIVIDER>
|
||||||
*/
|
*/
|
||||||
CORE_TICKS
|
CORE_TICKS
|
||||||
get_time(void) {
|
get_time(void)
|
||||||
CORE_TICKS elapsed = (CORE_TICKS)(MYTIMEDIFF(stop_time_val, start_time_val));
|
{
|
||||||
return elapsed;
|
CORE_TICKS elapsed
|
||||||
|
= (CORE_TICKS)(MYTIMEDIFF(stop_time_val, start_time_val));
|
||||||
|
return elapsed;
|
||||||
}
|
}
|
||||||
/* Function : time_in_secs
|
/* Function : time_in_secs
|
||||||
Convert the value returned by get_time to seconds.
|
Convert the value returned by get_time to seconds.
|
||||||
@ -149,9 +159,11 @@ get_time(void) {
|
|||||||
floating point. Default implementation implemented by the EE_TICKS_PER_SEC
|
floating point. Default implementation implemented by the EE_TICKS_PER_SEC
|
||||||
macro above.
|
macro above.
|
||||||
*/
|
*/
|
||||||
secs_ret time_in_secs(CORE_TICKS ticks) {
|
secs_ret
|
||||||
secs_ret retval = ((secs_ret)ticks) / (secs_ret)EE_TICKS_PER_SEC;
|
time_in_secs(CORE_TICKS ticks)
|
||||||
return retval;
|
{
|
||||||
|
secs_ret retval = ((secs_ret)ticks) / (secs_ret)EE_TICKS_PER_SEC;
|
||||||
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
ee_u32 default_num_contexts = 1;
|
ee_u32 default_num_contexts = 1;
|
||||||
@ -160,18 +172,27 @@ ee_u32 default_num_contexts = 1;
|
|||||||
Target specific initialization code
|
Target specific initialization code
|
||||||
Test for some common mistakes.
|
Test for some common mistakes.
|
||||||
*/
|
*/
|
||||||
void portable_init(core_portable *p, int *argc, char *argv[]) {
|
void
|
||||||
if (sizeof(ee_ptr_int) != sizeof(ee_u8 *)) {
|
portable_init(core_portable *p, int *argc, char *argv[])
|
||||||
ee_printf("ERROR! Please define ee_ptr_int to a type that holds a "
|
{
|
||||||
"pointer!\n");
|
if (sizeof(ee_ptr_int) != sizeof(ee_u8 *))
|
||||||
}
|
{
|
||||||
if (sizeof(ee_u32) != 4) {
|
ee_printf(
|
||||||
ee_printf("ERROR! Please define ee_u32 to a 32b unsigned type!\n");
|
"ERROR! Please define ee_ptr_int to a type that holds a "
|
||||||
}
|
"pointer!\n");
|
||||||
p->portable_id = 1;
|
}
|
||||||
ee_printf("portable_init finished.\n");
|
if (sizeof(ee_u32) != 4)
|
||||||
|
{
|
||||||
|
ee_printf("ERROR! Please define ee_u32 to a 32b unsigned type!\n");
|
||||||
|
}
|
||||||
|
p->portable_id = 1;
|
||||||
|
ee_printf("portable_init finished.\n");
|
||||||
}
|
}
|
||||||
/* Function : portable_fini
|
/* Function : portable_fini
|
||||||
Target specific final code
|
Target specific final code
|
||||||
*/
|
*/
|
||||||
void portable_fini(core_portable *p) { p->portable_id = 0; }
|
void
|
||||||
|
portable_fini(core_portable *p)
|
||||||
|
{
|
||||||
|
p->portable_id = 0;
|
||||||
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
1
benchmarks/dhrystone/.gitignore
vendored
1
benchmarks/dhrystone/.gitignore
vendored
@ -1,3 +1,2 @@
|
|||||||
dhrystone
|
dhrystone
|
||||||
/dhrystone.dis
|
/dhrystone.dis
|
||||||
build/
|
|
@ -1,31 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.21)
|
|
||||||
project(dhrystone C)
|
|
||||||
set(TARGET dhrystone)
|
|
||||||
|
|
||||||
option(HAVE_NO_INIT_FINI "Enable NO_INIT_FINI" OFF)
|
|
||||||
|
|
||||||
if(HAVE_NO_INIT_FINI)
|
|
||||||
#if HAVE_NO_INIT_FINI is ON
|
|
||||||
add_definitions(-DHAVE_NO_INIT_FINI)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(ITERATIONS 50000) # 20000 for TGC
|
|
||||||
|
|
||||||
add_executable(${TARGET} dhry_1.c dhry_2.c dhry_stubs.c)
|
|
||||||
target_include_directories(${TARGET} PRIVATE ${CMAKE_CURRENT_LIST_DIR})
|
|
||||||
target_compile_options(${TARGET} PRIVATE -fno-inline -fno-builtin-printf -fno-common -Wno-implicit -funroll-loops -fpeel-loops -fgcse-sm -fgcse-las)
|
|
||||||
target_compile_definitions(${TARGET} PRIVATE ITERATIONS=${ITERATIONS} HZ=32768 TIME NO_INIT)
|
|
||||||
|
|
||||||
set(BOARD "iss" CACHE STRING "Target board")
|
|
||||||
add_subdirectory(../../bare-metal-bsp bsp)
|
|
||||||
target_link_libraries(${TARGET} PRIVATE bsp)
|
|
||||||
target_link_options(${TARGET} PRIVATE LINKER:--wrap=scanf)
|
|
||||||
#target_link_options(${TARGET} PRIVATE LINKER:--wrap=scanf -Wl,--no-gc-sections)
|
|
||||||
|
|
||||||
target_link_options(${TARGET} PRIVATE -Wl,-Map=${TARGET}.map)
|
|
||||||
include(CMakePrintHelpers)
|
|
||||||
cmake_print_properties(TARGETS ${TARGET} PROPERTIES COMPILE_DEFINITIONS COMPILE_OPTIONS LINK_OPTIONS INTERFACE_LINK_OPTIONS)
|
|
||||||
|
|
||||||
add_custom_command(TARGET ${TARGET} POST_BUILD
|
|
||||||
COMMAND ${CMAKE_OBJDUMP} -S ${TARGET}.elf > ${TARGET}.dis
|
|
||||||
COMMENT "Creating disassembly for ${TARGET}")
|
|
@ -1,70 +0,0 @@
|
|||||||
{
|
|
||||||
"version": 3,
|
|
||||||
"vendor": {
|
|
||||||
"conan": {}
|
|
||||||
},
|
|
||||||
"cmakeMinimumRequired": {
|
|
||||||
"major": 3,
|
|
||||||
"minor": 24,
|
|
||||||
"patch": 0
|
|
||||||
},
|
|
||||||
"configurePresets": [
|
|
||||||
{
|
|
||||||
"name": "debug",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Debug",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "debug_moon",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Debug",
|
|
||||||
"BOARD": "moonlight",
|
|
||||||
"HAVE_NO_INIT_FINI": "ON",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "debug_tgc",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Debug",
|
|
||||||
"BOARD": "tgc_vp",
|
|
||||||
"HAVE_NO_INIT_FINI": "ON",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "debug_64",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Debug",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "debug_64_moon",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Debug",
|
|
||||||
"BOARD": "moonlight",
|
|
||||||
"HAVE_NO_INIT_FINI": "ON",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "debug_64_tgc",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Debug",
|
|
||||||
"BOARD": "tgc_vp",
|
|
||||||
"HAVE_NO_INIT_FINI": "ON",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "release",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Release",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -15,9 +15,9 @@ else
|
|||||||
RISCV_ABI:=ilp32
|
RISCV_ABI:=ilp32
|
||||||
endif
|
endif
|
||||||
# '-lgcc -lm' are needed to add softfloat routines
|
# '-lgcc -lm' are needed to add softfloat routines
|
||||||
CFLAGS := -g -O3 -DITERATIONS=$(ITERATIONS) -DHZ=32768 -DTIME -DNO_INIT -fno-inline -fno-builtin-printf -fno-common -Wno-implicit \
|
CFLAGS := -g -march=$(RISCV_ARCH)_zicsr_zifencei -mabi=$(RISCV_ABI) -mcmodel=medlow -O3 -DITERATIONS=$(ITERATIONS) -DHZ=32768 -DTIME -DNO_INIT -fno-inline -fno-builtin-printf -fno-common -Wno-implicit \
|
||||||
-funroll-loops -fpeel-loops -fgcse-sm -fgcse-las
|
-funroll-loops -fpeel-loops -fgcse-sm -fgcse-las
|
||||||
LDFLAGS := -Wl,--wrap=scanf
|
LDFLAGS := -g -march=$(RISCV_ARCH)_zicsr_zifencei -mabi=$(RISCV_ABI) -mcmodel=medlow -Wl,--wrap=scanf -Wl,--wrap=printf -Wl,--wrap=exit -lgcc -lm
|
||||||
|
|
||||||
TOOL_DIR=$(dir $(compiler))
|
TOOL_DIR=$(dir $(compiler))
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include <unistd.h>
|
|
||||||
#ifndef ITERATIONS
|
#ifndef ITERATIONS
|
||||||
#define ITERATIONS 20000
|
#define ITERATIONS 20000
|
||||||
#endif
|
#endif
|
||||||
@ -7,16 +6,20 @@
|
|||||||
/* The functions in this file are only meant to support Dhrystone on an
|
/* The functions in this file are only meant to support Dhrystone on an
|
||||||
* embedded RV32 system and are obviously incorrect in general. */
|
* embedded RV32 system and are obviously incorrect in general. */
|
||||||
|
|
||||||
long time(void) { return get_timer_value(); }
|
long time(void)
|
||||||
|
{
|
||||||
|
return get_timer_value();
|
||||||
|
}
|
||||||
|
|
||||||
// set the number of dhrystone iterations
|
// set the number of dhrystone iterations
|
||||||
void __wrap_scanf(const char *fmt, int *n) { *n = ITERATIONS; }
|
void __wrap_scanf(const char* fmt, int* n)
|
||||||
|
{
|
||||||
// extern volatile uint64_t tohost;
|
*n = ITERATIONS;
|
||||||
|
}
|
||||||
void exit(int n) {
|
|
||||||
// tohost = 0x1;
|
extern volatile uint32_t tohost;
|
||||||
write_hex(STDERR_FILENO, 1);
|
|
||||||
for (;;)
|
void exit(int n){
|
||||||
;
|
tohost = 0x1;
|
||||||
|
for (;;);
|
||||||
}
|
}
|
||||||
|
108
benchmarks/dhrystone_run_multiple.py
Normal file
108
benchmarks/dhrystone_run_multiple.py
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import time
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
def run_command(command, cwd=None):
|
||||||
|
"""Run a shell command in the specified directory and return its output."""
|
||||||
|
result = subprocess.run(
|
||||||
|
command,
|
||||||
|
shell=True,
|
||||||
|
cwd=cwd,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
check=False,
|
||||||
|
)
|
||||||
|
return result.stdout.decode("utf-8"), result.stderr.decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
def build_test_cases(makefile_dir, iterations):
|
||||||
|
"""Run the Makefile with the specified iterations."""
|
||||||
|
make_command = f"make clean && make ITERATIONS={iterations}"
|
||||||
|
stdout, stderr = run_command(make_command, cwd=makefile_dir)
|
||||||
|
if stderr:
|
||||||
|
raise RuntimeError(f"Error during make: {stderr}")
|
||||||
|
|
||||||
|
|
||||||
|
def main(simulator_path, makefile_dir):
|
||||||
|
# Directory for generated test cases
|
||||||
|
generated_dir = makefile_dir.parent / "workspace"
|
||||||
|
os.makedirs(generated_dir, exist_ok=True)
|
||||||
|
|
||||||
|
# Define the iterations
|
||||||
|
iterations_list = [10, 20, 30]
|
||||||
|
# 15 value up to 6.000.000 evenly apart on a log scale
|
||||||
|
iterations_list = [
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
4,
|
||||||
|
8,
|
||||||
|
17,
|
||||||
|
34,
|
||||||
|
69,
|
||||||
|
141,
|
||||||
|
287,
|
||||||
|
582,
|
||||||
|
1182,
|
||||||
|
2401,
|
||||||
|
4878,
|
||||||
|
9910,
|
||||||
|
20133,
|
||||||
|
40914,
|
||||||
|
83103,
|
||||||
|
168830,
|
||||||
|
343042,
|
||||||
|
696712,
|
||||||
|
1414641,
|
||||||
|
2874878,
|
||||||
|
5837995,
|
||||||
|
]
|
||||||
|
|
||||||
|
for iteration in iterations_list:
|
||||||
|
try:
|
||||||
|
# Update the Makefile with the current ITERATIONS value
|
||||||
|
build_test_cases(makefile_dir, iteration)
|
||||||
|
except RuntimeError as e:
|
||||||
|
print(f"Error during compilation with ITERATIONS={iteration}: {e}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Run the simulator with the generated test case
|
||||||
|
exe = makefile_dir / "dhrystone.elf"
|
||||||
|
if not exe.is_file():
|
||||||
|
exit(f"{exe} does not exist")
|
||||||
|
verbose_exe = generated_dir / "bin" / f"dhrystone_{iteration}.elf"
|
||||||
|
os.makedirs(verbose_exe.parent, exist_ok=True)
|
||||||
|
shutil.copy(exe, verbose_exe)
|
||||||
|
backends = ["interp", "llvm", "tcc", "asmjit"]
|
||||||
|
for backend in backends:
|
||||||
|
log_file = os.path.join(generated_dir, f"{backend}_{iteration}.log")
|
||||||
|
|
||||||
|
sim_command = f"{simulator_path} -f {exe} --backend {backend}"
|
||||||
|
start_time = time.time()
|
||||||
|
sim_stdout, sim_stderr = run_command(sim_command)
|
||||||
|
end_time = time.time()
|
||||||
|
elapsed_time = end_time - start_time
|
||||||
|
|
||||||
|
# Save the output to the logfile
|
||||||
|
with open(log_file, "w", encoding="utf8") as f:
|
||||||
|
f.write(sim_stdout)
|
||||||
|
if sim_stderr:
|
||||||
|
f.write(f"\nErrors:\n{sim_stderr}")
|
||||||
|
|
||||||
|
print(
|
||||||
|
f"Ran {backend} in {elapsed_time:.2f} s, Output saved to {backend}_{iteration}.log"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Run simulations with generated test cases."
|
||||||
|
)
|
||||||
|
parser.add_argument("simulator_path", help="Path to the simulator executable.")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
dhrystone_path = Path(__file__).parent / "dhrystone"
|
||||||
|
main(args.simulator_path, dhrystone_path)
|
86
benchmarks/visualize_runtimes.py
Normal file
86
benchmarks/visualize_runtimes.py
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
import argparse
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import plotly.express as px
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
|
def parse_logs(log_dir):
|
||||||
|
results = []
|
||||||
|
for filename in os.listdir(log_dir):
|
||||||
|
if filename.endswith(".log"):
|
||||||
|
filepath = os.path.join(log_dir, filename)
|
||||||
|
with open(filepath, "r", encoding="utf8") as file:
|
||||||
|
for line in file:
|
||||||
|
if (
|
||||||
|
"Executed" in line
|
||||||
|
and "instructions" in line
|
||||||
|
and "during" in line
|
||||||
|
and "resulting in" in line
|
||||||
|
):
|
||||||
|
parts = line.split()
|
||||||
|
instructions = int(parts[3])
|
||||||
|
time_idx = parts.index("during") + 1
|
||||||
|
time = int(parts[time_idx].rstrip("ms"))
|
||||||
|
mips_idx = parts.index("resulting") + 2
|
||||||
|
mips = float(parts[mips_idx].rstrip("MIPS"))
|
||||||
|
backend, iterations, _ = re.split(r"[_.]", filename)
|
||||||
|
|
||||||
|
results.append(
|
||||||
|
{
|
||||||
|
"backend": backend,
|
||||||
|
"run_count": int(iterations),
|
||||||
|
"instructions": instructions,
|
||||||
|
"time": time,
|
||||||
|
"mips": mips,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
def write_yaml(results, output_file):
|
||||||
|
with open(output_file, "w", encoding="utf8") as file:
|
||||||
|
yaml.dump(results, file)
|
||||||
|
|
||||||
|
|
||||||
|
def visualize_mips_over_instructions(yaml_file):
|
||||||
|
# Read data from YAML file
|
||||||
|
with open(yaml_file, "r", encoding="utf8") as file:
|
||||||
|
data = yaml.safe_load(file)
|
||||||
|
|
||||||
|
# Extract instructions and MIPS values
|
||||||
|
run_count = [entry["run_count"] for entry in data]
|
||||||
|
mips = [entry["mips"] for entry in data]
|
||||||
|
backends = [entry["backend"] for entry in data]
|
||||||
|
# Create scatter plot using Plotly Express
|
||||||
|
fig = px.line(
|
||||||
|
x=run_count,
|
||||||
|
y=mips,
|
||||||
|
color=backends,
|
||||||
|
labels={"x": "Dhrystone Iterations", "y": "MIPS", "color": "Backend"},
|
||||||
|
title="MIPS over Amount of Dhrystone Iterations",
|
||||||
|
log_x=True,
|
||||||
|
)
|
||||||
|
fig.show()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="""
|
||||||
|
Parse log files and extract relevant information. Create a 'results.yaml' file and visualize it.
|
||||||
|
Intended to be run after 'dhrystone_run_multiple.py'"""
|
||||||
|
)
|
||||||
|
parser.add_argument("log_dir", help="Path to the directory containing log files.")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
result_file = Path(__file__).parent / "results.yaml"
|
||||||
|
if not result_file.is_file():
|
||||||
|
results = parse_logs(args.log_dir)
|
||||||
|
write_yaml(results, result_file)
|
||||||
|
visualize_mips_over_instructions(result_file)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
1
hello-world/.gitignore
vendored
1
hello-world/.gitignore
vendored
@ -1,3 +1,2 @@
|
|||||||
/hello
|
/hello
|
||||||
/hello.dis
|
/hello.dis
|
||||||
build/
|
|
@ -1,23 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.21)
|
|
||||||
project(hello-world C)
|
|
||||||
set(TARGET hello)
|
|
||||||
option(HAVE_NO_INIT_FINI "Enable NO_INIT_FINI" OFF)
|
|
||||||
|
|
||||||
if(HAVE_NO_INIT_FINI)
|
|
||||||
#if HAVE_NO_INIT_FINI is ON
|
|
||||||
add_definitions(-DHAVE_NO_INIT_FINI)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_executable(${TARGET} hello.c)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
set(BOARD "iss" CACHE STRING "Target board")
|
|
||||||
message(" BOARD = ${BOARD}")
|
|
||||||
add_subdirectory(../bare-metal-bsp bsp)
|
|
||||||
target_link_libraries(${TARGET} PRIVATE bsp)
|
|
||||||
target_link_options(${TARGET} PRIVATE -Wl,-Map=${TARGET}.map)
|
|
||||||
|
|
||||||
add_custom_command(TARGET ${TARGET} POST_BUILD
|
|
||||||
COMMAND ${CMAKE_OBJDUMP} -S ${TARGET}.elf > ${TARGET}.dis
|
|
||||||
COMMENT "Creating disassembly for ${TARGET}")
|
|
@ -1,70 +0,0 @@
|
|||||||
{
|
|
||||||
"version": 3,
|
|
||||||
"vendor": {
|
|
||||||
"conan": {}
|
|
||||||
},
|
|
||||||
"cmakeMinimumRequired": {
|
|
||||||
"major": 3,
|
|
||||||
"minor": 24,
|
|
||||||
"patch": 0
|
|
||||||
},
|
|
||||||
"configurePresets": [
|
|
||||||
{
|
|
||||||
"name": "debug",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Debug",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "debug_moon",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Debug",
|
|
||||||
"BOARD": "moonlight",
|
|
||||||
"HAVE_NO_INIT_FINI": "ON",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "debug_tgc",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Debug",
|
|
||||||
"BOARD": "tgc_vp",
|
|
||||||
"HAVE_NO_INIT_FINI": "ON",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "debug_64",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Debug",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "debug_64_moon",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Debug",
|
|
||||||
"BOARD": "moonlight",
|
|
||||||
"HAVE_NO_INIT_FINI": "ON",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "debug_64_tgc",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Debug",
|
|
||||||
"BOARD": "tgc_vp",
|
|
||||||
"HAVE_NO_INIT_FINI": "ON",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv64gc.cmake"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "release",
|
|
||||||
"cacheVariables": {
|
|
||||||
"CMAKE_BUILD_TYPE": "Release",
|
|
||||||
"CMAKE_TOOLCHAIN_FILE": "../../bare-metal-bsp/cmake/rv32imc.cmake"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,37 +1,24 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "encoding.h"
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include <string.h>
|
#include "encoding.h"
|
||||||
|
|
||||||
int factorial(int i) {
|
int factorial(int i){
|
||||||
|
|
||||||
volatile int result = 1;
|
volatile int result = 1;
|
||||||
for (int ii = 1; ii <= i; ii++) {
|
for (int ii = 1; ii <= i; ii++) {
|
||||||
result = result * ii;
|
result = result * ii;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
|
||||||
extern volatile uintptr_t tohost;
|
|
||||||
|
|
||||||
void write_tohost(char *string) {
|
|
||||||
volatile uint64_t payload[4] = {64, 0, (uintptr_t)string,
|
|
||||||
(strlen(string) + 1)};
|
|
||||||
tohost = (uintptr_t)payload;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
char string[] = "hello world with write in hello";
|
{
|
||||||
|
volatile int result = factorial (10);
|
||||||
write_tohost(string);
|
printf("Factorial is %d\n", result);
|
||||||
|
printf("End of execution");
|
||||||
write(STDOUT_FILENO, string, sizeof(string));
|
return 0;
|
||||||
|
|
||||||
int result = factorial(10);
|
|
||||||
printf("Factorial is %d", result);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user