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

Small fix to mitigate overflow in Convolution.cc #2992

Merged
merged 4 commits into from
Jan 16, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
mitigating some overflow error with floats
  • Loading branch information
System User committed Jan 16, 2019
commit a3464d01fe14faec651454c9b31f1807e871a7b4
4 changes: 2 additions & 2 deletions src/nnet3/convolution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ static void ComputeTempMatrixSize(const ConvolutionComputationOptions &opts,
// work out how many rows the temporary matrix should have, taking
// into account the specified memory limit.
temp_rows = computation->num_t_out * computation->num_images;
BaseFloat num_megabytes = (4 * temp_rows * temp_cols) / 1000000.0,
BaseFloat num_megabytes = (4 * (temp_rows / 1000.0) * (temp_cols / 1000.0)),
megabyte_limit = opts.max_memory_mb;
// C++ rounds down; here, we want to round up so we add one.
int32 ratio = 1.0 + num_megabytes / megabyte_limit;
Expand All @@ -986,7 +986,7 @@ static void ComputeTempMatrixSize(const ConvolutionComputationOptions &opts,
// >= temp_rows so that we don't have a small leftover piece.
int32 new_num_t_out = (computation->num_t_out + ratio - 1) / ratio;
temp_rows = new_num_t_out * computation->num_images;
BaseFloat new_num_megabytes = (4 * temp_rows * temp_cols) / 1000000.0;
BaseFloat new_num_megabytes = (4 * (temp_rows / 1000.0) * (temp_cols / 1000.0));
// make sure we're within the memory limit.
if (new_num_megabytes > 1.01 * megabyte_limit) {
KALDI_WARN << "Memory consumed in convolution is more than requested "
Expand Down