1/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16#ifndef TENSORFLOW_CORE_COMMON_RUNTIME_SESSION_FACTORY_H_
17#define TENSORFLOW_CORE_COMMON_RUNTIME_SESSION_FACTORY_H_
18
19#include <string>
20
21#include "tensorflow/core/lib/core/errors.h"
22#include "tensorflow/core/lib/core/status.h"
23#include "tensorflow/core/lib/gtl/array_slice.h"
24#include "tensorflow/core/platform/types.h"
25
26namespace tensorflow {
27
28class Session;
29struct SessionOptions;
30
31class SessionFactory {
32 public:
33 // Creates a new session and stores it in *out_session, or fails with an error
34 // status if the Session could not be created. Caller takes ownership of
35 // *out_session if this returns OkStatus().
36 virtual Status NewSession(const SessionOptions& options,
37 Session** out_session) = 0;
38
39 virtual bool AcceptsOptions(const SessionOptions& options) = 0;
40
41 // Abort and close all existing sessions, disconnecting their resources from
42 // future sessions.
43 //
44 // Reset() allows misbehaving or slow sessions to be aborted and closed, and
45 // causes their resources eventually to be released. Reset() does not wait
46 // for the computations in old sessions to cease; it merely starts the
47 // process of tearing them down. However, if a new session is started after
48 // a Reset(), the new session is isolated from changes that old sessions
49 // (started prior to the Reset()) may continue to make to resources, provided
50 // all those resources are in containers listed in "containers".
51 //
52 // Old sessions may continue to have side-effects on resources not in
53 // containers listed in "containers", and thus may affect future
54 // sessions' results in ways that are hard to predict. Thus, if well-defined
55 // behavior is desired, is it recommended that all containers be listed in
56 // "containers".
57 //
58 // If the "containers" vector is empty, the default container is assumed.
59 // If the "containers" vector is non-empty, the default container should be
60 // listed explicitly.
61 //
62 // Sessions that support resource containers should override this function.
63 virtual Status Reset(const SessionOptions& options,
64 const std::vector<string>& containers) {
65 return errors::Unimplemented("Reset()");
66 }
67
68 virtual ~SessionFactory() {}
69 static void Register(const string& runtime_type, SessionFactory* factory);
70 static Status GetFactory(const SessionOptions& options,
71 SessionFactory** out_factory);
72};
73
74} // namespace tensorflow
75
76#endif // TENSORFLOW_CORE_COMMON_RUNTIME_SESSION_FACTORY_H_
77