From a235cf5e21d337279435991c786a147c84ce92ee Mon Sep 17 00:00:00 2001 From: Vincent Zhao Date: Thu, 18 May 2017 12:45:45 +0100 Subject: [PATCH 1/3] fixed package definition --- .../dfe_snippets/kernels/PaddingKernel.java | 48 +++++++++++++++++++ .../dfe_snippets/kernels/UnpaddingKernel.java | 48 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 src/com/custom_computing_ic/dfe_snippets/kernels/PaddingKernel.java create mode 100644 src/com/custom_computing_ic/dfe_snippets/kernels/UnpaddingKernel.java 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..1407ed9 --- /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 + */ + protected PaddingKernel(KernelParameters parameters, 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/UnpaddingKernel.java b/src/com/custom_computing_ic/dfe_snippets/kernels/UnpaddingKernel.java new file mode 100644 index 0000000..3d5ea93 --- /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); + } + } +} From d9442edeb260aea9683fe02106a7e8847df7252e Mon Sep 17 00:00:00 2001 From: Vincent Zhao Date: Thu, 18 May 2017 14:14:12 +0100 Subject: [PATCH 2/3] fixed severe typos --- .../dfe_snippets/kernels/PaddingKernel.java | 2 +- .../dfe_snippets/kernels/UnpaddingKernel.java | 2 +- .../dfe_snippets/manager/ManagerUtils.java | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/com/custom_computing_ic/dfe_snippets/kernels/PaddingKernel.java b/src/com/custom_computing_ic/dfe_snippets/kernels/PaddingKernel.java index 1407ed9..ec756a0 100644 --- a/src/com/custom_computing_ic/dfe_snippets/kernels/PaddingKernel.java +++ b/src/com/custom_computing_ic/dfe_snippets/kernels/PaddingKernel.java @@ -27,7 +27,7 @@ public class PaddingKernel extends Kernel { * @param bitWidth number of bits to be processed in each cycle * @param dbg flag to decide whether to output debug information */ - protected PaddingKernel(KernelParameters parameters, boolean dbg) { + public PaddingKernel(KernelParameters parameters, int bitWidth, boolean dbg) { super(parameters); DFEVar nInputs = io.scalarInput(SCALAR_NUM_INP, dfeUInt(32)); diff --git a/src/com/custom_computing_ic/dfe_snippets/kernels/UnpaddingKernel.java b/src/com/custom_computing_ic/dfe_snippets/kernels/UnpaddingKernel.java index 3d5ea93..d01ac0f 100644 --- a/src/com/custom_computing_ic/dfe_snippets/kernels/UnpaddingKernel.java +++ b/src/com/custom_computing_ic/dfe_snippets/kernels/UnpaddingKernel.java @@ -29,7 +29,7 @@ public class UnpaddingKernel extends Kernel { * @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) { + public UnpaddingKernel(KernelParameters parameters, int bitWidth, boolean dbg) { super(parameters); DFEVar nInputs = io.scalarInput(SCALAR_NUM_INP, dfeUInt(32)); 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"); From 7ce8859390400cceabd4ce8bcb0bdaf43e1328cb Mon Sep 17 00:00:00 2001 From: Vincent Zhao Date: Fri, 19 May 2017 14:01:23 +0100 Subject: [PATCH 3/3] Add resource usage table --- .../custom_computing_ic/dfe_snippets/kernels/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/com/custom_computing_ic/dfe_snippets/kernels/README.md 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 |