diff --git a/CMakeLists.txt b/CMakeLists.txt index 1054e3d78c..0f4cc88df9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,6 @@ if(NOT DEFINED CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "RelWithDebInfo") endif() -add_subdirectory(src/Core) +add_subdirectory(src/cil) cmake_policy(POP) diff --git a/Wrappers/Python/cil/framework/__init__.py b/Wrappers/Python/cil/framework/__init__.py index bda9fdb11e..66aaab679a 100644 --- a/Wrappers/Python/cil/framework/__init__.py +++ b/Wrappers/Python/cil/framework/__init__.py @@ -16,7 +16,7 @@ # Authors: # CIL Developers, listed at: https://github.com/TomographicImaging/CIL/blob/master/NOTICE.txt -from .cilacc import cilacc +from cil import cilacc from .acquisition_data import AcquisitionData from .acquisition_geometry import AcquisitionGeometry, SystemConfiguration from .data_container import DataContainer diff --git a/Wrappers/Python/cil/framework/cilacc.py b/Wrappers/Python/cil/framework/cilacc.py index 88e7046dc0..e7da2e5c5b 100644 --- a/Wrappers/Python/cil/framework/cilacc.py +++ b/Wrappers/Python/cil/framework/cilacc.py @@ -15,11 +15,6 @@ # # Authors: # CIL Developers, listed at: https://github.com/TomographicImaging/CIL/blob/master/NOTICE.txt -import ctypes -from pathlib import Path +import cil.cilacc as cilacc -try: - cilacc_path = next((Path(__file__).parent.parent / 'lib').resolve().glob("*cilacc.*")) -except StopIteration: - raise FileNotFoundError("cilacc library not found") -cilacc = ctypes.cdll.LoadLibrary(str(cilacc_path)) +cilacc = cilacc diff --git a/Wrappers/Python/cil/framework/data_container.py b/Wrappers/Python/cil/framework/data_container.py index 508291ba9c..46ffa03852 100644 --- a/Wrappers/Python/cil/framework/data_container.py +++ b/Wrappers/Python/cil/framework/data_container.py @@ -16,14 +16,13 @@ # Authors: # CIL Developers, listed at: https://github.com/TomographicImaging/CIL/blob/master/NOTICE.txt import copy -import ctypes import warnings from functools import reduce from numbers import Number import numpy -from .cilacc import cilacc +from cil import cilacc from cil.utilities.multiprocessing import NUM_THREADS @@ -636,8 +635,6 @@ def _axpby(self, a, b, y, out, dtype=numpy.float32, num_threads=NUM_THREADS): :type num_threads: int, optional, default 1/2 CPU of the system ''' - c_float_p = ctypes.POINTER(ctypes.c_float) - c_double_p = ctypes.POINTER(ctypes.c_double) #convert a and b to numpy arrays and get the reference to the data (length = 1 or ndx.size) try: @@ -676,19 +673,19 @@ def _axpby(self, a, b, y, out, dtype=numpy.float32, num_threads=NUM_THREADS): ndb = ndb.astype(dtype, casting='same_kind') if dtype == numpy.float32: - x_p = ndx.ctypes.data_as(c_float_p) - y_p = ndy.ctypes.data_as(c_float_p) - out_p = ndout.ctypes.data_as(c_float_p) - a_p = nda.ctypes.data_as(c_float_p) - b_p = ndb.ctypes.data_as(c_float_p) + x_p = ndx + y_p = ndy + out_p = ndout + a_p = nda + b_p = ndb f = cilacc.saxpby elif dtype == numpy.float64: - x_p = ndx.ctypes.data_as(c_double_p) - y_p = ndy.ctypes.data_as(c_double_p) - out_p = ndout.ctypes.data_as(c_double_p) - a_p = nda.ctypes.data_as(c_double_p) - b_p = ndb.ctypes.data_as(c_double_p) + x_p = ndx + y_p = ndy + out_p = ndout + a_p = nda + b_p = ndb f = cilacc.daxpby else: @@ -698,24 +695,6 @@ def _axpby(self, a, b, y, out, dtype=numpy.float32, num_threads=NUM_THREADS): # int psaxpby(float * x, float * y, float * out, float a, float b, long size) - cilacc.saxpby.argtypes = [ctypes.POINTER(ctypes.c_float), # pointer to the first array - ctypes.POINTER(ctypes.c_float), # pointer to the second array - ctypes.POINTER(ctypes.c_float), # pointer to the third array - ctypes.POINTER(ctypes.c_float), # pointer to A - ctypes.c_int, # type of type of A selector (int) - ctypes.POINTER(ctypes.c_float), # pointer to B - ctypes.c_int, # type of type of B selector (int) - ctypes.c_longlong, # type of size of first array - ctypes.c_int] # number of threads - cilacc.daxpby.argtypes = [ctypes.POINTER(ctypes.c_double), # pointer to the first array - ctypes.POINTER(ctypes.c_double), # pointer to the second array - ctypes.POINTER(ctypes.c_double), # pointer to the third array - ctypes.POINTER(ctypes.c_double), # type of A (c_double) - ctypes.c_int, # type of type of A selector (int) - ctypes.POINTER(ctypes.c_double), # type of B (c_double) - ctypes.c_int, # type of type of B selector (int) - ctypes.c_longlong, # type of size of first array - ctypes.c_int] # number of threads if f(x_p, y_p, out_p, a_p, a_vec, b_p, b_vec, ndx.size, num_threads) != 0: raise RuntimeError('axpby execution failed') diff --git a/Wrappers/Python/cil/optimisation/operators/GradientOperator.py b/Wrappers/Python/cil/optimisation/operators/GradientOperator.py index 56dd9b1b1b..3ce0affb35 100644 --- a/Wrappers/Python/cil/optimisation/operators/GradientOperator.py +++ b/Wrappers/Python/cil/optimisation/operators/GradientOperator.py @@ -267,49 +267,8 @@ def adjoint(self, x, out=None): tmp += self.FD.adjoint(x.get_item(i)) return tmp -import ctypes - -c_float_p = ctypes.POINTER(ctypes.c_float) - -cilacc.openMPtest.restypes = ctypes.c_int32 -cilacc.openMPtest.argtypes = [ctypes.c_int32] - -cilacc.fdiff4D.restype = ctypes.c_int32 -cilacc.fdiff4D.argtypes = [ctypes.POINTER(ctypes.c_float), - ctypes.POINTER(ctypes.c_float), - ctypes.POINTER(ctypes.c_float), - ctypes.POINTER(ctypes.c_float), - ctypes.POINTER(ctypes.c_float), - ctypes.c_size_t, - ctypes.c_size_t, - ctypes.c_size_t, - ctypes.c_size_t, - ctypes.c_int32, - ctypes.c_int32, - ctypes.c_int32] - -cilacc.fdiff3D.restype = ctypes.c_int32 -cilacc.fdiff3D.argtypes = [ctypes.POINTER(ctypes.c_float), - ctypes.POINTER(ctypes.c_float), - ctypes.POINTER(ctypes.c_float), - ctypes.POINTER(ctypes.c_float), - ctypes.c_size_t, - ctypes.c_size_t, - ctypes.c_size_t, - ctypes.c_int32, - ctypes.c_int32, - ctypes.c_int32] - -cilacc.fdiff2D.restype = ctypes.c_int32 -cilacc.fdiff2D.argtypes = [ctypes.POINTER(ctypes.c_float), - ctypes.POINTER(ctypes.c_float), - ctypes.POINTER(ctypes.c_float), - ctypes.c_size_t, - ctypes.c_size_t, - ctypes.c_int32, - ctypes.c_int32, - ctypes.c_int32] +import cil.cilacc as cilacc class Gradient_C(LinearOperator): @@ -378,7 +337,7 @@ def ndarray_as_c_pointer(ndx): def direct(self, x, out=None): ndx = np.asarray(x.as_array(), dtype=np.float32, order='C') - x_p = Gradient_C.ndarray_as_c_pointer(ndx) + x_p = ndx if out is None: out = self.range_geometry().allocate(None) @@ -391,7 +350,7 @@ def direct(self, x, out=None): ndout.insert(ind, out.get_item(0).as_array()) #insert channels dc at correct point for channel data #pass list of all arguments - arg1 = [Gradient_C.ndarray_as_c_pointer(ndout[i]) for i in range(len(ndout))] + arg1 = [ndout[i] for i in range(len(ndout))] arg2 = [el for el in self.domain_shape] args = arg1 + arg2 + [self.bnd_cond, 1, self.num_threads] status = self.fd(x_p, *args) @@ -424,7 +383,7 @@ def adjoint(self, x, out=None): out = self.domain_geometry().allocate(None) ndout = np.asarray(out.as_array(), dtype=np.float32, order='C') - out_p = Gradient_C.ndarray_as_c_pointer(ndout) + out_p = ndout if self.split is False: ndx = [el.as_array() for el in x.containers] @@ -437,7 +396,7 @@ def adjoint(self, x, out=None): if el != 1: ndx[i]/=el - arg1 = [Gradient_C.ndarray_as_c_pointer(ndx[i]) for i in range(self.ndim)] + arg1 = [ndx[i] for i in range(self.ndim)] arg2 = [el for el in self.domain_shape] args = arg1 + arg2 + [self.bnd_cond, 0, self.num_threads] diff --git a/Wrappers/Python/cil/processors/cilacc_binner.py b/Wrappers/Python/cil/processors/cilacc_binner.py index 5b9edccbef..5f26a022ef 100644 --- a/Wrappers/Python/cil/processors/cilacc_binner.py +++ b/Wrappers/Python/cil/processors/cilacc_binner.py @@ -19,10 +19,7 @@ from cil.framework import cilacc import numpy as np -import ctypes -c_float_p = ctypes.POINTER(ctypes.c_float) -c_size_t_p = ctypes.POINTER(ctypes.c_size_t) class Binner_IPP(object): @@ -48,30 +45,17 @@ def __init__(self, shape_in, shape_out, start_index, binning): """ - cilacc.Binner_new.argtypes = [c_size_t_p,c_size_t_p,c_size_t_p,c_size_t_p] - cilacc.Binner_new.restype = ctypes.c_void_p - - cilacc.Binner_bin.argtypes = [ ctypes.c_void_p, c_float_p,c_float_p] - cilacc.Binner_bin.restype = ctypes.c_int32 - - cilacc.Binner_delete.argtypes = [ ctypes.c_void_p] - cilacc.Binner_delete.restype = ctypes.c_void_p shape_in_arr = np.array(shape_in, np.uintp) shape_out_arr = np.array(shape_out, np.uintp) start_index_arr = np.array(start_index, np.uintp) binning_arr = np.array(binning, np.uintp) - shape_in_p = shape_in_arr.ctypes.data_as(c_size_t_p) - shape_out_p = shape_out_arr.ctypes.data_as(c_size_t_p) - ind_start_p = start_index_arr.ctypes.data_as(c_size_t_p) - binning_p = binning_arr.ctypes.data_as(c_size_t_p) - for i in range(4): - if shape_out_p[i] * binning_p[i] + ind_start_p[i] > shape_in_p[i]: + if shape_out_arr[i] * binning_arr[i] + start_index_arr[i] > shape_in_arr[i]: raise ValueError("Input dimension mismatch on dimension {0}".format(i)) - self.obj = cilacc.Binner_new(shape_in_p, shape_out_p, ind_start_p, binning_p) + self.obj = cilacc.Binner_new(shape_in_arr, shape_out_arr, start_index_arr, binning_arr) def bin(self, array_in, array_binned): @@ -88,10 +72,8 @@ def bin(self, array_in, array_binned): array_binned : ndarray Must have shape corresponding to shape_out. Data type float32. C ordered, contiguous memory """ - data_p = array_in.ctypes.data_as(c_float_p) - data_out_p = array_binned.ctypes.data_as(c_float_p) - return cilacc.Binner_bin(self.obj, data_p, data_out_p) + return cilacc.Binner_bin(self.obj, array_in, array_binned) def __del__(self): """This deletes the cilacc Binner object diff --git a/Wrappers/Python/cil/recon/FBP.py b/Wrappers/Python/cil/recon/FBP.py index ccf55eaa00..ac371fa44c 100644 --- a/Wrappers/Python/cil/recon/FBP.py +++ b/Wrappers/Python/cil/recon/FBP.py @@ -22,11 +22,8 @@ from scipy.fft import fftfreq import numpy as np -import ctypes from tqdm import tqdm -c_float_p = ctypes.POINTER(ctypes.c_float) -c_double_p = ctypes.POINTER(ctypes.c_double) try: cilacc.filter_projections_avh @@ -34,23 +31,6 @@ except AttributeError: has_ipp = False -if has_ipp: - cilacc.filter_projections_avh.argtypes = [ctypes.POINTER(ctypes.c_float), # pointer to the data array - ctypes.POINTER(ctypes.c_float), # pointer to the filter array - ctypes.POINTER(ctypes.c_float), # pointer to the weights array - ctypes.c_int16, #order of the fft - ctypes.c_long, #num_proj - ctypes.c_long, #pix_v - ctypes.c_long] #pix_x - - cilacc.filter_projections_vah.argtypes = [ctypes.POINTER(ctypes.c_float), # pointer to the data array - ctypes.POINTER(ctypes.c_float), # pointer to the filter array - ctypes.POINTER(ctypes.c_float), # pointer to the weights array - ctypes.c_int16, #order of the fft - ctypes.c_long, #pix_v - ctypes.c_long, #num_proj - ctypes.c_long] #pix_x - class GenericFilteredBackProjection(Reconstructor): """ Abstract Base Class GenericFilteredBackProjection holding common and virtual methods for FBP and FDK @@ -314,9 +294,9 @@ def _pre_filtering(self,acquistion_data): .format(filter_array.size,self.fft_order)) #call ext function - data_ptr = acquistion_data.array.ctypes.data_as(c_float_p) - filter_ptr = filter_array.ctypes.data_as(c_float_p) - weights_ptr = self._weights.ctypes.data_as(c_float_p) + data_ptr = acquistion_data.array + filter_ptr = filter_array + weights_ptr = self._weights ag = acquistion_data.geometry if ag.dimension_labels == ('angle','vertical','horizontal'): diff --git a/pyproject.toml b/pyproject.toml index 846644715e..689940160a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,10 @@ requires = [ "setuptools>=64", "setuptools_scm>=8", "scikit-build-core>=0.10", - #"ipp-devel==2021.12.*", # PyPI conflicts with conda package + "nanobind", + "ipp-devel>=2022.1", + "ipp-static>=2022.1", + "intel-openmp", ] build-backend = "scikit_build_core.build" @@ -62,7 +65,7 @@ dependencies = [ "h5py", #"ipp==2021.12.*", # PyPI conflicts with conda package "numba", - "numpy>=1.23", + "numpy>=1.23,<2.0", "olefile>=0.46", "pillow", "pywavelets", @@ -76,7 +79,7 @@ plugins = [ #"tomophantom==2.0.0", # [linux] # missing from PyPI ] gpu = [ - "astra-toolbox>=1.9.9.dev5,<=2.1", # [not osx] + "astra-toolbox", # [not osx] #"tigre>=2.4,<=2.6", # missing from PyPI ] [dependency-groups] diff --git a/recipe/bld.bat b/recipe/bld.bat index 97fb90517d..9c2c5e601b 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -4,5 +4,5 @@ set SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL=%PKG_VERSION% if not "%GIT_DESCRIBE_NUMBER%"=="0" ( set SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL=%PKG_VERSION%.dev%GIT_DESCRIBE_NUMBER%+%GIT_DESCRIBE_HASH% ) -pip install . --no-deps +uv pip install . --no-deps if errorlevel 1 exit 1 diff --git a/recipe/build.sh b/recipe/build.sh index 872bff219b..a3eb4a8e39 100755 --- a/recipe/build.sh +++ b/recipe/build.sh @@ -13,4 +13,4 @@ export SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL="${PKG_VERSION}" if test "${GIT_DESCRIBE_NUMBER}" != "0"; then export SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL="${PKG_VERSION}.dev${GIT_DESCRIBE_NUMBER}+${GIT_DESCRIBE_HASH}" fi -pip install . --no-deps -Ccmake.args="${extra_args}" +uv pip install . --no-deps diff --git a/recipe/conda_build_config.yaml b/recipe/conda_build_config.yaml index 82f4f59048..750bb6b7f9 100644 --- a/recipe/conda_build_config.yaml +++ b/recipe/conda_build_config.yaml @@ -19,7 +19,7 @@ #creates pairs of versions using zip_keys, lists must be the same length ipp_version: - - '2021.12' + - '2022.1' python: - 3.10 - 3.10 diff --git a/recipe/meta.yaml b/recipe/meta.yaml index 7f2bb87005..ea173d955c 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -39,10 +39,7 @@ test: requirements: build: - python - - numpy {{ numpy }} - - pip - - setuptools >=64 - - setuptools_scm >=8 + - uv - cmake # [not osx] - cmake >=3.16 # [osx] - libgcc-ng # [linux] @@ -51,10 +48,6 @@ requirements: - openmp # [osx] - vc 14 # [win] - ninja # [not win] - - ipp-include {{ ipp_version }} - - ipp-devel {{ ipp_version }} - - ipp {{ ipp_version }} - - scikit-build-core >=0.10 run: - python @@ -71,7 +64,6 @@ requirements: - olefile >=0.46 - pywavelets - cil-data >=22 - - {{ pin_compatible('ipp', min_pin='x.x', max_pin='x.x') }} - tqdm - numba diff --git a/src/Core/cmake/FindIPP.cmake b/src/Core/cmake/FindIPP.cmake deleted file mode 100644 index b5c402d202..0000000000 --- a/src/Core/cmake/FindIPP.cmake +++ /dev/null @@ -1,25 +0,0 @@ -# Outputs: IPP_FOUND, IPP_INCLUDE_DIRS, IPP_LIBRARIES - -find_path(IPP_ROOT_DIR include/ipp.h PATHS ${IPP_ROOT} $ENV{IPPROOT} $ENV{CONDA_PREFIX}) -find_path(IPP_INCLUDE_DIR ipp.h PATHS ${IPP_ROOT_DIR}/include) - -if(APPLE) - set(IPP_PRE "lib") - set(IPP_POST ".a") -elseif(NOT WIN32) - set(IPP_PRE "lib") - set(IPP_POST ".so") -endif() -find_library(IPP_CORE ${IPP_PRE}ippcore${IPP_POST} PATHS ${IPP_ROOT_DIR}) -find_library(IPP_S ${IPP_PRE}ipps${IPP_POST} PATHS ${IPP_ROOT_DIR}) -find_library(IPP_VM ${IPP_PRE}ippvm${IPP_POST} PATHS ${IPP_ROOT_DIR}) -find_library(IPP_I ${IPP_PRE}ippi${IPP_POST} PATHS ${IPP_ROOT_DIR}) - -if(IPP_INCLUDE_DIR AND IPP_CORE AND IPP_S AND IPP_VM AND IPP_I) - message(STATUS "IPP found in: ${IPP_ROOT_DIR}") - set(IPP_FOUND TRUE) - set(IPP_INCLUDE_DIRS "${IPP_INCLUDE_DIR}") - set(IPP_LIBRARIES "${IPP_CORE};${IPP_S};${IPP_VM};${IPP_I}") -else() - message(STATUS "IPP not found") -endif() diff --git a/src/Core/include/dll_export.h b/src/Core/include/dll_export.h deleted file mode 100644 index b803702650..0000000000 --- a/src/Core/include/dll_export.h +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2019 United Kingdom Research and Innovation -// Copyright 2019 The University of Manchester -// -// 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. -// -// Authors: -// CIL Developers, listed at: https://github.com/TomographicImaging/CIL/blob/master/NOTICE.txt - -#pragma once -#ifndef DLLEXPORT_H -#define DLLEXPORT_H - -#if defined(_WIN32) || defined(__WIN32__) -#if defined(dll_EXPORTS) // add by CMake -#define DLL_EXPORT __declspec(dllexport) -#define EXPIMP_TEMPLATE -#else -#define DLL_EXPORT __declspec(dllexport) -#define EXPIMP_TEMPLATE extern -#endif -#elif defined(linux) || defined(__linux) || defined(__APPLE__) -#define DLL_EXPORT -#ifndef __cdecl -#define __cdecl -#endif -#endif - -#endif -//define int64_t -#if defined(dll_EXPORTS) -using int64_t = __int64; -#endif - -#ifdef _MSC_VER -//typedef __int64 int64; // 64-bit unsigned integer - using int64 = __int64; -#else -//typedef long long int64; //64-bit unsigned integer - using int64 = long long; -#endif diff --git a/src/Core/Binning.cpp b/src/cil/Binning.cpp similarity index 91% rename from src/Core/Binning.cpp rename to src/cil/Binning.cpp index b5631267d0..076e165b39 100644 --- a/src/Core/Binning.cpp +++ b/src/cil/Binning.cpp @@ -24,6 +24,8 @@ #include "ipp.h" #include #include "utilities.h" +#include +#include class Binner { @@ -190,9 +192,15 @@ void Binner::bin_4D(const float* data_in, float* data_binned) } -extern "C" -{ - void Binner_delete(void* binner) { delete (Binner*)binner; } - void* Binner_new(const size_t* shape_in, const size_t* shape_out, const size_t* pixel_index_start, const size_t* binning_list) { return new Binner(shape_in, shape_out, pixel_index_start, binning_list); } - int Binner_bin(void* binner, const float* data_in, float* data_binned) { return ((Binner*)binner)->bin(data_in, data_binned); } -} +void Binner_delete(void* binner) { delete (Binner*)binner; } +void* Binner_new( + Shape shape_in, + Shape shape_out, + Shape pixel_index_start, + Shape binning_list) { + return new Binner(shape_in.data(), shape_out.data(), pixel_index_start.data(), binning_list.data()); + } +int Binner_bin(void* binner, DataInput data_in, DataBinned data_binned) { + return ((Binner*)binner)->bin(data_in.data(), data_binned.data()); + } + diff --git a/src/Core/CMakeLists.txt b/src/cil/CMakeLists.txt similarity index 80% rename from src/Core/CMakeLists.txt rename to src/cil/CMakeLists.txt index 51aaa92851..0b68efa826 100644 --- a/src/Core/CMakeLists.txt +++ b/src/cil/CMakeLists.txt @@ -20,14 +20,14 @@ set (CMAKE_CXX_STANDARD_REQUIRED ON) if(NOT DEFINED CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE RelWithDebInfo) endif() +find_package(Python 3.8 COMPONENTS Interpreter Development.Module REQUIRED) -message ("OpenMP_CXX_FLAGS ${OpenMP_CXX_FLAGS}") +find_package(nanobind CONFIG REQUIRED) + +find_package(IPP REQUIRED CONFIG) find_package(OpenMP REQUIRED) -add_definitions(${OpenMP_CXX_FLAGS}) -if (WIN32) - add_definitions("/Ddll_EXPORTS") -endif() + if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNUCC") # appends some flags @@ -35,6 +35,9 @@ if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNUCC") # add_compile_options(-march=native -mavx ) endif() +message ("OpenMP_CXX_FLAGS ${OpenMP_CXX_FLAGS}") +#add_definitions(${OpenMP_CXX_FLAGS}) + message("CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}") message("CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS}") message("CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS}") @@ -49,10 +52,7 @@ else() set (OpenMP_EXE_LINKER_FLAGS ${OpenMP_C_FLAGS}) endif() -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -find_package(IPP) - -list(APPEND cilacc_SOURCES utilities.cpp axpby.cpp FiniteDifferenceLibrary.cpp) +list(APPEND cilacc_SOURCES utilities.cpp axpby.cpp FiniteDifferenceLibrary.cpp nanobind.cpp) list(APPEND cilacc_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/include) list(APPEND cilacc_LIBRARIES ${OpenMP_EXE_LINKER_FLAGS}) @@ -60,16 +60,19 @@ if(IPP_FOUND) list(APPEND cilacc_SOURCES FBP_filtering.cpp Binning.cpp) list(APPEND cilacc_INCLUDES ${IPP_INCLUDE_DIRS}) list(APPEND cilacc_LIBRARIES ${IPP_LIBRARIES}) + message(STATUS "IPP Libraries Found") else() message(WARNING "IPP libraries not found, FBP_filtering not in build") endif() +message(STATUS ${cilacc_INCLUDES}) +message(STATUS ${IPP_LIBRARIES}) -add_library(cilacc SHARED ${cilacc_SOURCES}) -target_link_libraries(cilacc ${cilacc_LIBRARIES}) +nanobind_add_module( + cilacc + NB_STATIC + ${cilacc_SOURCES} +) include_directories(cilacc PUBLIC ${cilacc_INCLUDES}) +target_link_libraries(cilacc PUBLIC ${cilacc_LIBRARIES}) -install(TARGETS cilacc - LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME}/lib - RUNTIME DESTINATION ${SKBUILD_PROJECT_NAME}/lib) -install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ - DESTINATION ${SKBUILD_PROJECT_NAME}/include/${SKBUILD_PROJECT_NAME}) +install(TARGETS cilacc LIBRARY DESTINATION cil) diff --git a/src/Core/FBP_filtering.cpp b/src/cil/FBP_filtering.cpp similarity index 83% rename from src/Core/FBP_filtering.cpp rename to src/cil/FBP_filtering.cpp index 82a694ce82..ebcc6585a5 100644 --- a/src/Core/FBP_filtering.cpp +++ b/src/cil/FBP_filtering.cpp @@ -18,7 +18,7 @@ #include "FBP_filtering.h" -int filter_projections_avh(float * data, const float * filter, const float* weights, int order, long num_proj, long pix_y, long pix_x) +int filter_projections_avh(DataFloat data, DataFloatConst filter, DataFloatConst weights, int order, long num_proj, long pix_y, long pix_x) { //set up int width = 1 << order; @@ -61,12 +61,12 @@ int filter_projections_avh(float * data, const float * filter, const float* weig for (j = 0; j < half_pixy; j++) { row_start = (size_t)2 * j * pix_x; - out_ptr = &data[proj_start + row_start]; - ippsMul_32f_I(weights+row_start, out_ptr, 2* pix_x); + out_ptr = &data.data()[proj_start + row_start]; + ippsMul_32f_I(weights.data()+row_start, out_ptr, 2* pix_x); ippsSet_32fc({ 0.f,0.f }, src, width); ippsRealToCplx_32f(out_ptr, out_ptr + pix_x, src + offset, pix_x); ippsFFTFwd_CToC_32fc(src, dst, pSpec, pMemBuffer); - ippsMul_32f32fc_I(filter, dst, width); + ippsMul_32f32fc_I(filter.data(), dst, width); ippsFFTInv_CToC_32fc(dst, src, pSpec, pMemBuffer); ippsCplxToReal_32fc(src + offset, out_ptr, out_ptr+pix_x, pix_x); } @@ -76,13 +76,13 @@ int filter_projections_avh(float * data, const float * filter, const float* weig if (pix_y % 2) { row_start = (size_t)pix_y * pix_x - pix_x; - out_ptr = &data[proj_start + row_start]; + out_ptr = &data.data()[proj_start + row_start]; - ippsMul_32f_I(weights + row_start, out_ptr, pix_x); + ippsMul_32f_I(weights.data() + row_start, out_ptr, pix_x); ippsSet_32fc({ 0.f,0.f }, src, width); ippsRealToCplx_32f(out_ptr, NULL, src + offset, pix_x); ippsFFTFwd_CToC_32fc(src, dst, pSpec, pMemBuffer); - ippsMul_32f32fc_I(filter, dst, width); + ippsMul_32f32fc_I(filter.data(), dst, width); ippsFFTInv_CToC_32fc(dst, src, pSpec, pMemBuffer); ippsReal_32fc(src + offset, out_ptr, pix_x); } @@ -96,7 +96,7 @@ int filter_projections_avh(float * data, const float * filter, const float* weig ippFree(pMemSpec); return 0; } -int filter_projections_vah(float* data, const float* filter, const float* weights, int order, long pix_y, long num_proj, long pix_x) +int filter_projections_vah(DataFloat data, DataFloatConst filter, DataFloatConst weights, int order, long pix_y, long num_proj, long pix_x) { //set up int width = 1 << order; @@ -124,7 +124,7 @@ int filter_projections_vah(float* data, const float* filter, const float* weight while (k < pix_y) { size_t col_start = (size_t)k * num_proj * pix_x; - const float* weights_ptr = &weights[(size_t)k * pix_x]; + const float* weights_ptr = &weights.data()[(size_t)k * pix_x]; k++; #pragma omp parallel @@ -140,14 +140,14 @@ int filter_projections_vah(float* data, const float* filter, const float* weight for (j = 0; j < half_proj; j++) { row_start = (size_t)2 * j * pix_x; - out_ptr = &data[col_start + row_start]; + out_ptr = &data.data()[col_start + row_start]; ippsMul_32f_I(weights_ptr, out_ptr, pix_x); ippsMul_32f_I(weights_ptr, out_ptr + pix_x, pix_x); ippsSet_32fc({ 0.f,0.f }, src, width); ippsRealToCplx_32f(out_ptr, out_ptr + pix_x, src + offset, pix_x); ippsFFTFwd_CToC_32fc(src, dst, pSpec, pMemBuffer); - ippsMul_32f32fc_I(filter, dst, width); + ippsMul_32f32fc_I(filter.data(), dst, width); ippsFFTInv_CToC_32fc(dst, src, pSpec, pMemBuffer); ippsCplxToReal_32fc(src + offset, out_ptr, out_ptr + pix_x, pix_x); } @@ -157,12 +157,12 @@ int filter_projections_vah(float* data, const float* filter, const float* weight if (num_proj % 2) { row_start = (size_t)num_proj * pix_x - pix_x; - out_ptr = &data[col_start + row_start]; + out_ptr = &data.data()[col_start + row_start]; ippsMul_32f_I(weights_ptr, out_ptr, pix_x); ippsSet_32fc({ 0.f,0.f }, src, width); ippsRealToCplx_32f(out_ptr, NULL, src + offset, pix_x); ippsFFTFwd_CToC_32fc(src, dst, pSpec, pMemBuffer); - ippsMul_32f32fc_I(filter, dst, width); + ippsMul_32f32fc_I(filter.data(), dst, width); ippsFFTInv_CToC_32fc(dst, src, pSpec, pMemBuffer); ippsReal_32fc(src + offset, out_ptr, pix_x); } diff --git a/src/Core/FiniteDifferenceLibrary.cpp b/src/cil/FiniteDifferenceLibrary.cpp similarity index 85% rename from src/Core/FiniteDifferenceLibrary.cpp rename to src/cil/FiniteDifferenceLibrary.cpp index e5776bb848..87c628faff 100644 --- a/src/Core/FiniteDifferenceLibrary.cpp +++ b/src/cil/FiniteDifferenceLibrary.cpp @@ -17,10 +17,9 @@ // CIL Developers, listed at: https://github.com/TomographicImaging/CIL/blob/master/NOTICE.txt // Sam Tygier (UKRI-STFC) - #include "FiniteDifferenceLibrary.h" -DLL_EXPORT int openMPtest(int nThreads) +int openMPtest(int nThreads) { omp_set_num_threads(nThreads); @@ -538,7 +537,14 @@ int fdiff_adjoint_periodic(float *outimagefull, const float *inimageXfull, const return 0; } -DLL_EXPORT int fdiff4D(float *imagefull, float *gradCfull, float *gradZfull, float *gradYfull, float *gradXfull, size_t nc, size_t nz, size_t ny, size_t nx, int boundary, int direction, int nThreads) + int fdiff4D(nb::ndarray imagefull, + nb::ndarray gradCfull, + nb::ndarray gradZfull, + nb::ndarray gradYfull, + nb::ndarray gradXfull, + size_t nc, size_t nz, size_t ny, size_t nx, + int boundary, int direction, + int nThreads) { int nThreads_initial; threads_setup(nThreads, &nThreads_initial); @@ -547,22 +553,28 @@ DLL_EXPORT int fdiff4D(float *imagefull, float *gradCfull, float *gradZfull, flo if (boundary) { if (direction) - status = fdiff_direct_periodic(imagefull, gradXfull, gradYfull, gradZfull, gradCfull, nx, ny, nz, nc); + status = fdiff_direct_periodic(imagefull.data(), gradXfull.data(), gradYfull.data(), gradZfull.data(), gradCfull.data(), nx, ny, nz, nc); else - status = fdiff_adjoint_periodic(imagefull, gradXfull, gradYfull, gradZfull, gradCfull, nx, ny, nz, nc); + status = fdiff_adjoint_periodic(imagefull.data(), gradXfull.data(), gradYfull.data(), gradZfull.data(), gradCfull.data(), nx, ny, nz, nc); } else { if (direction) - status = fdiff_direct_neumann(imagefull, gradXfull, gradYfull, gradZfull, gradCfull, nx, ny, nz, nc); + status = fdiff_direct_neumann(imagefull.data(), gradXfull.data(), gradYfull.data(), gradZfull.data(), gradCfull.data(), nx, ny, nz, nc); else - status = fdiff_adjoint_neumann(imagefull, gradXfull, gradYfull, gradZfull, gradCfull, nx, ny, nz, nc); + status = fdiff_adjoint_neumann(imagefull.data(), gradXfull.data(), gradYfull.data(), gradZfull.data(), gradCfull.data(), nx, ny, nz, nc); } omp_set_num_threads(nThreads_initial); return status; } -DLL_EXPORT int fdiff3D(float *imagefull, float *gradZfull, float *gradYfull, float *gradXfull, size_t nz, size_t ny, size_t nx, int boundary, int direction, int nThreads) +int fdiff3D(nb::ndarray imagefull, + nb::ndarray gradZfull, + nb::ndarray gradYfull, + nb::ndarray gradXfull, + size_t nz, size_t ny, size_t nx, + int boundary, int direction, + int nThreads) { int nThreads_initial; threads_setup(nThreads, &nThreads_initial); @@ -571,22 +583,27 @@ DLL_EXPORT int fdiff3D(float *imagefull, float *gradZfull, float *gradYfull, flo if (boundary) { if (direction) - status = fdiff_direct_periodic(imagefull, gradXfull, gradYfull, gradZfull, NULL, nx, ny, nz, 1); + status = fdiff_direct_periodic(imagefull.data(), gradXfull.data(), gradYfull.data(), gradZfull.data(), NULL, nx, ny, nz, 1); else - status = fdiff_adjoint_periodic(imagefull, gradXfull, gradYfull, gradZfull, NULL, nx, ny, nz, 1); + status = fdiff_adjoint_periodic(imagefull.data(), gradXfull.data(), gradYfull.data(), gradZfull.data(), NULL, nx, ny, nz, 1); } else { if (direction) - status = fdiff_direct_neumann(imagefull, gradXfull, gradYfull, gradZfull, NULL, nx, ny, nz, 1); + status = fdiff_direct_neumann(imagefull.data(), gradXfull.data(), gradYfull.data(), gradZfull.data(), NULL, nx, ny, nz, 1); else - status = fdiff_adjoint_neumann(imagefull, gradXfull, gradYfull, gradZfull, NULL, nx, ny, nz, 1); + status = fdiff_adjoint_neumann(imagefull.data(), gradXfull.data(), gradYfull.data(), gradZfull.data(), NULL, nx, ny, nz, 1); } omp_set_num_threads(nThreads_initial); return status; } -DLL_EXPORT int fdiff2D(float *imagefull, float *gradYfull, float *gradXfull, size_t ny, size_t nx, int boundary, int direction, int nThreads) +int fdiff2D(nb::ndarray imagefull, + nb::ndarray gradYfull, + nb::ndarray gradXfull, + size_t ny, size_t nx, + int boundary, int direction, + int nThreads) { int nThreads_initial; threads_setup(nThreads, &nThreads_initial); @@ -595,16 +612,16 @@ DLL_EXPORT int fdiff2D(float *imagefull, float *gradYfull, float *gradXfull, siz if (boundary) { if (direction) - status = fdiff_direct_periodic(imagefull, gradXfull, gradYfull, NULL, NULL, nx, ny, 1, 1); + status = fdiff_direct_periodic(imagefull.data(), gradXfull.data(), gradYfull.data(), NULL, NULL, nx, ny, 1, 1); else - status = fdiff_adjoint_periodic(imagefull, gradXfull, gradYfull, NULL, NULL, nx, ny, 1, 1); + status = fdiff_adjoint_periodic(imagefull.data(), gradXfull.data(), gradYfull.data(), NULL, NULL, nx, ny, 1, 1); } else { if (direction) - status = fdiff_direct_neumann(imagefull, gradXfull, gradYfull, NULL, NULL, nx, ny, 1, 1); + status = fdiff_direct_neumann(imagefull.data(), gradXfull.data(), gradYfull.data(), NULL, NULL, nx, ny, 1, 1); else - status = fdiff_adjoint_neumann(imagefull, gradXfull, gradYfull, NULL, NULL, nx, ny, 1, 1); + status = fdiff_adjoint_neumann(imagefull.data(), gradXfull.data(), gradYfull.data(), NULL, NULL, nx, ny, 1, 1); } omp_set_num_threads(nThreads_initial); diff --git a/src/Core/axpby.cpp b/src/cil/axpby.cpp similarity index 68% rename from src/Core/axpby.cpp rename to src/cil/axpby.cpp index 3bdcab726a..c147a5d30f 100644 --- a/src/Core/axpby.cpp +++ b/src/cil/axpby.cpp @@ -104,7 +104,13 @@ int daxpby_asbv(const double * x, const double * y, double * out, double a, cons } return 0; } -DLL_EXPORT int saxpby(const float * x, const float * y, float * out, const float *a, int a_type, const float* b, int b_type, int64 size, int nThreads) + +int saxpby(DataFloatInput x, DataFloatInput y, + DataFloatOutput out, + DataFloatInput a, int type_a, + DataFloatInput b, int type_b, + int64 size, int nThreads + ) { //type = 0 float //type = 1 array of floats @@ -114,20 +120,25 @@ DLL_EXPORT int saxpby(const float * x, const float * y, float * out, const float int nThreads_initial; threads_setup(nThreads, &nThreads_initial); - if (a_type == 0 && b_type == 0) - saxpby_asbs(x, y, out, *a, *b, size, nThreads); - else if (a_type == 1 && b_type == 1) - saxpby_avbv(x, y, out, a, b, size, nThreads); - else if (a_type == 0 && b_type == 1) - saxpby_asbv(x, y, out, *a, b, size, nThreads); - else if (a_type == 1 && b_type == 0) - saxpby_asbv(y, x, out, *b, a, size, nThreads); + if (type_a == 0 && type_b == 0) + saxpby_asbs(x.data(), y.data(), out.data(), *a.data(), *b.data(), size, nThreads); + else if (type_a == 1 && type_b == 1) + saxpby_avbv(x.data(), y.data(), out.data(), a.data(), b.data(), size, nThreads); + else if (type_a == 0 && type_b == 1) + saxpby_asbv(x.data(), y.data(), out.data(), *a.data(), b.data(), size, nThreads); + else if (type_a == 1 && type_b == 0) + saxpby_asbv(y.data(), x.data(), out.data(), *b.data(), a.data(), size, nThreads); omp_set_num_threads(nThreads_initial); return 0; } -DLL_EXPORT int daxpby(const double * x, const double * y, double * out, const double *a, int a_type, const double* b, int b_type, int64 size, int nThreads) + +int daxpby(DataDoubleInput x, DataDoubleInput y, + DataDoubleOutput out, + DataDoubleInput a, int type_a, + DataDoubleInput b, int type_b, + int64 size, int nThreads) { //type = 0 double //type = 1 array of double @@ -137,14 +148,14 @@ DLL_EXPORT int daxpby(const double * x, const double * y, double * out, const do int nThreads_initial; threads_setup(nThreads, &nThreads_initial); - if (a_type == 0 && b_type == 0) - daxpby_asbs(x, y, out, *a, *b, size, nThreads); - else if (a_type == 1 && b_type == 1) - daxpby_avbv(x, y, out, a, b, size, nThreads); - else if (a_type == 0 && b_type == 1) - daxpby_asbv(x, y, out, *a, b, size, nThreads); - else if (a_type == 1 && b_type == 0) - daxpby_asbv(y, x, out, *b, a, size, nThreads); + if (type_a == 0 && type_b == 0) + daxpby_asbs(x.data(), y.data(), out.data(), *a.data(), *b.data(), size, nThreads); + else if (type_a == 1 && type_b == 1) + daxpby_avbv(x.data(), y.data(), out.data(), a.data(), b.data(), size, nThreads); + else if (type_a == 0 && type_b == 1) + daxpby_asbv(x.data(), y.data(), out.data(), *a.data(), b.data(), size, nThreads); + else if (type_a == 1 && type_b == 0) + daxpby_asbv(y.data(), x.data(), out.data(), *b.data(), a.data(), size, nThreads); omp_set_num_threads(nThreads_initial); diff --git a/src/Core/include/Binning.h b/src/cil/include/Binning.h similarity index 65% rename from src/Core/include/Binning.h rename to src/cil/include/Binning.h index 669a10c0c7..c2a343790b 100644 --- a/src/Core/include/Binning.h +++ b/src/cil/include/Binning.h @@ -15,16 +15,22 @@ // // Authors: // CIL Developers, listed at: https://github.com/TomographicImaging/CIL/blob/master/NOTICE.txt -#ifndef _BINNER_H_ -#define _BINNER_H_ #include -#include "dll_export.h" +#include +#include + +namespace nb = nanobind; + +using Shape = nb::ndarray; +using DataInput = nb::ndarray; +using DataBinned = nb::ndarray; + +void Binner_delete(void* binner); +void* Binner_new(Shape shape_in, + Shape shape_out, + Shape pixel_index_start, + Shape binning_list +); +int Binner_bin(void* binner, DataInput data_in, DataBinned data_binned); -extern "C" -{ - DLL_EXPORT void Binner_delete(void* binner); - DLL_EXPORT void* Binner_new(const size_t* shape_in, const size_t* shape_out, const size_t* pixel_index_start, const size_t* binning_list); - DLL_EXPORT int Binner_bin(void* binner, const float* data_in, float* data_binned); -} -#endif diff --git a/src/Core/include/FBP_filtering.h b/src/cil/include/FBP_filtering.h similarity index 67% rename from src/Core/include/FBP_filtering.h rename to src/cil/include/FBP_filtering.h index 8a8db3b499..5068712be0 100644 --- a/src/Core/include/FBP_filtering.h +++ b/src/cil/include/FBP_filtering.h @@ -19,18 +19,18 @@ #include #include #include "ipp.h" +#include #include #include #include -#include "dll_export.h" #include "utilities.h" +#include +namespace nb = nanobind; + +using DataFloatConst = nb::ndarray; +using DataFloat = nb::ndarray; + +int filter_projections_avh(DataFloat data, DataFloatConst filter, DataFloatConst weights, int order, long num_proj, long pix_y, long pix_x); +int filter_projections_vah(DataFloat data, DataFloatConst filter, DataFloatConst weights, int order, long pix_y, long num_proj, long pix_x); -#ifdef __cplusplus -extern "C" { -#endif - DLL_EXPORT int filter_projections_avh(float* data, const float* filter, const float* weights, int order, long num_proj, long pix_y, long pix_x); - DLL_EXPORT int filter_projections_vah(float* data, const float* filter, const float* weights, int order, long pix_y, long num_proj, long pix_x); -#ifdef __cplusplus -} -#endif diff --git a/src/Core/include/FiniteDifferenceLibrary.h b/src/cil/include/FiniteDifferenceLibrary.h similarity index 67% rename from src/Core/include/FiniteDifferenceLibrary.h rename to src/cil/include/FiniteDifferenceLibrary.h index 80d11c9740..1a50d0684d 100644 --- a/src/Core/include/FiniteDifferenceLibrary.h +++ b/src/cil/include/FiniteDifferenceLibrary.h @@ -19,24 +19,39 @@ #include #include #include -#include "omp.h" -#include "dll_export.h" +#include #include "utilities.h" +#include +namespace nb = nanobind; + + int fdiff_direct_neumann(const float *inimagefull, float *outimageXfull, float *outimageYfull, float *outimageZfull, float *outimageCfull, size_t nx, size_t ny, size_t nz, size_t nc); int fdiff_direct_periodic(const float *inimagefull, float *outimageXfull, float *outimageYfull, float *outimageZfull, float *outimageCfull, size_t nx, size_t ny, size_t nz, size_t nc); int fdiff_adjoint_neumann(float *outimagefull, const float *inimageXfull, const float *inimageYfull, const float *inimageZfull, const float *inimageCfull, size_t nx, size_t ny, size_t nz, size_t nc); int fdiff_adjoint_periodic(float *outimagefull, const float *inimageXfull, const float *inimageYfull, const float *inimageZfull, const float *inimageCfull, size_t nx, size_t ny, size_t nz, size_t nc); -#ifdef __cplusplus -extern "C" { -#endif -DLL_EXPORT int openMPtest(int nThreads); -DLL_EXPORT int fdiff4D(float *imagefull, float *gradCfull, float *gradZfull, float *gradYfull, float *gradXfull, size_t nc, size_t nz, size_t ny, size_t nx, int boundary, int direction, int nThreads); -DLL_EXPORT int fdiff3D(float *imagefull, float *gradZfull, float *gradYfull, float *gradXfull, size_t nz, size_t ny, size_t nx, int boundary, int direction, int nThreads); -DLL_EXPORT int fdiff2D(float *imagefull, float *gradYfull, float *gradXfull, size_t ny, size_t nx, int boundary, int direction, int nThreads); +int openMPtest(int nThreads); +int fdiff4D(nb::ndarray imagefull, + nb::ndarray gradCfull, + nb::ndarray gradZfull, + nb::ndarray gradYfull, + nb::ndarray gradXfull, + size_t nc, size_t nz, size_t ny, + size_t nx, int boundary, int direction, + int nThreads); +int fdiff3D(nb::ndarray imagefull, + nb::ndarray gradZfull, + nb::ndarray gradYfull, + nb::ndarray gradXfull, + size_t nz, size_t ny, size_t nx, + int boundary, int direction, + int nThreads); +int fdiff2D(nb::ndarray imagefull, + nb::ndarray gradYfull, + nb::ndarray gradXfull, + size_t ny, size_t nx, + int boundary, int direction, + int nThreads); -#ifdef __cplusplus -} -#endif diff --git a/src/Core/include/axpby.h b/src/cil/include/axpby.h similarity index 71% rename from src/Core/include/axpby.h rename to src/cil/include/axpby.h index 048a9b7e98..cefc4c44cc 100644 --- a/src/Core/include/axpby.h +++ b/src/cil/include/axpby.h @@ -15,12 +15,24 @@ // // Authors: // CIL Developers, listed at: https://github.com/TomographicImaging/CIL/blob/master/NOTICE.txt + #include #include #include -#include "omp.h" -#include "dll_export.h" +#include #include "utilities.h" +#include + +namespace nb = nanobind; + +using int64 = long long; + +using DataFloatInput = nb::ndarray; +using DataDoubleInput = nb::ndarray; + +using DataFloatOutput = nb::ndarray; +using DataDoubleOutput = nb::ndarray; + int saxpby_asbs(const float * x, const float * y, float * out, float a, float b, int64 size, int nThreads); int saxpby_avbv(const float * x, const float * y, float * out, const float * a, const float * b, int64 size, int nThreads); @@ -29,13 +41,14 @@ int daxpby_asbs(const double * x, const double * y, double * out, double a, doub int daxpby_avbv(const double * x, const double * y, double * out, const double * a, const double * b, int64 size, int nThreads); int daxpby_asbv(const double * x, const double * y, double * out, double a, const double * b, int64 size, int nThreads); -#ifdef __cplusplus -extern "C" { -#endif - -DLL_EXPORT int saxpby(const float * x, const float * y, float * out, const float * a, int type_a, const float * b, int type_b, int64 size, int nThreads); -DLL_EXPORT int daxpby(const double * x, const double * y, double * out, const double * a, int type_a, const double * b, int type_b, int64 size, int nThreads); +int saxpby(DataFloatInput x, DataFloatInput y, + DataFloatOutput out, + DataFloatInput a, int type_a, + DataFloatInput b, int type_b, + int64 size, int nThreads); +int daxpby(DataDoubleInput x, DataDoubleInput y, + DataDoubleOutput out, + DataDoubleInput a, int type_a, + DataDoubleInput b, int type_b, + int64 size, int nThreads); -#ifdef __cplusplus -} -#endif diff --git a/src/Core/include/utilities.h b/src/cil/include/utilities.h similarity index 97% rename from src/Core/include/utilities.h rename to src/cil/include/utilities.h index 54a75ccc16..f3d0a47838 100644 --- a/src/Core/include/utilities.h +++ b/src/cil/include/utilities.h @@ -15,6 +15,7 @@ // // Authors: // CIL Developers, listed at: https://github.com/TomographicImaging/CIL/blob/master/NOTICE.txt -#include "omp.h" + +#include void threads_setup(int nThreads_requested, int *nThreads_current); diff --git a/src/cil/nanobind.cpp b/src/cil/nanobind.cpp new file mode 100644 index 0000000000..14adfc4194 --- /dev/null +++ b/src/cil/nanobind.cpp @@ -0,0 +1,25 @@ + +#include +#include "axpby.h" +#include "Binning.h" +#include "FBP_filtering.h" +#include "FiniteDifferenceLibrary.h" + +NB_MODULE(cilacc, m) { + m.def("saxpby", &saxpby); + m.def("daxpby", &daxpby); + + m.def("Binner_delete", &Binner_delete); + m.def("Binner_new", &Binner_new); + m.def("Binner_bin", &Binner_bin); + + m.def("filter_projections_avh", &filter_projections_avh); + m.def("filter_projections_vah", &filter_projections_vah); + + m.def("openMPtest", &openMPtest); + m.def("fdiff4D", &fdiff4D); + m.def("fdiff3D", &fdiff3D); + m.def("fdiff2D", &fdiff2D); + + m.doc() = "C-Extension for CIL"; +} diff --git a/src/Core/utilities.cpp b/src/cil/utilities.cpp similarity index 100% rename from src/Core/utilities.cpp rename to src/cil/utilities.cpp