[go: nahoru, domu]

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

Sign compare warning fixes batch 1 #40371

Merged
Show file tree
Hide file tree
Changes from 10 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ImportQuantStatsPass
// If the index is out of range, this method returns false. Otherwise it
// returns true if the value is a float tensor.
bool IsQuantizableResult(Operation *op, int index) {
if (index < 0 || index >= op->getNumResults()) return false;
if (index < 0 || index >= static_cast<int>(op->getNumResults())) return false;
Value res = op->getResult(index);
return res.getType().isa<ShapedType>() &&
res.getType().cast<ShapedType>().getElementType().isa<FloatType>();
Expand Down Expand Up @@ -158,7 +158,7 @@ void ImportQuantStatsPass::ImportAsStatsOps(OpBuilder b, Operation *op,
InsertStatsOpAtResult(b, op->getResult(index), layer_stats, axis_stats,
axis);
} else {
for (int i = 0; i < op->getNumResults(); ++i) {
for (int i = 0, e = op->getNumResults(); i < e; ++i) {
if (IsQuantizableResult(op, i)) {
InsertStatsOpAtResult(b, op->getResult(i), layer_stats, axis_stats,
axis);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool ParseInputNodeQuantSpecs(absl::string_view node_names,
std::vector<double> node_mins;
if (!min_values.empty()) {
std::vector<std::string> node_mins_str = absl::StrSplit(min_values, ',');
for (int i = 0; i < node_mins_str.size(); i++) {
for (int i : llvm::seq<int>(node_mins_str.size())) {
tg-at-google marked this conversation as resolved.
Show resolved Hide resolved
double value;
if (!absl::SimpleAtod(node_mins_str[i], &value)) {
return true;
Expand All @@ -60,7 +60,7 @@ bool ParseInputNodeQuantSpecs(absl::string_view node_names,
std::vector<double> node_maxs;
if (!max_values.empty()) {
std::vector<std::string> node_maxs_str = absl::StrSplit(max_values, ',');
for (int i = 0; i < node_maxs_str.size(); i++) {
for (int i : llvm::seq<int>(node_maxs_str.size())) {
double value;
if (!absl::SimpleAtod(node_maxs_str[i], &value)) {
llvm::errs() << "Unexpected mins: " << node_maxs_str[i] << "\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class QuantizationDriver {
return;
if (current_op == op) llvm::errs() << "===>>>";
llvm::errs() << op->getName() << " : (";
for (auto i = 0; i < op->getNumOperands(); ++i) {
for (int i = 0, e = op->getNumOperands(); i < e; ++i) {
if (auto params = GetOperandQuantState(op, i).params)
params.print(llvm::errs());
else
Expand All @@ -303,7 +303,7 @@ class QuantizationDriver {
llvm::errs() << ",";
}
llvm::errs() << ") -> (";
for (auto i = 0; i < op->getNumResults(); ++i) {
for (int i = 0, e = op->getNumResults(); i < e; ++i) {
if (auto params = GetResultQuantState(op, i).params)
params.print(llvm::errs());
else
Expand Down
10 changes: 5 additions & 5 deletions tensorflow/compiler/mlir/lite/quantization/quantization_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static Type GetQuantizedType(Builder builder, Type input_type,
} else if (min.size() == max.size()) {
auto shape = input_type.dyn_cast<ShapedType>();
if (!shape || shape.getRank() <= quant_dim ||
min.size() != shape.getDimSize(quant_dim)) {
static_cast<int64_t>(min.size()) != shape.getDimSize(quant_dim)) {
return {};
}
// TODO(b/141508873): the quantization dim is set to the last dimension.
Expand All @@ -75,7 +75,7 @@ TypeAttr RescaleQuantizedType(Type input, Attribute factor) {
if (auto qtype = ele_type.dyn_cast<quant::UniformQuantizedPerAxisType>()) {
ArrayRef<double> scales = qtype.getScales();
// Broadcasting hasn't been implemented yet.
if (scales.size() != factor_values.getNumElements()) return {};
if (static_cast<int64_t>(scales.size()) != factor_values.getNumElements()) return {};
SmallVector<double, 4> new_scales;
new_scales.reserve(scales.size());
auto scales_iter = scales.begin();
Expand Down Expand Up @@ -269,7 +269,7 @@ Type GetUniformQuantizedPerAxisTypeForWeight(ElementsAttr attr, int quant_dim,
bool narrow_range) {
Builder builder(attr.getContext());
auto shape = attr.getType().cast<ShapedType>().getShape();
if (shape.size() <= quant_dim) return {};
if (static_cast<int>(shape.size()) <= quant_dim) return {};
// `symmetric` can only be used when it is `signed` and `narrow_range`.
if (symmetric && (!is_signed || !narrow_range)) return {};

Expand Down Expand Up @@ -334,7 +334,7 @@ quant::QuantizedType GetUniformQuantizedTypeForBias(
const std::vector<quant::QuantizedType>& op_types) {
if (op_types.empty()) return {};

int axis_size = 1;
size_t axis_size = 1;
int32_t quant_dim = -1;
Type expressed_type;
// Requires all the op types are valid UniformQuantizedTypes or
Expand Down Expand Up @@ -368,7 +368,7 @@ quant::QuantizedType GetUniformQuantizedTypeForBias(
scales[index_scale.index()] *= index_scale.value();
}
} else if (auto type = op_type.dyn_cast<quant::UniformQuantizedType>()) {
for (int index = 0; index != axis_size; ++index) {
for (int index = 0, e = axis_size; index != e; ++index) {
scales[index] *= type.getScale();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ std::string MakeUniqueFilename(string name) {
static NameCounts& instance = *new NameCounts;

// Remove illegal characters from `name`.
for (int i = 0; i < name.size(); ++i) {
for (int i = 0, e = name.size(); i < e; ++i) {
char ch = name[i];
if (ch == '/' || ch == '[' || ch == ']' || ch == '*' || ch == '?' ||
ch == '\\') {
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/compiler/mlir/xla/ir/chlo_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static Type GetBroadcastType(Type x, Type y, Type element_type,

if (shape_x.size() == shape_y.size()) {
llvm::SmallVector<int64_t, 4> out_shape(shape_x.size());
for (int i = 0; i < shape_x.size(); i++) {
for (int i = 0, e = shape_x.size(); i < e; i++) {
auto x_val = shape_x[i];
auto y_val = shape_y[i];
if (x_val == -1 || y_val == -1) {
Expand Down
6 changes: 3 additions & 3 deletions tensorflow/compiler/mlir/xla/ir/hlo_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ DenseIntElementsAttr BuildConvPaddingAttrs(

int rank = padding_low.size();
SmallVector<int64_t, 8> padding;
for (unsigned i = 0; i < rank; ++i) {
for (unsigned i = 0, e = rank; i < e; ++i) {
padding.push_back(GetPaddingValue(padding_attr, {i, 0}) + padding_low[i]);
padding.push_back(GetPaddingValue(padding_attr, {i, 1}) + padding_high[i]);
}
Expand Down Expand Up @@ -853,7 +853,7 @@ static Attribute foldConcatenateHelper(ConcatenateOp* op,
auto shape = type.getShape();

size_t top_size = 1;
for (int i = 0; i < axis; i++) {
for (int i = 0, e = axis; i < e; i++) {
top_size = top_size * shape[i];
}

Expand Down Expand Up @@ -1118,7 +1118,7 @@ static LogicalResult Verify(MapOp op) {
// increasing.
auto values = op.dimensions().getValues<int64_t>();
auto dimensions = std::vector<int64_t>{values.begin(), values.end()};
for (int i = 0; i < dimensions.size(); ++i) {
for (int i = 0, e = dimensions.size(); i < e; ++i) {
if (dimensions[i] != i)
return op.emitOpError() << "requires monotonically increasing dimension "
"numbers, but got: "
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/compiler/xla/window_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Window MakeWindow(absl::Span<const int64> sizes,
absl::Span<const int64> strides) {
Window window;
CHECK_EQ(sizes.size(), strides.size());
for (auto nb = 0; nb < sizes.size(); ++nb) {
for (auto nb = 0; static_cast<size_t>(nb) < sizes.size(); ++nb) {
auto* dimension = window.add_dimensions();
dimension->set_size(sizes[nb]);
dimension->set_stride(strides[nb]);
Expand Down
6 changes: 3 additions & 3 deletions tensorflow/core/kernels/batch_kernels.cc
Original file line number Diff line number Diff line change
Expand Up @@ -486,18 +486,18 @@ class BatchResource : public ResourceBase {
std::map<string, std::vector<Tensor>> split_tensors;

DCHECK_EQ(batch->task(0).context->num_outputs(), combined_outputs.size());
if (combined_outputs.size() != batch->task(0).context->num_outputs()) {
if (static_cast<int>(combined_outputs.size()) != batch->task(0).context->num_outputs()) {
return errors::Internal("Wrong number of batched output tensors");
}

// Generate 'split_tensors' and populate the context outputs.
for (int i = 0; i < combined_outputs.size(); ++i) {
for (size_t i = 0; i < combined_outputs.size(); ++i) {
const Tensor& output_tensor = combined_outputs[i];
if (output_tensor.shape().dims() == 0) {
return errors::FailedPrecondition(
"Batched output tensor has 0 dimensions");
}
if (output_tensor.shape().dim_size(0) != batch->size() + padding_size) {
if (output_tensor.shape().dim_size(0) != static_cast<long long int>(batch->size() + padding_size)) {
return errors::FailedPrecondition(
"Batched output tensor's 0th dimension does not equal the sum of "
"the 0th dimension sizes of the input tensors");
Expand Down
4 changes: 2 additions & 2 deletions tensorflow/core/kernels/data/prefetch_autotuner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ void PrefetchAutotuner::RecordConsumption(size_t current_buffer_size) {
case Mode::kDisabled:
return;
case Mode::kUpswing:
if (current_buffer_size == buffer_limit_) {
if (static_cast<tensorflow::int64>(current_buffer_size) == buffer_limit_) {
mode_ = Mode::kDownswing;
}
return;
case Mode::kDownswing:
if (current_buffer_size == 0) {
if (buffer_limit_ >= kBufferLimitThreshold) {
if (buffer_limit_ >= static_cast<tensorflow::int64>(kBufferLimitThreshold)) {
buffer_limit_ += kBufferLimitThreshold;
} else {
buffer_limit_ *= 2;
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/core/kernels/quantization_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ inline void RequantizeManyInNewRangeReference(const qint32* input, int64 count,
// that could be easily adapted for a SIMD implementation. It should also be
// possible to perform all the calculations in 32-bit rather than 64, but
// that's not been implemented yet.
for (size_t index = 0; index < count; ++index) {
for (size_t index = 0; static_cast<tensorflow::int64>(index) < count; ++index) {
const int64 input_value = static_cast<int64>(input[index]);
const int64 fp_value =
((input_value * range_scale_fp) >> 32) + input_offset_fp;
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/core/platform/s3/s3_file_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ Status S3FileSystem::MultiPartCopy(const Aws::String& source,
// wait on the mutex until notify is called
// then check the finished parts as there could be false notifications
multi_part_copy_cv.wait(lock, [&finishedPartStates, num_parts] {
return finishedPartStates.size() == num_parts;
return static_cast<const int>(finishedPartStates.size()) == num_parts;
});
}
// check if there was any error for any part
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/core/profiler/utils/derived_timeline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void DerivedXLineBuilder::ExpandOrAddLevelEvent(const XEvent& event,
}

void DerivedXLineBuilder::ResetLastEvents(int level) {
for (int i = level; i < last_event_by_level_.size(); ++i) {
for (int i = level; i < static_cast<int>(last_event_by_level_.size()); ++i) {
last_event_by_level_[i] = absl::nullopt;
}
if (level == 0) ResetDependentLines();
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/core/profiler/utils/derived_timeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class DerivedXLineBuilder {
std::vector<DerivedXLineBuilder*> dependent_lines);

void ExpandOrAddEvents(const std::vector<XEvent>& event_per_level) {
for (int level = 0; level < event_per_level.size(); ++level) {
for (size_t level = 0; level < event_per_level.size(); ++level) {
ExpandOrAddLevelEvent(event_per_level[level], level);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/core/profiler/utils/xplane_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void SortXSpace(XSpace* space) {
// smaller than these value.
void NormalizeTimestamps(XPlane* plane, uint64 start_time_ns) {
for (XLine& line : *plane->mutable_lines()) {
if (line.timestamp_ns() >= start_time_ns) {
if (line.timestamp_ns() >= static_cast<long int>(start_time_ns)) {
line.set_timestamp_ns(line.timestamp_ns() - start_time_ns);
}
}
Expand Down
4 changes: 2 additions & 2 deletions tensorflow/core/util/bcast.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ BCastList<N>::BCastList(const BCastList::Vec (&x)[N],
if (x[i] != x[0]) {
all_equal = false;
}
if (x[i].size() > largest_rank) {
if (static_cast<int>(x[i].size()) > largest_rank) {
largest_rank = x[i].size();
}
}
Expand Down Expand Up @@ -176,7 +176,7 @@ BCastList<N>::BCastList(const BCastList::Vec (&x)[N],

// 1-extend and align all vectors.
for (int i = 0; i < N; ++i) {
if (copy[i].size() < largest_rank) {
if (static_cast<int>(copy[i].size()) < largest_rank) {
copy[i].resize(largest_rank, 1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ::tensorflow::Status ConvertTrivialTileToConcat::Run(Model* model,
// It then just becomes a concat along that dimension.
int non_one_dims = 0;
int concat_axis = 0;
for (int i = 0; i < multiples.size(); ++i) {
for (size_t i = 0; i < multiples.size(); ++i) {
if (multiples[i] != 1) {
++non_one_dims;
concat_axis = i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ bool TransposeAffectsMemoryOrder(std::vector<int> perm,
// just the shape) then the flat buffer representation shouldn't change.
std::vector<int> old_major_index_ordering;
std::vector<int> new_major_index_ordering;
for (int i = 0; i < in_shape.size(); i++) {
for (int i = 0; static_cast<size_t>(i) < in_shape.size(); i++) {
if (in_shape[i] != 1) {
old_major_index_ordering.push_back(i);
}
Expand Down
2 changes: 1 addition & 1 deletion tensorflow/lite/toco/graph_transformations/dequantize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void DequantizeBuffer(Array* array) {
auto& new_data = array->GetMutableBuffer<ArrayDataType::kFloat>().data;
new_data.resize(old_data.size());
const auto& qparams = array->GetQuantizationParams();
for (int i = 0; i < old_data.size(); i++) {
for (size_t i = 0; i < old_data.size(); i++) {
new_data[i] = qparams.scale * (old_data[i] - qparams.zero_point);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ::tensorflow::Status DropFakeQuant::Run(Model* model, std::size_t op_index,
}

// Drop min/max inputs
for (int i = 1; i < fakequant_op->inputs.size(); i++) {
for (size_t i = 1; i < fakequant_op->inputs.size(); i++) {
if (CountOpsWithInput(*model, fakequant_op->inputs[i]) == 1) {
model->EraseArray(fakequant_op->inputs[i]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ ::tensorflow::Status EnsureUint8WeightsSafeForFastInt8Kernels::Run(
int index_of_previous_bad_value = 0;
bool changed = false;

for (int i = 0; i < buffer_data.size(); i++) {
for (size_t i = 0; i < buffer_data.size(); i++) {
if (buffer_data[i] == 0) {
count_bad++;
if (count_bad > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ bool IsBroadcastingOp(const Model& model, Operator* op) {
// Concatenation of identical inputs is usually a broadcast.
if (op->type == OperatorType::kConcatenation) {
// Verify that all inputs are the same.
for (int i = 1; i < op->inputs.size(); ++i) {
for (size_t i = 1; i < op->inputs.size(); ++i) {
if (op->inputs[i] != op->inputs[0]) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ bool CheckTwoUnidirectionalSequenceOpsAreValid(
return false;

// Make sure the inputs datatype matches.
for (int i = 0; i < fw_sequence_op->inputs.size(); ++i) {
for (size_t i = 0; i < fw_sequence_op->inputs.size(); ++i) {
const auto& fw_input_array_name = fw_sequence_op->inputs[i];
const auto& bw_input_array_name = bw_sequence_op->inputs[i];
if (model.HasArray(fw_input_array_name) &&
Expand All @@ -137,7 +137,7 @@ bool CheckTwoUnidirectionalSequenceOpsAreValid(
}

// Make sure the outputs datatype matches.
for (int i = 0; i < fw_sequence_op->outputs.size(); ++i) {
for (size_t i = 0; i < fw_sequence_op->outputs.size(); ++i) {
const auto& fw_output_array_name = fw_sequence_op->outputs[i];
const auto& bw_output_array_name = bw_sequence_op->outputs[i];
if (model.HasArray(fw_output_array_name) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ bool HardcodeMinMaxForPack(Model* model, Operator* op) {
}
const auto& first_input_minmax = first_input_array.GetMinMax();

for (int i = 1; i < op->inputs.size(); i++) {
for (size_t i = 1; i < op->inputs.size(); i++) {
const auto& input_array = model->GetArray(op->inputs[i]);
if (!input_array.minmax) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ ::tensorflow::Status IdentifyNearestUpsample::Run(Model* model,
shape_array.data_type = ArrayDataType::kInt32;
auto& shape_buffer = shape_array.GetMutableBuffer<ArrayDataType::kInt32>();
// This is what imagined as the original shape.
for (int i = 0; i < imagined_original_shape.size(); ++i) {
for (size_t i = 0; i < imagined_original_shape.size(); ++i) {
shape_buffer.data.push_back(imagined_original_shape.at(i));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ std::vector<int32> ReshapeToTranspose(const Model& model,
std::vector<int> not_one_indices;

// Separate into one indices and not one indices.
for (int i = 0; i < in_shape.size(); i++) {
for (size_t i = 0; i < in_shape.size(); i++) {
if (in_shape[i] == 1) {
one_indices.push_back(i);
} else {
Expand Down Expand Up @@ -167,7 +167,7 @@ ::tensorflow::Status MergeReshapeIntoPrecedingTranspose::Run(

// Combine the permutations.
const auto& transpose_perm = transpose_op->perm;
for (int i = 0; i < merged_perm.size(); i++) {
for (size_t i = 0; i < merged_perm.size(); i++) {
merged_perm[i] = transpose_perm[merged_perm[i]];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ ::tensorflow::Status PropagateArrayDataTypes::Run(Model* model,
if (unsupported_op->output_data_types.size() < op->outputs.size()) {
return ::tensorflow::Status::OK();
}
for (int i = 0; i < op->outputs.size(); ++i) {
for (size_t i = 0; i < op->outputs.size(); ++i) {
const string& output = op->outputs[i];
const ArrayDataType data_type = unsupported_op->output_data_types[i];
model->GetArray(output).data_type = data_type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ bool RecursivelyBackwardPropagateDataType(GraphTransformation* transformation,
ArrayDataType new_data_type,
const MinMax& new_minmax) {
bool did_change = false;
for (int input_index = 0; input_index < op->inputs.size(); ++input_index) {
for (size_t input_index = 0; input_index < op->inputs.size(); ++input_index) {
const auto& input = op->inputs[input_index];
auto& input_array = model->GetArray(input);

Expand Down
Loading