ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Session.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
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
17#include "Session.h"
18
19#include <map>
20#include <memory>
21
22using std::make_unique;
23
24namespace
25{
26
27std::map<enco::SessionID, std::unique_ptr<enco::Code>> sess_to_code;
28std::map<const coco::Module *, enco::SessionID> module_to_sess;
29std::map<const coco::Data *, enco::SessionID> data_to_sess;
30
31} // namespace
32
33namespace enco
34{
35
37{
38 static uint32_t sess = 0;
39 SessionID curr{sess++};
40
41 sess_to_code[curr] = make_unique<Code>(m, d);
42 module_to_sess[m] = curr;
43 data_to_sess[d] = curr;
44
45 return curr;
46}
47
48SessionID session(const coco::Module *m) { return module_to_sess.at(m); }
49SessionID session(const coco::Data *d) { return data_to_sess.at(d); }
50
51coco::Module *module(const SessionID &sess) { return sess_to_code.at(sess)->module(); }
52coco::Data *data(const SessionID &sess) { return sess_to_code.at(sess)->data(); }
53
54Code *code(const SessionID &sess) { return sess_to_code.at(sess).get(); }
55
56} // namespace enco
Top-level element of coco IR which represents a neural network.
Definition Module.h:34
Definition Bundle.h:26
coco::Data * data(const SessionID &sess)
Definition Session.cpp:52
Code * code(const SessionID &sess)
Definition Session.cpp:54
uint32_t SessionID
Definition Session.h:26
SessionID session(const coco::Module *m)
Definition Session.cpp:48
coco::Module * module(const SessionID &sess)
Definition Session.cpp:51
SessionID make_session(coco::Module *m, coco::Data *d)
Definition Session.cpp:36
Core coco entity for constant weights.
Definition Data.h:31