[go: up one dir, main page]

Menu

[r353]: / trunk / cocolib / tc / tc.cuh  Maximize  Restore  History

Download this file

144 lines (118 with data), 3.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* -*-c++-*- */
/** \file curvature_linear.cuh
Total mean curvature - linear data term.
Local CUDA workspace structure definition.
Copyright (C) 2010 Bastian Goldluecke,
<first name>AT<last name>.net
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "../cuda/cuda_convolutions.h"
namespace coco {
enum DUAL_VARIABLES {
PX1, PX2,
PY1, PY2,
PZ1, PZ2,
LAMBDA_X,
LAMBDA_Y,
LAMBDA_Z,
NUM_DUAL,
};
enum {
NUM_DUAL_ROF = 2,
};
// Workspace structure, stores allocated GPU data
struct tc_workspace
{
// Redundant data
size_t _W;
size_t _H;
size_t _num_dual;
// Smoothness constants
stcflt _lambda;
stcflt _tv_lambda;
stcflt _rof_lambda;
// Flag if curvature is active (for debugging)
bool _curvature;
// Flag if xi or lambda is a CPU variable
bool _cpu_xi;
// Primal variable
stcflt *_u;
stcflt *_uq;
stcflt *_u_star;
// Derivative of dual
stcflt *_D;
// Dual variables
// Temp computations
stcflt *_px;
stcflt *_py;
// For TV of u
stcflt *_pxq;
stcflt *_pyq;
// For TC: same ordering as _vq for each variable
std::vector<stcflt*> _p[NUM_DUAL];
// Data term
stcflt *_a;
// Data term (ROF)
stcflt *_f;
// Data term mask (e.g. for inpainting)
stcflt *_mask;
// Data term kernels (e.g. deblurring)
coco::cuda_kernel *_b;
coco::cuda_kernel *_bq;
// Precomputed curvature weight
stcflt *_cp;
stcflt *_cp_cpu;
// Saves last computed stats about energy
double _energy;
double _energy_data_term;
double _energy_curvature;
double _energy_tv;
double _energy_lambda;
double _energy_cv;
// Energy computation states
bool _compute_energy_rof;
bool _compute_energy_inpainting;
// Number of bytes in each layer
size_t _Nf;
// Number of bytes per layer array
size_t _Nv;
// Curvature window
size_t _N;
int _N2;
// Energy integration scales (TODO: does it make sense?)
double _energy_scale_v;
double _energy_scale_u;
// ALGORITHM INTERNALS
// Step sizes (primal/dual)
stcflt _sigma;
stcflt _tv_sigma;
// FISTA
// Lipschitz constant
stcflt _L;
// Relaxation factor
stcflt _t;
// Computation parameters
dim3 _dimGrid;
dim3 _dimBlock;
};
// Reset norm of xi
bool clear_xi_norm( coco::tc_workspace *w );
// Initialize ROF step sizes
bool cv_init_rof_stepsize( tc_data *data, double lambda );
// Perform one ROF iteration
bool cv_rof_iteration( tc_data *data );
// Offset macros
// Offset to field with y/z coordinates
#define AOFF( y0,y1, z0,z1 ) ( (y0 + N*( y1 + N*( z0 + N*z1 ))) * W*H )
// Index of field with y/z coordinates
#define AIND( y0,y1, z0,z1 ) ( (y0) + N*( (y1) + N*( (z0) + N*(z1) )))
}