Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to speed up STIR acquisition data algebra by avoiding unnecessary 0-fill of newly created data. #1549

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Next Next commit
employed initialise_with_0 flag to reduce unnecessary 0-fill
evgueni-ovtchinnikov committed Dec 9, 2024
commit 3b2b84cb5f856e7f94013f338db710daaa22e331
6 changes: 6 additions & 0 deletions src/buildblock/ProjDataInMemory.cxx
Original file line number Diff line number Diff line change
@@ -73,12 +73,18 @@ ProjDataInMemory::ProjDataInMemory(shared_ptr<const ExamInfo> const& exam_info_s
void
ProjDataInMemory::create_buffer(const bool initialise_with_0)
{
if (!initialise_with_0) {
this->buffer.set_initialise_with_zeros(false);
this->buffer.grow(0, this->size_all());
return;
}
#if 0
float *b = new float[this->size_all()];
if (initialise_with_0)
memset(b, 0, this->size_all()*sizeof(float));
return b;
#else
this->buffer.set_initialise_with_zeros(true);
this->buffer = Array<1, float>(static_cast<int>(this->size_all()));
#endif
}
11 changes: 11 additions & 0 deletions src/include/stir/Array.h
Original file line number Diff line number Diff line change
@@ -569,6 +569,15 @@ class Array<1, elemT> : public NumericVectorWithOffset<elemT, elemT>
inline const elemT& at(const BasicCoordinate<1, int>& c) const;
//@}

void set_initialise_with_zeros(bool iwz)
{
init_with_zeros_ = iwz;
}
bool get_initialise_with_zeros() const
{
return init_with_zeros_;
}
Comment on lines +572 to +579
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will need to be removed


private:
// Make sure we can call init() recursively.
template <int num_dimensions2, class elemT2>
@@ -579,6 +588,8 @@ class Array<1, elemT> : public NumericVectorWithOffset<elemT, elemT>
\arg data_ptr should start to a contiguous block of correct size
*/
inline void init(const IndexRange<1>& range, elemT* const data_ptr, bool copy_data);

bool init_with_zeros_= 0;
};

END_NAMESPACE_STIR
6 changes: 6 additions & 0 deletions src/include/stir/Array.inl
Original file line number Diff line number Diff line change
@@ -583,6 +583,12 @@ Array<1, elemT>::resize(const int min_index, const int max_index)
const size_type oldlength = this->size();

base_type::resize(min_index, max_index);

if (!get_initialise_with_zeros()) {
this->check_state();
return;
}

if (oldlength == 0)
{
for (int i = this->get_min_index(); i <= this->get_max_index(); i++)