Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrated PaddingKernel and UnpaddingKernel into dfe-snippets #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
10 changes: 10 additions & 0 deletions src/com/custom_computing_ic/dfe_snippets/kernels/README.md
Original file line number Diff line number Diff line change
@@ -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 |
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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");
Expand Down