Skip to content

Commit

Permalink
Optimise comparison vs end() during spatial message iteration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robadob committed Oct 16, 2020
1 parent 0c95352 commit bd9c2f8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 14 deletions.
32 changes: 25 additions & 7 deletions include/flamegpu/runtime/messaging/Spatial2D/Spatial2DDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ class MsgSpatial2D::In {
, cell_index_max(_cell_index_max)
, cell_index(_cell_index) {
relative_cell = relative_cell_y;
}
}
/**
* False minimal constructor used by iterator::end()
*/
__device__ Message(const Filter &parent)
: _parent(parent) { }
/**
* Equality operator
* Compares all internal member vars for equality
Expand All @@ -66,11 +71,17 @@ class MsgSpatial2D::In {
&& this->cell_index == rhs.cell_index;
}
/**
* Inequality operator
* Returns inverse of equality operator
* @see operator==(const Message&)
* This should only be called to compare against end()
* It has been modified to check for end of iteration with minimal instructions
* Therefore it does not even perform the equality operation
* @note Use operator==() if proper equality is required
*/
__device__ bool operator!=(const Message& rhs) const { return !(*this == rhs); }
__device__ bool operator!=(const Message& rhs) const {
// The incoming Message& is end(), so we don't care about that
// We only care that the host object has reached end
// When the strip number equals 2, it has exceeded the [-1, 1] range
return !(this->relative_cell >= 2);
}
/**
* Updates the message to return variables from the next message in the message list
* @return Returns itself
Expand Down Expand Up @@ -112,6 +123,12 @@ class MsgSpatial2D::In {
// Increment to find first message
++_message;
}
/**
* False constructor
* Only used by Filter::end(), creates a null objct
*/
__device__ iterator(const Filter &parent)
: _message(parent) { }
/**
* Moves to the next message
* (Prefix increment operator)
Expand Down Expand Up @@ -165,8 +182,9 @@ class MsgSpatial2D::In {
* @note This iterator is the same for all message list subsets
*/
inline __device__ iterator end(void) const {
// Final bin, as the constructor calls increment operator
return iterator(*this, 1, 1, 0);
// Empty init, because this object is never used
// iterator equality doesn't actually check the end object
return iterator(*this);
}

private:
Expand Down
32 changes: 25 additions & 7 deletions include/flamegpu/runtime/messaging/Spatial3D/Spatial3DDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,34 @@ class MsgSpatial3D::In {
relative_cell[0] = relative_cell_y;
relative_cell[1] = relative_cell_z;
}
/**
* False minimal constructor used by iterator::end()
*/
__device__ Message(const Filter &parent)
: _parent(parent) { }
/**
* Equality operator
* Compares all internal member vars for equality
* @note Does not compare _parent
*/
__device__ bool operator==(const Message& rhs) const {
__device__ bool operator==(const Message &rhs) const {
return this->relative_cell[0] == rhs.relative_cell[0]
&& this->relative_cell[1] == rhs.relative_cell[1]
&& this->cell_index_max == rhs.cell_index_max
&& this->cell_index == rhs.cell_index;
}
/**
* Inequality operator
* Returns inverse of equality operator
* @see operator==(const Message&)
* This should only be called to compare against end()
* It has been modified to check for end of iteration with minimal instructions
* Therefore it does not even perform the equality operation
* @note Use operator==() if proper equality is required
*/
__device__ bool operator!=(const Message& rhs) const { return !(*this == rhs); }
__device__ bool operator!=(const Message&) const {
// The incoming Message& is end(), so we don't care about that
// We only care that the host object has reached end
// When the strip number equals 2, it has exceeded the [-1, 1] range
return !(this->relative_cell[0] >= 2);
}
/**
* Updates the message to return variables from the next message in the message list
* @return Returns itself
Expand Down Expand Up @@ -120,6 +131,12 @@ class MsgSpatial3D::In {
// Increment to find first message
++_message;
}
/**
* False constructor
* Only used by Filter::end(), creates a null objct
*/
__device__ iterator(const Filter &parent)
: _message(parent) { }
/**
* Moves to the next message
* (Prefix increment operator)
Expand Down Expand Up @@ -174,8 +191,9 @@ class MsgSpatial3D::In {
* @note This iterator is the same for all message list subsets
*/
inline __device__ iterator end(void) const {
// Final bin, as the constructor calls increment operator
return iterator(*this, 1, 1, 1, 0);
// Empty init, because this object is never used
// iterator equality doesn't actually check the end object
return iterator(*this);
}

private:
Expand Down

0 comments on commit bd9c2f8

Please sign in to comment.