• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2019 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 #include "tensorflow/compiler/xla/tests/verified_hlo_module.h"
16 
17 #include "absl/strings/str_cat.h"
18 #include "absl/strings/string_view.h"
19 #include "tensorflow/compiler/xla/service/hlo_parser.h"
20 #include "tensorflow/compiler/xla/status_macros.h"
21 #include "tensorflow/compiler/xla/util.h"
22 #include "tensorflow/core/lib/core/errors.h"
23 #include "tensorflow/core/lib/core/status.h"
24 #include "tensorflow/core/platform/logging.h"
25 #include "tensorflow/core/platform/test.h"
26 
27 namespace xla {
28 
ParseHloStringAndVerifyModule(absl::string_view str)29 Status VerifiedHloModule::ParseHloStringAndVerifyModule(absl::string_view str) {
30   TF_RET_CHECK(computation_count() == 0);
31   auto parser = HloParser::CreateHloParserForTests(str);
32   TF_RETURN_IF_ERROR(parser->Run(this));
33   return Verify();
34 }
35 
VerifyOrAddFailure(absl::string_view message)36 void VerifiedHloModule::VerifyOrAddFailure(absl::string_view message) {
37   Status status = Verify();
38   if (!status.ok()) {
39     ADD_FAILURE() << "HloVerifier failed on module " << name()
40                   << (message.empty() ? "" : absl::StrCat(" (", message, ")"))
41                   << ": " << status;
42     LOG(ERROR) << "Contents of bad module:";
43     XLA_LOG_LINES(tensorflow::ERROR, ToString());
44   }
45 }
46 
Verify()47 Status VerifiedHloModule::Verify() {
48   if (computation_count() == 0) {
49     // The computation was never built. Nothing to verify.
50     return Status::OK();
51   }
52   return verifier_.Run(this).status();
53 }
54 
55 }  // namespace xla
56