From 11199684baba00298c5fab2599c87fc80456ac16 Mon Sep 17 00:00:00 2001 From: Edoardo Pasca Date: Wed, 4 Jul 2018 22:53:24 +0100 Subject: relaxed requirement of finding GPU bindings --- Wrappers/Python/ccpi/filters/regularisers.py | 38 +++++++++++++++++++++------- Wrappers/Python/conda-recipe/meta.yaml | 4 +-- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/Wrappers/Python/ccpi/filters/regularisers.py b/Wrappers/Python/ccpi/filters/regularisers.py index 52c7974..c7ae808 100644 --- a/Wrappers/Python/ccpi/filters/regularisers.py +++ b/Wrappers/Python/ccpi/filters/regularisers.py @@ -3,7 +3,11 @@ script which assigns a proper device core function based on a flag ('cpu' or 'gp """ from ccpi.filters.cpu_regularisers import TV_ROF_CPU, TV_FGP_CPU, TV_SB_CPU, dTV_FGP_CPU, TNV_CPU, NDF_CPU, Diff4th_CPU, TGV_CPU, LLT_ROF_CPU -from ccpi.filters.gpu_regularisers import TV_ROF_GPU, TV_FGP_GPU, TV_SB_GPU, dTV_FGP_GPU, NDF_GPU, Diff4th_GPU, TGV_GPU, LLT_ROF_GPU +try: + from ccpi.filters.gpu_regularisers import TV_ROF_GPU, TV_FGP_GPU, TV_SB_GPU, dTV_FGP_GPU, NDF_GPU, Diff4th_GPU, TGV_GPU, LLT_ROF_GPU + gpu_enabled = True +except ImportError: + gpu_enabled = False from ccpi.filters.cpu_regularisers import NDF_INPAINT_CPU, NVM_INPAINT_CPU def ROF_TV(inputData, regularisation_parameter, iterations, @@ -13,12 +17,14 @@ def ROF_TV(inputData, regularisation_parameter, iterations, regularisation_parameter, iterations, time_marching_parameter) - elif device == 'gpu': + elif device == 'gpu' and gpu_enabled: return TV_ROF_GPU(inputData, regularisation_parameter, iterations, time_marching_parameter) else: + if not gpu_enabled and device == 'gpu': + raise ValueError ('GPU is not available') raise ValueError('Unknown device {0}. Expecting gpu or cpu'\ .format(device)) @@ -32,7 +38,7 @@ def FGP_TV(inputData, regularisation_parameter,iterations, methodTV, nonneg, printM) - elif device == 'gpu': + elif device == 'gpu' and gpu_enabled: return TV_FGP_GPU(inputData, regularisation_parameter, iterations, @@ -41,6 +47,8 @@ def FGP_TV(inputData, regularisation_parameter,iterations, nonneg, printM) else: + if not gpu_enabled and device == 'gpu': + raise ValueError ('GPU is not available') raise ValueError('Unknown device {0}. Expecting gpu or cpu'\ .format(device)) def SB_TV(inputData, regularisation_parameter, iterations, @@ -52,7 +60,7 @@ def SB_TV(inputData, regularisation_parameter, iterations, tolerance_param, methodTV, printM) - elif device == 'gpu': + elif device == 'gpu' and gpu_enabled: return TV_SB_GPU(inputData, regularisation_parameter, iterations, @@ -60,6 +68,8 @@ def SB_TV(inputData, regularisation_parameter, iterations, methodTV, printM) else: + if not gpu_enabled and device == 'gpu': + raise ValueError ('GPU is not available') raise ValueError('Unknown device {0}. Expecting gpu or cpu'\ .format(device)) def FGP_dTV(inputData, refdata, regularisation_parameter, iterations, @@ -74,7 +84,7 @@ def FGP_dTV(inputData, refdata, regularisation_parameter, iterations, methodTV, nonneg, printM) - elif device == 'gpu': + elif device == 'gpu' and gpu_enabled: return dTV_FGP_GPU(inputData, refdata, regularisation_parameter, @@ -85,6 +95,8 @@ def FGP_dTV(inputData, refdata, regularisation_parameter, iterations, nonneg, printM) else: + if not gpu_enabled and device == 'gpu': + raise ValueError ('GPU is not available') raise ValueError('Unknown device {0}. Expecting gpu or cpu'\ .format(device)) def TNV(inputData, regularisation_parameter, iterations, tolerance_param): @@ -101,7 +113,7 @@ def NDF(inputData, regularisation_parameter, edge_parameter, iterations, iterations, time_marching_parameter, penalty_type) - elif device == 'gpu': + elif device == 'gpu' and gpu_enabled: return NDF_GPU(inputData, regularisation_parameter, edge_parameter, @@ -109,6 +121,8 @@ def NDF(inputData, regularisation_parameter, edge_parameter, iterations, time_marching_parameter, penalty_type) else: + if not gpu_enabled and device == 'gpu': + raise ValueError ('GPU is not available') raise ValueError('Unknown device {0}. Expecting gpu or cpu'\ .format(device)) def DIFF4th(inputData, regularisation_parameter, edge_parameter, iterations, @@ -119,13 +133,15 @@ def DIFF4th(inputData, regularisation_parameter, edge_parameter, iterations, edge_parameter, iterations, time_marching_parameter) - elif device == 'gpu': + elif device == 'gpu' and gpu_enabled: return Diff4th_GPU(inputData, regularisation_parameter, edge_parameter, iterations, time_marching_parameter) else: + if not gpu_enabled and device == 'gpu': + raise ValueError ('GPU is not available') raise ValueError('Unknown device {0}. Expecting gpu or cpu'\ .format(device)) def TGV(inputData, regularisation_parameter, alpha1, alpha0, iterations, @@ -137,7 +153,7 @@ def TGV(inputData, regularisation_parameter, alpha1, alpha0, iterations, alpha0, iterations, LipshitzConst) - elif device == 'gpu': + elif device == 'gpu' and gpu_enabled: return TGV_GPU(inputData, regularisation_parameter, alpha1, @@ -145,15 +161,19 @@ def TGV(inputData, regularisation_parameter, alpha1, alpha0, iterations, iterations, LipshitzConst) else: + if not gpu_enabled and device == 'gpu': + raise ValueError ('GPU is not available') raise ValueError('Unknown device {0}. Expecting gpu or cpu'\ .format(device)) def LLT_ROF(inputData, regularisation_parameterROF, regularisation_parameterLLT, iterations, time_marching_parameter, device='cpu'): if device == 'cpu': return LLT_ROF_CPU(inputData, regularisation_parameterROF, regularisation_parameterLLT, iterations, time_marching_parameter) - elif device == 'gpu': + elif device == 'gpu' and gpu_enabled: return LLT_ROF_GPU(inputData, regularisation_parameterROF, regularisation_parameterLLT, iterations, time_marching_parameter) else: + if not gpu_enabled and device == 'gpu': + raise ValueError ('GPU is not available') raise ValueError('Unknown device {0}. Expecting gpu or cpu'\ .format(device)) def NDF_INP(inputData, maskData, regularisation_parameter, edge_parameter, iterations, diff --git a/Wrappers/Python/conda-recipe/meta.yaml b/Wrappers/Python/conda-recipe/meta.yaml index 4774563..ca28bae 100644 --- a/Wrappers/Python/conda-recipe/meta.yaml +++ b/Wrappers/Python/conda-recipe/meta.yaml @@ -21,7 +21,7 @@ requirements: - numpy x.x - setuptools - cython - - cil_regulariser + - cil_regulariser =={{ environ['CIL_VERSION'] }} - vc 14 # [win and py36] - vc 14 # [win and py35] - vc 9 # [win and py27] @@ -30,7 +30,7 @@ requirements: run: - python - numpy x.x - - cil_regulariser + - cil_regulariser =={{ environ['CIL_VERSION'] }} - vc 14 # [win and py36] - vc 14 # [win and py35] - vc 9 # [win and py27] -- cgit v1.2.3 From 70e86868640390c4dde0ad67670707467f9773f9 Mon Sep 17 00:00:00 2001 From: Edoardo Pasca Date: Wed, 4 Jul 2018 22:56:09 +0100 Subject: fixes for windows shared library --- Core/regularisers_CPU/FGP_dTV_core.h | 2 +- Core/regularisers_CPU/SB_TV_core.h | 0 Core/regularisers_CPU/TNV_core.h | 17 ++++++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) mode change 100755 => 100644 Core/regularisers_CPU/SB_TV_core.h diff --git a/Core/regularisers_CPU/FGP_dTV_core.h b/Core/regularisers_CPU/FGP_dTV_core.h index 95dc249..8d721d5 100644 --- a/Core/regularisers_CPU/FGP_dTV_core.h +++ b/Core/regularisers_CPU/FGP_dTV_core.h @@ -52,7 +52,7 @@ limitations under the License. #ifdef __cplusplus extern "C" { #endif -float dTV_FGP_CPU_main(float *Input, float *InputRef, float *Output, float lambdaPar, int iterationsNumb, float epsil, float eta, int methodTV, int nonneg, int printM, int dimX, int dimY, int dimZ); +CCPI_EXPORT float dTV_FGP_CPU_main(float *Input, float *InputRef, float *Output, float lambdaPar, int iterationsNumb, float epsil, float eta, int methodTV, int nonneg, int printM, int dimX, int dimY, int dimZ); CCPI_EXPORT float GradNorm_func2D(float *B, float *B_x, float *B_y, float eta, int dimX, int dimY); CCPI_EXPORT float ProjectVect_func2D(float *R1, float *R2, float *B_x, float *B_y, int dimX, int dimY); diff --git a/Core/regularisers_CPU/SB_TV_core.h b/Core/regularisers_CPU/SB_TV_core.h old mode 100755 new mode 100644 diff --git a/Core/regularisers_CPU/TNV_core.h b/Core/regularisers_CPU/TNV_core.h index 1559b83..c082694 100644 --- a/Core/regularisers_CPU/TNV_core.h +++ b/Core/regularisers_CPU/TNV_core.h @@ -4,6 +4,7 @@ #include #include "omp.h" #include "utils.h" +#include "CCPiDefines.h" #define fTiny 0.00000001f #define fLarge 100000000.0f @@ -31,10 +32,16 @@ See the License for the specific language governing permissions and limitations under the License. */ -float TNV_CPU_main(float *Input, float *u, float lambda, int maxIter, float tol, int dimX, int dimY, int dimZ); +#ifdef __cplusplus +extern "C" { +#endif +CCPI_EXPORT float TNV_CPU_main(float *Input, float *u, float lambda, int maxIter, float tol, int dimX, int dimY, int dimZ); /*float PDHG(float *A, float *B, float tau, float sigma, float theta, float lambda, int p, int q, int r, float tol, int maxIter, int d_c, int d_w, int d_h);*/ -float proxG(float *u_upd, float *v, float *f, float taulambda, int dimX, int dimY, int dimZ); -float gradient(float *u_upd, float *gradx_upd, float *grady_upd, int dimX, int dimY, int dimZ); -float proxF(float *gx, float *gy, float *vx, float *vy, float sigma, int p, int q, int r, int dimX, int dimY, int dimZ); -float divergence(float *qx_upd, float *qy_upd, float *div_upd, int dimX, int dimY, int dimZ); +CCPI_EXPORT float proxG(float *u_upd, float *v, float *f, float taulambda, int dimX, int dimY, int dimZ); +CCPI_EXPORT float gradient(float *u_upd, float *gradx_upd, float *grady_upd, int dimX, int dimY, int dimZ); +CCPI_EXPORT float proxF(float *gx, float *gy, float *vx, float *vy, float sigma, int p, int q, int r, int dimX, int dimY, int dimZ); +CCPI_EXPORT float divergence(float *qx_upd, float *qy_upd, float *div_upd, int dimX, int dimY, int dimZ); +#ifdef __cplusplus +} +#endif \ No newline at end of file -- cgit v1.2.3