1/**
2 * Copyright (c) Glow Contributors. See CONTRIBUTORS file.
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 GLOW_RUNTIME_EXECUTOR_H
17#define GLOW_RUNTIME_EXECUTOR_H
18
19#include "glow/Runtime/RuntimeTypes.h"
20
21#include <functional>
22#include <map>
23#include <memory>
24
25namespace glow {
26namespace runtime {
27
28/// This is an interface to an executor that can run and results the results of
29/// a partitioned graph.
30class Executor {
31public:
32 /// Destructor.
33 virtual ~Executor() = default;
34
35 /// Run the DAG specified by \p root using \p bindings and call \cb with the
36 /// results. \p runId is used to identify the run for logging and metrics
37 /// purposes.
38 /// cb will be called with a result code, the run ID and a PlaceholderBindings
39 /// containing placeholder-tensor mappings for the nodes in the DAG that have
40 /// no postrequisites (i.e. the final results) in addition to the mappings
41 /// present in \p bindings.
42 virtual void run(const DAGNode *root,
43 std::unique_ptr<ExecutionContext> context,
44 RunIdentifierTy runId, ResultCBTy cb) = 0;
45
46 /// Shutdown the Executor. Should block until all active requests are complete
47 /// and prevent new requests from being initiated.
48 virtual void shutdown() = 0;
49
50 /// Setup context pool for new network.
51 virtual void createPool(const DAGNode *root, unsigned poolSize,
52 bool enableP2P, bool enableDRT) = 0;
53
54 /// Free the context pool for given network.
55 virtual void freePool(const DAGNode *root) = 0;
56};
57
58} // namespace runtime
59} // namespace glow
60#endif
61