diff --git a/src/com/custom_computing_ic/dfe_snippets/kernels/PaddingKernel.java b/src/com/custom_computing_ic/dfe_snippets/kernels/PaddingKernel.java new file mode 100644 index 0000000..ec756a0 --- /dev/null +++ b/src/com/custom_computing_ic/dfe_snippets/kernels/PaddingKernel.java @@ -0,0 +1,48 @@ +package com.custom_computing_ic.dfe_snippets.kernels; + +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.stdlib.core.CounterChain; + +/** + * Pads the inputs with 0 after nInputs have been processed. + * + * Scalars: + * NUM_INP - number of inputs that will be received from a previous kernel. + * TOTAL_CYCLES - number of cycles that this kernel should give an output. + * + * @since 18/05/2017 + */ +public class PaddingKernel extends Kernel { + public static final String INP_NAME = "PADDING_INP"; + public static final String OUT_NAME = "PADDING_OUT"; + public static final String SCALAR_NUM_INP = "NUM_INP"; + public static final String SCALAR_TOTAL_CYCLES = "TOTAL_CYCLES"; + + /** + * Constructor of the Padding Kernel. + * + * @param parameters parameters for this kernel passed from a manager + * @param bitWidth number of bits to be processed in each cycle + * @param dbg flag to decide whether to output debug information + */ + public PaddingKernel(KernelParameters parameters, int bitWidth, boolean dbg) { + super(parameters); + + DFEVar nInputs = io.scalarInput(SCALAR_NUM_INP, dfeUInt(32)); + DFEVar totalCycles = io.scalarInput(SCALAR_TOTAL_CYCLES, dfeUInt(32)); + + CounterChain chain = control.count.makeCounterChain(); + DFEVar cycles = chain.addCounter(totalCycles, 1); + DFEVar paddingCycles = cycles >= nInputs; + + DFEVar input = io.input(INP_NAME, dfeRawBits(bitWidth), ~paddingCycles); + DFEVar out = paddingCycles ? 0 : input; + io.output(OUT_NAME, out, dfeRawBits(bitWidth)); + + if (dbg) { + debug.simPrintf("PADDING: %d (%d) nInputs %d\n", cycles, totalCycles, nInputs); + } + } +} diff --git a/src/com/custom_computing_ic/dfe_snippets/kernels/README.md b/src/com/custom_computing_ic/dfe_snippets/kernels/README.md new file mode 100644 index 0000000..1f2833d --- /dev/null +++ b/src/com/custom_computing_ic/dfe_snippets/kernels/README.md @@ -0,0 +1,10 @@ +# Kernels + +This directory contains kernels that can be used for general MaxJ design development. + +## Resource Usage + +| Kernel Name | LUTs | FFs | BRAM | DSP | +|-----------------------|------|-----|------|-----| +| `PaddingKernel(32)` | 428 | 929 | 0 | 0 | +| `UnpaddingKernel(32)` | 416 | 933 | 0 | 0 | diff --git a/src/com/custom_computing_ic/dfe_snippets/kernels/UnpaddingKernel.java b/src/com/custom_computing_ic/dfe_snippets/kernels/UnpaddingKernel.java new file mode 100644 index 0000000..d01ac0f --- /dev/null +++ b/src/com/custom_computing_ic/dfe_snippets/kernels/UnpaddingKernel.java @@ -0,0 +1,48 @@ +package com.custom_computing_ic.dfe_snippets.kernels; + +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.stdlib.core.CounterChain; + +/** + * Un-pads the inputs and will not output zeros after + * nInputs have been processed. + * + * Scalars: + * NUM_INP - number of input data that are valid for output + * TOTAL_CYCLES - number of cycles that this kernel should + * receive data from the previous kernel + * + * @since 18/05/2017 + */ +public class UnpaddingKernel extends Kernel { + public static final String INP_NAME = "UNPADDING_INP"; + public static final String OUT_NAME = "UNPADDING_OUT"; + public static final String SCALAR_NUM_INP = "NUM_INP"; + public static final String SCALAR_TOTAL_CYCLES = "TOTAL_CYCLES"; + + /** + * Constructor of the Unpadding Kernel. + * + * @param parameters parameters for this kernel passed from a manager + * @param bitWidth number of bits to be processed in each cycle + * @param dbg flag to decide whether to output debug information + */ + public UnpaddingKernel(KernelParameters parameters, int bitWidth, boolean dbg) { + super(parameters); + + DFEVar nInputs = io.scalarInput(SCALAR_NUM_INP, dfeUInt(32)); + DFEVar totalCycles = io.scalarInput(SCALAR_TOTAL_CYCLES, dfeUInt(32)); + CounterChain chain = control.count.makeCounterChain(); + DFEVar cycles = chain.addCounter(totalCycles, 1); + DFEVar unpaddingCycles = cycles >= nInputs; + + DFEVar input = io.input(INP_NAME, dfeRawBits(bitWidth)); + io.output(OUT_NAME, input, dfeRawBits(bitWidth), ~unpaddingCycles); + + if (dbg) { + debug.simPrintf("UNPADDING: %d (%d) nInputs %d\n", cycles, totalCycles, nInputs); + } + } +} diff --git a/src/com/custom_computing_ic/dfe_snippets/manager/ManagerUtils.java b/src/com/custom_computing_ic/dfe_snippets/manager/ManagerUtils.java index 98d5b7d..c304916 100644 --- a/src/com/custom_computing_ic/dfe_snippets/manager/ManagerUtils.java +++ b/src/com/custom_computing_ic/dfe_snippets/manager/ManagerUtils.java @@ -178,6 +178,10 @@ public static void addLinearStreamFromLMemToKernel(LMemInterface iface, KernelBl LMemCommandGroup.MemoryAccessPattern.LINEAR_1D); } + public static void addLinearStreamFromLMemToKernel(LMemCommandGroup group, KernelBlock kernel, String src, String dst) { + kernel.getInput(dst) <== group.addStreamFromLMem(src); + } + @Deprecated public static void addLinearStreamFromKernelToLmem(CustomManager m, KernelBlock kernel, String name) { m.addStreamToOnCardMemory( @@ -201,6 +205,10 @@ public static void addLinearStreamFromKernelToLMem(LMemInterface iface, KernelBl LMemCommandGroup.MemoryAccessPattern.LINEAR_1D) <== kernel.getOutput(src); } + public static void addLinearStreamFromKernelToLMem(LMemCommandGroup group, KernelBlock kernel, String src, String dst) { + group.addStreamToLMem(dst) <== kernel.getOutput(src); + } + public static void ignoreLMemStreams(EngineInterface ei) { ei.ignoreLMem("cpu2lmem"); ei.ignoreStream("fromcpu");