-
Notifications
You must be signed in to change notification settings - Fork 2
Compiling a Trilliasm Kernel
epeguero edited this page Jun 3, 2020
·
1 revision
Once you've coded your very own Trilliasm kernel, you can invoke the trillium compiler via the trilliasm.mk
Makefile.
To understand how to do this, study this example Makefile for vvadd
:
#1. pass 'arguments' to trillium makefile
TRILLIASM_FUN_NAME= vvadd_execute_simd
TRILLIASM_KERNEL = vvadd_kernel_be.c
TRILLIUM_DIR=../../../trillium
RV_CC=/data/phil/riscv-rv64g/bin/riscv64-unknown-linux-gnu-gcc
CFLAGS=-D_N_SPS=16 -DVEC_4_SIMD -O3 --std=gnu11 -static -I../common/ -T../common/spm.ld -lpthread -lm
#2. include the trillium makefile
include $(TRILLIUM_DIR)/trilliasm.mk
# Now we have access to the trillium compiler recipe: $(TRILLIASM_KERNEL:.c=.o)
# (along with intermediate recipes for the scalar, vector, and combined assembly files)
#3. Build your benchmark by isolating trillium '.o' recipe from other '.o' recipes (See the $(C_OBJS_NOKERN) recipe below)
C_SRCS_NOKERN := main.c vvadd.c $(wildcard ../common/*.c)
C_OBJS_NOKERN := $(C_SRCS_NOKERN:.c=.o)
# installed cross compiler gcc for riscv
vvadd : $(TRILLIASM_KERNEL:.c=.o) $(C_OBJS_NOKERN)
$(RV_CC) $^ $(CFLAGS) -o $@
run : vvadd
~/gem5-mesh/build/RVSP/gem5.opt ~/gem5-mesh/configs/phil/brg_hammerblade.py \
--cmd=vvadd \
--options="1024" \
--num-cpus=16 \
--vector
# Static Pattern: only applies to files listed in C_OBJS_NOKERN
$(C_OBJS_NOKERN): %.o : %.c
$(RV_CC) $(CFLAGS) -c $^ -o $@
clean:
rm -rf *.o *.s vvadd m5out
The trilliasm compiler generates an object file from a trilliasm kernel in the following steps:
- compile the kernel with
#define SCALAR_CORE
to an assembly file - compile the kernel with
#define VECTOR_CORE
to an assembly file - run gluing script (
glue.py
) to combine 1. and 2. into a single assembly file - compile the assembly file from 3. to an object file
trilliasm.mk
generates a recipe corresponding to the above. To do so, it requires the following variables:
-
TRILLIASM_KERNEL
: name of the trilliasm kernel file used in benchmark (e.g.:vvadd_kernel.c
) -
TRILLIASM_FUN_NAME
: name of function in the kernel file containing trilliasm kernel (hack currently needed by gluer)
In addition, trilliasm.mk
requires the following bindings, for which defaults exist:
-
TRILLIUM_DIR
: relative path to trillium directory (default:../../../trillium
) *COMMON_PATH
: relative path tocommon
folder containing benchmark dependencies (default:../common
) -
RV_CC
: path to RV compiler (default:/data/phil/riscv-rv64g/bin/riscv64-unknown-linux-gnu-gcc
) -
CFLAGS
: flags to pass toRV_CC
compiler (default:-D_N_SPS=16 -O3 --std=gnu11 -static -I$(COMMON_PATH) -T$(COMMON_PATH)/spm.ld -lpthread -lm
)
A final note: trilliasm.mk
internally defines KERNEL_NAME=$(basename $(TRILLIASM_KERNEL))
, which you may also use for convenience.