forked from custom-computing-ic/dfe-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
1,340,795 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
set_source_files_properties( | ||
ParallelMovingAverage/ParallelMovingAverage_dfe.o PROPERTIES | ||
EXTERNAL_OBJECT TRUE # Identifies this as an object file | ||
GENERATED TRUE # Avoids need for file to exist at configure-time | ||
) | ||
|
||
set_source_files_properties( | ||
OptionPricing/OptionPricing_dfe.o PROPERTIES | ||
EXTERNAL_OBJECT TRUE # Identifies this as an object file | ||
GENERATED TRUE # Avoids need for file to exist at configure-time | ||
) | ||
|
||
add_library(Bitstreams | ||
ParallelMovingAverage/ParallelMovingAverage.cpp ParallelMovingAverage/ParallelMovingAverage_dfe.o | ||
OptionPricing/OptionPricing.cpp OptionPricing/OptionPricing_dfe.o) | ||
|
||
target_link_libraries(Bitstreams maxeleros slic m pthread) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# ---- Available DFE hardware settings ---- | ||
DFEModel=MAIA | ||
|
||
MPCX=true | ||
DEVICENUM=MAIA | ||
SLIC_CONF="default_engine_resource = 192.168.0.10" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# ---- Available DFE hardware settings ---- | ||
DFEModel=MAX3424A | ||
|
||
MPCX=false | ||
DEVICENUM=3424 | ||
SLICCONFIG= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
#################################################### | ||
# Makefile ------- Thomas Chau 2013 # | ||
# Tested for MaxCompiler 2013.2.2 # | ||
#################################################### | ||
# 1) For SLiC interface only | ||
# If you are using MaxCompilerRT, | ||
# use maxfilecompile instead of sliccompile | ||
# and change LFLAGS -lslic to -lmaxcompilerrt | ||
# 2) This makefile depends on project-specific | ||
# settings defined in project's Makefile | ||
# 3) Usage: use project's makefile (navigate | ||
# to project's directory and use makefile there) | ||
# | ||
|
||
# ---- Common Configuration Defaults ---- | ||
|
||
NUMDEVICES ?= 1 | ||
|
||
# ---- Paths ---- | ||
ifndef $(MAXCOMPILER_BUILD_DIR) | ||
MAXCOMPILER_BUILD_DIR=. | ||
endif | ||
SIMMAXDIR=$(MAXCOMPILER_BUILD_DIR)/$(PRJ)_$(DFEModel)_DFE_SIM/results | ||
DFEMAXDIR=$(MAXCOMPILER_BUILD_DIR)/$(PRJ)_$(DFEModel)_DFE/results | ||
MAXELEROSDIR_SIM:=$(MAXCOMPILERDIR)/lib/maxeleros-sim | ||
|
||
# ---- Source files ---- | ||
ENGINEFILES=$(wildcard *.maxj) | ||
CPUFILES=$(wildcard *.c *.cpp) | ||
|
||
# ---- Compiler settings ---- | ||
|
||
# detect the language: do we have .cpp extensions? | ||
ifneq ($(findstring cpp, $(CPUFILES)), ) | ||
# language: C++ | ||
CXX ?= icpc | ||
CPUCOMPILER = $(CXX) | ||
|
||
# Assuming CXX points to g++/c++ by default | ||
COMPILER_CFLAGS = -fopenmp | ||
OPT_FLAGS = -march=native -O3 | ||
|
||
ifeq ($(CXX), icpc) | ||
COMPILER_CFLAGS = -openmp | ||
OPT_FLAGS = -xHost -O3 | ||
endif | ||
else | ||
# language: C | ||
CC ?= icc | ||
CPUCOMPILER = $(CC) | ||
|
||
# Assuming CC points to gcc/cc by default | ||
COMPILER_CFLAGS = -std=c99 -fopenmp | ||
OPT_FLAGS = -march=native -O3 | ||
|
||
ifeq ($(CC), icc) | ||
COMPILER_CFLAGS = -std=c99 -openmp | ||
OPT_FLAGS = -xHost -O3 | ||
endif | ||
endif | ||
|
||
|
||
# ---- Command alias ---- | ||
|
||
|
||
MAXFILECOMPILE=maxfilecompile | ||
SLICCOMPILE=sliccompile | ||
MAXGUESSBUILDDIR=maxGuessBuildDir | ||
MAXFILESTITCH=maxfilestitch | ||
MAXJAVARUN=maxJavaRun | ||
MAXJC=maxjc | ||
MAXDEBUG=maxdebug | ||
MAXRENDERGRAPHS=maxRenderGraphs | ||
MAXCOMPILERSIM=maxcompilersim | ||
|
||
MAXOS_HW=/opt/maxeler/maxeleros/lib/libmaxeleros.so | ||
MAXOS_SIM=$(MAXELEROSDIR_SIM)/lib/libmaxeleros.so | ||
|
||
JFLAGS=-cp $(MAXCOMPILERDIR)/lib/MaxCompiler.jar -1.6 -d . | ||
CFLAGS= $(COMPILER_CFLAGS) $(OPT_FLAGS) -Wall -I${MAXCOMPILERDIR}/include -I${MAXCOMPILERDIR}/include/slic -I${MAXELEROSDIR}/include -D_XOPEN_SOURCE=600 | ||
LFLAGS=-L${MAXCOMPILERDIR}/lib -L${MAXELEROSDIR}/lib -lmaxeleros -lslic -lm -lpthread | ||
|
||
# Add this on the command line to pass to make when compiling | ||
# Useful for debug/optimization flags | ||
EXTRA_CFLAGS?= | ||
|
||
# This is set in the gdbsim/gdbdfe targets | ||
DEBUG_FLAGS?= | ||
|
||
ALL_FLAGS = $(CFLAGS) $(EXTRA_CFLAGS) $(DEBUG_FLAGS) | ||
# ---- Default DFE ---- | ||
DFEID=/dev/maxeler0 | ||
|
||
# Files to remove on clean | ||
TRASH=*~ ../src/*~ *.o | ||
DIST_TRASH=Maxfiles.h *.class *.o debug* *.dot *.png | ||
|
||
help: | ||
@ echo "Current configuration:" | ||
@ echo " Compiler $(CC)" | ||
@ echo " Optimizations $(OPT_FLAGS)" | ||
@ echo " MAXCOMPILERDIR $(MAXCOMPILERDIR)" | ||
@ echo "" | ||
@ echo "Available targets: " | ||
@ echo " runsim -- build and run design in simulation (requires MaxCompiler license)" | ||
@ echo " stopsim -- stop the currently running simulated device" | ||
@ echo " build -- build the design in hardware (requires MaxCompiler license)" | ||
@ echo " run -- run design in hardware (requires local access to a DFE)" | ||
@ echo " debug -- debug a simulation design using MaxDebug" | ||
@ echo " debughw -- debug a hardware design using MaxDebug (requires local access to DFE)" | ||
@ echo " gdbsim, gdbdfe -- build CPU code with debug symbols" | ||
@ echo " cleansim, cleandfe, clean -- clean executables for simulation, hardware or both" | ||
@ echo " distcleansim, distcleanhw, distclean -- delete the entire sim, hw or both directories" | ||
@ echo " help -- print this help message" | ||
|
||
|
||
all: runsim build | ||
|
||
.PHONY: stopsim run cleansim cleandfe debug debughw | ||
|
||
# ---- Simulation ---- | ||
|
||
$(SIMMAXDIR)/$(PRJ).max: $(ENGINEFILES) | ||
$(MAXJC) $(JFLAGS) $(ENGINEFILES) | ||
MAXAPPJCP=. $(MAXJAVARUN) -v -m 8192 $(MANAGER) DFEModel=$(DFEModel) maxFileName=$(PRJ) target='DFE_SIM' enableMPCX=$(MPCX) | ||
cp $(SIMMAXDIR)/$(PRJ).h $(SIMMAXDIR)/Maxfiles.h | ||
|
||
$(PRJ)_sim.o: $(SIMMAXDIR)/$(PRJ).max | ||
$(SLICCOMPILE) $< $@ | ||
|
||
$(PRJ)_simc.o: $(CPUFILES) | ||
$(CPUCOMPILER) $< $(ALL_FLAGS) -I$(SIMMAXDIR) -D__SIM__ -DDESIGN_NAME=$(PRJ) -c -o $@ | ||
|
||
$(PRJ)_sim: $(PRJ)_sim.o $(PRJ)_simc.o | ||
$(CPUCOMPILER) $(ALL_FLAGS) -o $@ $^ $(LFLAGS) | ||
|
||
runsim: $(PRJ)_sim | ||
$(MAXCOMPILERSIM) -n $(USER)a -c$(DEVICENUM) -d$(NUMDEVICES) restart | ||
SLIC_CONF+="use_simulation=$(USER)a" LD_PRELOAD=$(MAXOS_SIM) ./$(PRJ)_sim $(USER)a0:$(USER)a | ||
make stopsim | ||
|
||
stopsim: | ||
$(MAXCOMPILERSIM) -n $(USER)a -c$(DEVICENUM) stop | ||
|
||
gdbsim: | ||
DEBUG_FLAGS="-O0 -g" make $(PRJ)_sim | ||
LD_PRELOAD=$(MAXOS_SIM) gdb $(PRJ)_sim | ||
|
||
# ---- DFE ---- | ||
|
||
par: $(ENGINEFILES) | ||
$(MAXJC) $(JFLAGS) $(ENGINEFILES) | ||
MAXAPPJCP=. $(MAXJAVARUN) -v -m 8192 $(MANAGER) DFEModel=$(DFEModel) maxFileName=$(PRJ) target='DFE' enableMPCX=$(MPCX) | ||
cp $(DFEMAXDIR)/$(PRJ).h $(DFEMAXDIR)/Maxfiles.h | ||
|
||
$(PRJ)_dfe.o: $(PRJ).max | ||
$(SLICCOMPILE) $< $@ | ||
|
||
$(PRJ)_dfec.o: $(CPUFILES) | ||
$(CPUCOMPILER) $< $(ALL_FLAGS) -I$(DFEMAXDIR) -DDESIGN_NAME=$(PRJ) -c -o $@ | ||
|
||
$(PRJ)_dfe: $(PRJ)_dfe.o $(PRJ)_dfec.o | ||
$(CPUCOMPILER) $(ALL_FLAGS) -o $@ $^ $(LFLAGS) | ||
|
||
build: $(PRJ)_dfe | ||
|
||
run: | ||
SLIC_CONF=$(SLIC_CONF) LD_PRELOAD=$(MAXOS_HW) ./${PRJ}_dfe | ||
|
||
gdbdfe: | ||
DEBUG_FLAGS="-O0 -g" make build | ||
LD_PRELOAD=$(MAXOS_HW) gdb $(PRJ)_dfe | ||
|
||
# ---- Clean ---- | ||
|
||
cleansim: | ||
rm -f $(PRJ)_sim $(TRASH) | ||
|
||
cleandfe: | ||
rm -f $(PRJ)_dfe $(TRASH) | ||
|
||
clean: cleansim cleandfe | ||
|
||
distcleansim: cleansim | ||
rm -rf $(DIST_TRASH) $(PRJ)_$(DFEModel)_DFE_SIM | ||
|
||
distcleandfe: cleandfe | ||
rm -rf $(DIST_TRASH) $(PRJ)_$(DFEModel)_DFE | ||
|
||
distclean: distcleansim distcleandfe | ||
|
||
# ---- Debug ---- | ||
|
||
debug: | ||
maxdebug -v -g $(PRJ)Graph -s $(PRJ)Graph -c -k $(KERNEL) -d $(USER)a0:$(USER)a $(SIMMAXDIR)/$(PRJ).max | ||
|
||
debughw: | ||
maxdebug -v -g $(PRJ)Graph -s $(PRJ)Graph -c -k $(KERNEL) -d $(DFEID) $(DFEMAXDIR)/$(PRJ).max |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import com.maxeler.maxcompiler.v2.kernelcompiler.types.base.DFEVar; | ||
import com.maxeler.maxcompiler.v2.kernelcompiler.types.base.DFEType; | ||
import com.maxeler.maxcompiler.v2.kernelcompiler.stdlib.KernelMath; | ||
import com.maxeler.maxcompiler.v2.kernelcompiler.types.base.DFEFix.SignMode; | ||
import com.maxeler.maxcompiler.v2.kernelcompiler.KernelLib; | ||
|
||
class FPExpCore extends KernelLib | ||
{ | ||
//the hardware type | ||
private DFEType inputType; | ||
private DFEType roughType; | ||
|
||
private DFEVar dout; | ||
private DFEVar din; | ||
|
||
private int wF; | ||
|
||
FPExpCore(KernelLib owner, int wE, int ext_wF, DFEVar ext_din) | ||
{ | ||
super(owner); | ||
int guardBits = 3; | ||
|
||
if( ext_wF > 50-2-guardBits ) | ||
{ | ||
wF = 50-2-guardBits; | ||
din = ext_din.cast( dfeFloat(wE, wF) ); | ||
} | ||
else | ||
{ | ||
wF = ext_wF; | ||
din = ext_din; | ||
} | ||
|
||
//define the type and input stream | ||
inputType = dfeFloat(wE, wF); | ||
|
||
//define the rough type | ||
if( wF > 10 ) | ||
roughType = dfeFloat(wE, 10); | ||
else | ||
roughType = dfeFloat(wE, wF); | ||
|
||
DFEVar roughInput = din.cast( roughType ); | ||
// 1/log(2) | ||
DFEVar log2_1 = constant.var( roughType, 1.44269504); | ||
|
||
DFEVar E_mul = roughInput * log2_1; | ||
//E should be in wE length, so that we can easily add back to wE | ||
DFEVar E = KernelMath.floor( E_mul, dfeInt(wE+1) ); | ||
|
||
//debug.printf("E is %d\n", E); | ||
|
||
//compute Y | ||
DFEVar E_float = E.cast( dfeFloat(wE, wF) ); | ||
DFEVar log2 = constant.var( dfeFloat(wE, wF), Math.log(2) ); | ||
//debug.printf("E_float is %g\n", E_float); | ||
DFEVar Y = din - (E_float*log2); | ||
|
||
//correct Y if it is neg | ||
//advoid using too small | ||
DFEVar rangeAdj = (Y < 0.2); | ||
DFEVar newY = rangeAdj ? Y + log2 : Y; | ||
DFEVar newE = rangeAdj ? E-1 : E; | ||
|
||
//debug.printf("Y = %g\n", Y); | ||
|
||
//debug.printf("Y is %g\n", Y); | ||
|
||
//eval eY using the fixed point evaluator | ||
//and then recombine it to floating point format | ||
DFEVar Y_fix = newY.cast( dfeFix(0, wF+guardBits, SignMode.UNSIGNED) ); | ||
KernelMath.Range range = new KernelMath.Range(0, 0.95); | ||
DFEVar eY = KernelMath.exp( range, Y_fix, dfeFix(2, wF+guardBits, SignMode.UNSIGNED) ); | ||
|
||
DFEVar eY_float = eY.cast( inputType ); | ||
//debug.printf("eY is %g\n", eY_float ); | ||
|
||
DFEVar eY_raw = eY_float.cast( dfeRawBits( wE+wF ) ); | ||
DFEVar eY_f = eY_raw.slice(0, wF-1); | ||
DFEVar eY_e = eY_raw.slice(wF-1, wE); | ||
DFEVar eY_s = eY_raw.slice(wF+wE-1, 1); | ||
|
||
DFEVar new_e = (eY_e.cast( dfeUInt(wE) ).cast(dfeInt(wE+1)) + newE).cast(dfeUInt(wE)); | ||
DFEVar new_e_raw = new_e.cast( dfeRawBits(wE) ); | ||
DFEVar out = eY_s.cat( new_e_raw ).cat( eY_f ); | ||
dout = out.cast( inputType ).cast( dfeFloat(wE, ext_wF) ); | ||
|
||
} | ||
|
||
public DFEVar getOutput() | ||
{ | ||
return dout; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#################################################### | ||
# Makefile ------- Thomas Chau 2013 # | ||
# Tested for MaxCompiler 2013.2.2 # | ||
#################################################### | ||
# 1) For SLiC interface only | ||
# If you are using MaxCompilerRT, | ||
# use maxfilecompile instead of sliccompile | ||
# and change LFLAGS -lslic to -lmaxcompilerrt | ||
# 2) This makefile uses common settings and | ||
# compilation targets defined in the root folder | ||
# 3) Usage | ||
# ----- | ||
# Build and run simulation: make runsim | ||
# Kill failed simulation: make stopsim | ||
# Debug simulation: make debug | ||
# Build DFE: make build | ||
# Run DFE: make run | ||
# Clean binaries: make clean | ||
# Clean all generated files: make distclean | ||
|
||
|
||
# ---- Project settings ---- | ||
|
||
WHEREISROOT=.. | ||
|
||
|
||
# Assuming Kernel and Manager class names follow the pattern below: | ||
PRJ=OptionPricing | ||
KERNEL=$(PRJ)Kernel | ||
MANAGER=$(PRJ)Manager | ||
|
||
|
||
# Using known hardware settings | ||
include $(WHEREISROOT)/Makefile.Max3.hardware | ||
|
||
|
||
# Using common compillation targets and compiler settings | ||
include $(WHEREISROOT)/Makefile.common |
Oops, something went wrong.