xref: /aosp_15_r20/external/federated-compute/fcp/client/lc_runner.h (revision 14675a029014e728ec732f129a32e299b2da0601)
1 /*
2  * Copyright 2020 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef FCP_CLIENT_LC_RUNNER_H_
17 #define FCP_CLIENT_LC_RUNNER_H_
18 
19 #include <string>
20 
21 #include "absl/container/flat_hash_map.h"
22 #include "absl/status/status.h"
23 #include "fcp/base/monitoring.h"
24 #include "fcp/client/event_publisher.h"
25 #include "fcp/client/flags.h"
26 #include "fcp/client/log_manager.h"
27 #include "fcp/client/opstats/opstats_logger.h"
28 #include "fcp/client/phase_logger.h"
29 #include "fcp/client/simple_task_environment.h"
30 
31 namespace fcp {
32 namespace client {
33 
34 // Prod entry point for running a local computation. Concurrent calls, with
35 // the same SimpleTaskEnvironment::GetBaseDir(), are not supported.
36 // If the training conditions are not met, return CANCELLED status.
37 // If the plan cannot be parsed, return INVALID_ARGUMENT status.
38 // If the plan does not contain tensorSpec, return INVALID_ARGUMENT status.
39 // If the plan does not contain LocalComputeIORouter, return INVALID_ARGUMENT
40 // status.
41 // If the plan contains ClientExecutions, return INVALID_ARGUMENT status.
42 // If the plan expects input tensors other than dataset token, input dir and
43 // output dir, return INVALID_ARGUMENT status.
44 // If Tensorflow completes, return OK status.
45 // If Tensorflow was interrupted, return CANCELLED status.
46 absl::Status RunLocalComputation(
47     SimpleTaskEnvironment* env_deps, EventPublisher* event_publisher,
48     LogManager* log_manager, const Flags* flags,
49     const std::string& session_name, const std::string& plan_uri,
50     const std::string& input_dir_uri, const std::string& output_dir_uri,
51     const absl::flat_hash_map<std::string, std::string>& input_resources);
52 
53 // This is exposed for use in tests that require a mocked OpStatsLogger.
54 // Otherwise, this is used internally by the other RunLocalComputation
55 // method once the OpStatsLogger object has been created.
56 absl::Status RunLocalComputation(
57     PhaseLogger& phase_logger, SimpleTaskEnvironment* env_deps,
58     LogManager* log_manager,
59     ::fcp::client::opstats::OpStatsLogger* opstats_logger, const Flags* flags,
60     const std::string& plan_uri, const std::string& input_dir_uri,
61     const std::string& output_dir_uri,
62     const absl::flat_hash_map<std::string, std::string>& input_resources,
63     const SelectorContext& selector_context);
64 
65 }  // namespace client
66 }  // namespace fcp
67 
68 #endif  // FCP_CLIENT_LC_RUNNER_H_
69