Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CAMP
campvis-public
Commits
ace48281
Commit
ace48281
authored
Jan 20, 2015
by
Declara Denis
Committed by
Christian Schulte zu Berge
Feb 18, 2015
Browse files
Added time driven Monitor to CM Solver
parent
57fcba2d
Changes
11
Hide whitespace changes
Inline
Side-by-side
modules/cudaconfidencemaps/core/cudaconfidencemaps_cuda.cu
View file @
ace48281
#include
"cudaconfidencemaps_cuda.h"
#include
"cudautils.h"
#include
"cuspmonitors.h"
#include
<cusp/blas.h>
#include
<cusp/dia_matrix.h>
...
...
@@ -69,32 +70,6 @@ namespace cuda {
float
systemSolveTime
;
};
template
<
typename
ValueType
>
class
iteration_monitor
:
public
cusp
::
default_monitor
<
ValueType
>
{
typedef
typename
cusp
::
norm_type
<
ValueType
>::
type
Real
;
typedef
cusp
::
default_monitor
<
ValueType
>
super
;
public:
template
<
typename
Vector
>
iteration_monitor
(
const
Vector
&
b
,
size_t
iteration_limit
=
500
)
:
super
(
b
,
iteration_limit
,
0.0
f
,
0.0
f
)
{
}
template
<
typename
Vector
>
bool
finished
(
const
Vector
&
r
)
{
// Only if the maximum iteration count has been reached, actually go ahead and
// compute the error
if
(
super
::
iteration_count
()
>=
super
::
iteration_limit
())
{
super
::
r_norm
=
cusp
::
blas
::
nrm2
(
r
);
return
true
;
}
return
false
;
}
};
CudaConfidenceMapsSystemSolver
::
CudaConfidenceMapsSystemSolver
()
:
_gpuData
(
new
CudaConfidenceMapsSystemGPUData
())
{
...
...
@@ -173,12 +148,12 @@ namespace cuda {
}
// FIXME: Remove errorTolerance parameter
void
CudaConfidenceMapsSystemSolver
::
solve
(
int
maximumIterations
,
float
errorTolerance
)
{
void
CudaConfidenceMapsSystemSolver
::
solve
(
float
millisecondBudget
)
{
// Measure execution time and record it in the _gpuData datastructure
CUDAClock
clock
;
clock
.
start
();
// The solution is computed using Conjugate Gradient with a Diagonal (Jacobi) preconditioner
iteration
_monitor
<
float
>
monitor
(
_gpuData
->
b_d
,
m
aximumIterations
);
deadline
_monitor
<
float
>
monitor
(
_gpuData
->
b_d
,
m
illisecondBudget
);
cusp
::
precond
::
diagonal
<
float
,
cusp
::
device_memory
>
M
(
_gpuData
->
L_d
);
cusp
::
krylov
::
cg
(
_gpuData
->
L_d
,
_gpuData
->
x_d
,
_gpuData
->
b_d
,
monitor
,
M
);
_gpuData
->
solutionResidualNorm
=
monitor
.
residual_norm
();
...
...
modules/cudaconfidencemaps/core/cudaconfidencemaps_cuda.h
View file @
ace48281
...
...
@@ -58,10 +58,9 @@ namespace cuda {
/**
* After calling \see uploadImage(), this functions launches a solver on the GPU that will solve
* the diffusion problem.
* \param maximumIterations maximum number of iterations the solver will preform
* \param errorTolerance if the solution error sinks below this value, the solver stops early
* \param millisecondBudget the time budget the solver has to come up with a solution.
*/
void
solve
(
int
maximumIterations
,
float
errorTolerance
);
void
solve
(
float
millisecondBudget
);
/**
* Returns a host buffer of the last solution computed by the solver. The pointer is guaranteed to
...
...
modules/cudaconfidencemaps/core/cuspmonitors.h
0 → 100644
View file @
ace48281
#ifndef CUSPMONITORS_H__
#define CUSPMONITORS_H__
#include
<cusp/monitor.h>
#include
<tbb/tick_count.h>
namespace
campvis
{
namespace
cuda
{
/**
* This class allows to execute a fixed number of conjugate gradient iterations
* in CUSP. Unlike the default_monitor, this class only calculates the residual
* norm when the iteration count is reached.
*/
template
<
typename
ValueType
>
class
iteration_monitor
:
public
cusp
::
default_monitor
<
ValueType
>
{
typedef
typename
cusp
::
norm_type
<
ValueType
>::
type
Real
;
typedef
cusp
::
default_monitor
<
ValueType
>
super
;
public:
template
<
typename
Vector
>
iteration_monitor
(
const
Vector
&
b
,
size_t
iteration_limit
=
500
)
:
super
(
b
,
iteration_limit
,
0.0
f
,
0.0
f
)
{
}
template
<
typename
Vector
>
bool
finished
(
const
Vector
&
r
)
{
// Only if the maximum iteration count has been reached, actually go ahead and
// compute the error
if
(
super
::
iteration_count
()
>=
super
::
iteration_limit
())
{
super
::
r_norm
=
cusp
::
blas
::
nrm2
(
r
);
return
true
;
}
return
false
;
}
};
/**
* This monitor allows to set a deadline, after which the computation has to stop.
*/
template
<
typename
ValueType
>
class
deadline_monitor
:
public
cusp
::
default_monitor
<
ValueType
>
{
typedef
typename
cusp
::
norm_type
<
ValueType
>::
type
Real
;
typedef
cusp
::
default_monitor
<
ValueType
>
super
;
public:
template
<
typename
Vector
>
deadline_monitor
(
const
Vector
&
b
,
float
milliseconds
)
:
super
(
b
,
0
,
0.0
f
,
0.0
f
),
_startTime
(
tbb
::
tick_count
::
now
()),
_seconds
(
milliseconds
/
1000.0
f
)
{
}
template
<
typename
Vector
>
bool
finished
(
const
Vector
&
r
)
{
// Only if the deadline is reached, stop and compute the error
if
((
tbb
::
tick_count
::
now
()
-
_startTime
).
seconds
()
>
_seconds
)
{
super
::
r_norm
=
cusp
::
blas
::
nrm2
(
r
);
return
true
;
}
return
false
;
}
private:
tbb
::
tick_count
_startTime
;
float
_seconds
;
};
}
}
#endif // CUSPMONITORS_H__
\ No newline at end of file
modules/cudaconfidencemaps/cudaconfidencemaps.cmake
View file @
ace48281
...
...
@@ -47,7 +47,10 @@ IF(ModuleEnabled)
ENDIF
()
# CUSP Include directory
CUDA_INCLUDE_DIRECTORIES
(
${
ThisModDir
}
/ext/cusplibrary-0.4.0
)
CUDA_INCLUDE_DIRECTORIES
(
${
ThisModDir
}
/ext/cusplibrary-0.4.0
${
TBB_INCLUDE_DIR
}
)
# Build CUDA portion of the code (STATICALLY!?)
FILE
(
GLOB cuda_SOURCES modules/cudaconfidencemaps/core/*.cu
)
...
...
@@ -55,10 +58,6 @@ IF(ModuleEnabled)
${
cuda_SOURCES
}
)
# Make sure code can find the CUSP include files included with this module
#SET(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};"-I ${ThisModDir}/ext/cusplibrary-0.4.0")
set
(
CUDA_NVCC_FLAGS
"ajkladjfl"
CACHE STRING
"adsf"
)
# Link CUDA code to module
LIST
(
APPEND ThisModExternalLibs cudaconfidencemaps-cuda
)
ELSE
()
...
...
modules/cudaconfidencemaps/pipelines/cudaconfidencemapsdemo.cpp
View file @
ace48281
...
...
@@ -30,18 +30,17 @@
namespace
campvis
{
CudaConfidenceMapsDemo
::
CudaConfidenceMapsDemo
(
DataContainer
*
dc
)
:
AutoEvaluationPipeline
(
dc
)
,
_usIgtlReader
()
,
_usCropFilter
(
&
_canvasSize
)
CudaConfidenceMapsDemo
::
CudaConfidenceMapsDemo
(
DataContainer
*
dc
)
:
AutoEvaluationPipeline
(
dc
)
,
_usIgtlReader
()
,
_usCropFilter
(
&
_canvasSize
)
,
_usBlurFilter
(
&
_canvasSize
)
,
_usResampler
(
&
_canvasSize
)
,
_usMapsSolver
()
,
_usFusion
(
&
_canvasSize
)
,
_usFanRenderer
(
&
_canvasSize
)
,
p_iterations
(
"Iterations"
,
"Number of CG Iterations"
,
150
,
1
,
500
)
,
p_autoIterationCount
(
"AutoIterationCount"
,
"Estimate iteration count based on time slot"
,
true
)
,
p_
timeSlot
(
"TimeSlo
t"
,
"Milliseconds per frame"
,
32.0
f
,
10.0
f
,
25
0.0
f
)
,
p_
millisecondBudget
(
"MillisecondBudge
t"
,
"Milliseconds per frame"
,
32.0
f
,
10.0
f
,
100
0.0
f
)
,
p_connectToIGTLinkServer
(
"ConnectToIGTLink"
,
"Connect/Disconnect to IGTLink"
)
,
p_gaussianFilterSize
(
"GaussianSigma"
,
"Blur amount"
,
2.5
f
,
1.0
f
,
10.0
f
)
,
p_resamplingScale
(
"ResampleScale"
,
"Resample Scale"
,
0.25
f
,
0.01
f
,
1.0
f
)
...
...
@@ -52,21 +51,18 @@ namespace campvis {
,
p_useAlphaBetaFilter
(
"UseAlphaBetaFilter"
,
"Alpha-Beta-Filter"
,
true
)
,
p_fanHalfAngle
(
"FanHalfAngle"
,
"Fan Half Angle"
,
37.0
f
,
1.0
f
,
90.0
f
)
,
p_fanInnerRadius
(
"FanInnerRadius"
,
"Fan Inner Radius"
,
0.222
f
,
0.001
f
,
0.999
f
)
,
_cgIterationsPerMsRunningAverage
(
1.0
f
)
,
_cgTimeslotRunningAverage
(
1.0
f
)
,
_statisticsLastUpdateTime
()
{
addProcessor
(
&
_usIgtlReader
);
addProcessor
(
&
_usCropFilter
);
addProcessor
(
&
_usIgtlReader
);
addProcessor
(
&
_usCropFilter
);
addProcessor
(
&
_usBlurFilter
);
addProcessor
(
&
_usResampler
);
addProcessor
(
&
_usMapsSolver
);
addProcessor
(
&
_usFusion
);
addProcessor
(
&
_usFanRenderer
);
addProperty
(
p_iterations
);
addProperty
(
p_autoIterationCount
);
addProperty
(
p_
timeSlo
t
);
addProperty
(
p_
millisecondBudge
t
);
addProperty
(
p_connectToIGTLinkServer
);
addProperty
(
p_gaussianFilterSize
);
addProperty
(
p_resamplingScale
);
...
...
@@ -98,8 +94,8 @@ namespace campvis {
// Create connectors
_usIgtlReader
.
p_targetImagePrefix
.
setValue
(
"us.igtl."
);
_usCropFilter
.
p_inputImage
.
setValue
(
"us.igtl.CAMPUS"
);
_usCropFilter
.
p_outputImage
.
setValue
(
"us"
);
_usCropFilter
.
p_inputImage
.
setValue
(
"us.igtl.CAMPUS"
);
_usCropFilter
.
p_outputImage
.
setValue
(
"us"
);
_usBlurFilter
.
p_inputImage
.
setValue
(
"us"
);
_usBlurFilter
.
p_outputImage
.
setValue
(
"us.blurred"
);
...
...
@@ -125,9 +121,6 @@ namespace campvis {
_renderTargetID
.
setValue
(
"us.fused_fan"
);
// Bind pipeline proeprties to processor properties
p_iterations
.
addSharedProperty
(
&
_usMapsSolver
.
p_iterations
);
//p_autoIterationCount.addSharedProperty();
//p_timeSlot.addSharedProperty();
p_connectToIGTLinkServer
.
addSharedProperty
(
&
_usIgtlReader
.
p_connect
);
p_gaussianFilterSize
.
addSharedProperty
(
&
_usBlurFilter
.
p_sigma
);
p_resamplingScale
.
addSharedProperty
(
&
_usResampler
.
p_resampleScale
);
...
...
@@ -151,6 +144,7 @@ namespace campvis {
else
{
// Only launch the pipeline if the IgtlReader has recieved new data
if
(
!
_usIgtlReader
.
isValid
())
{
float
millisecondBudget
=
p_millisecondBudget
.
getValue
();
auto
startTime
=
tbb
::
tick_count
::
now
();
// Make sure that the whole pipeline gets invalidated
...
...
@@ -160,12 +154,13 @@ namespace campvis {
_usMapsSolver
.
invalidate
(
AbstractProcessor
::
INVALID_RESULT
);
_usFusion
.
invalidate
(
AbstractProcessor
::
INVALID_RESULT
);
executeProcessorAndCheckOpenGLState
(
&
_usIgtlReader
);
executeProcessorAndCheckOpenGLState
(
&
_usCropFilter
);
executeProcessorAndCheckOpenGLState
(
&
_usBlurFilter
);
executeProcessorAndCheckOpenGLState
(
&
_usIgtlReader
);
executeProcessorAndCheckOpenGLState
(
&
_usCropFilter
);
executeProcessorAndCheckOpenGLState
(
&
_usBlurFilter
)
;
executeProcessorAndCheckOpenGLState
(
&
_usResampler
);
auto
solverStartTime
=
tbb
::
tick_count
::
now
();
_usMapsSolver
.
p_millisecondBudget
.
setValue
(
millisecondBudget
);
executeProcessorAndCheckOpenGLState
(
&
_usMapsSolver
);
auto
solverEndTime
=
tbb
::
tick_count
::
now
();
...
...
@@ -186,24 +181,6 @@ namespace campvis {
string
<<
"Error: "
<<
_usMapsSolver
.
getResidualNorm
()
<<
std
::
endl
;
_usFanRenderer
.
p_text
.
setValue
(
string
.
str
());
}
auto
ms
=
(
solverEndTime
-
solverStartTime
).
seconds
()
*
1000.0
f
;
auto
iterationsPerMs
=
_usMapsSolver
.
getActualConjugentGradientIterations
()
/
ms
;
// Factor out the time needed for pre- and postprocessing the image from the time slot
float
timeSlot
=
(
p_timeSlot
.
getValue
()
-
(
solverStartTime
-
startTime
).
seconds
()
*
1000.0
f
-
(
endTime
-
solverEndTime
).
seconds
()
*
1000.0
f
);
// Compute the running average using an exponential filter
float
expAlpha
=
0.05
f
;
_cgIterationsPerMsRunningAverage
=
_cgIterationsPerMsRunningAverage
*
(
1.0
f
-
expAlpha
)
+
iterationsPerMs
*
expAlpha
;
_cgTimeslotRunningAverage
=
_cgTimeslotRunningAverage
*
(
1.0
f
-
expAlpha
)
+
timeSlot
*
expAlpha
;
int
iterations
=
static_cast
<
int
>
(
_cgTimeslotRunningAverage
*
_cgIterationsPerMsRunningAverage
);
p_iterations
.
setValue
(
iterations
);
}
}
}
...
...
modules/cudaconfidencemaps/pipelines/cudaconfidencemapsdemo.h
View file @
ace48281
...
...
@@ -72,7 +72,7 @@ namespace campvis {
protected:
OpenIGTLinkClient
_usIgtlReader
;
GlImageCrop
_usCropFilter
;
GlImageCrop
_usCropFilter
;
GlGaussianFilter
_usBlurFilter
;
GlImageResampler
_usResampler
;
CudaConfidenceMapsSolver
_usMapsSolver
;
...
...
@@ -80,9 +80,8 @@ namespace campvis {
UsFanRenderer
_usFanRenderer
;
NumericProperty
<
int
>
p_iterations
;
BoolProperty
p_autoIterationCount
;
FloatProperty
p_
timeSlo
t
;
FloatProperty
p_
millisecondBudge
t
;
ButtonProperty
p_connectToIGTLinkServer
;
...
...
@@ -98,9 +97,6 @@ namespace campvis {
FloatProperty
p_fanHalfAngle
;
FloatProperty
p_fanInnerRadius
;
float
_cgIterationsPerMsRunningAverage
;
float
_cgTimeslotRunningAverage
;
tbb
::
tick_count
_statisticsLastUpdateTime
;
};
...
...
modules/cudaconfidencemaps/processors/cudaconfidencemapssolver.cpp
View file @
ace48281
...
...
@@ -41,7 +41,7 @@ namespace campvis {
,
p_outputConfidenceMap
(
"OutputConfidenceMap"
,
"Output Confidence Map"
,
"us.confidence"
,
DataNameProperty
::
WRITE
)
,
p_resetResult
(
"ResetSolution"
,
"Reset solution vector"
)
,
p_use8Neighbourhood
(
"Use8Neighbourhood"
,
"Use 8 Neighbourhood (otherwise 4)"
,
true
)
,
p_
iterations
(
"IterationCount"
,
"Conjugate Gradient Iterations"
,
2
00
,
1
,
500
)
,
p_
millisecondBudget
(
"IterationCount"
,
"Conjugate Gradient Iterations"
,
2
5.0
f
,
1.0
f
,
1000.0
f
)
,
p_gradientScaling
(
"GradientScaling"
,
"Scaling factor for gradients"
,
2.0
f
,
0.001
f
,
10.0
f
)
,
p_paramAlpha
(
"Alpha"
,
"Alpha (TGC)"
,
2.0
f
,
0.001
f
,
10.0
f
)
,
p_paramBeta
(
"Beta"
,
"Beta (Weight mapping)"
,
20.0
f
,
0.001
f
,
200.0
f
)
...
...
@@ -57,7 +57,7 @@ namespace campvis {
addProperty
(
p_resetResult
);
addProperty
(
p_use8Neighbourhood
);
addProperty
(
p_
iterations
);
addProperty
(
p_
millisecondBudget
);
addProperty
(
p_gradientScaling
);
addProperty
(
p_paramAlpha
);
addProperty
(
p_paramBeta
);
...
...
@@ -84,7 +84,7 @@ namespace campvis {
ImageRepresentationLocal
::
ScopedRepresentation
img
(
data
,
p_inputImage
.
getValue
());
if
(
img
!=
0
)
{
bool
use8Neighbourhood
=
p_use8Neighbourhood
.
getValue
();
int
iterations
=
p_iterations
.
getValue
();
float
millisecondBudget
=
p_millisecondBudget
.
getValue
();
float
gradientScaling
=
p_gradientScaling
.
getValue
();
float
alpha
=
p_paramAlpha
.
getValue
();
float
beta
=
p_paramBeta
.
getValue
();
...
...
@@ -99,7 +99,7 @@ namespace campvis {
auto
image
=
(
unsigned
char
*
)
img
->
getWeaklyTypedPointer
().
_pointer
;
_solver
.
uploadImage
(
image
,
size
.
x
,
size
.
y
,
gradientScaling
,
alpha
,
beta
,
gamma
,
use8Neighbourhood
);
_solver
.
solve
(
iterations
,
1e-10
f
);
_solver
.
solve
(
millisecondBudget
);
const
float
*
solution
=
_solver
.
getSolution
(
size
.
x
,
size
.
y
);
...
...
modules/cudaconfidencemaps/processors/cudaconfidencemapssolver.h
View file @
ace48281
...
...
@@ -90,7 +90,7 @@ namespace campvis {
BoolProperty
p_use8Neighbourhood
;
///< Wether to use 8- or 4-neighbourhood
Numeric
Property
<
int
>
p_iterations
;
///< Number of CG-Iterations to do
Float
Property
p_millisecondBudget
;
///< Maximum number of ms the solver can run
FloatProperty
p_gradientScaling
;
FloatProperty
p_paramAlpha
;
...
...
modules/cudaconfidencemaps/processors/usfanrenderer.cpp
View file @
ace48281
...
...
@@ -71,7 +71,7 @@ namespace campvis {
// Creates the grid, with the origin at the center of the top edge, with the +y axis representing depth
_grid
=
GeometryDataFactory
::
createGrid
(
cgt
::
vec3
(
-
0.5
f
,
1.0
f
,
0.0
f
),
cgt
::
vec3
(
0.5
f
,
0.0
f
,
0.0
f
),
cgt
::
vec3
(
0.0
f
,
1.0
f
,
0.0
f
),
cgt
::
vec3
(
1.0
f
,
0.0
f
,
0.0
f
),
16
,
4
);
32
,
32
);
// Initialize font rendering
updateFontAtlas
();
...
...
modules/openigtlink/processors/openigtlinkclient.cpp
View file @
ace48281
...
...
@@ -160,7 +160,7 @@ namespace campvis {
// If the voxel size boundled with the packet is practically 0.0f, make it 1.0f
// this makes sure we don't get invalid mapping informations (non invertable matrix)
if
(
minElem
(
voxelSize
)
<=
1e-10
f
)
{
voxelSize
=
1.0
f
;
voxelSize
=
cgt
::
vec3
(
1.0
f
)
;
}
size_t
dimensionality
=
(
size_i
[
2
]
==
1
)
?
((
size_i
[
1
]
==
1
)
?
1
:
2
)
:
3
;
...
...
modules/preprocessing/glsl/glimageresampler.frag
View file @
ace48281
...
...
@@ -35,7 +35,7 @@ uniform sampler2D _texture;
#endif
void
main
()
{
#ifdef GLRESAMPLER_3D
#ifdef GLRESAMPLER_3D
vec4
sample
=
texture
(
_texture
,
vec3
(
ex_TexCoord
.
xy
,
_zTexCoord
));
#endif
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment