Skip to content

Commit 35cccdc

Browse files
authored
Merge pull request #189 from vais-ral/fix-conda-build
2 parents 2403627 + 2970d59 commit 35cccdc

File tree

11 files changed

+58
-81
lines changed

11 files changed

+58
-81
lines changed

CMakeLists.txt

-13
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,6 @@ if(NOT CMAKE_BUILD_TYPE)
88
endif()
99
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
1010

11-
# The version number.
12-
set (RGL_VERSION_MAJOR 1)
13-
set (RGL_VERSION_MINOR 0)
14-
15-
set (CIL_VERSION_MAJOR 0)
16-
set (CIL_VERSION_MINOR 10)
17-
set (CIL_VERSION_PATCH 2)
18-
19-
# set (CIL_VERSION '${CIL_VERSION_MAJOR}.${CIL_VERSION_MINOR}.${CIL_VERSION_PATCH}' CACHE INTERNAL "Core Imaging Library version" FORCE)
20-
# get CIL_VERSION from environment variable and set it in cmake
21-
set (CIL_VERSION $ENV{CIL_VERSION} CACHE INTERNAL "Core Imaging Library version" FORCE)
22-
message(STATUS "CIL_VERSION: ${CIL_VERSION}")
23-
2411
# set the Python variables for the Conda environment
2512
#include(${CMAKE_SOURCE_DIR}/CMake/FindAnacondaEnvironment.cmake)
2613

Installation.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ git clone https://github.com/vais-ral/CCPi-Regularisation-Toolkit
4040
cd CCPi-Regularisation-Toolkit
4141
cmake -S . -B ./build_proj -DBUILD_MATLAB_WRAPPER=ON -DBUILD_PYTHON_WRAPPER=ON -DBUILD_CUDA=ON -DCMAKE_INSTALL_PREFIX=./install
4242
cmake --build ./build_proj --target install
43+
pip install ./src/Python
4344
```
4445

4546
### Python
@@ -55,11 +56,9 @@ conda install ccpi-regulariser -c ccpi -c conda-forge
5556
#### Python (conda-build)
5657

5758
```sh
58-
export CIL_VERSION=$(date +%Y.%m.%d) # UNIX
59-
# set CIL_VERSION=24.3.0 # Windows
6059
conda build recipe/ --numpy 1.23 --python 3.10
61-
conda install ccpi-regulariser=${CIL_VERSION} --use-local --force-reinstall # doesn't work?
62-
conda install -c file://${CONDA_PREFIX}/conda-bld/ ccpi-regulariser=${CIL_VERSION} --force-reinstall # try this one
60+
conda install ccpi-regulariser --use-local --force-reinstall # doesn't work?
61+
conda install -c file://${CONDA_PREFIX}/conda-bld/ ccpi-regulariser --force-reinstall # try this one
6362
cd demos/
6463
python demo_cpu_regularisers.py # to run CPU demo
6564
python demo_gpu_regularisers.py # to run GPU demo
@@ -81,7 +80,7 @@ pip install git+https://github.com/vais-ral/CCPi-Regularisation-Toolkit
8180
If passed `BUILD_PYTHON_WRAPPER=ON`, CMake will install libraries in-place under `./src/Python`, followed by running `python -m pip install ./src/Python`.
8281
(Note that libraries are also installed under the user-specified `${CMAKE_INSTALL_PREFIX}`, which could be set to a throwaway directory, e.g. `-DCMAKE_INSTALL_PREFIX=./install`).
8382

84-
If Python is not picked by CMake you can provide the additional flag to CMake `-DPYTHON_EXECUTABLE=/path/to/executable/python`.
83+
If Python is not found by CMake you can provide the additional flag to CMake `-DPYTHON_EXECUTABLE=/path/to/executable/python`.
8584

8685
Tests can also be run in-place after the build:
8786

build/run.sh

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ rm -r ../build_proj
66
mkdir ../build_proj
77
cd ../build_proj/
88
#make clean
9-
export CIL_VERSION=23.04.1
109
# install Python modules without CUDA
1110
#cmake ../ -DBUILD_PYTHON_WRAPPER=ON -DBUILD_MATLAB_WRAPPER=OFF -DBUILD_CUDA=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./install
1211
# install Python modules with CUDA

recipe/bld.bat

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
IF NOT DEFINED CIL_VERSION (
2-
ECHO CIL_VERSION Not Defined.
3-
exit 1
4-
)
5-
6-
mkdir "%SRC_DIR%\test"
7-
ROBOCOPY /E "%RECIPE_DIR%\..\test" "%SRC_DIR%\test"
8-
cd %SRC_DIR%
9-
10-
:: issue cmake to create setup.py
11-
cmake -G "NMake Makefiles" %RECIPE_DIR%\..\ -DBUILD_PYTHON_WRAPPERS=ON -DCONDA_BUILD=ON -DBUILD_CUDA=ON -DCMAKE_BUILD_TYPE="Release" -DLIBRARY_LIB="%CONDA_PREFIX%\lib" -DLIBRARY_INC="%CONDA_PREFIX%" -DCMAKE_INSTALL_PREFIX="%PREFIX%\Library"
12-
13-
nmake install
14-
if errorlevel 1 exit 1
1+
mkdir "%SRC_DIR%\test"
2+
ROBOCOPY /E "%RECIPE_DIR%\..\test" "%SRC_DIR%\test"
3+
if exist "%RECIPE_DIR%\..\build_proj" (
4+
rd /s /q "%RECIPE_DIR%\..\build_proj"
5+
)
6+
7+
:: add -G "Visual Studio 16 2019" to the cmake command to specify the generator
8+
:: add -DCUDA_TOOLKIT_ROOT_DIR="C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.4" to the cmake command to specify the CUDA toolkit
9+
cmake -S "%SRC_DIR%" -B "%RECIPE_DIR%\..\build_proj" -DBUILD_PYTHON_WRAPPERS=ON -DCONDA_BUILD=ON -DBUILD_CUDA=ON -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DLIBRARY_INC="%CONDA_PREFIX%" -DCMAKE_INSTALL_PREFIX="%RECIPE_DIR%\..\install"
10+
cmake --build "%RECIPE_DIR%\..\build_proj" --target install --config RelWithDebInfo
11+
%PYTHON% -m pip install "%SRC_DIR%\src\Python"
12+
13+
if errorlevel 1 exit 1

recipe/build.sh

100644100755
+4-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
set -xe
1+
set -xe
22
cp -rv "$RECIPE_DIR/../test" "$SRC_DIR/"
33

4-
cd $SRC_DIR
5-
6-
cmake -G "Unix Makefiles" $RECIPE_DIR/../ -DBUILD_PYTHON_WRAPPER=ON -DCONDA_BUILD=ON -DBUILD_CUDA=ON -DCMAKE_BUILD_TYPE="Release" -DLIBRARY_LIB=$CONDA_PREFIX/lib -DLIBRARY_INC=$CONDA_PREFIX -DCMAKE_INSTALL_PREFIX=$PREFIX
7-
8-
make install
4+
cmake -S "$SRC_DIR" -B "$RECIPE_DIR/../build_proj" -DBUILD_PYTHON_WRAPPER=ON -DCONDA_BUILD=ON -DBUILD_CUDA=ON -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DLIBRARY_INC=$CONDA_PREFIX -DCMAKE_INSTALL_PREFIX="$RECIPE_DIR/../install"
5+
cmake --build "$RECIPE_DIR/../build_proj" --target install
6+
$PYTHON -m pip install "$SRC_DIR/src/Python"

recipe/meta.yaml

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
# https://docs.conda.io/projects/conda-build/en/stable/resources/define-metadata.html#loading-data-from-other-files
2+
# TODO: use scikit-build-core & setuptools_scm instead
3+
{% set project = load_file_data('../src/Python/pyproject.toml', from_recipe_dir=True).get('project', {}) %}
14
package:
2-
name: ccpi-regulariser
3-
version: {{ environ.get('GIT_DESCRIBE_TAG','v')[1:] }}
5+
name: {{ project.get('name') }}
6+
version: {{ project.get('version') }}
47

58
build:
69
preserve_egg_dir: False
710
number: {{ environ.get('GIT_DESCRIBE_NUMBER', 0) }}
8-
script_env:
9-
- CIL_VERSION
1011

1112
source:
1213
path: ..
@@ -25,7 +26,7 @@ requirements:
2526
- pip
2627
- vc 14 # [win]
2728
- cmake
28-
- ripgrep
29+
- ripgrep
2930

3031
run:
3132
- {{ pin_compatible('numpy', min_pin='x.x', max_pin='x.x') }}
@@ -34,6 +35,6 @@ requirements:
3435
- libgcc-ng # [unix]
3536

3637
about:
37-
home: http://www.ccpi.ac.uk
38-
license: BSD license
39-
summary: 'CCPi Core Imaging Library Quantification Toolbox'
38+
home: https://tomographicimaging.github.io/CIL/
39+
license: Apache-2.0
40+
summary: 'The set of CPU/GPU optimised regularisation modules for iterative image reconstruction and other image processing tasks'

src/Core/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ endif()
6363
if (BUILD_CUDA)
6464
find_package(CUDA)
6565
if (CUDA_FOUND)
66-
set(CUDA_NVCC_FLAGS "-Xcompiler -fPIC -shared -D_FORCE_INLINES")
66+
if (UNIX)
67+
set(CUDA_NVCC_FLAGS "-Xcompiler -fPIC -shared -D_FORCE_INLINES")
68+
endif()
6769
message(STATUS "CUDA_NVCC_FLAGS: ${CUDA_NVCC_FLAGS}")
6870
CUDA_ADD_LIBRARY(cilregcuda SHARED
6971
${CMAKE_CURRENT_SOURCE_DIR}/regularisers_GPU/TV_ROF_GPU_core.cu

src/Python/CMakeLists.txt

+8-10
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,20 @@ project(regulariserPython)
33
message(STATUS "Creating Python Wrapper")
44
#include (GenerateExportHeader)
55

6+
cmake_policy(SET CMP0094 NEW)
7+
set(Python_FIND_REGISTRY LAST) # prefer active over base conda env
8+
set(Python_FIND_VIRTUALENV STANDARD) # use PATH to search
69
find_package(Python COMPONENTS Interpreter REQUIRED)
710

811
set(PIP_CMAKE_DEPS cilreg)
912
if(TARGET cilregcuda)
1013
list(APPEND PIP_CMAKE_DEPS cilregcuda)
1114
endif()
12-
if (UNIX)
13-
install(TARGETS ${PIP_CMAKE_DEPS}
14-
LIBRARY DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/ccpi/filters"
15-
CONFIGURATIONS ${CMAKE_BUILD_TYPE})
16-
elseif(WIN32)
17-
install(TARGETS ${PIP_CMAKE_DEPS}
18-
RUNTIME DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/ccpi/filters"
19-
ARCHIVE DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/ccpi/filters"
20-
CONFIGURATIONS ${CMAKE_BUILD_TYPE})
21-
endif()
15+
install(TARGETS ${PIP_CMAKE_DEPS}
16+
LIBRARY DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/ccpi/filters"
17+
RUNTIME DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/ccpi/filters"
18+
ARCHIVE DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/ccpi/filters"
19+
CONFIGURATIONS ${CMAKE_BUILD_TYPE})
2220

2321
add_custom_target(PythonWrapper ALL
2422
COMMAND "${Python_EXECUTABLE}" -m pip install "${CMAKE_CURRENT_SOURCE_DIR}" --verbose

src/Python/ccpi/filters/TV.py

+2
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,8 @@ def TV_ENERGY(U, U0, lambdaPar, type, E_val=None):
471471
TGV_GPU = None
472472
dTV_FGP_GPU = None
473473

474+
PatchSelect_GPU = None
475+
474476
if cilregcuda is not None:
475477
def TV_ROF_GPU(inputData, regularisation_parameter, iterationsNumb,
476478
marching_step_parameter, tolerance_param, gpu_device, out=None, infovector=None):

src/Python/ccpi/filters/utils.py

+14-22
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
11
import platform
22
import ctypes
33
import os
4+
import warnings
45

5-
if platform.system() == 'Linux':
6-
dll = 'libcilreg.so'
7-
elif platform.system() == 'Windows':
8-
dll_file = 'cilreg.dll'
9-
dll = ctypes.util.find_library(dll_file)
10-
elif platform.system() == 'Darwin':
11-
dll = 'libcilreg.dylib'
6+
try:
7+
pre = {'Linux': 'lib', 'Windows': '', 'Darwin': 'lib'}[platform.system()]
8+
except KeyError:
9+
raise ValueError(f"unsupported platform: {platform.system()}")
1210
else:
13-
raise ValueError('Not supported platform, ', platform.system())
11+
ext = {'Linux': '.so', 'Windows': '.dll', 'Darwin': '.dylib'}[platform.system()]
1412

15-
cilreg = ctypes.cdll.LoadLibrary(os.path.join(os.path.dirname(__file__), dll))
13+
_here = os.path.dirname(__file__)
14+
dll = f'{pre}cilreg{ext}'
15+
cilreg = ctypes.cdll.LoadLibrary(os.path.join(_here, dll))
1616

17+
gpudll = f'{pre}cilregcuda{ext}'
1718
try:
18-
if platform.system() == 'Linux':
19-
gpudll = 'libcilregcuda.so'
20-
elif platform.system() == 'Windows':
21-
gpudll_file = 'cilregcuda.dll'
22-
gpudll = ctypes.util.find_library(gpudll_file)
23-
elif platform.system() == 'Darwin':
24-
gpudll = 'libcilregcuda.dylib'
25-
else:
26-
raise ValueError('Not supported platform, ', platform.system())
27-
28-
cilregcuda = ctypes.cdll.LoadLibrary(os.path.join(os.path.dirname(__file__), gpudll))
29-
except OSError as ose:
30-
print(ose)
19+
cilregcuda = ctypes.cdll.LoadLibrary(os.path.join(_here, gpudll))
20+
except Exception as exc:
21+
warnings.warn(str(exc), ImportWarning, stacklevel=2)
22+
warnings.warn(f"Found: {os.listdir(_here)}", ImportWarning, stacklevel=2)
3123
cilregcuda = None

src/Python/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ include = ["ccpi", "ccpi.*"]
88

99
[project]
1010
version = "24.0.0"
11-
name='ccpi-regularisers'
11+
name = "ccpi-regulariser"

0 commit comments

Comments
 (0)