Skip to content

Commit

Permalink
Add explanatory comments & simplity interval comparison operator
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom94 committed Apr 21, 2022
1 parent 5d91020 commit be46066
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions include/tiny-cuda-nn/gpu_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,10 @@ struct Interval {
size_t start, end;

bool operator<(const Interval& other) const {
if (end < other.end) {
return true;
} else if (end == other.end) {
return start < other.start;
} else {
return false;
}
// This operator is used to sort non-overlapping intervals. Since intervals
// may be empty, the second half of the following expression is required to
// resolve ambiguity when `end` of adjacent empty intervals is equal.
return end < other.end || (end == other.end && start < other.start);
}

bool overlaps(const Interval& other) const {
Expand Down Expand Up @@ -503,6 +500,9 @@ class GPUMemoryArena {
}

size_t start = best_candidate->start;

// Note: the += operator can turn `best_candidate` into an empty interval, which is fine because it will
// be absorbed into adjacent free intervals in later calls to `merge_adjacent_intervals`.
m_allocated_intervals[start] = best_candidate->start += n_bytes;

enlarge(size());
Expand Down

0 comments on commit be46066

Please sign in to comment.