[XLA] Clamp indices in DynamicSlice and DynamicUpdateSlice instead of wrapping.
authorMichael Kuperstein <mkuper@google.com>
Fri, 18 May 2018 01:09:45 +0000 (18:09 -0700)
committerTensorFlower Gardener <gardener@tensorflow.org>
Fri, 18 May 2018 01:12:26 +0000 (18:12 -0700)
commitaca0458707fa63626c78acfeae2ade9ee78c54d1
tree7ad7f92113da51e79e0718e0b8c768f7c155cad2
parenta7fcec1b6e4832d03d796c3437c1fb00577ffc5c
[XLA] Clamp indices in DynamicSlice and DynamicUpdateSlice instead of wrapping.

This implements the following index clamping in all backends (CPU, GPU, Interpreter):

for(int i = 0; i < rank; ++i)
  start_index[i] = clamp(start_index[i], 0, output_dim_size[i] - update_dim_size[i])

Which ensures the slice (or update region) is always inbounds w.r.t the input.

PiperOrigin-RevId: 197082276
tensorflow/compiler/xla/reference_util.h
tensorflow/compiler/xla/service/elemental_ir_emitter.cc
tensorflow/compiler/xla/service/hlo_evaluator_typed_visitor.h
tensorflow/compiler/xla/service/llvm_ir/ops.cc
tensorflow/compiler/xla/tests/dynamic_ops_test.cc