pyushkevich / greedy

Very fast greedy diffeomorphic registration code
GNU General Public License v3.0
62 stars 17 forks source link

Errors building in docker #23

Open vanossj opened 3 years ago

vanossj commented 3 years ago

I've been trying to get greedy to build in a docker container but I'm running into errors with isnan

ITK: 4.12.2 greedy: a9fcaac

Dockerfile

FROM ubuntu:18.04
RUN apt-get update && DEBIAN_FRONTEND="noninteractive" apt-get install -y build-essential cmake ninja-build
COPY ITK /ITK
RUN mkdir itk_build;cd itk_build;cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_TESTING=OFF /ITK;ninja
COPY greedy /greedy
RUN mkdir greedy_build;cd greedy_build; cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DITK_DIR=/itk_build /greedy;ninja
ENTRYPOINT [ "bash" ]

ITK builds fine but when it gets to greedy I get error messages like

FAILED: CMakeFiles/greedyapi.dir/src/MultiImageRegistrationHelper.cxx.o 
/usr/bin/c++  -DITK_IO_FACTORY_REGISTER_MANAGER -IITKIOFactoryRegistration -I/ITK/Modules/Segmentation/Watersheds/include -I/ITK/Modules/Segmentation/Voronoi/include -I/ITK/Modules/Video/IO/include -I/ITK/Modules/Video/Filtering/include -I/ITK/Modules/Video/Core/include -I/ITK/Modules/Bridge/VTK/include -I/ITK/Modules/Core/TestKernel/include -I/ITK/Modules/Filtering/SpatialFunction/include -I/ITK/Modules/Registration/RegistrationMethodsv4/include -I/ITK/Modules/Segmentation/RegionGrowing/include -I/ITK/Modules/Filtering/QuadEdgeMeshFiltering/include -I/ITK/Modules/Numerics/NeuralNetworks/include -I/ITK/Modules/Registration/Metricsv4/include -I/ITK/Modules/Numerics/Optimizersv4/include -I/ITK/Modules/Segmentation/MarkovRandomFieldsClassifiers/include -I/ITK/Modules/Segmentation/LevelSetsv4/include -I/ITK/Modules/Segmentation/LabelVoting/include -I/ITK/Modules/Segmentation/KLMRegionGrowing/include -I/ITK/Modules/Filtering/ImageNoise/include -I/ITK/Modules/Filtering/ImageFusion/include -I/ITK/Modules/IO/VTK/include -I/ITK/Modules/IO/TransformMatlab/include -I/ITK/Modules/IO/TransformInsightLegacy/include -I/ITK/Modules/IO/TransformHDF5/include -I/ITK/Modules/IO/TransformBase/include -I/ITK/Modules/IO/TransformFactory/include -I/ITK/Modules/IO/Stimulate/include -I/ITK/Modules/IO/Siemens/include -I/ITK/Modules/IO/RAW/include -I/ITK/Modules/IO/PNG/include -I/ITK/Modules/ThirdParty/PNG/src -I/itk_build/Modules/ThirdParty/PNG/src -I/ITK/Modules/IO/NRRD/include -I/ITK/Modules/ThirdParty/NrrdIO/src/NrrdIO -I/itk_build/Modules/ThirdParty/NrrdIO/src/NrrdIO -I/ITK/Modules/IO/NIFTI/include -I/ITK/Modules/IO/Meta/include -I/ITK/Modules/IO/Mesh/include -I/ITK/Modules/IO/MRC/include -I/ITK/Modules/IO/LSM/include -I/ITK/Modules/IO/TIFF/include -I/ITK/Modules/ThirdParty/TIFF/src -I/itk_build/Modules/ThirdParty/TIFF/src/itktiff -I/itk_build/Modules/ThirdParty/TIFF/src -I/ITK/Modules/IO/JPEG/include -I/ITK/Modules/ThirdParty/JPEG/src -I/itk_build/Modules/ThirdParty/JPEG/src -I/ITK/Modules/IO/HDF5/include -I/ITK/Modules/IO/GIPL/include -I/ITK/Modules/IO/GE/include -I/ITK/Modules/IO/IPL/include -I/ITK/Modules/IO/GDCM/include -I/ITK/Modules/IO/CSV/include -I/ITK/Modules/IO/BioRad/include -I/ITK/Modules/IO/BMP/include -I/itk_build/Modules/ThirdParty/HDF5/src -I/ITK/Modules/ThirdParty/HDF5/src -I/ITK/Modules/Filtering/GPUThresholding/include -I/ITK/Modules/Filtering/GPUSmoothing/include -I/ITK/Modules/Registration/GPUPDEDeformable/include -I/ITK/Modules/Registration/GPUCommon/include -I/ITK/Modules/Filtering/GPUImageFilterBase/include -I/ITK/Modules/Filtering/GPUAnisotropicSmoothing/include -I/ITK/Modules/Core/GPUFiniteDifference/include -I/ITK/Modules/Core/GPUCommon/include -I/ITK/Modules/ThirdParty/GIFTI/src/gifticlib -I/ITK/Modules/ThirdParty/NIFTI/src/nifti/znzlib -I/ITK/Modules/ThirdParty/NIFTI/src/nifti/niftilib -I/ITK/Modules/ThirdParty/GDCM/src/gdcm/Source/DataStructureAndEncodingDefinition -I/ITK/Modules/ThirdParty/GDCM/src/gdcm/Source/MessageExchangeDefinition -I/ITK/Modules/ThirdParty/GDCM/src/gdcm/Source/InformationObjectDefinition -I/ITK/Modules/ThirdParty/GDCM/src/gdcm/Source/Common -I/ITK/Modules/ThirdParty/GDCM/src/gdcm/Source/DataDictionary -I/ITK/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat -I/itk_build/Modules/ThirdParty/GDCM/src/gdcm/Source/Common -I/itk_build/Modules/ThirdParty/GDCM -I/ITK/Modules/Registration/FEM/include -I/ITK/Modules/Registration/PDEDeformable/include -I/ITK/Modules/Numerics/FEM/include -I/ITK/Modules/Registration/Common/include -I/ITK/Modules/IO/SpatialObjects/include -I/ITK/Modules/IO/XML/include -I/ITK/Modules/ThirdParty/Expat/src/expat -I/itk_build/Modules/ThirdParty/Expat/src/expat -I/ITK/Modules/Numerics/Eigen/include -I/ITK/Modules/Filtering/DisplacementField/include -I/ITK/Modules/Filtering/DiffusionTensorImage/include -I/ITK/Modules/Filtering/Denoising/include -I/ITK/Modules/Segmentation/DeformableMesh/include -I/ITK/Modules/Filtering/Deconvolution/include -I/ITK/Modules/ThirdParty/DICOMParser/src/DICOMParser -I/itk_build/Modules/ThirdParty/DICOMParser/src/DICOMParser -I/ITK/Modules/Filtering/Convolution/include -I/ITK/Modules/Filtering/FFT/include -I/ITK/Modules/Filtering/Colormap/include -I/ITK/Modules/Segmentation/Classifiers/include -I/ITK/Modules/Segmentation/BioCell/include -I/ITK/Modules/Filtering/BiasCorrection/include -I/ITK/Modules/Numerics/Polynomials/include -I/ITK/Modules/Filtering/AntiAlias/include -I/ITK/Modules/Segmentation/LevelSets/include -I/ITK/Modules/Segmentation/SignedDistanceFunction/include -I/ITK/Modules/Numerics/Optimizers/include -I/ITK/Modules/Filtering/ImageFeature/include -I/ITK/Modules/Filtering/ImageSources/include -I/ITK/Modules/Filtering/ImageGradient/include -I/ITK/Modules/Filtering/Smoothing/include -I/ITK/Modules/Filtering/ImageCompare/include -I/ITK/Modules/IO/ImageBase/include -I/itk_build/Modules/IO/ImageBase -I/ITK/Modules/Filtering/FastMarching/include -I/ITK/Modules/Core/QuadEdgeMesh/include -I/ITK/Modules/Filtering/DistanceMap/include -I/ITK/Modules/Numerics/NarrowBand/include -I/ITK/Modules/Filtering/ImageLabel/include -I/ITK/Modules/Filtering/BinaryMathematicalMorphology/include -I/ITK/Modules/Filtering/MathematicalMorphology/include -I/ITK/Modules/Segmentation/ConnectedComponents/include -I/ITK/Modules/Filtering/Thresholding/include -I/ITK/Modules/Filtering/ImageIntensity/include -I/ITK/Modules/Filtering/Path/include -I/ITK/Modules/Filtering/ImageStatistics/include -I/ITK/Modules/Core/SpatialObjects/include -I/ITK/Modules/ThirdParty/MetaIO/src/MetaIO/src -I/itk_build/Modules/ThirdParty/MetaIO/src/MetaIO/src -I/ITK/Modules/ThirdParty/ZLIB/src -I/itk_build/Modules/ThirdParty/ZLIB/src -I/ITK/Modules/Core/Mesh/include -I/ITK/Modules/Filtering/ImageCompose/include -I/ITK/Modules/Filtering/LabelMap/include -I/ITK/Modules/Filtering/AnisotropicSmoothing/include -I/ITK/Modules/Filtering/ImageGrid/include -I/ITK/Modules/Core/ImageFunction/include -I/ITK/Modules/Core/Transform/include -I/ITK/Modules/Numerics/Statistics/include -I/itk_build/Modules/ThirdParty/Netlib -I/ITK/Modules/Core/ImageAdaptors/include -I/ITK/Modules/Filtering/CurvatureFlow/include -I/ITK/Modules/Filtering/ImageFilterBase/include -I/ITK/Modules/Core/FiniteDifference/include -I/ITK/Modules/Core/Common/include -I/itk_build/Modules/Core/Common -I/ITK/Modules/ThirdParty/VNLInstantiation/include -I/itk_build/Modules/ThirdParty/VNL/src/vxl/core -I/itk_build/Modules/ThirdParty/VNL/src/vxl/vcl -I/itk_build/Modules/ThirdParty/VNL/src/vxl/v3p/netlib -I/ITK/Modules/ThirdParty/VNL/src/vxl/core -I/ITK/Modules/ThirdParty/VNL/src/vxl/vcl -I/ITK/Modules/ThirdParty/VNL/src/vxl/v3p/netlib -I/itk_build/Modules/ThirdParty/KWSys/src -I/ITK/Modules/ThirdParty/KWIML/src -I/itk_build/Modules/ThirdParty/KWIML/src -I/itk_build/Modules/ThirdParty/DoubleConversion/src/double-conversion -I/ITK/Modules/ThirdParty/DoubleConversion/src/double-conversion -I/greedy/src -I/greedy/src/ITKFilters/include -I. -O3 -DNDEBUG   -std=gnu++1z -MD -MT CMakeFiles/greedyapi.dir/src/MultiImageRegistrationHelper.cxx.o -MF CMakeFiles/greedyapi.dir/src/MultiImageRegistrationHelper.cxx.o.d -o CMakeFiles/greedyapi.dir/src/MultiImageRegistrationHelper.cxx.o -c /greedy/src/MultiImageRegistrationHelper.cxx
/greedy/src/MultiImageRegistrationHelper.cxx: In instantiation of 'void MultiImageOpticalFlowHelper<TFloat, VDim>::BuildCompositeImages(double) [with TFloat = float; unsigned int VDim = 2]':
/greedy/src/MultiImageRegistrationHelper.cxx:1267:16:   required from here
/greedy/src/MultiImageRegistrationHelper.cxx:254:27: error: 'isnan' was not declared in this scope
         nans_fixed = isnan(LDDMMType::img_voxel_sum(fltExtractFixed->GetOutput()));
                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/greedy/src/MultiImageRegistrationHelper.cxx:254:27: note: suggested alternatives:
In file included from /usr/include/c++/7/complex:44:0,
                 from /ITK/Modules/Core/Common/include/itkNumericTraits.h:54,
                 from /ITK/Modules/Core/Common/include/itkConceptChecking.h:32,
                 from /ITK/Modules/Core/Common/include/itkAtomicIntDetail.h:39,
                 from /ITK/Modules/Core/Common/include/itkAtomicInt.h:38,
                 from /ITK/Modules/Core/Common/include/itkTimeStamp.h:33,
                 from /ITK/Modules/Core/Common/include/itkLightObject.h:23,
                 from /ITK/Modules/Core/Common/include/itkObject.h:31,
                 from /ITK/Modules/Core/Common/include/itkDataObject.h:31,
                 from /ITK/Modules/Core/Common/include/itkImageBase.h:31,
                 from /greedy/src/MultiImageRegistrationHelper.h:30,
                 from /greedy/src/MultiImageRegistrationHelper.cxx:27:

full log: build.log

neuronflow commented 9 months ago

did you solve it?

pyushkevich commented 9 months ago

Unless you are running an old version of the code, greedy should be built with ITK5.

Here is a dockerfile that builds greedy and other tools from our group:

https://github.com/pyushkevich/tk-docker

And the container itself is pyushkevich/tk:latest

On Wed, Dec 20, 2023 at 7:11 PM neuronflow @.***> wrote:

did you solve it?

— Reply to this email directly, view it on GitHub https://github.com/pyushkevich/greedy/issues/23#issuecomment-1865301221, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJPEW73IQMREXCRESE774DYKN5EDAVCNFSM4X5MYASKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBWGUZTAMJSGIYQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

neuronflow commented 9 months ago

Thank you. Will this work on ARM CPUs, specifically M1 Apple silicon?

pyushkevich commented 9 months ago

The Docker container won't work on M1, but I believe the script in the Dockerfile should work.

On Thu, Dec 21, 2023 at 9:26 AM neuronflow @.***> wrote:

Thank you. Will this work on ARM CPUs, specifically M1 Apple silicon?

— Reply to this email directly, view it on GitHub https://github.com/pyushkevich/greedy/issues/23#issuecomment-1866362168, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJPEW4HRVVYZAATLJK5Y63YKRBK3AVCNFSM4X5MYASKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBWGYZTMMRRGY4A . You are receiving this because you commented.Message ID: @.***>

neuronflow commented 9 months ago

we are trying to build greedy in a debian based docker running on an M1 Mac without success so far.

Here are our current efforts:

FROM python:3.10.13-bullseye

ARG BUILD_JOBS=16

# # Setup LST-AI
RUN mkdir -p /custom_apps/lst_directory

# Install prerequisites
# c.f. https://greedy.readthedocs.io/en/latest/install.html#compiling-from-source-code
RUN apt-get update && \
    apt-get install -y cmake g++ git

# Install additional dependencies for VTK
RUN apt-get install -y libgl1-mesa-dev libxt-dev

# Install libpng
RUN apt-get install -y libpng-dev

# Build VTK
# Download and unpack VTK
WORKDIR /VTK
RUN git clone https://gitlab.kitware.com/vtk/vtk.git
WORKDIR /VTK/vtk
RUN git checkout v9.1.0

# Create and navigate to the build directory for VTK
RUN mkdir VTK-build
WORKDIR /VTK/vtk/VTK-build

# Run CMake to configure and build VTK
RUN cmake -DCMAKE_BUILD_TYPE=Release ..
RUN make -j ${BUILD_JOBS}
RUN make install

# Build ITK
# c.f. https://itk.org/Wiki/ITK/Getting_Started/Build/Linux
# Clone the ITK repository
RUN git clone https://github.com/InsightSoftwareConsortium/ITK.git /ITK
WORKDIR /ITK

# Checkout the specific version
RUN git checkout v5.1.2

# Create and navigate to the build directory
RUN mkdir -p /ITK/build
WORKDIR /ITK/build

# Run CMake to configure and build ITK
RUN cmake -DModule_ITKPNG=ON \
          -DITK_USE_SYSTEM_PNG=ON \
          -DBUILD_TESTING=OFF \
          -DCMAKE_BUILD_TYPE=Release ..
# run build process
RUN make -j ${BUILD_JOBS}
RUN make install

# Clone the greedy repository
RUN git clone https://github.com/pyushkevich/greedy /greedy
WORKDIR /greedy
RUN git checkout 1eafa4c6659b7a669fb299ce98d9531fc23e332a

# Set the working directory to the build directory
WORKDIR /greedy/build

# Run ccmake from the build directory
RUN cmake -DITK_DIR=/ITK/build \
          -DVTK_DIR=/VTK/vtk/VTK-build \
          -DCMAKE_BUILD_TYPE=Release \
           ..
RUN make -j ${BUILD_JOBS}
RUN make install

currently when we run greedy inside the container we get:

greedy: error while loading shared libraries: libvtkIOPLY-9.1.so.1: cannot open shared object file: No such file or directory
pyushkevich commented 9 months ago

Sounds like LD_LIBRARY_PATH should be set in the environment to point to where the VTK build places the .so files. Or in your VTK build, make it be static.

On Thu, Dec 21, 2023 at 11:08 AM neuronflow @.***> wrote:

we are trying to build greedy in a debian based docker running on an M1 Mac without success so far.

Here are our current efforts:

FROM python:3.10.13-bullseye

ARG BUILD_JOBS=16

Setup LST-AI

RUN mkdir -p /custom_apps/lst_directory

Install prerequisites

c.f. https://greedy.readthedocs.io/en/latest/install.html#compiling-from-source-code

RUN apt-get update && \ apt-get install -y cmake g++ git

Install additional dependencies for VTK

RUN apt-get install -y libgl1-mesa-dev libxt-dev

Install libpng

RUN apt-get install -y libpng-dev

Build VTK

Download and unpack VTK

WORKDIR /VTK RUN git clone https://gitlab.kitware.com/vtk/vtk.git WORKDIR /VTK/vtk RUN git checkout v9.1.0

Create and navigate to the build directory for VTK

RUN mkdir VTK-build WORKDIR /VTK/vtk/VTK-build

Run CMake to configure and build VTK

RUN cmake -DCMAKE_BUILD_TYPE=Release .. RUN make -j ${BUILD_JOBS} RUN make install

Build ITK

c.f. https://itk.org/Wiki/ITK/Getting_Started/Build/Linux

Clone the ITK repository

RUN git clone https://github.com/InsightSoftwareConsortium/ITK.git /ITK WORKDIR /ITK

Checkout the specific version

RUN git checkout v5.1.2

Create and navigate to the build directory

RUN mkdir -p /ITK/build WORKDIR /ITK/build

Run CMake to configure and build ITK

RUN cmake -DModule_ITKPNG=ON \ -DITK_USE_SYSTEM_PNG=ON \ -DBUILD_TESTING=OFF \ -DCMAKE_BUILD_TYPE=Release ..

run build process

RUN make -j ${BUILD_JOBS} RUN make install

Clone the greedy repository

RUN git clone https://github.com/pyushkevich/greedy /greedy WORKDIR /greedy RUN git checkout 1eafa4c6659b7a669fb299ce98d9531fc23e332a

Set the working directory to the build directory

WORKDIR /greedy/build

Run ccmake from the build directory

RUN cmake -DITK_DIR=/ITK/build \ -DVTK_DIR=/VTK/vtk/VTK-build \ -DCMAKE_BUILD_TYPE=Release \ .. RUN make -j ${BUILD_JOBS} RUN make install

currently when we run greedy inside the container we get:

greedy: error while loading shared libraries: libvtkIOPLY-9.1.so.1: cannot open shared object file: No such file or directory

— Reply to this email directly, view it on GitHub https://github.com/pyushkevich/greedy/issues/23#issuecomment-1866574920, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJPEW7UVK6YUXLYFPRYBCDYKRNH7AVCNFSM4X5MYASKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBWGY2TONBZGIYA . You are receiving this because you commented.Message ID: @.***>

neuronflow commented 9 months ago

The Docker container won't work on M1, but I believe the script in the Dockerfile should work. On Thu, Dec 21, 2023 at 9:26 AM neuronflow @.> wrote: Thank you. Will this work on ARM CPUs, specifically M1 Apple silicon? — Reply to this email directly, view it on GitHub <#23 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJPEW4HRVVYZAATLJK5Y63YKRBK3AVCNFSM4X5MYASKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOBWGYZTMMRRGY4A . You are receiving this because you commented.Message ID: @.>

Thanks, I will try to find out how to implement what you suggested.

Meanwhile I used your Dockerfile to build an image on my M1 system and added our payload to it. However, when I create containers from it I get:

WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
Python 3.10.0
jilei-hao commented 9 months ago

@neuronflow do you need to run greedy on a M1 machine, or do you need to run it on another linux machine?

If your greedy is meant to be running on a M1 machine, try this binary instead of building from scratch.

neuronflow commented 9 months ago

@jilei-hao We need to run greedy inside a Linux-based docker container running on OSX on a M1 machine.

We managed to get it running now, thanks to the advice from @pyushkevich.

This file seems to work:

FROM python:3.10.13-bullseye

ARG BUILD_JOBS=8

# # Setup LST-AI
RUN mkdir -p /custom_apps/lst_directory

# Install prerequisites
# c.f. https://greedy.readthedocs.io/en/latest/install.html#compiling-from-source-code
RUN apt-get update && \
    apt-get install -y cmake g++ git

# Install additional dependencies for VTK
RUN apt-get install -y libgl1-mesa-dev libxt-dev

# Install libpng
RUN apt-get install -y libpng-dev

# Build VTK
# Download and unpack VTK
WORKDIR /VTK
RUN git clone https://gitlab.kitware.com/vtk/vtk.git
WORKDIR /VTK/vtk
RUN git checkout v9.1.0

# Create and navigate to the build directory for VTK
RUN mkdir VTK-build
WORKDIR /VTK/vtk/VTK-build
# ENV LD_LIBRARY_PATH=/VTK/vtk/VTK-build:$LD_LIBRARY_PATH

# Run CMake to configure and build VTK
RUN cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF ..
RUN make -j ${BUILD_JOBS}
RUN make install

# Build ITK
# c.f. https://itk.org/Wiki/ITK/Getting_Started/Build/Linux
# Clone the ITK repository
RUN git clone https://github.com/InsightSoftwareConsortium/ITK.git /ITK
WORKDIR /ITK

# Checkout the specific version
RUN git checkout v5.1.2

# Create and navigate to the build directory
RUN mkdir -p /ITK/build
WORKDIR /ITK/build

# Run CMake to configure and build ITK
RUN cmake -DModule_ITKPNG=ON \
          -DITK_USE_SYSTEM_PNG=ON \
          -DBUILD_TESTING=OFF \
          -DBUILD_SHARED_LIBS=OFF \
          -DCMAKE_BUILD_TYPE=Release ..
# run build process
RUN make -j ${BUILD_JOBS}
RUN make install

# Clone the greedy repository
RUN git clone https://github.com/pyushkevich/greedy /greedy
WORKDIR /greedy
RUN git checkout 1eafa4c6659b7a669fb299ce98d9531fc23e332a

# Set the working directory to the build directory
WORKDIR /greedy/build

# Run ccmake from the build directory
RUN cmake -DITK_DIR=/ITK/build \
          -DVTK_DIR=/VTK/vtk/VTK-build \
          -DCMAKE_BUILD_TYPE=Release \
          -DBUILD_SHARED_LIBS=OFF \
           ..
RUN make -j ${BUILD_JOBS}
RUN make install