| 162 | } |
| 163 | |
| 164 | Status XlaOpKernelContext::ConstantInputReshaped( |
| 165 | int index, absl::Span<const int64> new_dims, |
| 166 | xla::Literal* constant_literal) { |
| 167 | XlaExpression e = InputExpression(index); |
| 168 | xla::StatusOr<absl::optional<Tensor>> constant_or_status = |
| 169 | e.ResolveConstant(compiler()->client(), dynamic_dimension_is_minus_one_); |
| 170 | if (!constant_or_status.ok()) { |
| 171 | Status status = constant_or_status.status(); |
| 172 | errors::AppendToMessage(&status, "while evaluating input ", index, " of ", |
| 173 | context_->op_kernel().type_string(), |
| 174 | " operator as a compile-time constant."); |
| 175 | return status; |
| 176 | } |
| 177 | absl::optional<Tensor> constant = constant_or_status.ValueOrDie(); |
| 178 | if (!constant.has_value()) { |
| 179 | return errors::InvalidArgument( |
| 180 | "Input ", index, " to node `", context_->op_kernel().name(), |
| 181 | "` with op ", context_->op_kernel().type_string(), |
| 182 | " must be a compile-time constant.\n\n" |
| 183 | "XLA compilation requires that operator arguments that represent " |
| 184 | "shapes or dimensions be evaluated to concrete values at compile time. " |
| 185 | "This error means that a shape or dimension argument could not be " |
| 186 | "evaluated at compile time, usually because the value of the argument " |
| 187 | "depends on a parameter to the computation, on a variable, or on a " |
| 188 | "stateful operation such as a random number generator."); |
| 189 | } |
| 190 | |
| 191 | Tensor temp(constant->dtype()); |
| 192 | if (!temp.CopyFrom(*constant, TensorShape(new_dims))) { |
| 193 | return errors::InvalidArgument( |
| 194 | context_->op_kernel().name(), " input ", index, " has shape ", |
| 195 | constant->shape().DebugString(), |
| 196 | " but was asked to be reshaped to incompatible shape ", |
| 197 | TensorShape(new_dims).DebugString()); |
| 198 | } |
| 199 | |
| 200 | TF_ASSIGN_OR_RETURN(*constant_literal, HostTensorToLiteral(temp)); |
| 201 | return Status::OK(); |
| 202 | } |
| 203 | |
| 204 | // Converts an int32 or int64 scalar literal to an int64. |
| 205 | static Status LiteralToInt64Scalar(const xla::LiteralSlice& literal, |
nothing calls this directly
no test coverage detected