FROM ubuntu:18.04 #################################### # Basic system setup #################################### ARG DEBIAN_FRONTEND=noninteractive RUN apt-get update && \ apt-get --yes dist-upgrade && \ apt-get --yes --no-install-recommends install python3 python3-pip python3-dev git wget make gnupg cmake libtbb-dev libeigen3-dev g++-8 gfortran RUN pip3 install --verbose setuptools wheel cython RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 100 RUN update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 100 #################################### # MKL setup #################################### RUN wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB && \ apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB && \ rm -f GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB && \ sh -c 'echo deb https://apt.repos.intel.com/mkl all main > /etc/apt/sources.list.d/intel-mkl.list' && \ apt-get --yes update RUN apt-get --yes install intel-mkl-2019.3-062 #################################### # Build Numpy #################################### WORKDIR /root RUN wget -c https://github.com/numpy/numpy/archive/v1.17.3.tar.gz -O - | tar -xz WORKDIR numpy-1.17.3 RUN echo '\ [mkl] \n\ library_dirs = /opt/intel/compilers_and_libraries/linux/mkl/lib/intel64 \n\ include_dirs = /opt/intel/compilers_and_libraries/linux/mkl/include \n\ runtime_library_dirs = /opt/intel/compilers_and_libraries/linux/mkl/lib/intel64 \n\ mkl_libs = mkl_rt \n\ lapack_libs = mkl_lapack95_lp64 \n\ ' > site.cfg RUN CFLAGS="-O3" pip3 install . --global-option=build_ext --global-option=--rpath=/opt/intel/compilers_and_libraries/linux/mkl/lib/intel64 WORKDIR /root RUN rm -rf /root/numpy* #################################### # Build OpenCV #################################### WORKDIR /root # 4.2.0 Segfault # 3.4.9 Segfault # 3.4.5 Segfault # 3.4.4 Segfault (had to also add -DOPENCV_SKIP_PYTHON_LOADER=ON -DOPENCV_PYTHON3_INSTALL_PATH=/usr/local/lib/python3.6/dist-packages/ ) # 3.4.3 Good # 3.4.2 Good ARG cv_version=3.4.5 RUN wget -c https://github.com/opencv/opencv/archive/$cv_version.tar.gz -O - | tar -xz WORKDIR opencv_build RUN cmake \ -DCMAKE_CXX_COMPILER=/usr/bin/g++ \ -DCMAKE_CXX_FLAGS="-march=native" \ -DPYTHON3_EXECUTABLE=/usr/bin/python3 \ -DEIGEN_INCLUDE_PATH=/usr/include/eigen3/ \ -DCMAKE_BUILD_TYPE=Release \ -DBUILD_opencv_python2=OFF \ -DWITH_MKL=ON \ -DWITH_EIGEN=ON \ -DBUILD_EXAMPLES=OFF \ -DBUILD_DOCS=OFF \ -DBUILD_PERF_TESTS=OFF \ -DBUILD_TESTS=OFF \ /root/opencv-$cv_version # needed for 3.4.4 build: # -DOPENCV_SKIP_PYTHON_LOADER=ON \ # -DOPENCV_PYTHON3_INSTALL_PATH=/usr/local/lib/python3.6/dist-packages/ \ # these doesn't seem to affect the issue: # -DWITH_OPENMP=OFF \ # -DMKL_USE_MULTITHREAD=ON \ # -DMKL_WITH_TBB=ON \ # -DWITH_TBB=ON \ # -DBUILD_TBB=OFF \ RUN make all -j12 RUN make install WORKDIR /root RUN rm -rf opencv* #################################### # Run Test #################################### WORKDIR /root RUN echo '\ import sys, ctypes \n\ if len(sys.argv) > 1 and sys.argv[1] == "fix": \n\ ctypes.CDLL("/usr/local/lib/libopencv_core.so") \n\ ctypes.CDLL("/usr/local/lib/libopencv_imgproc.so") \n\ import numpy, cv2 \n\ cv2.dft(numpy.zeros((10,10))) \n\ ' > test.py