Lichee_RV学习系列--CoreMark-Pro移植

Lichee_RV学习系列文章目录

Lichee_RV学习系列—认识Lichee Rv Dock、环境搭建和编译第一个程序
Lichee_RV学习系列—移植dhrystone



一、CoreMark-Pro简介

它也是和dhrystone一样,是一个测试CPU处理能力的一个程序,俗称跑分,CPU能跑多少分,CPU的处理能力就多高。

它可以在8位到64位的CPU上运行,而且跑分的可信度比dhrystone要高。

CoreMark-Pro是一个先进的市场处理器测试基准,跑分可信度高。EEMBC CoreMark和CoreMarkPRO共同提供了涵盖从低端微控制器到高性能计算处理器的标准基准测试。EEMBC CoreMark PRO基准测试包含五个常见的整数工作负载和四个常见的浮点工作负载。

CoMark-Pro分别会生成9个测试文件,分别对于一下测试

cjpeg-rose7-preset.exe  linear_alg-mid-100x100-sp.exe  parser-125k.exe     zip-test.exe
core.exe                loops-all-mid-10k-sp.exe       radix2-big-64k.exe
nnet_test.exe                  sha-test.exe

这些文件的测试内容包括:

  • JPEG压缩
  • ZIP压缩
  • XML解析
  • CoreMark版本的密集内存测试
  • Radix-2 快速傅里叶变换(FFT)
  • A simple neural-net
  • Livermore循环基准测试的一个大大改进的版本
  • LINPACK软件包导出的旋转高斯消去法

CoreMark官方链接

二、获取源码

github官方链接

gitee:xiaojie开源的riscv版本

详细的文档源码里面有,在docx目录中,简单的入门在官网github简介下面也有介绍,本文主要是参考github简介和core mark prou移植xiaojie开源的代码去跑的

三、编译coremark-pro

1、配置coremark-pro

配置两个文件就行,一个是交叉工具链编译的文件,一个是操作系统配置的文件

首先我们需要先进入源码目录,进入配置文件的目录

cd util/make
复制交叉编译工具链的文件
cp gcc-cross-linux.mak gcc-cross-riscv.mak
复制操作系统配置
cp linux64.mak riscv64.mak


配置交叉工具 gcc-cross-riscv.mak文件,配置好TOOLS和TPREF变量即可,这两个你的是交叉编译工具链所在的位置

TOOLS	= /home/allwinner/workspace/tina-D1-H/prebuilt/gcc/linux-x86/riscv/toolchain-thead-glibc/riscv64-glibc-gcc-thead_20200702
TPREF = riscv64-unknown-linux-gnu-
#  File : util/make/gcc-cross-linux.mak
#	GCC Tool Definitions, Host Compile and Run, cross from host to a linux target
#
#  EEMBC : Technical Advisory Group (TechTAG)
#------------------------------------------------------------------------------
# Copyright (c) 1998-2007 by the EDN Embedded Microprocessor 
# Benchmark Consortium (EEMBC), Inc. All Rights Reserved.
#==============================================================================

# RUN OPTIONS SECTION
# Build or run options (i.e. profiling, simulation)

# SYSTEM ENVIRONMENT SECTION

# Tools Root Directory
# This example uses a cross compiler built with crosstool targeting x86 linux.

#***********fixme sajid ******
#TOOLS	= /opt/crosstool/gcc-3.3.6-glibc-2.3.2/i386-unknown-linux-gnu
#TPREF = i386-unknown-linux-gnu-
# compiler path is = /opt/riscv/bin/riscv64-unknown-linux-gnu-gcc
TOOLS	= /home/allwinner/workspace/tina-D1-H/prebuilt/gcc/linux-x86/riscv/toolchain-thead-glibc/riscv64-glibc-gcc-thead_20200702
TPREF = riscv64-unknown-linux-gnu-
#********************
# And this shows compiling to a big endian mips linux
# TOOLS	= /opt/crosstool/gcc-3.3.6-glibc-2.3.2/mips-unknown-linux-gnu
# TPREF = mips-unknown-linux-gnu-
# * remember to set big endian flags below for this setting!
#SHELL	= /bin/bash

# Tools Executables, Output File Flag and Output File Types

# Variable: CC
#	name of the compiler
CC		= $(TOOLS)/bin/$(TPREF)gcc
# Solaris: /usr/ccs/bin/as requires space after -o passed from gcc.
OBJOUT	= -o 
COBJT	= -c 
CINCD	= -I 
CDEFN	= -D 
OEXT = .o

AS		= $(TOOLS)/bin/$(TPREF)as

LD		= $(TOOLS)/bin/$(TPREF)gcc
EXEOUT	= -o 
EXE		= .exe

AR		= $(TOOLS)/bin/$(TPREF)ar
LIBTYPE	= .a
LIBOUT	= 

# Some Tool Chains require specific perl version. 
# makefile default setting can be overridden here.
#PERL=`which perl`

# COMPILER SECTION

INCLUDE = $(TOOLS)/include

COMPILER_FLAGS	= -g -O2 $(CDEFN)NDEBUG $(CDEFN)HOST_EXAMPLE_CODE=1
COMPILER_NOOPT	= -O0 $(CDEFN)NDEBUG $(CDEFN)HOST_EXAMPLE_CODE=1
COMPILER_DEBUG	= -O0 -g $(CDEFN)HOST_EXAMPLE_CODE=1 -DBMDEBUG=1 -DTHDEBUG=1
PACK_OPTS = 

#Variable: CFLAGS 
#	Options for the compiler.
ifdef DDB
 CFLAGS = $(COMPILER_DEBUG) $(COMPILER_DEFS) $(PLATFORM_DEFS) $(PACK_OPTS)
else
 ifdef DDN
  CFLAGS = $(COMPILER_NOOPT) $(COMPILER_DEFS) $(PLATFORM_DEFS) $(PACK_OPTS) 
 else
  CFLAGS = $(COMPILER_FLAGS) $(COMPILER_DEFS) $(PLATFORM_DEFS) $(PACK_OPTS)
 endif
endif
ifdef DDT
 CFLAGS += -DTHDEBUG=1
endif

WARNING_OPTIONS	=	\
        -Wall -Wno-long-long -fno-asm -fsigned-char 

# Additional include files not in dependancies or system include.
COMPILER_INCLUDES = 
# Override harness thincs, make sure you take care of the harness paths
#THINCS=

#Variable: COMPILER_DEFINES
# Optional - Passed to compiler, here or in makefile to override THCFG defines.
COMPILER_DEFINES += HAVE_SYS_STAT_H=1 USE_NATIVE_PTHREAD=1 GCC_INLINE_MACRO=1
# For Big Endian Targets, using 0/1 also allows support for
# files that do not have EEMBC includes. (Don't quote the string)
#COMPILER_DEFINES += EE_BIG_ENDIAN=1 EE_LITTLE_ENDIAN=0
COMPILER_DEFS = $(addprefix $(CDEFN),$(COMPILER_DEFINES))
PLATFORM_DEFS = $(addprefix $(CDEFN),$(PLATFORM_DEFINES))

# ASSEMBLER SECTION

ASSEMBLER_FLAGS		= 
ASSEMBLER_INCLUDES	=

# LINKER SECTION
# -lm is optional. Some linkers (linux gcc) do not include math library by default.
LINKER_FLAGS	+= -lm -lpthread  

LINKER_INCLUDES	= 
# Some linkers do not re-scan libraries, and require some libraries 
# to be placed last on the command line to resolve references.
# some linkers require -lrt since they do not include realtime clock functions by default.
LINKER_LAST 	+= -lrt
#LINKER_LAST 	+= 

# LIBRARIAN SECTION
LIBRARY_FLAGS	= scr

# SIZE SECTION
SIZE	= $(TOOLS)/bin/$(TPREF)size
SIZE_FLAGS		= 

# CONTROL SECTION

ARFLAGS = $(LIBRARY_FLAGS)
LIBRARY     = $(AR) $(ARFLAGS)
LIBRARY_LAST =

配置操作系统riscv64.mak文件
这里我们需要配置PLATFORM和TOOLCHAIN

PLATFORM=riscv64 #分别是存放文件的目录名称
TOOLCHAIN=gcc-cross-riscv #交叉编译工具链
# File: util/make/linux64.mak
# Optional specific files for specialized run and results extraction
PLATFORM=riscv64
SHELL=/bin/bash

ifndef TOOLCHAIN
#TOOLCHAIN=gcc64
TOOLCHAIN=gcc-cross-riscv
endif

# Flag: LOAD
#	Use LOAD to define command used for loading the image to the target
LOAD =

# Flag: RUN
#	Use this flag to define a command needed to run the image
#
#	Example: if you need to run the image with a simulator, set this flag to point to the simulator executable
RUN			=
# Flag: RUN
#	Use this flag to supply flags before the image name and parameters
#
#	Example: if you need want to run the image using gdb, you probably need to set this flag to --args
RUN_FLAGS	=

ifeq ($(DO_PROFILE),yes)
	RUN_FLAGS			= 
	RUN = function dorun() {
    
     \
	BENCHNAME=`basename $$1 .exe` && \
	$$@ &&\
	gprof $$1 gmon.out > $(DIR_LOG)/$$BENCHNAME.gprof && \
	mv gmon.out $(DIR_LOG)/$$BENCHNAME.gmon ;\
	} && dorun 
endif
ifeq ($(DO_VALGRIND),yes)
	RUN_FLAGS		= 
	RUN			= valgrind --log-fd=1 --tool=memcheck -v --leak-check=yes --show-reachable=yes
endif
ifeq ($(DO_MICA),yes)
	RUN_FLAGS			= 
	RUN = function dorun() {
    
     \
	BENCHNAME=`basename $$1 .exe` && echo "will do $$@" && \
	pin -t mica -controller-start-int3 1 -controller-stop-int3 2 -- $$@ $$DATA_CMD &&\
	mkdir -p $(DIR_LOG)/mica/$$BENCHNAME && mv *pin.out $(DIR_LOG)/mica/$$BENCHNAME ;\
	} && dorun 
endif
ifeq ($(DO_APROF),yes)
	RUN_FLAGS			= 
	RUN = function dorun() {
    
     \
	BENCHNAME=`basename $$1 .exe` && \
	/opt/valgrind/bin/valgrind --tool=aprof $$@ &&\
	mkdir -p $(DIR_LOG)/aprof/$$BENCHNAME && mv *.aprof $(DIR_LOG)/aprof/$$BENCHNAME ;\
	} && dorun 
endif

#Flag: PLATFORM_DEFINES 
#	Use PLATFORM_DEFINES to set platform specific compiler flags. E.g. set the timer resolution to millisecs with TIMER_RES_DIVIDER=1000
#	Or add HAVE_PTHREAD_SETAFFINITY_NP=1 HAVE_PTHREAD_SELF=1 to enable affinity (must port the relevant functions in <mith/al/src/al_smp.c>.
PLATFORM_DEFINES = EE_SIZEOF_INT=4 EE_SIZEOF_LONG=8

# Flag: CMD_SEP
#	Use CMD_SEP if a separator is required before run flags (e.g. --)
CMD_SEP=
# Flag: XCMD
#	Define XCMD on command line to pass flag at run time to workloads, or here if you want to override the default in <util/make/common.mak>

#FLAG: COPY_DATA
#	How should data be copied so that it is available for the executable?
#	Common ways include: 
#	- scp <target_ip>:<target_dir>(if target allows ssh connection)
#	- invoking a special command line tool to transfer the data
#	- copy (for file systems that do not support links)
#	- link (for file systems where a simple symbolic link will work)
COPY_DATA=cp -Ru --remove-destination 

2、编译coremark-pro

回到源码目录
在这里插入图片描述
执行编译命令
make TARGET=riscv64 build
编译完成后,九个可执行文件保存在builds目录下,可执行文件在builds/riscv64/gcc-cross-riscv/bin中

在这里插入图片描述

如果是这个命令 make TARGET=linux64 XCMD='-c4' certify-all,将运行9个测试,但是前提是开发板中已经有编译工具链和perl脚本,Lichee Rv Docv中并没有,这里仅仅在虚拟机中简单运行跑一跑

下面是我跑的分

WORKLOAD RESULTS TABLE

                                                 MultiCore SingleCore           
Workload Name                                     (iter/s)   (iter/s)    Scaling
----------------------------------------------- ---------- ---------- ----------
cjpeg-rose7-preset                                   56.18      29.85       1.88
core                                                  0.79       0.32       2.47
linear_alg-mid-100x100-sp                            89.45      43.14       2.07
loops-all-mid-10k-sp                                  3.42       1.55       2.21
nnet_test                                             3.70       1.77       2.09
parser-125k                                          10.36       4.10       2.53
radix2-big-64k                                      263.30     114.89       2.29
sha-test                                             74.63      41.32       1.81
zip-test                                             71.43      29.41       2.43

MARK RESULTS TABLE

Mark Name                                        MultiCore SingleCore    Scaling
----------------------------------------------- ---------- ---------- ----------
CoreMark-PRO                                       2393.66    1096.18       2.18

四、开发板中简单运行coremark-pro

将bin中的文件上传到开发板,下面是我运行每一个文件输出的信息

cjpeg-rose7-preset.exe

-- Items:total(ticks)=83
-- Items:total(secs)=   0.083
-- Done:cjpeg-rose7-preset=236760500

core.exe

-- Items:total(ticks)=10267
-- Items:total(secs)=  10.267
-- Done:core=490760323

linear_alg-mid-100x100-sp.exe

-- Items:total(ticks)=170
-- Items:total(secs)=    0.17
-- Done:linear_alg-mid-100x100-sp=1046644201

loops-all-mid-10k-sp.exe

-- Items:total(ticks)=10927
-- Items:total(secs)=  10.927
-- Done:loops-all-mid-10k-sp=1814569103

nnet_test.exe

-- Items:total(ticks)=3047
-- Items:total(secs)=   3.047
-- Done:nnet_test=549578576

parser-125k.exe

-- Items:total(ticks)=1996
-- Items:total(secs)=   1.996
-- Done:parser-125k=780641437

radix2-big-64k.exe

-- Items:total(ticks)=133
-- Items:total(secs)=   0.133
-- Done:radix2-big-64k=1862946660

sha-test.exe

-- Items:total(ticks)=155
-- Items:total(secs)=   0.155
-- Done:sha-test=1050863061

zip-test.exe

-- Items:total(ticks)=280
-- Items:total(secs)=    0.28
-- Done:zip-test=946108807

五、小问题

小问题就自己记录,以后如果还记得如何解决的话,会回来更新的

问题一:复制交叉编译工具链的文件gcc-cross-linux.mak,用这个编译出来的core.exe不能执行,出现一下错误,但是用gcc64.mak这个文件来配置交叉编译工具链编译的core.exe却能执行

root@MaixLinux:/mnt/gcc-cross-riscv/bin# ./core.exe
ERROR: ee_ptr_int is not a datatype that holds an int pointer!
ERROR: Please modify the datatypes in core_portme.h!
-  Info: Starting Run...
Segmentation fault

问题二:用官方的源代码去编译,缺少cjpeg-rose7-preset.exe这个文件,但是使用gitee xiaojie 的代码去编译却没问题,我查看宏也是正常设置好的,不知道为啥

猜你喜欢

转载自blog.csdn.net/weixin_46185705/article/details/128647012
今日推荐