| 76 | } // namespace tensorflow |
| 77 | |
| 78 | int main(int argc, char* argv[]) { |
| 79 | tensorflow::port::InitMain(argv[0], &argc, &argv); |
| 80 | tensorflow::string job_spec; |
| 81 | tensorflow::string job_name; |
| 82 | int num_cpus = 1; |
| 83 | int num_gpus = 0; |
| 84 | int task_index = 0; |
| 85 | std::vector<tensorflow::Flag> flag_list = { |
| 86 | tensorflow::Flag("tf_jobs", &job_spec, "job specification"), |
| 87 | tensorflow::Flag("tf_job", &job_name, "job name"), |
| 88 | tensorflow::Flag("tf_task", &task_index, "task index"), |
| 89 | tensorflow::Flag("num_cpus", &num_cpus, "number of CPUs"), |
| 90 | tensorflow::Flag("num_gpus", &num_gpus, "number of GPUs"), |
| 91 | }; |
| 92 | tensorflow::string usage = tensorflow::Flags::Usage(argv[0], flag_list); |
| 93 | const bool parse_result = tensorflow::Flags::Parse(&argc, argv, flag_list); |
| 94 | if (!parse_result || argc != 1) { |
| 95 | LOG(ERROR) << usage; |
| 96 | return -1; |
| 97 | } |
| 98 | |
| 99 | tensorflow::ServerDef def; |
| 100 | tensorflow::Status s = tensorflow::FillServerDef(job_spec, job_name, num_cpus, |
| 101 | num_gpus, task_index, &def); |
| 102 | if (!s.ok()) { |
| 103 | LOG(ERROR) << "Could not parse job spec: " << s.error_message() << "\n" |
| 104 | << usage; |
| 105 | return -1; |
| 106 | } |
| 107 | |
| 108 | std::unique_ptr<tensorflow::ServerInterface> svr; |
| 109 | s = tensorflow::NewServer(def, &svr); |
| 110 | |
| 111 | if (!s.ok()) { |
| 112 | LOG(ERROR) << "Could not create server: " << s.error_message(); |
| 113 | return -1; |
| 114 | } |
| 115 | TF_QCHECK_OK(svr->Start()); |
| 116 | TF_QCHECK_OK(svr->Join()); |
| 117 | |
| 118 | // NOTE(mrry): Unreachable code. |
| 119 | return 0; |
| 120 | } |