Skip to content

Commit

Permalink
perf: Increase performance of trace_beam
Browse files Browse the repository at this point in the history
Increase performance of `trace_beam` using pointer arithmetic, bypassing the torch indexing.
This saves ~30s in the rain simulation making it ~40% faster.
  • Loading branch information
TomSchammo committed Nov 14, 2024
1 parent 4d807c8 commit 79c68d3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cpp/src/raytracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@ constexpr tensor_size_t min_intersect_dist = 1;
nf_split_factor) %
(360 * nf_split_factor);

for (auto i = split_index[index].item<tensor_size_t>();
i < split_index[index + 1].item<tensor_size_t>(); i++) {
const auto si_ptr = split_index.data_ptr<float>();

// NOLINTBEGIN (*-pro-bounds-pointer-arithmetic)
for (auto i = static_cast<tensor_size_t>(si_ptr[index]);
i < static_cast<tensor_size_t>(si_ptr[index + 1]); i++) {
const auto nf = noise_filter[i];
const auto nf_ptr = nf.data_ptr<float>();

const auto sphere = nf.index({Slice(0, 3)});

const auto nf3_val = nf[3].item<float>();
const auto nf3_val = nf_ptr[3];

if (beam_length < nf3_val) {
return -1;
Expand All @@ -72,12 +76,13 @@ constexpr tensor_size_t min_intersect_dist = 1;

if (const auto dist_beam_sphere =
sqrt(nf3_val * nf3_val - length_beam_sphere * length_beam_sphere);
dist_beam_sphere < nf[4].item<float>()) {
dist_beam_sphere < nf_ptr[4]) {

return nf3_val;
}
}
}
// NOLINTEND (*-pro-bounds-pointer-arithmetic)

return -1;
}
Expand Down

0 comments on commit 79c68d3

Please sign in to comment.