Showing results for 
Show  only  | Search instead for 
Did you mean: 
Registered: ‎06-28-2020

How to add g++ compiler optimization flags in Petalinux 2017.2 for Xilinx's ZYNQ 7045

I am using ZYNQ XCZ7045 FFG676 (-1) based development board and booting Petalinux 2017.2 for a custom image processing application. 


I am executing an OpenCV code only on the dual-core ARM Cortex-A9 processor (with no PL inclusion) by custom adding the C++ app (as suggested in Petalinux 2017.2 user guide) into Petalinux. 

Further to boost the software performance of the ARM processor with NEON, I referred to Xilinx's Application Note XAPP1206 v1.1


Following step 1) Added the NEON optimized libraries (OpenCV, Pixman & Eigen) from petalinux rootfs packages. 


But to complete Step 2)  i.e, Use Compiler Automatic Vectorization 

I am not able to understand where I should add the compiler optimization flags that is mentioned such as: 

 -O3 -mcpu=cortex-a9 -mfpu=neon -ftree-vectorize -mvectorize-with-neon-quad
-mfloat-abi=hard -ffast-math

I tried to add the above flags in the Makefile present in the below path

<plnx-project-folder>/project-spec/meta-user/recipes-apps/myapp1/files/Makefile  as,


APP = myapp1

# Add any other object files to this list below
APP_OBJS = myapp1.o

all: build

build: $(APP)

CXXFLAGS += -mcpu=cortex-a9
CXXFLAGS += -mfpu=neon
CXXFLAGS += -ftree-vectorize
CXXFLAGS += -mvectorize-with-neon-quad
CXXFLAGS += -mfloat-abi= hard
CXXFLAGS += -ffast-math

CXXFLAGS += $(shell pkg-config --cflags opencv)
LDFLAGS += $(shell pkg-config --libs opencv)


rm -f $(APP) *.elf *.gdb *.o


and also tried to add them in CMakeLists.txt present in the path, 

<plnx-project-folder>/build/tmp/work/cortexa9hf-neon-xilinx-linux-gnueabi/myapp1/1.0-r0/CMakeLists.txt as, 


# cmake needs this line
cmake_minimum_required(VERSION 2.8)

add_definitions(-std=c99 -Ofast -mcpu=cortex-a9 -mfpu=neon -ftree-vectorize -mvectorize-with-neon-quad -mfloat-abi=hard -ffast-math -Werror=return-type)

# Define project name

# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
find_package(OpenCV REQUIRED)

# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")

# Add OpenCV headers location to your include paths

# Declare the executable target built from your sources
add_executable(myapp1 myapp1.cpp)

# Link your application with OpenCV libraries
target_link_libraries(myapp1 ${OpenCV_LIBS})


But both the process did not impart any improvements on the speed of program execution.

Further even when I set the default optimization flags -O0, the performance is same. 


Can anyone suggest how and what all processor optimizations can be added and where to add them, in Petalinux 2017.2?

Tags (3)
0 Kudos
0 Replies