commtechs bench: add calc_mat calculation lib
* Add a matrice calculation as one of the possible calculation * Modify the makefile to permit calculation lib compilation * Reorganize the makefile to be able to execute the default target
This commit is contained in:
parent
f9128c0348
commit
f4b3904541
|
@ -1,61 +1,67 @@
|
||||||
# Directories
|
# Directories
|
||||||
OBJDIR=obj
|
OBJDIR:=obj
|
||||||
BINDIR=bin
|
BINDIR:=bin
|
||||||
SRCDIR=src
|
SRCDIR:=src
|
||||||
INCDIR=include
|
INCDIR:=include
|
||||||
LIBDIR=lib
|
LIBDIR:=lib
|
||||||
LOGDIR=logs
|
LOGDIR:=logs
|
||||||
LOCALDIR=$(HOME)/local
|
LOCALDIR:=$(HOME)/local
|
||||||
PAPIHIGHLEVELLIBDIR=lib
|
PAPIHIGHLEVELLIBDIR:=lib
|
||||||
PAPIHIGHLEVELINCDIR=include
|
PAPIHIGHLEVELINCDIR:=include
|
||||||
|
CALCDIR:=calculation
|
||||||
|
|
||||||
# Compilation flags
|
# Compilation flags
|
||||||
# I know -finline-functions and -finline-functions-called-once are enabled by
|
# I know -finline-functions and -finline-functions-called-once are enabled by
|
||||||
# -O3 but I did this in case gcc behaviour change one day
|
# -O3 but I did this in case gcc behaviour change one day
|
||||||
CFLAGS=-g -O3 -finline-functions -finline-functions-called-once -Wall -Werror
|
CFLAGS:=-g -O3 -finline-functions -finline-functions-called-once -Wall -Werror
|
||||||
LDFLAGS=-L$(LIBDIR) -L$(LOCALDIR)/$(PAPIHIGHLEVELLIBDIR) -Wl,-rpath-link,$(HOME)/local/lib -lpthread -lpapihighlevel -ldl
|
LDFLAGS:=-L$(LIBDIR) -L$(LOCALDIR)/$(PAPIHIGHLEVELLIBDIR) -Wl,-rpath-link,$(HOME)/local/lib -lpthread -lpapihighlevel -ldl
|
||||||
|
|
||||||
# Executables
|
# Executables
|
||||||
CC=gcc
|
CC=gcc
|
||||||
|
|
||||||
# Files
|
# Files
|
||||||
BINNAMES=asm_cache_comm c_cache_comm pipe_comm shared_mem_comm shared_mem_opt_comm jikes_barrier_comm fake_comm
|
BINNAMES:=asm_cache_comm c_cache_comm pipe_comm shared_mem_comm shared_mem_opt_comm jikes_barrier_comm fake_comm
|
||||||
BINS=$(patsubst %, $(BINDIR)/%, $(BINNAMES))
|
CALCLIBSNAMES:=calc_mat
|
||||||
MAIN_OBJS=main.o common.o
|
BINS:=$(patsubst %,$(BINDIR)/%,$(BINNAMES))
|
||||||
COMMON_LIB_OBJS=common.o
|
CALCLIBS:=$(patsubst %,$(LIBDIR)/lib%.so.1,$(CALCLIBSNAMES))
|
||||||
|
MAIN_OBJS:=main.o common.o
|
||||||
|
COMMON_LIB_OBJS:=common.o
|
||||||
|
|
||||||
.PHONY: all tidy clean distclean symlink
|
.PHONY: all tidy clean distclean
|
||||||
.SECONDARY:
|
.SECONDARY:
|
||||||
.SUFFIXES: .c .o
|
.SUFFIXES: .c .o
|
||||||
|
|
||||||
default: $(BINS)
|
default: $(BINS) $(CALCLIBS)
|
||||||
|
|
||||||
ifneq (,$(findstring $(MAKECMDGOALS),$(BINS)))
|
|
||||||
BASE_TARGET=$(patsubst $(BINDIR)/%_comm,%,$(MAKECMDGOALS))
|
|
||||||
|
|
||||||
# Compilation of binary
|
# Compilation of binary
|
||||||
$(BINDIR)/$(BASE_TARGET)_comm: $(patsubst %,$(OBJDIR)/$(BASE_TARGET)_%,$(MAIN_OBJS)) $(LIBDIR)/lib$(BASE_TARGET).a
|
$(BINDIR)/%_comm: $(patsubst %,$(OBJDIR)/\%/%,$(MAIN_OBJS)) $(LIBDIR)/lib%.a
|
||||||
if [ ! -d $(BINDIR) ] ; then mkdir $(BINDIR) ; fi
|
if [ ! -d $(BINDIR) ] ; then mkdir $(BINDIR) ; fi
|
||||||
$(CC) -o $@ $^ $(LDFLAGS)
|
$(CC) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
||||||
# Compilation of library
|
# Creation of comm library
|
||||||
$(LIBDIR)/lib$(BASE_TARGET).a: $(OBJDIR)/$(BASE_TARGET).o $(patsubst %,$(OBJDIR)/$(BASE_TARGET)_%,$(COMMON_LIB_OBJS))
|
$(LIBDIR)/lib%.a: $(OBJDIR)/%.o $(patsubst %,$(OBJDIR)/\%/%,$(COMMON_LIB_OBJS))
|
||||||
if [ ! -d $(LIBDIR) ] ; then mkdir $(LIBDIR) ; fi
|
if [ ! -d $(LIBDIR) ] ; then mkdir $(LIBDIR) ; fi
|
||||||
$(AR) -rcus $@ $^
|
$(AR) -rcus $@ $^
|
||||||
|
|
||||||
# Compile common source files
|
# Creation of calc library
|
||||||
$(OBJDIR)/$(BASE_TARGET)_%.o: $(SRCDIR)/%.c symlink
|
$(LIBDIR)/libcalc_%.so.1: $(OBJDIR)/$(CALCDIR)/calc_%.o
|
||||||
if [ ! -d $(OBJDIR) ] ; then mkdir $(OBJDIR) ; fi
|
if [ ! -d $(LIBDIR) ] ; then mkdir $(LIBDIR) ; fi
|
||||||
$(CC) $(CFLAGS) -I$(INCDIR) -I$(LOCALDIR)/$(PAPIHIGHLEVELINCDIR) -c $< -o $@
|
$(CC) $(LDFLAGS) -shared -Wl,-soname,libcalc_$*.so.1 -o $@ $<
|
||||||
endif
|
|
||||||
|
|
||||||
# Compile non common source files
|
# Compile lib specific source files
|
||||||
$(OBJDIR)/%.o: $(SRCDIR)/%.c symlink
|
$(OBJDIR)/%.o: $(SRCDIR)/%.c $(INCDIR)/%_comm.h $(INCDIR)/commtech.h
|
||||||
if [ ! -d $(OBJDIR) ] ; then mkdir $(OBJDIR) ; fi
|
if [ ! -d $(OBJDIR) ] ; then mkdir $(OBJDIR) ; fi
|
||||||
|
cd $(INCDIR) ; ln -sfT $*_comm.h specific_comm.h
|
||||||
$(CC) $(CFLAGS) -I$(INCDIR) -c $< -o $@
|
$(CC) $(CFLAGS) -I$(INCDIR) -c $< -o $@
|
||||||
|
|
||||||
symlink:
|
# Rule for compiling common source files using libcomm is at the end of
|
||||||
ln -sfT $(BASE_TARGET)_comm.h $(INCDIR)/specific_comm.h
|
# this file, after the .SECONDEXPANSION target
|
||||||
|
|
||||||
|
# Compile source files not using libcomm
|
||||||
|
$(OBJDIR)/$(CALCDIR)/%.o: $(SRCDIR)/$(CALCDIR)/%.c
|
||||||
|
if [ ! -d $(OBJDIR) ] ; then mkdir $(OBJDIR) ; fi
|
||||||
|
if [ ! -d $(OBJDIR)/$(CALCDIR) ] ; then mkdir $(OBJDIR)/$(CALCDIR) ; fi
|
||||||
|
$(CC) $(CFLAGS) -I$(INCDIR) -c $< -o $@
|
||||||
|
|
||||||
#.%.d: %.c
|
#.%.d: %.c
|
||||||
# gcc $(CFLAGS) -MM $^ | sed -e 's/\([^:]*\):\(.*\)/\1 $@: \2 Makefile/' > $@
|
# gcc $(CFLAGS) -MM $^ | sed -e 's/\([^:]*\):\(.*\)/\1 $@: \2 Makefile/' > $@
|
||||||
|
@ -82,3 +88,13 @@ distclean: clean
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
.SECONDEXPANSION:
|
||||||
|
|
||||||
|
# Compile common source files using libcomm
|
||||||
|
$(OBJDIR)/%.o: $(SRCDIR)/$$(*F).c $(INCDIR)/$$(*D)_comm.h $(INCDIR)/commtech.h
|
||||||
|
if [ ! -d $(OBJDIR) ] ; then mkdir $(OBJDIR) ; fi
|
||||||
|
if [ ! -d $(OBJDIR)/$(*D) ] ; then mkdir $(OBJDIR)/$(*D) ; fi
|
||||||
|
cd $(INCDIR) ; ln -sfT $(*D)_comm.h specific_comm.h
|
||||||
|
$(CC) $(CFLAGS) -I$(INCDIR) -I$(LOCALDIR)/$(PAPIHIGHLEVELINCDIR) -c $< -o $@
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
#define likely(x) __builtin_expect(!!(x), 1)
|
||||||
|
#define unlikely(x) __builtin_expect(!!(x), 0)
|
||||||
|
|
||||||
|
|
||||||
|
static int *mat, *vect;
|
||||||
|
static int li;
|
||||||
|
static int n = 16, m = 16; /* Size of the matrice: n lines, m columns */
|
||||||
|
|
||||||
|
void init_calc(void)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
srand(42);
|
||||||
|
mat = (int *) malloc(n * m * sizeof(int));
|
||||||
|
vect = (int *) malloc(m * sizeof(int));
|
||||||
|
for (i = 0; i < n * m; i++)
|
||||||
|
mat[i] = rand();
|
||||||
|
li = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *do_calc(void)
|
||||||
|
{
|
||||||
|
int co, p = 0;
|
||||||
|
|
||||||
|
for (co = 0; co < m; co++)
|
||||||
|
p += mat[li * m + co] * vect[li];
|
||||||
|
mat[li * m] = p;
|
||||||
|
if (unlikely(++li >= n))
|
||||||
|
li = 0;
|
||||||
|
return &mat[li * m];
|
||||||
|
}
|
||||||
|
|
||||||
|
void end_calc(void)
|
||||||
|
{
|
||||||
|
free(mat);
|
||||||
|
free(vect);
|
||||||
|
}
|
Loading…
Reference in New Issue