1

I use GaussianBlur on windows and ubuntu, the time of release mode in ubuntu is almost equal to debug mode in windows?

in vs2017 Release and debug mode I open /openmp /fp:fast /sdl- /permissive- /Gy /Oi /arch:AVX2 /O2 /Ot /MD.

And opencv3.4.0 build in ubuntu 16.04:

cmake -D WITH_TBB=ON -D WITH_OPENMP=ON -D WITH_IPP=ON -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_EXAMPLES=OFF -D WITH_NVCUVID=ON -D WITH_CUDA=ON -D BUILD_DOCS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_TESTS=OFF -D WITH_CSTRIPES=ON -D WITH_OPENCL=ON CMAKE_INSTALL_PREFIX=/usr/local/ ..

makefile:

CC = g++
OPENCV_INC_PATH := ./opencv-3.4.0/include
OPENCV_LIB_PATH := ./opencv-3.4.0/build/lib
OBJS = edgeBlend.o
LIBS = edgeBlend.so
INCLUDE_PATH := -I ${OPENCV_INC_PATH}
LIB_PATH := -L ${OPENCV_LIB_PATH}

CXXFLAGS := ${INCLUDE_PATH} ${LIB_PATH} -Wall -O2 -std=c++11 -fPIC -march=native -ffast-math -fopenmp
LD_FLAGS := -lopencv_core -lz -lrt -ldl -lm -lpthread -ljpeg -ltiff -lpng -lopnecv_imgproc

all : $(LIB)
%.o : %.cpp
        $(CC) $(CXXFLAGS) -c $< -o $(@)
$(LIB) : $(OBJS)
        rm -f $(@)
        $(CC) $^ -shared -o $(@) ${LIB_PATH} ${LD_FLAGS}
        rm -f $(OBJS)
clean:
        rm -f $(OBJS) $(LIB) 

Following is my code, image size is 640*480*3:

double start = cv::getTickCount();

cv::GaussianBlur(img_cont, edge_gau, Size(3, 3), 0.8);

cv::GaussianBlur(img_back, img_gau, Size(3, 3), 0.8);

double end = cv::getTickCount();

double time = (end - start) / cv::getTickFrequency();

windows:

debug cost time: 0.02s

release cost time:0.005s

ubuntu:

release cost time: 0.02s

pofeishit
  • 11
  • 2

1 Answers1

3

It seems to me that your optimization flags don't make for a fair comparison. It may not be the root cause, but here are some ideas:

  • Please check the actual gcc flags (make clean; make VERBOSE=1) and not just the cmake invocation.
  • You are allowing /fp:fast in MSVC but not -ffast-math on gcc? Or are you? Please show the actual flags.
  • You allow the compiler to use AVX2 on Windows, but not on Linux? (Hard to be sure without seeing the gcc line.) I'm not sure what the defaults are, but usually they try to maximize compatibility. Try compiling with -march=native instead.
  • The bulk of the work may or may not happen in the opencv library, depending on whether your methods get are inlined (from header files) or implemented as call into the library itself.
  • Check if the -fopenmp flag is actually present. Note that openmp performance can also be affected by environment variables like OMP_NUM_THREADS.
  • Are you sure you are using your own opencv library and not the one from the distribution? Use ldd to check.
maxy
  • 4,971
  • 1
  • 23
  • 25