Skip to content

Commit

Permalink
remove redundant checks on projectors
Browse files Browse the repository at this point in the history
forward/back projector was running checks on _density_ptr, even though
it was created/tested before.

callgrind shows that has_same_charecteristics is actually surprisingly
expensive (as it calls Array::get_index_range(), which is slow).
So now we avoid doing those checks.

This results in a (quite small) speed-up, only relevant for GPU projectors.
  • Loading branch information
KrisThielemans committed Aug 29, 2023
1 parent 478165b commit f35b8e9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/include/stir/recon_buildblock/BackProjectorByBin.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,17 @@ void back_project(const RelatedViewgrams<float>&,
If overriding this function in a derived class, you need to call this one.
*/
virtual void check(const ProjDataInfo& proj_data_info) const;

//! check if the arguments are the same as what was used for set_up()
/*! calls error() if anything is wrong.
If overriding this function in a derived class, you need to call this one.
Calls check(const ProjDataInfo&)
*/
virtual void check(const ProjDataInfo& proj_data_info, const DiscretisedDensity<3,float>& density_info) const;

bool _already_set_up;

//! Clone of the density sptr set with set_up()
Expand Down
10 changes: 10 additions & 0 deletions src/include/stir/recon_buildblock/ForwardProjectorByBin.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,17 @@ virtual void set_up(
If overriding this function in a derived class, you need to call this one.
*/
virtual void check(const ProjDataInfo& proj_data_info) const;

//! check if the arguments are the same as what was used for set_up()
/*! calls error() if anything is wrong.
If overriding this function in a derived class, you need to call this one.
Calls check(const ProjDataInfo&)
*/
virtual void check(const ProjDataInfo& proj_data_info, const DiscretisedDensity<3,float>& density_info) const;

bool _already_set_up;

//! The density ptr set with set_up()
Expand Down
11 changes: 9 additions & 2 deletions src/recon_buildblock/BackProjectorByBin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,20 @@ set_up(const shared_ptr<const ProjDataInfo>& proj_data_info_sptr,

void
BackProjectorByBin::
check(const ProjDataInfo& proj_data_info, const DiscretisedDensity<3,float>& density_info) const
check(const ProjDataInfo& proj_data_info) const
{
if (!this->_already_set_up)
error("BackProjectorByBin method called without calling set_up first.");
if (!(*this->_proj_data_info_sptr >= proj_data_info))
error(boost::format("BackProjectorByBin set-up with different geometry for projection data.\nSet_up was with\n%1%\nCalled with\n%2%")
% this->_proj_data_info_sptr->parameter_info() % proj_data_info.parameter_info());
}

void
BackProjectorByBin::
check(const ProjDataInfo& proj_data_info, const DiscretisedDensity<3,float>& density_info) const
{
this->check(proj_data_info);
if (! this->_density_sptr->has_same_characteristics(density_info))
error("BackProjectorByBin set-up with different geometry for density or volume data.");
}
Expand Down Expand Up @@ -265,7 +272,7 @@ back_project(const RelatedViewgrams<float>& viewgrams,
if (!_density_sptr)
error("You need to call start_accumulating_in_new_target() before back_project()");

check(*viewgrams.get_proj_data_info_sptr(), *_density_sptr);
check(*viewgrams.get_proj_data_info_sptr());

#ifdef STIR_OPENMP
const int thread_num=omp_get_thread_num();
Expand Down
11 changes: 9 additions & 2 deletions src/recon_buildblock/ForwardProjectorByBin.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,20 @@ set_up(const shared_ptr<const ProjDataInfo>& proj_data_info_sptr,

void
ForwardProjectorByBin::
check(const ProjDataInfo& proj_data_info, const DiscretisedDensity<3,float>& density_info) const
check(const ProjDataInfo& proj_data_info) const
{
if (!this->_already_set_up)
error("ForwardProjectorByBin method called without calling set_up first.");
if (!(*this->_proj_data_info_sptr >= proj_data_info))
error(boost::format("ForwardProjectorByBin set-up with different geometry for projection data.\nSet_up was with\n%1%\nCalled with\n%2%")
% this->_proj_data_info_sptr->parameter_info() % proj_data_info.parameter_info());
}

void
ForwardProjectorByBin::
check(const ProjDataInfo& proj_data_info, const DiscretisedDensity<3,float>& density_info) const
{
this->check(proj_data_info);
if (! this->_density_sptr->has_same_characteristics(density_info))
error("ForwardProjectorByBin set-up with different geometry for density or volume data.");
}
Expand Down Expand Up @@ -254,7 +261,7 @@ forward_project(RelatedViewgrams<float>& viewgrams,
if (!_density_sptr)
error("You need to call set_input() forward_project()");

check(*viewgrams.get_proj_data_info_sptr(), *_density_sptr);
check(*viewgrams.get_proj_data_info_sptr());

// first check symmetries
{
Expand Down

0 comments on commit f35b8e9

Please sign in to comment.