Using DDR - 2023.1 English

Vitis Tutorials: Hardware Acceleration (XD099)

Document ID
Release Date
2023.1 English

The kernel code is a simple vector addition with the following function signature.

void vadd(
  const unsigned int *in1, // Read-Only Vector 1
  const unsigned int *in2, // Read-Only Vector 2
  unsigned int *out,       // Output Result
  int dsize,                // Size in integer
  const unsigned int kernel_loop, // Running the same kernel operations kernel_loop times
  bool addRandom           // Address Pattern is random
  • in1 and in2: Inputs for streaming data from DDR over AXI interfaces.

  • out: Output for streaming output results of vector addition writing in DDR over AXI interface.

  • dsize: Sets the size of memory access from kernel ports accessing DDR.

  • kernel_loop: Number of times the kernel operations are being called to keep the kernel busy accessing memory.

  • addRandom: Enables random access if set to 1.

For more information on the kernel source code, refer to <Project>/reference_files/kernel.cpp.

The ports to DDR banks connectivity is established with the system port mapping option using the --sp switch. This switch allows the developer to map the kernel ports to specific global memory banks. For more information, refer to Mapping Kernel Ports to Memory in the Vitis User Guide.

The contents of the example connectivity file, DDR_connectivity.cfg are shown in the following code. Makefile target will create this file automatically.


The host code creates three buffers, one each in DDR0, DDR1, and DDR2. Refer to host code available in <Project>/reference_files/host.cpp. Each buffer connects to a single DDR bank with a capacity of 16 GB, which is higher than the buffer size used in this application. You should be able to migrate up to max 4 GB due to limitations on the Linux kernel.

The following code creates the three buffers of size vector_size_bytes.

134 : cl::Buffer(context,CL_MEM_USE_HOST_PTR | CL_MEM_READ_ONLY, vector_size_bytes, &source_in1[total_data_size]);
135 : cl::Buffer(context,CL_MEM_USE_HOST_PTR | CL_MEM_READ_ONLY, vector_size_bytes, &source_in2[total_data_size]);
136 : cl::Buffer(context,CL_MEM_USE_HOST_PTR | CL_MEM_WRITE_ONLY, vector_size_bytes, &source_hw_results[total_data_size]);
140 : krnl_vector_add.setArg(1, buffer_in2[j]));
141 : krnl_vector_add.setArg(0, buffer_in1[j]));
142 : krnl_vector_add.setArg(2, buffer_output[j]));

For more information on the kernel source code, refer to <Project>/reference_files/host.cpp.