Home | History | Annotate | Download | only in service
      1 /* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
      2 
      3 Licensed under the Apache License, Version 2.0 (the "License");
      4 you may not use this file except in compliance with the License.
      5 You may obtain a copy of the License at
      6 
      7     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 Unless required by applicable law or agreed to in writing, software
     10 distributed under the License is distributed on an "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 See the License for the specific language governing permissions and
     13 limitations under the License.
     14 ==============================================================================*/
     15 
     16 #include "tensorflow/compiler/xla/service/source_map_util.h"
     17 
     18 #include "tensorflow/compiler/xla/util.h"
     19 
     20 namespace xla {
     21 namespace source_map_util {
     22 namespace {
     23 
     24 Status InvalidParameterArgumentV(const OpMetadata& op_metadata,
     25                                  const char* format, va_list args) {
     26   string message;
     27   tensorflow::strings::Appendv(&message, format, args);
     28   if (!op_metadata.source_file().empty()) {
     29     tensorflow::strings::Appendf(&message, " (%s:%d)",
     30                                  op_metadata.source_file().c_str(),
     31                                  op_metadata.source_line());
     32   }
     33   return InvalidArgument("%s", message.c_str());
     34 }
     35 
     36 }  // namespace
     37 
     38 Status InvalidParameterArgument(const OpMetadata& op_metadata,
     39                                 const char* format, ...) {
     40   va_list args;
     41   va_start(args, format);
     42   Status result = InvalidParameterArgumentV(op_metadata, format, args);
     43   va_end(args);
     44   return result;
     45 }
     46 
     47 Status InvalidParameterArgument(Executable* executable, int parameter_number,
     48                                 const char* format, ...) {
     49   va_list args;
     50   va_start(args, format);
     51   if (executable != nullptr && executable->has_module()) {
     52     const HloModule& module = executable->module();
     53     const HloComputation& computation = *module.entry_computation();
     54     HloInstruction* param = computation.parameter_instruction(parameter_number);
     55     const OpMetadata& metadata = param->metadata();
     56     Status result = InvalidParameterArgumentV(metadata, format, args);
     57     va_end(args);
     58     return result;
     59   }
     60   Status result = InvalidArgumentV(format, args);
     61   va_end(args);
     62   return result;
     63 }
     64 
     65 }  // namespace source_map_util
     66 }  // namespace xla
     67