From 4338380a8b540345096052ee30d8bbf668ce3c57 Mon Sep 17 00:00:00 2001 From: Edoardo Pasca Date: Mon, 29 Jan 2018 15:46:04 +0000 Subject: finds boost libraries during wrappers build (win) finds and set the correct name for the boost libraries. Builds GPU wrapper if CUDA is found. --- Wrappers/Python/conda-recipe/bld.bat | 7 +- Wrappers/Python/conda-recipe/build.sh | 6 +- Wrappers/Python/conda-recipe/meta.yaml | 1 + Wrappers/Python/setup-regularizers.py.in | 84 ++++++++++++++++++++++ Wrappers/Python/setup.py | 100 -------------------------- Wrappers/Python/src/cpu_regularizers.pyx | 19 +++++ Wrappers/Python/src/fista_module.cpp | 4 +- Wrappers/Python/test/test_cpu_regularizers.py | 5 +- 8 files changed, 118 insertions(+), 108 deletions(-) create mode 100644 Wrappers/Python/setup-regularizers.py.in delete mode 100644 Wrappers/Python/setup.py (limited to 'Wrappers') diff --git a/Wrappers/Python/conda-recipe/bld.bat b/Wrappers/Python/conda-recipe/bld.bat index fe3ddae..850905c 100644 --- a/Wrappers/Python/conda-recipe/bld.bat +++ b/Wrappers/Python/conda-recipe/bld.bat @@ -8,7 +8,10 @@ ROBOCOPY /E "%RECIPE_DIR%\..\.." "%SRC_DIR%\ccpi" ROBOCOPY /E "%RECIPE_DIR%\..\..\..\Core" "%SRC_DIR%\Core" cd %SRC_DIR%\ccpi\Python -%PYTHON% setup.py build_ext +:: issue cmake to create setup.py +cmake . + +%PYTHON% setup-regularizers.py build_ext if errorlevel 1 exit 1 -%PYTHON% setup.py install +%PYTHON% setup-regularizers.py install if errorlevel 1 exit 1 diff --git a/Wrappers/Python/conda-recipe/build.sh b/Wrappers/Python/conda-recipe/build.sh index aaf9a69..9ea4161 100644 --- a/Wrappers/Python/conda-recipe/build.sh +++ b/Wrappers/Python/conda-recipe/build.sh @@ -11,7 +11,9 @@ cd $SRC_DIR/ccpi/Python echo "$SRC_DIR/ccpi/Python" -$PYTHON setup.py build_ext -$PYTHON setup.py install +cmake . + +$PYTHON setup-regularizers.py build_ext +$PYTHON setup-regularizers.py install diff --git a/Wrappers/Python/conda-recipe/meta.yaml b/Wrappers/Python/conda-recipe/meta.yaml index c451b37..8b58738 100644 --- a/Wrappers/Python/conda-recipe/meta.yaml +++ b/Wrappers/Python/conda-recipe/meta.yaml @@ -21,6 +21,7 @@ requirements: - cil_regularizer - vc 14 # [win and py35] - vc 9 # [win and py27] + - cmake run: - python ==2.7 # [py27] diff --git a/Wrappers/Python/setup-regularizers.py.in b/Wrappers/Python/setup-regularizers.py.in new file mode 100644 index 0000000..3f4d2d7 --- /dev/null +++ b/Wrappers/Python/setup-regularizers.py.in @@ -0,0 +1,84 @@ +#!/usr/bin/env python + +import setuptools +from distutils.core import setup +from distutils.extension import Extension +from Cython.Distutils import build_ext + +import os +import sys +import numpy +import platform + +cil_version=os.environ['CIL_VERSION'] +if cil_version == '': + print("Please set the environmental variable CIL_VERSION") + sys.exit(1) + +library_include_path = "" +library_lib_path = "" +try: + library_include_path = os.environ['LIBRARY_INC'] + library_lib_path = os.environ['LIBRARY_LIB'] +except: + library_include_path = os.environ['PREFIX']+'/include' + pass + +extra_include_dirs = [numpy.get_include(), library_include_path] +#extra_library_dirs = [os.path.join(library_include_path, "..", "lib")] +extra_compile_args = [] +extra_library_dirs = [] +extra_compile_args = [] +extra_link_args = [] +extra_libraries = ['cilreg'] + +extra_include_dirs += [os.path.join(".." , ".." , "Core"), + os.path.join(".." , ".." , "Core", "regularizers_CPU"), + os.path.join(".." , ".." , "Core", "regularizers_GPU") , + "."] + +if platform.system() == 'Windows': + extra_compile_args[0:] = ['/DWIN32','/EHsc','/DBOOST_ALL_NO_LIB' , '/openmp' ] +else: + extra_compile_args = ['-fopenmp','-O2', '-funsigned-char', '-Wall', '-std=c++0x'] + extra_libraries += [@EXTRA_OMP_LIB@] + +extra_libraries += ["@BOOST_PYTHON_LIB@", "@BOOST_NUMPY_LIB@"] + + +setup( + name='ccpi', + description='CCPi Core Imaging Library - Image Regularizers', + version=cil_version, + cmdclass = {'build_ext': build_ext}, + ext_modules = [Extension("ccpi.filters.cpu_regularizers_boost", + sources=[os.path.join("." , "src", "fista_module.cpp" )], + include_dirs=extra_include_dirs, + library_dirs=extra_library_dirs, + extra_compile_args=extra_compile_args, + libraries=extra_libraries ), + + ], + zip_safe = False, + packages = {'ccpi','ccpi.filters'}, +) + +setup( + name='ccpi', + description='CCPi Core Imaging Library - Image Regularizers', + version=cil_version, + cmdclass = {'build_ext': build_ext}, + ext_modules = [Extension("ccpi.filters.cpu_regularizers_cython", + sources=[os.path.join("." , "src", "cpu_regularizers.pyx" ) ], + include_dirs=extra_include_dirs, + library_dirs=extra_library_dirs, + extra_compile_args=extra_compile_args, + libraries=extra_libraries ), + + ], + zip_safe = False, + packages = {'ccpi','ccpi.filters'}, +) + + +@SETUP_GPU_WRAPPERS@ \ No newline at end of file diff --git a/Wrappers/Python/setup.py b/Wrappers/Python/setup.py deleted file mode 100644 index 00c93fc..0000000 --- a/Wrappers/Python/setup.py +++ /dev/null @@ -1,100 +0,0 @@ -#!/usr/bin/env python - -import setuptools -from distutils.core import setup -from distutils.extension import Extension -from Cython.Distutils import build_ext - -import os -import sys -import numpy -import platform - -cil_version=os.environ['CIL_VERSION'] -if cil_version == '': - print("Please set the environmental variable CIL_VERSION") - sys.exit(1) - -library_include_path = "" -library_lib_path = "" -try: - library_include_path = os.environ['LIBRARY_INC'] - library_lib_path = os.environ['LIBRARY_LIB'] -except: - library_include_path = os.environ['PREFIX']+'/include' - pass - -extra_include_dirs = [numpy.get_include(), library_include_path] -#extra_library_dirs = [os.path.join(library_include_path, "..", "lib")] -extra_compile_args = [] -extra_library_dirs = [] -extra_compile_args = [] -extra_link_args = [] -extra_libraries = ['cilreg'] - -extra_include_dirs += [os.path.join(".." , ".." , "Core"), - os.path.join(".." , ".." , "Core", "regularizers_CPU"), - os.path.join(".." , ".." , "Core", "regularizers_GPU") , - "."] - -if platform.system() == 'Windows': - - - extra_compile_args[0:] = ['/DWIN32','/EHsc','/DBOOST_ALL_NO_LIB' , '/openmp' ] - - if sys.version_info.major == 3 : - extra_libraries += ['boost_python3-vc140-mt-1_64', 'boost_numpy3-vc140-mt-1_64'] - else: - extra_libraries += ['boost_python-vc90-mt-1_64', 'boost_numpy-vc90-mt-1_64'] -else: - extra_compile_args = ['-fopenmp','-O2', '-funsigned-char', '-Wall', '-std=c++0x'] - if sys.version_info.major == 3: - extra_libraries += ['boost_python3', 'boost_numpy3','gomp'] - else: - extra_libraries += ['boost_python', 'boost_numpy','gomp'] - -setup( - name='ccpi', - description='CCPi Core Imaging Library - Image Regularizers', - version=cil_version, - cmdclass = {'build_ext': build_ext}, - ext_modules = [Extension("ccpi.filters.gpu_regularizers", - sources=[ - os.path.join("." , "src", "gpu_regularizers.pyx" ), - ], - include_dirs=extra_include_dirs, - library_dirs=extra_library_dirs, - extra_compile_args=extra_compile_args, - libraries=extra_libraries ), - - ], - zip_safe = False, - packages = {'ccpi','ccpi.filters'}, -) - -setup( - name='ccpi', - description='CCPi Core Imaging Library - Image Regularizers', - version=cil_version, - cmdclass = {'build_ext': build_ext}, - ext_modules = [Extension("ccpi.filters.cpu_regularizers", - sources=[os.path.join("." , "src", "fista_module.cpp" ), - os.path.join("." , "src", "cpu_regularizers.pyx" ) - # os.path.join("@CMAKE_SOURCE_DIR@" , "main_func" , "regularizers_CPU", "FGP_TV_core.c"), - # os.path.join("@CMAKE_SOURCE_DIR@" , "main_func" , "regularizers_CPU", "SplitBregman_TV_core.c"), - # os.path.join("@CMAKE_SOURCE_DIR@" , "main_func" , "regularizers_CPU", "LLT_model_core.c"), - # os.path.join("@CMAKE_SOURCE_DIR@" , "main_func" , "regularizers_CPU", "PatchBased_Regul_core.c"), - # os.path.join("@CMAKE_SOURCE_DIR@" , "main_func" , "regularizers_CPU", "TGV_PD_core.c"), - # os.path.join("@CMAKE_SOURCE_DIR@" , "main_func" , "regularizers_CPU", "utils.c") - ], - include_dirs=extra_include_dirs, - library_dirs=extra_library_dirs, - extra_compile_args=extra_compile_args, - libraries=extra_libraries ), - - ], - zip_safe = False, - packages = {'ccpi','ccpi.filters'}, -) - - diff --git a/Wrappers/Python/src/cpu_regularizers.pyx b/Wrappers/Python/src/cpu_regularizers.pyx index e69de29..a8f8c8f 100644 --- a/Wrappers/Python/src/cpu_regularizers.pyx +++ b/Wrappers/Python/src/cpu_regularizers.pyx @@ -0,0 +1,19 @@ +# distutils: language=c++ +""" +Copyright 2018 CCPi +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Author: Edoardo Pasca +""" + +import cython +import numpy as np +cimport numpy as np diff --git a/Wrappers/Python/src/fista_module.cpp b/Wrappers/Python/src/fista_module.cpp index 3876cad..cef3ecc 100644 --- a/Wrappers/Python/src/fista_module.cpp +++ b/Wrappers/Python/src/fista_module.cpp @@ -1028,13 +1028,13 @@ bp::list TGV_PD(np::ndarray input, double d_lambda, double d_alpha1, double d_al return result; } -BOOST_PYTHON_MODULE(cpu_regularizers) +BOOST_PYTHON_MODULE(cpu_regularizers_boost) { np::initialize(); //To specify that this module is a package bp::object package = bp::scope(); - package.attr("__path__") = "cpu_regularizers"; + package.attr("__path__") = "cpu_regularizers_boost"; np::dtype dt1 = np::dtype::get_builtin(); np::dtype dt2 = np::dtype::get_builtin(); diff --git a/Wrappers/Python/test/test_cpu_regularizers.py b/Wrappers/Python/test/test_cpu_regularizers.py index 6c97875..9713baa 100644 --- a/Wrappers/Python/test/test_cpu_regularizers.py +++ b/Wrappers/Python/test/test_cpu_regularizers.py @@ -11,8 +11,9 @@ import numpy as np import os from enum import Enum import timeit -from ccpi.filters.cpu_regularizers import SplitBregman_TV , FGP_TV , LLT_model, \ - PatchBased_Regul , TGV_PD +from ccpi.filters.cpu_regularizers_boost import SplitBregman_TV , FGP_TV ,\ + LLT_model, PatchBased_Regul ,\ + TGV_PD ############################################################################### #https://stackoverflow.com/questions/13875989/comparing-image-in-url-to-image-in-filesystem-in-python/13884956#13884956 -- cgit v1.2.3