1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20/*!
21 * \file rpc_local_session.h
22 * \brief Local session that directs all request to the local runtime API.
23 */
24#ifndef TVM_RUNTIME_RPC_RPC_LOCAL_SESSION_H_
25#define TVM_RUNTIME_RPC_RPC_LOCAL_SESSION_H_
26
27#include <tvm/runtime/device_api.h>
28#include <tvm/runtime/packed_func.h>
29
30#include <functional>
31#include <string>
32#include <utility>
33
34#include "rpc_session.h"
35
36namespace tvm {
37namespace runtime {
38
39/*!
40 * \brief A local session that directly use the handle repr of the
41 * local tvm runtime objects on the same process.
42 */
43class LocalSession : public RPCSession {
44 public:
45 // function overrides
46 PackedFuncHandle GetFunction(const std::string& name) override;
47
48 void CallFunc(PackedFuncHandle func, const TVMValue* arg_values, const int* arg_type_codes,
49 int num_args, const FEncodeReturn& fencode_return) override;
50
51 void CopyToRemote(void* from_bytes, DLTensor* to, uint64_t nbytes) override;
52
53 void CopyFromRemote(DLTensor* from, void* to_bytes, uint64_t nbytes) override;
54
55 void FreeHandle(void* handle, int type_code) override;
56
57 DeviceAPI* GetDeviceAPI(Device dev, bool allow_missing = false) override;
58
59 bool IsLocalSession() const override { return true; }
60
61 protected:
62 /*!
63 * \brief internal encode return function.
64 * \param rv The return value.
65 * \param encode_return The encoding function.
66 */
67 void EncodeReturn(TVMRetValue rv, const FEncodeReturn& encode_return);
68};
69
70} // namespace runtime
71} // namespace tvm
72#endif // TVM_RUNTIME_RPC_RPC_LOCAL_SESSION_H_
73