Makefile/Command-Line Flow

You can create a design outside of the SDx IDE. This can be done in a general command-line flow, using individual SDx commands to build and compile the project, or be done with a Makefile flow. An example of the Makefile flow follows.
Note: The Makefile discussed here is from the cpp/getting_started/hello_vadd example in the SDSoC_Examples repository. See Getting Started with Examples for information on the example projects.

If you are using the command line interface and writing makefiles outside of the SDx™ IDE, you must include the platform using the -sds-pf command line option on every call to sdscc. You can also specify the software platform, which includes the operating system that runs on the target CPU, using the -sds-sys-config <system_configuration> command line option.

sdscc -sds-pf <platform path name>
Here, the platform is either a file path or a named platform within the <sdsoc_root>/platforms directory. To view the available base platforms from the command line, run the following command.
$ sdscc -sds -pf -list
# FPGA Board Platform (Default ~ zcu102)
PLATFORM := zcu102

# Run Target:
#   hw  - Compile for hardware
#   emu - Compile for emulation (Default)
TARGET := emu

# Current Directory
pwd := $(CURDIR)

# Points to Utility Directory
COMMON_REPO = ../../../
ABS_COMMON_REPO = $(shell readlink -f $(COMMON_REPO))

# Include Libraries
include $(ABS_COMMON_REPO)/libs/sds_utils/sds_utils.mk

At the beginning of the file, as shown above, you will need to define the inputs and any include files needed to build the design. In this design, the default platform of ZCU102 is used, as well as building for emulation. The include statement for the sds_utils.mk targets a header file that is used for performance timing (start/stop/pause).

# Target OS:
#     linux (Default), standalone
TARGET_OS := linux

# Emulation Mode:
#     debug     - Include debug data
#     optimized - Exclude debug data (Default)
EMU_MODE := optimized

# Additional sds++ flags - this should be reserved for sds++ flags defined
# at run-time. Other sds++ options should be defined in the makefile data section below
# section below
ADDL_FLAGS :=

The preceding section determines the target OS. If the platform is going to be running Linux, specify Linux, which is the default. To run the application on the bare mental of the processor, then select the standalone option. The emulation mode is also specified as either debug, to capture waveform data from the PL hardware emulation for viewing and debugging, or optimized, for faster emulation without capturing this hardware debug information.

# Set to 1 (number one) to enable sds++ verbose output
VERBOSE := 
# Build Executable
EXECUTABLE := run.elf 
# Build Directory
BUILD_DIR := build/$(PLATFORM)_$(TARGET_OS)_$(TARGET)

The executable file is defined, and the output directory for the build. For this project, the build will be located in build/zcu102_linux_emu based on the options of the Makefile. Specifying the BUILD_DIR this way will let you compare and constrast results between different builds, such as an emulation build and a hardware build.

# Source Files
SRC_DIR := src
OBJECTS += \
$(pwd)/$(BUILD_DIR)/main.o \
$(pwd)/$(BUILD_DIR)/vector_addition.o

# SDS Options
HW_FLAGS :=
HW_FLAGS += -sds-hw vadd_accel vector_addition.cpp -sds-end

EMU_FLAGS := 
ifeq ($(TARGET), emu)
	EMU_FLAGS := -mno-bitstream -mno-boot-files -emulation $(EMU_MODE)
endif
With the project and platforrm defined, you need to define the source files, and specify which function or file will be accelerated on the hardware. The -sds-hw flag specifies a function name to be compiled for hardware, and the source file it is found in. The EMU_FLAGS disable bitstream generation and bootfile generation for sds++/sdscc, and specify the emulation mode. Remember, EMU_MODE was previously set to be optimized.
Note: You can define multiple hardware functions in a design by replicating the HW_FLAGS += * line with additional flags.
# Compilation and Link Flags
IFLAGS := -I.
CFLAGS = -Wall -O3 -c
CFLAGS += -MT"$@" -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" 
CFLAGS += -I$(sds_utils_HDRS)
CFLAGS += $(ADDL_FLAGS)
LFLAGS = "$@" "$<" 
#+---------------------------------------------------------------------

SDSFLAGS := -sds -pf $(PLATFORM) \
	-target-os $(TARGET_OS) 

# SDS Compiler
CC := sds++ $(SDSFLAGS)
Like GCC, the sds++/sdcc compiler takes compiler flags. For this project, it will be producing warnings, perform a level 3 optimization, and compile only. In general, most of the standard GCC flags can be used as shown here. Next, the platform and target OS flags are set as defined earlier. Finally the compiler is specified as sds++ or sdscc, and the compiler flags applied.
Note: -MT, -MMD, -MP, -MF, etc are all gcc/g++ flags. Refer to the GCC documentation to understand what these specific flags will do.
all: $(BUILD_DIR)/$(EXECUTABLE)

$(BUILD_DIR)/$(EXECUTABLE): $(OBJECTS)
	mkdir -p $(BUILD_DIR)
	@echo 'Building Target: $@'
	@echo 'Trigerring: SDS++ Linker'
	cd $(BUILD_DIR) ; $(CC) -o $(EXECUTABLE) $(OBJECTS) $(EMU_FLAGS)
	@echo 'SDx Completed Building Target: $@'
	@echo ' '

$(pwd)/$(BUILD_DIR)/%.o: $(pwd)/$(SRC_DIR)/%.cpp
	@echo 'Building file: $<'
	@echo 'Invoking: SDS++ Compiler'
	mkdir -p $(BUILD_DIR)
	cd $(BUILD_DIR) ; $(CC) $(CFLAGS) -o $(LFLAGS) $(HW_FLAGS)
	@echo 'Finished building: $<'
	@echo ' '

In this part of the Makefile, notice that the $(pwd)/$(BUILD_DIR)/%.o section is building all the individual C/C++ files to their respective object files, and the section above it, $(Build_DIR/$(EXECUTABLE) links these object files together for the final generation of the ELF executable.

The Makefile effectively generates the following sds++ compiler command lines:
sds++ -sds-pf zcu102 -target-os linux -sds-sys-config a53_linux -Wall -O3 \
-c -MT"./main.o" -MMD -MP -MF"./main.d" -I../../../libs/sds_utils/ \
-o "./main.o" "./src/main.cpp" -sds-hw vadd_accel vector_addition.cpp -sds-end
sds++ -sds-pf zcu102 -target-os linux -sds-sys-config a53_linux -Wall -O3 \
-c -MT"./vector_addition.o" -MMD -MP -MF"./vector_addition.d" -I../../../libs/sds_utils/ \
-o "./vector_addition.o" "./src/vector_addition.cpp" -sds-hw vadd_accel vector_addition.cpp -sds-end
sds++ -sds-pf zcu102 -target-os linux -sds-sys-config a53_linux \
-o run.elf main.o vector_addition.o -mno-bitstream -mno-boot-files -emulation optimized

These three lines do the following things from the Makefile:

  1. Compile the main.cpp to main.o and vector_addition.cpp to vector_addition.o separately with the system configuration for Linux emulation
    Note: To build this design for hardware, the last command would need to generate a bitstream, boot files, and not be set to emulation. This can be done by removing the -mno-bitstream, -mno-boot-files, and -emulation optimized flags.
  2. Specify that the function vadd_accel is to be accelerated from the vector_addition.cpp
  3. Link the main.o and the vector_addition.o together in the executable file of run.elf