Tosa
tosa
¶
TInv = TypeVar('TInv', bound=TensorType)
module-attribute
¶
TOSA = Dialect('tosa', [ClampOp, ConstOp, RescaleOp, AddOp, SubOp, MulOp, SinOp, CosOp, ReciprocalOp, ReduceAllOp, ReduceAnyOp, ReduceMaxOp, ReduceMinOp, ReduceProductOp, ReduceSumOp, MatMulOp, MaxPool2DOp, AvgPool2DOp, ConcatOp, IfOp, YieldOp], [NanModeAttr, RoundingModeAttr])
module-attribute
¶
RoundingModeAttr
dataclass
¶
Bases: EnumAttribute[RoundingMode]
Rounding mode for tosa.rescale
See external documentation.
Source code in xdsl/dialects/tosa.py
NanMode
¶
NanModeAttr
dataclass
¶
Bases: EnumAttribute[NanMode]
Supported NaN propagation strategies See external documentation.
Source code in xdsl/dialects/tosa.py
ClampOp
dataclass
¶
Bases: IRDLOperation
Computes clamp(features, min, max)
See external documentation
Source code in xdsl/dialects/tosa.py
name = 'tosa.clamp'
class-attribute
instance-attribute
¶
T: VarConstraint = VarConstraint('T', AnyAttr())
class-attribute
¶
VALUE: AttrConstraint = IntegerAttr.constr(type=SignlessIntegerConstraint & T) | FloatAttr.constr(type=AnyFloatConstr & T)
class-attribute
¶
min_val = prop_def(VALUE)
class-attribute
instance-attribute
¶
max_val = prop_def(VALUE)
class-attribute
instance-attribute
¶
nan_mode = opt_prop_def(NanModeAttr, default_value=NanModeAttr(NanMode.PROPAGATE))
class-attribute
instance-attribute
¶
input = operand_def(TensorType.constr(T))
class-attribute
instance-attribute
¶
output = result_def(TensorType.constr(T))
class-attribute
instance-attribute
¶
irdl_options = (ParsePropInAttrDict(),)
class-attribute
instance-attribute
¶
assembly_format = '$input attr-dict `:` `(` type($input) `)` `->` type($output)'
class-attribute
instance-attribute
¶
ConstOp
¶
Bases: IRDLOperation
TOSA const operation.
See external documentation.
Source code in xdsl/dialects/tosa.py
RescaleOp
dataclass
¶
Bases: IRDLOperation
Tosa Rescale Operator
See external documentation
Source code in xdsl/dialects/tosa.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
name = 'tosa.rescale'
class-attribute
instance-attribute
¶
scale32 = prop_def(BoolAttr)
class-attribute
instance-attribute
¶
rounding_mode = prop_def(RoundingModeAttr, default_value=RoundingModeAttr(RoundingMode.SINGLE_ROUND))
class-attribute
instance-attribute
¶
per_channel = prop_def(BoolAttr)
class-attribute
instance-attribute
¶
input_unsigned = prop_def(BoolAttr)
class-attribute
instance-attribute
¶
output_unsigned = prop_def(BoolAttr)
class-attribute
instance-attribute
¶
input = operand_def(TensorType)
class-attribute
instance-attribute
¶
multiplier = operand_def(TensorType)
class-attribute
instance-attribute
¶
shift = operand_def(TensorType)
class-attribute
instance-attribute
¶
input_zp = operand_def(TensorType)
class-attribute
instance-attribute
¶
output_zp = operand_def(TensorType)
class-attribute
instance-attribute
¶
output = result_def(TensorType)
class-attribute
instance-attribute
¶
irdl_options = (ParsePropInAttrDict(),)
class-attribute
instance-attribute
¶
print(printer: Printer)
¶
Source code in xdsl/dialects/tosa.py
parse(parser: Parser)
classmethod
¶
Source code in xdsl/dialects/tosa.py
ElementwiseOperation
dataclass
¶
Bases: IRDLOperation, ABC
Abstract superclass for elementwise TOSA operations
Source code in xdsl/dialects/tosa.py
ElementwiseBinaryOperation
dataclass
¶
Bases: ElementwiseOperation
Abstract superclass for elementwise, binary TOSA operations.
Source code in xdsl/dialects/tosa.py
T: ClassVar = VarConstraint('T', AnyAttr())
class-attribute
instance-attribute
¶
input1 = operand_def(TensorType.constr(T))
class-attribute
instance-attribute
¶
input2 = operand_def(TensorType.constr(T))
class-attribute
instance-attribute
¶
output = result_def(TensorType.constr(T))
class-attribute
instance-attribute
¶
verify_() -> None
¶
Source code in xdsl/dialects/tosa.py
AddOp
dataclass
¶
Bases: ElementwiseBinaryOperation
Tosa elementwise add operation
See external documentation
Source code in xdsl/dialects/tosa.py
SubOp
dataclass
¶
Bases: ElementwiseBinaryOperation
Tosa elementwise subtraction operation
See external documentation
Source code in xdsl/dialects/tosa.py
name = 'tosa.sub'
class-attribute
instance-attribute
¶
MulOp
dataclass
¶
Bases: ElementwiseOperation
Tosa elementwise multiplication operation (Hadamard product)
See external documentation
Source code in xdsl/dialects/tosa.py
name = 'tosa.mul'
class-attribute
instance-attribute
¶
traits = traits_def(Commutative())
class-attribute
instance-attribute
¶
T: ClassVar = VarConstraint('T', AnyAttr())
class-attribute
instance-attribute
¶
input1 = operand_def(TensorType.constr(T))
class-attribute
instance-attribute
¶
input2 = operand_def(TensorType.constr(T))
class-attribute
instance-attribute
¶
shift = operand_def(TensorType[I8])
class-attribute
instance-attribute
¶
output = result_def(TensorType.constr(T))
class-attribute
instance-attribute
¶
verify_() -> None
¶
Source code in xdsl/dialects/tosa.py
ElementwiseUnaryOperation
dataclass
¶
Bases: ElementwiseOperation, Generic[TInv]
Abstract base class for elementwise unary operations on tensors of floating-point types
Source code in xdsl/dialects/tosa.py
SinOp
dataclass
¶
Bases: ElementwiseUnaryOperation[TensorType[AnyFloat]]
TOSA dialect operation computing sin(x) for each element in a tensor
See external documentation
Source code in xdsl/dialects/tosa.py
name = 'tosa.sin'
class-attribute
instance-attribute
¶
CosOp
dataclass
¶
Bases: ElementwiseUnaryOperation[TensorType[AnyFloat]]
TOSA dialect operation computing cos(x) for each element in a tensor
See external documentation
Source code in xdsl/dialects/tosa.py
name = 'tosa.cos'
class-attribute
instance-attribute
¶
ReciprocalOp
dataclass
¶
Bases: ElementwiseUnaryOperation[TensorType]
Elementwise reciprocal operation.
Source code in xdsl/dialects/tosa.py
name = 'tosa.reciprocal'
class-attribute
instance-attribute
¶
MatMulOp
dataclass
¶
Bases: IRDLOperation
TOSA dialect operation for computing 2D matmuls. Expects 3D tensors as input with leading rank of 1 element, e.g.
tensor<1x14x19xf32> * tensor<1x19x28xf32> -> tensor<1x14x28xf32>
The operands a_zp and b_zp are the zero-point which are used for quantized operations, can be set to 0.0 for no effect.
See external documentation.
Source code in xdsl/dialects/tosa.py
name = 'tosa.matmul'
class-attribute
instance-attribute
¶
T: ClassVar = VarConstraint('T', AnyAttr())
class-attribute
instance-attribute
¶
a = operand_def(TensorType.constr(T))
class-attribute
instance-attribute
¶
b = operand_def(TensorType.constr(T))
class-attribute
instance-attribute
¶
a_zp = operand_def(TensorType.constr(T))
class-attribute
instance-attribute
¶
b_zp = operand_def(TensorType.constr(T))
class-attribute
instance-attribute
¶
output = result_def(TensorType.constr(T))
class-attribute
instance-attribute
¶
assembly_format = 'operands attr-dict `:` functional-type(operands, results)'
class-attribute
instance-attribute
¶
traits = traits_def(Pure())
class-attribute
instance-attribute
¶
verify_() -> None
¶
Source code in xdsl/dialects/tosa.py
MaxPool2DOp
dataclass
¶
Bases: IRDLOperation
TOSA dialect operation for performing 2D max pooling on a tensor.
See external documentation.
Source code in xdsl/dialects/tosa.py
name = 'tosa.max_pool2d'
class-attribute
instance-attribute
¶
T: ClassVar = VarConstraint('T', AnyAttr())
class-attribute
instance-attribute
¶
input = operand_def(TensorType.constr(T))
class-attribute
instance-attribute
¶
output = result_def(TensorType.constr(T))
class-attribute
instance-attribute
¶
kernel = prop_def(DenseArrayBase[I64])
class-attribute
instance-attribute
¶
stride = prop_def(DenseArrayBase[I64])
class-attribute
instance-attribute
¶
pad = prop_def(DenseArrayBase[I64])
class-attribute
instance-attribute
¶
nan_mode = opt_prop_def(NanModeAttr, default_value=NanModeAttr(NanMode.PROPAGATE))
class-attribute
instance-attribute
¶
irdl_options = (ParsePropInAttrDict(),)
class-attribute
instance-attribute
¶
assembly_format = 'operands attr-dict `:` functional-type(operands, results)'
class-attribute
instance-attribute
¶
AvgPool2DOp
dataclass
¶
Bases: IRDLOperation
TOSA dialect operation for performing 2D average pooling on a tensor.
See external documentation.
Source code in xdsl/dialects/tosa.py
name = 'tosa.avg_pool2d'
class-attribute
instance-attribute
¶
input = operand_def(TensorType)
class-attribute
instance-attribute
¶
input_zp = operand_def(TensorType)
class-attribute
instance-attribute
¶
output_zp = operand_def(TensorType)
class-attribute
instance-attribute
¶
kernel = prop_def(DenseArrayBase)
class-attribute
instance-attribute
¶
stride = prop_def(DenseArrayBase)
class-attribute
instance-attribute
¶
pad = prop_def(DenseArrayBase)
class-attribute
instance-attribute
¶
acc_type = prop_def(TypeAttribute)
class-attribute
instance-attribute
¶
output = result_def(TensorType)
class-attribute
instance-attribute
¶
irdl_options = (ParsePropInAttrDict(),)
class-attribute
instance-attribute
¶
assembly_format = 'operands attr-dict `:` functional-type(operands, results)'
class-attribute
instance-attribute
¶
ConcatOp
¶
Bases: IRDLOperation
TOSA dialect operation for concatenating tensors.
See external documentation.
Source code in xdsl/dialects/tosa.py
name = 'tosa.concat'
class-attribute
instance-attribute
¶
tensors = var_operand_def(TensorType)
class-attribute
instance-attribute
¶
axis = prop_def(IntegerAttr[I32])
class-attribute
instance-attribute
¶
output = result_def(TensorType)
class-attribute
instance-attribute
¶
irdl_options = (ParsePropInAttrDict(),)
class-attribute
instance-attribute
¶
assembly_format = '$tensors attr-dict `:` `(` type($tensors) `)` `->` type($output)'
class-attribute
instance-attribute
¶
__init__(tensors: Sequence[SSAValue], axis: IntegerAttr, output_type: TensorType)
¶
YieldOp
dataclass
¶
Bases: IRDLOperation
TOSA operation for returning out of conditional and body of structured control flow
Source code in xdsl/dialects/tosa.py
name = 'tosa.yield'
class-attribute
instance-attribute
¶
inputs = var_operand_def(TensorType)
class-attribute
instance-attribute
¶
traits = lazy_traits_def(lambda: (IsTerminator(), HasParent(IfOp), Pure()))
class-attribute
instance-attribute
¶
assembly_format = '$inputs attr-dict `:` type($inputs)'
class-attribute
instance-attribute
¶
Outputs
dataclass
¶
Bases: CustomDirective
Source code in xdsl/dialects/tosa.py
IfOp
dataclass
¶
Bases: IRDLOperation
Conditional operation on tensors.
Source code in xdsl/dialects/tosa.py
name = 'tosa.cond_if'
class-attribute
instance-attribute
¶
cond = operand_def(TensorType(i1, []))
class-attribute
instance-attribute
¶
output = var_result_def(TensorType)
class-attribute
instance-attribute
¶
true_region = region_def('single_block')
class-attribute
instance-attribute
¶
false_region = region_def('single_block')
class-attribute
instance-attribute
¶
traits = traits_def(RecursiveMemoryEffect(), SingleBlockImplicitTerminator(YieldOp))
class-attribute
instance-attribute
¶
custom_directives = (Outputs,)
class-attribute
instance-attribute
¶
assembly_format = '$cond `:` type($cond) `->` custom<Outputs>(type($output)) $true_region `else` $false_region attr-dict'
class-attribute
instance-attribute
¶
ReductionOperation
dataclass
¶
Bases: IRDLOperation, ABC
Base class for all TOSA reduction operations
Source code in xdsl/dialects/tosa.py
input = operand_def(TensorType)
class-attribute
instance-attribute
¶
axis = prop_def(IntegerAttr[I32])
class-attribute
instance-attribute
¶
output = result_def(TensorType)
class-attribute
instance-attribute
¶
assembly_format = '$input attr-dict `:` functional-type(operands, results)'
class-attribute
instance-attribute
¶
irdl_options = (ParsePropInAttrDict(),)
class-attribute
instance-attribute
¶
ReduceAllOp
dataclass
¶
Bases: ReductionOperation
Reduce a tensor along the given axis with a logical AND operation
Source code in xdsl/dialects/tosa.py
name = 'tosa.reduce_all'
class-attribute
instance-attribute
¶
ReduceAnyOp
dataclass
¶
Bases: ReductionOperation
Reduce a tensor along the given axis with a logical OR operation
Source code in xdsl/dialects/tosa.py
name = 'tosa.reduce_any'
class-attribute
instance-attribute
¶
ReduceMaxOp
dataclass
¶
Bases: ReductionOperation
Reduce a tensor along the given axis by taking the maximum value
Source code in xdsl/dialects/tosa.py
ReduceMinOp
dataclass
¶
Bases: ReductionOperation
Reduce a tensor along the given axis by taking the minimum value
Source code in xdsl/dialects/tosa.py
ReduceProductOp
dataclass
¶
Bases: ReductionOperation
Reduce a tensor along the given axis by taking the product of all values
Source code in xdsl/dialects/tosa.py
name = 'tosa.reduce_product'
class-attribute
instance-attribute
¶
ReduceSumOp
dataclass
¶
Bases: ReductionOperation
Reduce a tensor along the given axis by taking the product of all values
Source code in xdsl/dialects/tosa.py
name = 'tosa.reduce_sum'
class-attribute
instance-attribute
¶
are_tosa_broadcastable(lhs: Attribute, rhs: Attribute, out: Attribute)
¶
Returns True if lhs and rhs have compatible shapes with broadcasting: the dimensions have to match, or one of them must be
equal to 1, in which case the corresponding resulting dimension must be equal to the non-1 dimension.
e.g.: [1, 2, 3] & [4, 2, 1] -> [4, 2, 3]