7. Class¶
7.1. Builder¶
-
std::ostream &operator<<(std::ostream &out, Builder builder)¶
Feed the built IR to the specific output stream.
-
class topsgraph::Builder¶
- #include <hlir_builder_common.h>
This class helps build IR, which consist of Ops.
Public Functions
-
bool IsDynamic() const¶
Judge if the build function is dynamic shape.
- Param
-
void SetFuncAttribute(const char *name, const Attribute &value)¶
Set function attribute parameters.
- Parameters
name -- attribute name
value -- attribute object
-
const Attribute GetFuncAttribute(const char *name) const¶
get function attribute parameters info.
- Parameters
name -- attribute name
- Returns
attribute object
-
void Print(std::ostream &out) const¶
Print the built IR to the specific output stream.
- Parameters
out -- Output stream
flags -- Print flag
-
void Dump() const¶
Print the built IR to stdout.
-
std::shared_ptr<Impl> GetImpl() const¶
pimpl, only used for internal developers.
-
bool HaveFunc(const char *func_name) const¶
Does the function name already exist.
- Parameters
func_name -- Name of the specific Function
- Returns
Returns true if it exists, otherwise returns false
-
bool IsDynamicShape(const char *func_name)¶
Judge if the function is of dynamic shape.
- Parameters
func_name -- the specified function name, default is main
- Returns
Judge result
- Returns
true -- the inputs of the specified func is of dynamic shape
false -- the inputs of the specified func is of static shape
-
std::shared_ptr<hlir::Module> GetModule()¶
Get built IR as hlir::Module instance.
- Returns
Built IR as hlir::Module instance
-
std::shared_ptr<char> GetModuleStr() const¶
Get the built IR string.
- Parameters
flags -- Print flag. Default: PrintingFlags::None.
- Returns
Built IR string.
-
std::size_t GetModuleHash() const¶
Get Built hlir::Module Hash.
- Returns
Built hlir::Module Hash.
-
Attribute GetModuleAttribute(const char *name) const¶
get module attribute parameters info.
- Parameters
name -- attribute name
- Returns
attribute object
-
Attribute GetFuncAttribute(const char *func_name, const char *name) const¶
get function attribute parameters info.
- Parameters
func_name -- Name of the specific Function
name -- attribute name
- Returns
attribute object
-
void SetModuleAttribute(const char *name, const Attribute &value)¶
Set module attribute parameters.
- Parameters
name -- attribute name
value -- attribute object
-
void SetModuleAttribute(const char *name, const std::vector<Attribute> &value)¶
Set module array attribute parameters.
- Parameters
name -- attribute name
value -- vector of attribute object
-
void SetFuncAttribute(const char *func_name, const char *name, const Attribute &value)¶
Set function attribute parameters.
- Parameters
func_name -- Name of the specific Function
name -- attribute name
value -- attribute object
-
void SetFuncAttribute(const char *func_name, const char *name, const std::vector<Attribute> &value)¶
Set function array attribute parameters.
- Parameters
func_name -- Name of the specific Function
name -- attribute name
value -- vector of attribute object
-
void SetMaxMinShape(const std::vector<std::vector<int64_t>> &max_shapes, const std::vector<std::vector<int64_t>> &min_shapes)¶
Set Dynamic input's max_shape_dim, min_shape_dim attributes. If the input dim is not unknown dim, the value in max_shape_dim and min_shape_dim is same, and equal to the real dim.
- Parameters
max_shapes -- input's max_shape_dims. max_shapes.size equal to the count of input op.
min_shapes -- input's min_shape_dims. min_shapes.size equal to the count of input op.
-
Op CreateInput(const Type &type, const char *func_name =
"main")¶ Create an input Op for a Function. You can smiply consider a Function as a C++ function which consist of Ops.
-
Op CreateInput(const Type &type, const std::vector<const char*> &symbolic_dims)¶
create an input op for 'main' function with symbolic dims.
ex1. input type: -1x1x3xf32, symbolic_dims is {"s0", "1", "3"} ex2. input type: f32, symbolic_dims is {} ex3. input type: 1x2xf32, symbolic_dims is {} or {"1", "2"}
-
bool IsDynamic() const¶
7.2. Type¶
-
std::ostream &operator<<(std::ostream &out, Type type)¶
Feed the Type information to the specific output stream.
-
class topsgraph::Type¶
- #include <hlir_builder_common.h>
This represents the output type of an Op. It contains the information of both the shape and the primitive type.
Public Functions
-
explicit Type(const PrimitiveType &primitive_type)¶
Constructor of an scalar Type.
- Parameters
primitive_type -- Data type of the scalar
-
bool IsDynamic() const¶
Judge if it's dynamic, i.e. with unknown dim shape or unrank.
- Returns
Judge result
- Returns
true -- Dynamic shape
false -- Static shape
-
bool IsTuple() const¶
Judge if it's a tuple type.
- Returns
Judge result
- Returns
true -- tuple
false -- others
-
const Shape GetShape() const¶
Get the shape.
- Returns
the shape
-
const PrimitiveType GetPrimitiveType() const¶
Get the data type.
- Returns
the data type
-
void Print(std::ostream &out) const¶
Print the Type information to the specific output stream.
- Parameters
out -- Output stream
-
bool operator==(const Type &other) const¶
Overloaded operator "==" to judge if 2 Type are the same.
- Parameters
type -- another Type instance
- Returns
Judge result
- Returns
true -- shape and primitive type are the same
false -- otherwise
-
bool operator!=(const Type &other) const¶
Overloaded operator "!=" to judge if 2 Type are different.
- Parameters
type -- another Type instance
- Returns
Judge result
- Returns
true -- shape or primitive type is different
false -- otherwise
-
std::shared_ptr<Impl> GetImpl() const¶
pimpl, only used for internal developers.
-
Type(const std::vector<int64_t> &shape, const PrimitiveType &primitive_type)¶
Constructor of an tensor Type.
- Parameters
shape -- Shape of the tensor
primitive_type -- Data type of the tensor
-
Type(const std::vector<std::vector<int64_t>> &shape, const std::vector<PrimitiveType> &primitive_type)¶
Constructor of an tuple Type.
- Parameters
shape -- Shape of the tuple
primitiveType -- Data type of the tuple
-
explicit Type(const std::vector<Type*> &types)¶
Constructor of an tuple Type.
- Parameters
types -- Vector of Type pointers
-
bool IsEmpty() const¶
Judge if it's empty, i.e. with empty shape and NONE data type.
-
void SetShape(const std::vector<int64_t> &shape)¶
Set the shape.
- Parameters
shape -- the shape
-
void AddDimSize(int64_t size)¶
Add a dimension at the back of the shape.
- Parameters
size -- the size to be added
-
void SetDimSize(int index, int64_t size)¶
Set the size of the specified dimension.
- Parameters
index -- the index of the specified dimension
size -- the size of the specified dimension
-
void SetPrimitiveType(const PrimitiveType &prim_type)¶
Set the data type.
- Parameters
prim_type -- the data type
-
int64_t GetTupleSize() const¶
Get the element number for the TUPLE type.
- Returns
0 if it is not a TUPLE, else the element number for the TUPLE
-
std::vector<std::vector<int64_t>> GetTupleShapes() const¶
Get the shapes or the TUPLE type.
- Returns
the shapes
-
std::vector<PrimitiveType> GetTuplePrimitiveTypes() const¶
Get the data types or the TUPLE type.
- Returns
the data types
-
int64_t GetDimSize(int index) const¶
Get the size of the specified dimension.
- Parameters
index -- the index of the specified dimension
- Returns
the size of the specified dimension
-
int64_t GetRank() const¶
Get the rank.
- Returns
the rank
-
int64_t GetSize() const¶
Get the total elemnent number.
- Returns
the total elemnent number.
-
explicit Type(const PrimitiveType &primitive_type)¶
7.3. Attribute¶
-
std::ostream &operator<<(std::ostream &out, Attribute attr)¶
Feed the Attribute information to the specific output stream.
-
class topsgraph::Attribute¶
Public Functions
-
explicit Attribute(const char *value)¶
Constructor of an attribute of type string.
- Parameters
value -- Incoming information data
-
explicit Attribute(bool value)¶
Constructor of an attribute of type bool.
- Parameters
value -- Incoming information data
-
explicit Attribute(int32_t value)¶
Constructor of an attribute of type int32_t.
- Parameters
value -- Incoming information data
-
explicit Attribute(int64_t value)¶
Constructor of an attribute of type int64_t.
- Parameters
value -- Incoming information data
-
explicit Attribute(float value)¶
Constructor of an attribute of type float.
- Parameters
value -- Incoming information data
-
explicit Attribute(double value)¶
Constructor of an attribute of type double.
- Parameters
value -- Incoming information data
-
explicit Attribute(Type type, const void *data)¶
Constructor of an attribute of type Dense.
- Parameters
type -- tensor type
data -- dense data pointer
-
void Print(std::ostream &out) const¶
Print the Attribute information to the specific output stream.
- Parameters
out -- Output stream
-
double GetValueAsDouble() const¶
Get the attribute value.
- Returns
If it is float and double type, return value, otherwise return 0.0
-
int64_t GetValueAsInt() const¶
Get the attribute value.
- Returns
If it is integer type, return value, otherwise return 0
-
bool GetValueAsBool() const¶
Get the attribute value.
- Returns
If it is bool type, return value, otherwise return 0
-
const char *GetValueAsString() const¶
Get the attribute value.
- Returns
If it is string type, return value, otherwise return nullptr.
-
std::shared_ptr<void> GetValueAsDataPtr() const¶
Get the attribute value.
- Returns
If it is dense type, return value, otherwise return 0
-
explicit Attribute(const char *value)¶
7.4. Op¶
-
std::ostream &operator<<(std::ostream &out, Op op)¶
Feed the Attribute information to the specific output stream.
-
class topsgraph::Op¶
- #include <hlir_builder_common.h>
This represents an instruction that has been enqueued using the Builder.
Public Functions
-
bool IsInited() const¶
Judge if this op has been initialized.
- Returns
Judge result
- Returns
true -- a valid op which has been inited.
false -- otherwise
-
bool IsArgument() const¶
Judge if it's an argument.
- Returns
Judge result
- Returns
true -- an argument which corresponding to a mlir::BlockArgument.
false -- otherwise
-
bool IsConstant() const¶
Judge if it's a constant op.
- Returns
Judge result
- Returns
true -- constant op
false -- otherwise
-
bool IsDynamic() const¶
Judge if it's dynamic shape.
- Returns
Judge result
- Returns
true -- dynamic shape
false -- static shape
-
const char *GetName() const¶
Get the op name.
- Returns
The op name, which is a constant char literal.
-
const Attribute GetAttribute(const char *name) const¶
get op attribute parameters info.
- Parameters
name -- attribute name
- Returns
attribute object
-
template<typename T>
inline T GetValue() const¶ get constant op's value.
basic types: bool, int8, int16, ...
dense elements: std::vector<basic types>
- Parameters
T -- const value type. support below types:
-
void Print(std::ostream &out) const¶
Print the Op IR to the specific output stream.
- Parameters
out -- Output stream
flags -- Print flag
-
void Dump() const¶
Dump op info.
-
std::shared_ptr<Impl> GetImpl() const¶
pimpl, only used for internal developers.
-
void SetAttribute(const char *name, const Attribute &value, const char *mode)¶
Set op attribute parameters.
- Parameters
name -- attribute name
value -- attribute object
mode -- mode of setting attribute of accessories. Options: "": do not set the attribute for accessories. "copy": copy the attribute for accessories. "derive": derive the attribute for accessories with postfix "_index", where index starts with 0. Only work for string.
-
void SetAttribute(const char *name, const std::vector<Attribute> &value)¶
Set op array attribute parameters.
- Parameters
name -- attribute name
value -- vector of attribute object
-
bool IsUnknownRank() const¶
Judge if its shape is unknown rank.
- Returns
Judge result
- Returns
true -- unknown rank
false -- otherwise
-
void SetMaxMinShape(const std::vector<int64_t> &max_shape, const std::vector<int64_t> &min_shape)¶
Set Dynamic op's max_shape_dim, min_shape_dim attributes. If the input dim is not unknown dim, the value in max_shape_dim and min_shape_dim is same, and equal to the real dim.
For tuple op, max_shape/min_shape including all outputs.
- Parameters
max_shape -- input's max_shape_dims.
min_shape -- input's min_shape_dims.
-
std::shared_ptr<void> GetConstDataPtr() const¶
Get data pointer of ConstOp.
- Returns
The data pointer of ConstOp, nullptr for other Ops
-
bool IsInited() const¶
7.5. Structs¶
-
class ConvDimensionNumbers¶
- #include <hlir_builder_structs.h>
Structure of dimension information for conv op.
-
class DimensionsLayout¶
- #include <hlir_builder_structs.h>
Structure of dimension information for layout.
-
class DotDimensionNumbers¶
- #include <hlir_builder_structs.h>
Structure of dimension information for dot product.
-
class GatherDimensionNumbers¶
- #include <hlir_builder_structs.h>
Structure of dimension information for gather.
-
class ScatterDimensionNumbers¶
- #include <hlir_builder_structs.h>
Structure of dimension information for scatter.