namespace loco
{
+// TODO Find a proper location for these declarations
+using GraphInputIndex = uint32_t;
+using GraphOutputIndex = uint32_t;
+
/**
* @brief Make a value visible to user
*/
public:
Node *from(void) const { return at(0)->node(); }
void from(Node *node) { at(0)->node(node); }
+
+public:
+ void index(const GraphOutputIndex &index);
+
+ /**
+ * @brief Get associated output index
+ *
+ * The behavior of this method is undefined when "index" is not set before.
+ *
+ * NOTE This method intentionally returns "GraphOutputIndex" instead of "const GraphOutputIndex &"
+ * not to expose the internal implementation details.
+ */
+ GraphOutputIndex index(void) const;
+
+private:
+ int64_t _index = -1; // Uninitialized
};
/**
{
public:
Pull() = default;
+
+public:
+ void index(const GraphInputIndex &index);
+
+ /**
+ * @brief Get associated input index
+ *
+ * The behavior of this method is undefined when "index" is not set before.
+ *
+ * NOTE This method intentionally returns "GraphInputIndex" instead of "const GraphInputIndex &"
+ * not to expose the internal implementation details.
+ */
+ GraphInputIndex index(void) const;
+
+private:
+ int64_t _index = -1; // Uninitialized
};
/**
#include "loco/IR/Nodes.h"
#include <cassert>
+#include <limits>
// This file validates "Nodes.h". Please DO NOT remove this file.
/**
+ * Push
+ */
+namespace loco
+{
+
+void Push::index(const GraphOutputIndex &index)
+{
+ // Push internally stores "GraphOutputIndex" as int64_t
+ _index = static_cast<int64_t>(index);
+}
+
+GraphOutputIndex Push::index(void) const
+{
+ assert(_index >= std::numeric_limits<GraphOutputIndex>::min());
+ assert(_index <= std::numeric_limits<GraphOutputIndex>::max());
+ return static_cast<GraphOutputIndex>(_index);
+}
+
+} // namespace loco
+
+/**
+ * Pull
+ */
+namespace loco
+{
+
+void Pull::index(const GraphInputIndex &index)
+{
+ // Push internally stores "GraphInputIndex" as int64_t
+ _index = static_cast<int64_t>(index);
+}
+
+GraphInputIndex Pull::index(void) const
+{
+ assert(_index >= std::numeric_limits<GraphInputIndex>::min());
+ assert(_index <= std::numeric_limits<GraphInputIndex>::max());
+ return static_cast<GraphInputIndex>(_index);
+}
+
+} // namespace loco
+
+/**
* ConstGen
*/
namespace loco
//
// What is "identity" network?
// - A network simply passes its input as its output
+//
+// TODO Create "Ouput" first and then create "Push" later
TEST(LOCO, identity_network)
{
auto g = loco::make_graph();
graph_output->name("output");
graph_output->node(push_node);
+
+ // Set Input Index
+ pull_node->index(0);
+
+ ASSERT_EQ(pull_node->index(), 0);
+
+ // Set Output Index
+ push_node->index(0);
+
+ ASSERT_EQ(push_node->index(), 0);
}