Poplar and PopLibs
VertexTemplates.hpp
Go to the documentation of this file.
1// Copyright (c) 2016 Graphcore Ltd. All rights reserved.
8#ifndef poputil_VertexTemplates_hpp
9#define poputil_VertexTemplates_hpp
10#include <poplar/Type.hpp>
11#include <string>
12
13namespace poputil {
14
15inline std::string templateVertexParams(bool first) {
16 if (first)
17 return "";
18 else
19 return ">";
20}
21
22template <typename... Args>
23inline std::string templateVertexParams(bool first, const std::string &val,
24 Args &&...args);
25
26template <typename... Args>
27inline std::string templateVertexParams(bool first, const char *val,
28 Args &&...args);
29
30template <typename... Args>
31inline std::string templateVertexParams(bool first, const poplar::Type &type,
32 Args &&...args);
33
34template <typename... Args>
35inline std::string templateVertexParams(bool first, bool b, Args &&...args);
36
37template <typename T> struct VertexTemplateToString {
38 static std::string to_string(const T &x) { return std::to_string(x); }
39};
40
41template <> struct VertexTemplateToString<poplar::StringRef> {
42 static std::string to_string(const poplar::StringRef &ref) { return ref; }
43};
44
45template <typename T, typename... Args>
46inline std::string templateVertexParams(bool first, const T &val,
47 Args &&...args) {
48 std::string p = first ? "<" : ",";
49 p += VertexTemplateToString<T>::to_string(val) +
50 templateVertexParams(false, std::forward<Args>(args)...);
51 return p;
52}
53
54template <typename... Args>
55inline std::string templateVertexParams(bool first, const poplar::Type &type,
56 Args &&...args) {
57 std::string p = first ? "<" : ",";
58 p += type.toString() +
59 templateVertexParams(false, std::forward<Args>(args)...);
60 return p;
61}
62
63template <typename... Args>
64inline std::string templateVertexParams(bool first, const std::string &val,
65 Args &&...args) {
66 std::string p = first ? "<" : ",";
67 p += val + templateVertexParams(false, std::forward<Args>(args)...);
68 return p;
69}
70
71template <typename... Args>
72inline std::string templateVertexParams(bool first, const char *val,
73 Args &&...args) {
74 std::string p = first ? "<" : ",";
75 p += val + templateVertexParams(false, std::forward<Args>(args)...);
76 return p;
77}
78
79template <typename... Args>
80inline std::string templateVertexParams(bool first, bool b, Args &&...args) {
81 std::string p = first ? "<" : ",";
82 auto bstr = (b ? "true" : "false");
83 p += bstr + templateVertexParams(false, std::forward<Args>(args)...);
84 return p;
85}
86
95template <typename... Args>
96inline std::string templateVertex(const std::string &name, Args &&...args) {
97 return name + templateVertexParams(true, std::forward<Args>(args)...);
98}
99
100} // namespace poputil
101
102#endif // poputil_VertexTemplates_hpp
Class representing device data types.
Definition: Type.hpp:42
StringRef toString() const
Get a string representation on a type.
Poplar classes and functions.
Definition: ArrayRef.hpp:14
General utility functions for building graphs.
Definition: GfloatExprUtil.hpp:23
std::string templateVertex(const std::string &name, Args &&...args)
Generate a string representation of a Vertex type for use by poplar::Graph::addVertex().
Definition: VertexTemplates.hpp:96