1 /* Copyright 2021 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 // This file uses absl libraries to parses command-line options and runs a
17 // given mlir file using test driver library.
18 //
19 // This is allowed to link against Tensorflow libraries.
20
21 #include "absl/strings/str_split.h"
22 #include "llvm/Support/Error.h"
23 #include "tensorflow/core/platform/init_main.h"
24 #include "tensorflow/core/runtime_fallback/bef_executor_flags.h"
25 #include "tensorflow/core/runtime_fallback/util/fallback_test_util.h"
26 #include "tfrt/bef_executor_driver/bef_executor_driver.h" // from @tf_runtime
27
main(int argc,char ** argv)28 int main(int argc, char** argv) {
29 tensorflow::port::InitMain(argv[0], &argc, &argv);
30
31 std::string input_filename = absl::GetFlag(FLAGS_input_filename);
32
33 // Ignore the positional argument if --input_filename is provided.
34 if (argc > 1 && input_filename == tfrt::kDefaultInputFilename) {
35 input_filename = argv[1];
36 }
37
38 // By default, absl::StrSplit includes empty string in its output.
39 std::vector<std::string> shared_libs =
40 absl::StrSplit(absl::GetFlag(FLAGS_shared_libs), ',', absl::SkipEmpty());
41 std::vector<std::string> functions =
42 absl::StrSplit(absl::GetFlag(FLAGS_functions), ',', absl::SkipEmpty());
43 std::string test_init_function = absl::GetFlag(FLAGS_test_init_function);
44
45 tfrt::RunBefConfig run_config;
46 run_config.program_name = argv[0];
47 run_config.input_filename = input_filename;
48 run_config.shared_libs = shared_libs;
49 run_config.functions = functions;
50 run_config.test_init_function = test_init_function;
51 run_config.work_queue_type = absl::GetFlag(FLAGS_work_queue_type);
52 run_config.host_allocator_type = absl::GetFlag(FLAGS_host_allocator_type);
53
54 return RunBefExecutor(
55 run_config,
56 [](tfrt::HostContext* host, tfrt::ResourceContext* resource_context)
57 -> llvm::Expected<tfrt::ExecutionContext> {
58 return tensorflow::tfd::CreateFallbackTestExecutionContext(
59 host, resource_context);
60 });
61 }
62