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

CherryPick:2.2 Fix tf.io.decode_raw bugs #50011

Merged
merged 2 commits into from
Jun 3, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 12 additions & 9 deletions tensorflow/core/kernels/decode_padded_raw_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.
#include "tensorflow/core/framework/common_shape_fns.h"
#include "tensorflow/core/framework/op.h"
#include "tensorflow/core/framework/op_kernel.h"
#include "tensorflow/core/framework/op_requires.h"
mihaimaruseac marked this conversation as resolved.
Show resolved Hide resolved
#include "tensorflow/core/framework/shape_inference.h"

namespace tensorflow {
Expand Down Expand Up @@ -83,14 +84,13 @@ class DecodePaddedRawOp : public OpKernel {
// can copy the memory directly.
if (!convert_data_endianness_ || sizeof(T) == 1) {
for (int64 i = 0; i < flat_in.size(); ++i) {
const T* in_data = reinterpret_cast<const T*>(flat_in(i).data());

if (flat_in(i).size() > fixed_length) {
memcpy(out_data, in_data, fixed_length);
} else {
memcpy(out_data, in_data, flat_in(i).size());
}
out_data += fixed_length;
const auto to_copy =
std::min(flat_in(i).size(), static_cast<size_t>(fixed_length));
memcpy(out_data, flat_in(i).data(), to_copy);
// Note: increase out_data by width since it's already of type T* so
// each shift amount is implicitly multiplied by sizeof(T) according to
// pointer arithmetic rules.
out_data += width;
}
} else {
// Otherwise, the data is not in the host's byte order, and rather than a
Expand All @@ -105,7 +105,10 @@ class DecodePaddedRawOp : public OpKernel {
p_in += sizeof(T), p_out += sizeof(T)) {
std::reverse_copy(p_in, p_in + sizeof(T), p_out);
}
out_data += fixed_length;
// Note: increase out_data by width since it's already of type T* so
// each shift amount is implicitly multiplied by sizeof(T) according to
// pointer arithmetic rules.
out_data += width;
}
}
}
Expand Down