Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-g committed Oct 4, 2015
2 parents e54ea66 + 8448257 commit c78042b
Show file tree
Hide file tree
Showing 10 changed files with 10,604 additions and 4,815 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ code. In case of underflow (requesting more entries than internally stored)

public class FetchSubTuple extends KernelLib
{
private static final int bufferDepth = 8;
private static final int bufferDepth = 4;

private DFEVectorType<DFEVar> m_tupleType;
private DFEVectorType<DFEVar> m_boolTupleType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
LUTs FFs BRAMs DSPs : FetchSubTuple.maxj
1898 109 1 0 : resources used by this file
0.36% 0.01% 0.04% 0.00% : % of available
19.24% 0.44% 0.70% 0.00% : % of total used
69.07% 0.73% 100.00% 0.00% : % of user resources
37207 685 4 0 : resources used by this file
7.09% 0.07% 0.16% 0.00% : % of available
77.40% 0.91% 0.69% 0.00% : % of total used
98.13% 1.29% 100.00% 0.00% : % of user resources

: //package com.custom_computing_ic.dfe_snippets.utils;
:
Expand Down Expand Up @@ -42,7 +42,7 @@
:
: public class FetchSubTuple extends KernelLib
: {
: private static final int bufferDepth = 8;
: private static final int bufferDepth = 4;
:
: private DFEVectorType<DFEVar> m_tupleType;
: private DFEVectorType<DFEVar> m_boolTupleType;
Expand Down Expand Up @@ -119,15 +119,15 @@
: DFEVar shiftLoop = tupleIndexType.newInstance(this);
:
: optimization.pushPipeliningFactor(0.0);
4 2 0 0 : DFEVar shift = control.count.pulse(1)? 0 : stream.offset(shiftLoop,-1);
10 10 0 0 : shiftLoop <== KernelMath.modulo(shift.cast(dfeUInt(m_tupleBitWidth+1)) +
6 0 0 0 : numElements.cast(dfeUInt(m_tupleBitWidth+1)), m_tupleSize)
9 2 0 0 : DFEVar shift = control.count.pulse(1)? 0 : stream.offset(shiftLoop,-1);
28 13 0 0 : shiftLoop <== KernelMath.modulo(shift.cast(dfeUInt(m_tupleBitWidth+1)) +
9 0 0 0 : numElements.cast(dfeUInt(m_tupleBitWidth+1)), m_tupleSize)
: .cast(tupleIndexType);
: optimization.popPipeliningFactor();
:
: for (int i = 0; i < m_tupleSize; i++)
: {
23 28 0 0 : mask[i] <== (i < numElements);
177 162 0 0 : mask[i] <== (i < numElements);
: }
: readEnable = null;
: if (m_tupleBitWidth == 0)
Expand All @@ -136,7 +136,7 @@
: }
: else
: {
99 64 1 0 : readEnable = mask.rotateElementsLeft(shift);
750 504 4 0 : readEnable = mask.rotateElementsLeft(shift);
: }
: optimization.pushPipeliningFactor(0.0);
: // all FIFOs have same depth +/-1 - just watching an arbitrary FIFO
Expand All @@ -145,8 +145,8 @@
:
: for (int i = 0; i < m_tupleSize; i++)
: {
3 4 0 0 : DFEVar pastDepth = control.count.pulse(1)? 0 : stream.offset(m_depth[i],-1);
72 0 0 0 : m_depth[i] <== pushEnable?
3 3 0 0 : DFEVar pastDepth = control.count.pulse(1)? 0 : stream.offset(m_depth[i],-1);
320 0 0 0 : m_depth[i] <== pushEnable?
: (readEnable[i]? pastDepth : (pastDepth+1))
: :(readEnable[i]? (pastDepth-1) : pastDepth);
: }
Expand All @@ -163,12 +163,12 @@
: for (int i = 0; i < m_tupleSize; i++)
: {
:
48 0 0 0 : DFEVar pastDepth = control.count.pulse(1)? 0 : stream.offset(m_depth[i],-1);
: DFEVar pastDepth = control.count.pulse(1)? 0 : stream.offset(m_depth[i],-1);
:
48 0 0 0 : DFEVar asIfReadEnable = (pushEnable & pastDepth.eq(0))?
130 0 0 0 : DFEVar asIfReadEnable = (pushEnable & pastDepth.eq(0))?
: inputTuple[i]
: : stream.offset(m_buffer[i][0],-1);
1536 0 0 0 : tuple[i] <== readEnable[i]? asIfReadEnable
10240 0 0 0 : tuple[i] <== readEnable[i]? asIfReadEnable
: : constant.var(m_contentType, 0);
: // shifting those FIFOs that are being read + inserting new entries
: for (int j = 0; j < bufferDepth; j++)
Expand All @@ -179,13 +179,13 @@
: }
: else
: {
48 0 0 0 : DFEVar asIfReadDisabled = (pushEnable & pastDepth.eq(j))?
387 0 0 0 : DFEVar asIfReadDisabled = (pushEnable & pastDepth.eq(j))?
: inputTuple[i]
: : stream.offset(m_buffer[i][j],-1);
: DFEVar asIfReadEnabled = (pushEnable & pastDepth.eq(j+1))?
16703 0 0 0 : DFEVar asIfReadEnabled = (pushEnable & pastDepth.eq(j+1))?
: inputTuple[i]
: : stream.offset(m_buffer[i][j+1],-1);
: m_buffer[i][j] <== readEnable[i]? asIfReadEnabled
8450 0 0 0 : m_buffer[i][j] <== readEnable[i]? asIfReadEnabled
: : asIfReadDisabled;
: }
: }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
LUTs FFs BRAMs DSPs : FetchSubTupleKernel.maxj
37304 826 4 0 : resources used by this file
7.11% 0.08% 0.16% 0.00% : % of available
77.61% 1.10% 0.69% 0.00% : % of total used
98.39% 1.55% 100.00% 0.00% : % of user resources

: /***
: Here we provide an example use case of irregular fetch buffer.
:
: Normally, each cycle we push tupleSize values to the buffer and fetch
: only the number of entries specified by control stream 'sizes'.
:
: The buffer occasionally issues stall signal (nextPushEnable() == 0)
: to avoid overflow of internal FIFOs. To complicate the example further,
: we occasionally disable data pushes and pops.
:
: */
:
: import com.maxeler.maxcompiler.v2.kernelcompiler.Kernel;
: import com.maxeler.maxcompiler.v2.kernelcompiler.KernelParameters;
: import com.maxeler.maxcompiler.v2.kernelcompiler.types.base.DFEVar;
: import com.maxeler.maxcompiler.v2.kernelcompiler.types.base.DFEType;
: import com.maxeler.maxcompiler.v2.kernelcompiler.types.composite.DFEVector;
: import com.maxeler.maxcompiler.v2.kernelcompiler.types.composite.DFEVectorType;
:
: //import com.custom_computing_ic.dfe_snippets.utils.FetchSubTuple;
:
: class FetchSubTupleKernel extends Kernel
: {
: private static final DFEType floatType = dfeFloat(11,53);
: private static final DFEType scalarType = dfeUInt(32);
:
: protected FetchSubTupleKernel(KernelParameters parameters, int tupleSize)
: {
: super(parameters);
:
: DFEVectorType<DFEVar> tupleType =
: new DFEVectorType<DFEVar> (floatType, tupleSize);
:
70 105 0 0 : DFEVar cycleCounter = control.count.simpleCounter(32);
3 1 0 0 : DFEVar prefetchEnable = cycleCounter < 1;
5 4 0 0 : DFEVar pushEnable = ~prefetchEnable & ( (cycleCounter < 27) | (cycleCounter > 30) );
14 4 0 0 : DFEVar popEnable = ~prefetchEnable & ( (cycleCounter < 10) | (cycleCounter > 11) );
:
:
:
:
: DFEVar dataRequestEnableLoop = dfeBool().newInstance(this);
2 4 0 0 : DFEVar dataRequestEnable = control.count.pulse(1)? 0 : stream.offset(dataRequestEnableLoop,-1);
:
1 1 0 0 : DFEVar pushEnable2 = dataRequestEnable & pushEnable;
:
: //debug.simPrintf("\ncycle=%d, pushEnable2=%d | ", cycleCounter, pushEnable2);
:
1 1 0 0 : DFEVector<DFEVar> input = io.input("input", tupleType, dataRequestEnable);
1 9 0 0 : DFEVar size = io.input("sizes", scalarType, popEnable);
:
: boolean alignOutput = false;
: FetchSubTuple buffer = new FetchSubTuple(this, "test", tupleSize, 64, floatType, alignOutput);
0 12 0 0 : DFEVar subTupleSize = (popEnable)? size: 0;
37207 685 4 0 : DFEVector<DFEVar> outTuple = buffer.popPush(subTupleSize, pushEnable2, input);
:
: dataRequestEnableLoop <== buffer.nextPushEnable();
:
: /*
: debug.simPrintf("|prefetchEnable=%d, pushEnable=%d, popEnable=%d, size=%d, subTupleSize=%d, dataRequestEnable=%d, nextPushEnable=%d, ",
: prefetchEnable, pushEnable, popEnable, size, subTupleSize, dataRequestEnable, dataRequestEnableLoop);
: debug.simPrintf("outTuple: ");
: for (int i = 0; i < tupleSize; i++)
: {
: debug.simPrintf("%f ", outTuple[i]);
: }
: */
: io.output("output", outTuple, tupleType);
: }
: }
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
LUTs FFs BRAMs DSPs : FetchSubTupleManager.maxj
37842 42581 4 0 : resources used by this file
7.21% 4.06% 0.16% 0.00% : % of available
78.73% 56.57% 0.69% 0.00% : % of total used
99.80% 80.07% 100.00% 0.00% : % of user resources

: import com.maxeler.maxcompiler.v2.managers.engine_interfaces.CPUTypes;
: import com.maxeler.maxcompiler.v2.managers.engine_interfaces.EngineInterface;
: import com.maxeler.maxcompiler.v2.managers.engine_interfaces.InterfaceParam;
: import com.maxeler.maxcompiler.v2.managers.custom.CustomManager;
: import com.maxeler.maxcompiler.v2.managers.custom.blocks.KernelBlock;
: import com.maxeler.maxcompiler.v2.build.EngineParameters;
:
: public class FetchSubTupleManager extends CustomManager{
:
: private static final String s_kernelName = "FetchSubTupleKernel";
: private static final int tupleSize = 160;
:
: FetchSubTupleManager(EngineParameters ep)
: {
: super(ep);
:
: config.setDefaultStreamClockFrequency(200);
:
:
37532 1189 4 0 : KernelBlock k = addKernel(new FetchSubTupleKernel(makeKernelParameters(s_kernelName), tupleSize));
:
: k.getInput("input") <== addStreamFromCPU("input");
: k.getInput("sizes") <== addStreamFromCPU("sizes");
: addStreamToCPU("output") <== k.getOutput("output");
: }
:
: private static EngineInterface interfaceDefault() {
: EngineInterface engine_interface = new EngineInterface();
: CPUTypes type = CPUTypes.INT32;
: int size = type.sizeInBytes();
: CPUTypes typeDouble = CPUTypes.DOUBLE;
: int sizeDouble = typeDouble.sizeInBytes();
:
: InterfaceParam numInputs = engine_interface.addParam("numInputs", CPUTypes.INT);
: InterfaceParam numCycles = engine_interface.addParam("numCycles", CPUTypes.INT);
: InterfaceParam inputSizeBytes = numInputs * sizeDouble;
: InterfaceParam sizesSizeBytes = numCycles * size;
:
: engine_interface.setTicks(s_kernelName, numCycles);
:
: engine_interface.setStream("input", typeDouble, inputSizeBytes);
: engine_interface.setStream("output", typeDouble, inputSizeBytes);
: engine_interface.setStream("sizes", type, sizesSizeBytes);
: return engine_interface;
: }
:
:
: public static void main(String[] args) {
37532 1189 4 0 : FetchSubTupleManager manager = new FetchSubTupleManager(new EngineParameters(args));
: manager.createSLiCinterface(interfaceDefault());
: manager.addMaxFileConstant("tupleSize", tupleSize);
310 41392 0 0 : manager.build();
: }
: }
Loading

0 comments on commit c78042b

Please sign in to comment.