Skip to content

Commit

Permalink
Avoid optional::value_or to skip materializing .item() when possible
Browse files Browse the repository at this point in the history
Reviewed By: sryap, zhangruiskyline

Differential Revision: D54173842

fbshipit-source-id: e31cd9c89f38b81f4e187936c3ca009130d94d10
  • Loading branch information
Shen Li authored and facebook-github-bot committed Feb 26, 2024
1 parent b584523 commit 70a1c96
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions fbgemm_gpu/src/jagged_tensor_ops/jagged_tensor_ops_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1161,8 +1161,11 @@ Tensor jagged_index_select_2d_forward_v2_impl(
const Tensor& input_offsets,
const Tensor& output_offsets,
const c10::optional<int64_t> optional_num_dense_output_rows) {
const auto num_dense_output_rows = optional_num_dense_output_rows.value_or(
output_offsets[output_offsets.numel() - 1].item<int64_t>());
// Intentionally not using optional::value_or here to avoid materializing
// .item() call when possible.
const auto num_dense_output_rows = optional_num_dense_output_rows.has_value()
? optional_num_dense_output_rows.value()
: output_offsets[output_offsets.numel() - 1].item<int64_t>();
static auto v1_op =
c10::Dispatcher::singleton()
.findSchemaOrThrow("fbgemm::jagged_index_select_2d_forward", "")
Expand Down

0 comments on commit 70a1c96

Please sign in to comment.