Poplar and PopLibs
OperationDefUtil.hpp
Go to the documentation of this file.
1// Copyright (c) 2021 Graphcore Ltd. All rights reserved.
8#ifndef popops_OperationDefUtil_hpp
9#define popops_OperationDefUtil_hpp
10
11#include <popops/Operation.hpp>
14
15namespace poputil {
16
17inline const char *asString(const popops::Operation &op) {
18 switch (op) {
19 case popops::Operation::ADD:
20 return "Add";
21 case popops::Operation::MUL:
22 return "Mul";
23 case popops::Operation::MIN:
24 return "Min";
25 case popops::Operation::MAX:
26 return "Max";
28 return "Logical And";
30 return "Logical Or";
32 return "Square Add";
34 return "Log Add";
35 }
36 throw poputil::poplibs_error("Unsupported operation type");
37}
38
40template <> struct VertexTemplateToString<popops::Operation> {
41 static std::string to_string(const popops::Operation &op) {
42 switch (op) {
43 case popops::Operation::ADD:
44 return "popops::Operation::ADD";
45 case popops::Operation::MUL:
46 return "popops::Operation::MUL";
47 case popops::Operation::MIN:
48 return "popops::Operation::MIN";
49 case popops::Operation::MAX:
50 return "popops::Operation::MAX";
52 return "popops::Operation::LOGICAL_AND";
54 return "popops::Operation::LOGICAL_OR";
56 return "popops::Operation::SQUARE_ADD";
58 return "popops::Operation::LOG_ADD";
59 }
60 throw poputil::poplibs_error("Unsupported operation type");
61 }
62};
63
64} // end namespace poputil
65#endif // popops_OperationDefUtil_hpp
Read/write types of operations used in a reduce.
Generate a string describing a vertex type.
Common functions, such as elementwise and reductions.
Definition: AllTrue.hpp:15
Operation
Type of operation to use in a reduction.
Definition: OperationDef.hpp:15
@ LOGICAL_OR
Only supports boolean operands.
@ LOG_ADD
Reduce using acc = a+log(1+exp(b-a))
@ SQUARE_ADD
Squares each element before applying ADD reduction.
@ LOGICAL_AND
Only supports boolean operands.
General utility functions for building graphs.
Definition: GfloatExprUtil.hpp:23
Define a PopLibs exception.
Class for PopLibs exceptions.
Definition: exceptions.hpp:17