Configuring the System Architecture

InSDAccel Compilation Flow and Execution Model, you learned of the two distinct phases in theSDAccel™environment kernel build process:

  1. Compilation stage: The compilation process is controlled by thexocc –coption. At the end of the compilation stage one or more kernel functions are compiled into separate.xofiles. At this stage, thexocccompiler extracts the hardware intent from the C/C++ code and associated pragmas. Refer to theSDx Command and Utility Reference Guidefor more information on thexocccompiler.
  2. Linking stage: The linking stage is controlled by thexocc –loption. During the linking process all the.xofiles are integrated into the FPGA hardware.

If needed, the kernel linking process can be customized to improve theSDAccelenvironment runtime performance. This chapter introduces a few such techniques.

Multiple Instances of a Kernel

By default, a single hardware instance is implemented from a kernel. If the host intends to execute the same kernel multiple times, then multiple such kernel executions take place on the same hardware instance sequentially. However, you can customize the kernel compilation (linking stage) to create multiple hardware instances from a single kernel. This can improve execution performance as the multiple kernel calls can now run concurrently, overlapping their execution while running on separate hardware instances.

Multiple instances of the kernel can be created by using thexocc -–nkswitch during linking.

For example, for a kernel namefoo, two hardware instances can be implemented as follows:

# xocc -–nk : xocc --nk foo:2

By default, the implemented instance names are_1and_2. However, you can optionally change the default instance names as shown below:

# xocc -–nk ::. xocc --nk foo:3:fooA.fooB.fooC

This example implements three identical copies, or hardware instances of kernelfoo, namedfooA,fooB, andfooCon the FPGA programmable logic.

Customization of DDR Bank to Kernel Connection

By default, all the memory interfaces from all the kernels are connected to a single global memory bank. As a result, only one memory interface at a time can transfer data to and from the memory bank, limiting the performance of the kernel. If the FPGA contains only one DDR (or global) memory bank, this is the only option.

However, some FPGA devices contain multiple DDR memory banks. You can customize the connections among the kernel memory interfaces and the DDR memory bank of such a device by altering the default connection.

The above approach can even improve the performance of a single kernel.

Consider the following example:

void cnn( int *image, // Read-Only Image int *weights, // Read-Only Weight Matrix int *out, // Output Filters/Images ... // Other input or Output ports #pragma HLS INTERFACE m_axi port=image offset=slave bundle=gmem #pragma HLS INTERFACE m_axi port=weights offset=slave bundle=gmem #pragma HLS INTERFACE m_axi port=out offset=slave bundle=gmem

The example shows two memory interface inputs for the kernel:imageandweights. If both are connected to the same DDR bank, a concurrent transfer of both of these inputs into the kernel is not possible.

The following steps are needed to implement separate DDR bank connections for theimageandweightsinputs:

  1. Specify separate bundle names for these inputs. This is discussed inMemory Data Inputs and Outputs. However, for reference the code is shown here again.
    void cnn( int *image, // Read-Only Image int *weights, // Read-Only Weight Matrix int *out, // Output Filters/Images ... // Other input or Output ports #pragma HLS INTERFACE m_axi port=image offset=slave bundle=gmem #pragma HLS INTERFACE m_axi port=weights offset=slave bundle=gmem1 #pragma HLS INTERFACE m_axi port=out offset=slave bundle=gmem
    IMPORTANT:When specifying a bundle=name, you should use all lowercase characters to be able to assign it to a specific memory bank using the --spoption.

    The memory interface inputsimageandweightsare assigned different bundle names in the example above.

  2. Alter the XOCC link process to create custom DDR bank connections. This is done using-–spswitch:
    --sp .:
    Where:
    • is the instance name of the kernel as specified by the--nkoption, described inMultiple Instances of a Kernel.
    • is the name of the interface bundle defined by the HLS INTERFACE pragma, includingm_axi_as a prefix, and thebundle=name when specified.
      TIP:If the port is not specified as part of a bundle, then the is the specified port=name, without the m_axi_prefix.
    • is denoted asbank0,bank1, etc. For a device with four DDR banks, the bank names arebank0,bank1,bank2, andbank3.

    For the above example, considering a single instance of thecnnkernel, the-–spswitch can be specified as follows:

    --sp cnn_1.m_axi_gmem:bank0 \ -–sp cnn_1.m_axi_gmem1:bank1

The customized bank connection needs to be reflected in the host code as well. This was previously discussed inSpecifying Exact Memory from the Host Code.

Note:You can choose not to customize the automatic memory mapping by the tool as long as the total number of memory interfaces is less than 15. If there are more than 15 memory interfaces, then you must explicitly perform the memory mapping as described in this chapter.

If-nkand-spswitches are used together for a kernel, each hardware instance should have identical memory connectivity. If not, you should use theOpenCL™sub-device to allocate each kernel instances separately in the host code.

Summary

This section discusses two powerful ways to customize the kernel compilation to improve the system performance during execution.
  1. Consider creating multiple instances of a kernel on the fabric of the FPGA by specifying thexocc --nkif the kernel is called multiple times from the host code.
  2. Consider using thexocc --spswitch to customize the DDR bank connection to kernel memory interfaces to achieve concurrent access.
Depending on the host and kernel design, these options can be exploited to improve the kernel acceleration on Xilinx®FPGAs.