1 /* Copyright 2015 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/core/public/session.h"
17
18 #include <string>
19
20 #include "tensorflow/core/common_runtime/session_factory.h"
21 #include "tensorflow/core/lib/core/errors.h"
22 #include "tensorflow/core/lib/monitoring/gauge.h"
23 #include "tensorflow/core/platform/logging.h"
24
25 namespace tensorflow {
26 namespace {
27
28 auto* session_created = monitoring::Gauge<bool, 0>::New(
29 "/tensorflow/core/session_created", "True if a session was created.");
30
31 } // namespace
32
Session()33 Session::Session() {}
34
~Session()35 Session::~Session() {}
36
Run(const RunOptions & run_options,const std::vector<std::pair<string,Tensor>> & inputs,const std::vector<string> & output_tensor_names,const std::vector<string> & target_tensor_names,std::vector<Tensor> * outputs,RunMetadata * run_metadata)37 Status Session::Run(const RunOptions& run_options,
38 const std::vector<std::pair<string, Tensor> >& inputs,
39 const std::vector<string>& output_tensor_names,
40 const std::vector<string>& target_tensor_names,
41 std::vector<Tensor>* outputs, RunMetadata* run_metadata) {
42 return errors::Unimplemented(
43 "Run with options is not supported for this session.");
44 }
45
PRunSetup(const std::vector<string> & input_names,const std::vector<string> & output_names,const std::vector<string> & target_nodes,string * handle)46 Status Session::PRunSetup(const std::vector<string>& input_names,
47 const std::vector<string>& output_names,
48 const std::vector<string>& target_nodes,
49 string* handle) {
50 return errors::Unimplemented(
51 "Partial run is not supported for this session.");
52 }
53
PRun(const string & handle,const std::vector<std::pair<string,Tensor>> & inputs,const std::vector<string> & output_names,std::vector<Tensor> * outputs)54 Status Session::PRun(const string& handle,
55 const std::vector<std::pair<string, Tensor> >& inputs,
56 const std::vector<string>& output_names,
57 std::vector<Tensor>* outputs) {
58 return errors::Unimplemented(
59 "Partial run is not supported for this session.");
60 }
61
NewSession(const SessionOptions & options)62 Session* NewSession(const SessionOptions& options) {
63 // Starts exporting metrics through a platform-specific monitoring API (if
64 // provided). For builds using "tensorflow/tsl/platform/default", this is
65 // currently a no-op.
66 session_created->GetCell()->Set(true);
67 Session* out_session;
68 Status s = NewSession(options, &out_session);
69 if (!s.ok()) {
70 LOG(ERROR) << "Failed to create session: " << s;
71 return nullptr;
72 }
73 return out_session;
74 }
75
NewSession(const SessionOptions & options,Session ** out_session)76 Status NewSession(const SessionOptions& options, Session** out_session) {
77 SessionFactory* factory;
78 Status s = SessionFactory::GetFactory(options, &factory);
79 if (!s.ok()) {
80 *out_session = nullptr;
81 LOG(ERROR) << "Failed to get session factory: " << s;
82 return s;
83 }
84 // Starts exporting metrics through a platform-specific monitoring API (if
85 // provided). For builds using "tensorflow/tsl/platform/default", this is
86 // currently a no-op.
87 session_created->GetCell()->Set(true);
88 s = factory->NewSession(options, out_session);
89 if (!s.ok()) {
90 *out_session = nullptr;
91 LOG(ERROR) << "Failed to create session: " << s;
92 }
93 return s;
94 }
95
Reset(const SessionOptions & options,const std::vector<string> & containers)96 Status Reset(const SessionOptions& options,
97 const std::vector<string>& containers) {
98 SessionFactory* factory;
99 TF_RETURN_IF_ERROR(SessionFactory::GetFactory(options, &factory));
100 return factory->Reset(options, containers);
101 }
102
103 } // namespace tensorflow
104