#include "enco/Backend.h"
+#include "Session.h"
+
#include "Code.h"
#include "CppCode.h"
void BackendImpl::compile(coco::Module *m, coco::Data *d)
{
+ make_session(m, d);
+
Code code{m, d};
// As explained below, the current implementation does not work if there is a pair of input/ouput
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Session.h"
+
+#include <nncc/foundation/Memory.h>
+
+#include <map>
+#include <memory>
+
+using nncc::foundation::make_unique;
+
+namespace
+{
+
+std::map<enco::SessionID, std::unique_ptr<enco::Code>> sess_to_code;
+std::map<const coco::Module *, enco::SessionID> module_to_sess;
+std::map<const coco::Data *, enco::SessionID> data_to_sess;
+
+} // namespace
+
+namespace enco
+{
+
+SessionID make_session(coco::Module *m, coco::Data *d)
+{
+ static uint32_t sess = 0;
+ SessionID curr{sess++};
+
+ sess_to_code[curr] = make_unique<Code>(m, d);
+ module_to_sess[m] = curr;
+ data_to_sess[d] = curr;
+
+ return curr;
+}
+
+SessionID session(const coco::Module *m) { return module_to_sess.at(m); }
+SessionID session(const coco::Data *d) { return data_to_sess.at(d); }
+
+coco::Module *module(const SessionID &sess) { return sess_to_code.at(sess)->module(); }
+coco::Data *data(const SessionID &sess) { return sess_to_code.at(sess)->data(); }
+
+Code *code(const SessionID &sess) { return sess_to_code.at(sess).get(); }
+
+} // namespace enco
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __ENCO_SESSION_H__
+#define __ENCO_SESSION_H__
+
+#include "Code.h"
+
+namespace enco
+{
+
+// TODO Rewrite this definition
+using SessionID = uint32_t;
+
+SessionID make_session(coco::Module *m, coco::Data *d);
+
+SessionID session(const coco::Module *m);
+SessionID session(const coco::Data *d);
+
+coco::Module *module(const SessionID &);
+coco::Data *data(const SessionID &);
+
+static inline coco::Module *module(const coco::Data *d) { return module(session(d)); }
+static inline coco::Data *data(const coco::Module *m) { return data(session(m)); }
+
+// WARN This API is introduced just for backward compatibility
+// Do NOT use this anymore as it will be removed
+Code *code(const SessionID &);
+
+} // namespace enco
+
+#endif // __ENCO_SESSION_H__
#include "Split.h"
#include "Usage.h"
+#include "Session.h"
#include <coco/IR.h>
class ANNOpBuilder : public coco::Instr::Visitor<Appender>
{
public:
- ANNOpBuilder(coco::Data *data) : _data{data}
+ // TODO Revise this constructor
+ ANNOpBuilder(coco::Data *data)
{
// DO NOTHING
}
private:
Appender conv2d(const coco::UnitF *unit) const
{
- auto _data = this->_data;
assert(unit->op()->asConv2D());
// TODO Rename "_binder"
- return [unit, _data](ANNBinder *_binder) {
+ return [unit](ANNBinder *_binder) {
+ auto _data = enco::data(unit->module());
auto conv = unit->op()->asConv2D();
auto ifm = _binder->addOperand<float>(unit->ifm());
auto ker = _binder->addOperand<float>(conv->ker());
{
using namespace nncc::core::ADT;
- auto data = this->_data;
assert(unit->op()->asConv2D());
- return [unit, data](ANNBinder *binder) {
+ return [unit](ANNBinder *binder) {
+ auto data = enco::data(unit->module());
auto conv = unit->op()->asConv2D();
assert(unit->ifm()->shape().depth() == conv->group());
};
}
-
-private:
- coco::Data *const _data;
};
namespace