Poplar and PopLibs
GraphElements.hpp
1// Copyright (c) 2015 Graphcore Ltd. All rights reserved.
2
3#ifndef poplar_GraphElements_hpp
4#define poplar_GraphElements_hpp
5
6#include <memory>
7#include <poplar/StringRef.hpp>
8
9namespace poplar {
10namespace core {
11class GraphBuilder;
12}
13class Graph;
14
19typedef unsigned vertex_id;
20
21class FieldRef;
22
27class VertexRef {
28 const core::GraphBuilder *graph;
29 vertex_id id;
30
31public:
32 VertexRef() {}
33
40 FieldRef operator[](StringRef fieldName) const;
41
42 vertex_id getId() const { return id; }
43
44private:
50 VertexRef(const core::GraphBuilder *graph, unsigned id)
51 : graph(graph), id(id) {}
52
53 friend class core::GraphBuilder;
54 friend class Graph;
55 friend class FieldRef;
56};
57
75class FieldRef {
76public:
77 // The vertex instance this field ref is for.
78 VertexRef vertex;
79 // The ID of the field within the vertex.
80 unsigned fieldId;
81 // If `indexed` is true this gives the value of the index, otherwise
82 // it is ignored.
83 std::size_t index;
84 // True if this is a references to a sub-element of the field.
85 bool indexed;
86
87 FieldRef() {}
88
95 FieldRef operator[](std::size_t index) const {
96 return FieldRef(vertex, fieldId, index);
97 }
98
99 bool isIndexed() const { return indexed; }
100 std::size_t getIndex() const { return index; }
101
102private:
108 FieldRef(VertexRef vertex, StringRef fieldName);
109
110 FieldRef(VertexRef vertex, unsigned fieldId);
111
116 FieldRef(VertexRef vertex, StringRef fieldName, std::size_t index);
117
118 FieldRef(VertexRef vertex, unsigned fieldId, std::size_t index);
119
120 friend class VertexRef;
121};
122
123inline FieldRef VertexRef::operator[](StringRef fieldName) const {
124 return FieldRef(*this, fieldName);
125}
126
132 unsigned computeset_id;
133
134public:
135 ComputeSet() {}
136
137 ComputeSet(unsigned id) : computeset_id(id) {}
138 unsigned getId() const { return computeset_id; }
139};
140
141inline bool operator==(const ComputeSet &lhs, const ComputeSet &rhs) {
142 return lhs.getId() == rhs.getId();
143}
144
148class Function {
149 unsigned function_id;
150
151public:
152 Function() {}
153
154 Function(unsigned id) : function_id(id) {}
155 unsigned getId() const { return function_id; }
156};
157
158inline bool operator==(const Function &lhs, const Function &rhs) {
159 return lhs.getId() == rhs.getId();
160}
161
165 unsigned function_buffer_id;
166
167public:
168 FunctionBuffer() {}
169 explicit FunctionBuffer(unsigned id) : function_buffer_id(id) {}
170 unsigned getId() const { return function_buffer_id; }
171};
172
173inline bool operator==(const FunctionBuffer &lhs, const FunctionBuffer &rhs) {
174 return lhs.getId() == rhs.getId();
175}
176
180 unsigned function_id;
181
182public:
183 HostFunction(unsigned id) : function_id(id) {}
184 unsigned getId() const { return function_id; }
185};
186
187} // End namespace poplar.
188
189#endif // poplar_GraphElements_hpp
A reference to a compute set within a graph.
Definition: GraphElements.hpp:131
A reference to a field within a vertex instance.
Definition: GraphElements.hpp:75
FieldRef operator[](std::size_t index) const
Access an element of a vector field.
Definition: GraphElements.hpp:95
A reference to a function buffer stored within a graph.
Definition: GraphElements.hpp:164
A reference to a function stored within a graph.
Definition: GraphElements.hpp:148
This class represents a graph program to be executed on the IPU.
Definition: Graph.hpp:52
A reference to a function in the host.
Definition: GraphElements.hpp:179
A reference to a vertex within a graph.
Definition: GraphElements.hpp:27
FieldRef operator[](StringRef fieldName) const
Access a field by name.
Definition: GraphElements.hpp:123
Poplar classes and functions.
Definition: ArrayRef.hpp:14
unsigned vertex_id
Vertex id.
Definition: GraphElements.hpp:13