Operators#
2024-09-30
122 min read time
operation#
-
struct operation#
The operation interface represents an action an instruction will perform. All operation classes must be CopyConstructible.
Public Functions
-
std::string name() const#
A unique name identifying the operation.
-
void finalize(context &ctx)#
An optional method that can be used to finalize the operator before running.
-
shape compute_shape(const std::vector<shape> &input) const#
This is used to compute the resulting shape from an operation. If an operation cannot be run with input shapes, then it should throw an exception.
-
argument compute(context &ctx, const shape &output, const std::vector<argument> &input) const#
This performs the operation’s computation.
This method can be optional when the operation is only used as a placeholder to be lowered later on.
- Parameters:
ctx – This is the context created by the
target
during compilation. Implementations can use the target’scontext
class rather than thecontext
interface class.output – Equivalent to running
compute_shape
with eachshape
of theargument
. For a fixed shape, the returned argument will have the same shape asoutput
. For a dynamic shape, the returnedargument
will be a fixed shape within the bounds set in the dynamic shapeoutput
.input – This is the
argument
result from the previous instruction’s computation.
- Returns:
Return an
argument
of the result computation. Theshape
ofargument
should be the same theoutput
shape.
-
std::string name() const#
operators#
-
namespace op#
Enums
-
enum class normalize_attribute#
normalize_attribute
settings: Note that default options are not included as enums.use_input
(default) vs.use_output
: Affects the rank of the attribute.use_input -> lens.size()
,use_output -> lens.size() + vec.size()
.use_rank (default) vs use_len:
use_rank
sets the max value/index of the attribute as the rank of lens.use_lens
sets the max value/index as the corresponding value in lens at the axes index. Uses the dynamic_dimension.max value for dynamic shapes. Returns the original vector (no normalization) if any of dynamic_dimension[axes] are not fixed.clip_min
vs.not_clip_min
(default): Clip values less than the minimum to the minimum or not.include_min
vs.exclude_min
(default): Include or exclude the minimum value/index for range checking and clipping.clip_max
vs.not_clip_max
(default): Clip values greater than the maximum or not.include_max
vs.exclude_max
(default): Include or exclude the maximum value/index for range checking and clipping.normalize_padding
: To normalize the padding to2*(pad ndim)
dimensions.
Values:
-
enumerator use_output#
-
enumerator use_len#
-
enumerator clip_max#
-
enumerator clip_min#
-
enumerator include_max#
-
enumerator include_min#
-
enumerator normalize_padding#
Functions
-
std::ostream &operator<<(std::ostream &os, pooling_mode v)#
-
std::ostream &operator<<(std::ostream &os, rnn_direction v)#
-
struct abs : public migraphx::internal::op::unary<abs>#
- #include <migraphx/op/abs.hpp>
Public Functions
-
inline auto apply() const#
-
inline auto apply() const#
-
struct acos : public migraphx::internal::op::unary<acos>#
- #include <migraphx/op/acos.hpp>
Public Functions
-
inline auto apply() const#
-
inline auto apply() const#
-
struct acosh : public migraphx::internal::op::unary<acosh>#
- #include <migraphx/op/acosh.hpp>
Public Functions
-
inline auto apply() const#
-
inline auto apply() const#
-
struct allocate#
- #include <migraphx/op/allocate.hpp>
Static allocate: No inputs:
allocate()
this.s
attribute set to the static output shape of the buffer.this.s
attribute can be set to a dynamic output shape; however this will allocate the maximum buffer size for that caseDynamic allocate: One input:
allocate(output_dims)
output_dims
are the output buffer dimensions and has a static shape. Eitherthis.s
orthis.buf_type
(but not both) must be set to calculate the dynamic output shape at compute time. Ifthis.buf_type
is set, the compute_shape() of allocate at compile time will have dynamic_dimensions from {0, max_int} with rank = output_dims.ndim(). Ifthis.s
is set then the compute_shape() will outputthis.s
;this.s
should be a dynamic shape.Public Functions
-
inline std::string name() const#
-
inline std::string name() const#
-
struct argmax#
- #include <migraphx/op/argmax.hpp>
-
struct argmin#
- #include <migraphx/op/argmin.hpp>
-
struct as_shape#
- #include <migraphx/op/as_shape.hpp>
Public Functions
-
inline std::string name() const#
-
inline std::string name() const#
-
struct asin : public migraphx::internal::op::unary<asin>#
- #include <migraphx/op/asin.hpp>
Public Functions
-
inline auto apply() const#
-
inline auto apply() const#
-
struct asinh : public migraphx::internal::op::unary<asinh>#
- #include <migraphx/op/asinh.hpp>
Public Functions
-
inline auto apply() const#
-
inline auto apply() const#
-
struct atan : public migraphx::internal::op::unary<atan>#
- #include <migraphx/op/atan.hpp>
Public Functions
-
inline auto apply() const#
-
inline auto apply() const#
-
struct atanh : public migraphx::internal::op::unary<atanh>#
- #include <migraphx/op/atanh.hpp>
Public Functions
-
inline auto apply() const#
-
inline auto apply() const#
-
template<class Derived>
struct binary : public migraphx::internal::op::op_name<Derived># - #include <migraphx/op/binary.hpp>
-
struct bitwise_and : public migraphx::internal::op::binary<bitwise_and>#
- #include <migraphx/op/bitwise_and.hpp>
-
struct broadcast#
- #include <migraphx/op/broadcast.hpp>
1 input version: Broadcasts a tensor from the original shape to the broadcast_lens by setting the stride of broadcasted dimensions to zero.
axis
attribute for a 1D input shape is the output dimension that stays the same. ex: broadcasting shape [1024] -> [4, 1024, 3] has axis = 1.For higher rank input shapes, axis is an offset parameter for the broadcasting. Such that this operator would work in the opposite direction of NumPy broadcasting (left-most to rightwards element-wise comparison) ex: broadcasting shape [2, 2] -> [2, 2, 3] with axis = 0
2 input version: Broadcast the first input 1D shape into the second input shape based on the axis parameter. Handles broadcasting a 1D static shape into a higher rank dynamic shape. broadcast_lens is not used
Public Functions
-
inline std::string name() const#
-
inline std::string name() const#
-
struct broadcast_for_dot#
- #include <migraphx/op/broadcast_for_dot.hpp>
Broadcast dimensions between two tensors for the
dot
operator. Essentially broadcasts between two shapes for dimensions other than the last two. This operator is only needed if one of the shapes are dynamic. Example: a = shape[{1, 4}, 3, 248, 248] b = shape[248, 365] broadcast_for_dot(a, b) => shape[{1, 4}, 3, 248, 248] (no change) broadcast_for_dot(b, a) => shape[{1, 4}, 3, 248, 365]
-
struct broadcast_with_dims#
- #include <migraphx/op/broadcast_with_dims.hpp>
Broadcast the input tensor to the shape defined by the values of the second input. Used as
broadcast_with_dims(input_tensor, dims)
, where dims is a vector of integer dimensions.input_tensor
must be broadcastable withdims
, otherwise this operator with throw at compute. This operator can be replaced withmultibroadcast(input_tensor)
if thedims
vector is constant.Example: input_tensor shape: lens = {2, 3}, strides = {3, 1} dims = [4, 1, 3] output shape: lens = {4, 2, 3}, strides = {0, 3, 1}
-
struct capture#
- #include <migraphx/op/capture.hpp>
Public Functions
-
inline std::string name() const#
Public Members
-
std::size_t ins_index#
-
inline std::string name() const#
-
struct ceil : public migraphx::internal::op::unary<ceil>#
- #include <migraphx/op/ceil.hpp>
Public Functions
-
inline auto apply() const#
-
inline auto apply() const#
-
struct clip#
- #include <migraphx/op/clip.hpp>
-
struct concat#
- #include <migraphx/op/concat.hpp>
Public Functions
-
inline std::string name() const#
Public Members
-
int64_t axis = 0#
-
inline std::string name() const#
-
struct contiguous#
- #include <migraphx/op/contiguous.hpp>
The contiguous operator takes a non-standard input tensor and returns the same tensor but in standard form. For example, if input tensor A which has lens = (4,5) is first transposed, i.e. lens = (5,4), this tensor’s data layout remained the same during the transpose operation; only it’s shape lengths and strides were changed. This leaves the tensor in a non-standard form. The contiguous operator copies the underlying data such that resulting tensor is returned to a standard form.
-
struct convolution#
- #include <migraphx/op/convolution.hpp>
Convolution operator. Does not support optimal dimensions for spatial dimensions. Returns empty optimals.
Public Functions
-
inline std::string name() const#
-
inline void check_attribute_size() const#
-
inline std::vector<std::size_t> calc_conv_lens(std::vector<std::size_t> x_lens, std::vector<std::size_t> w_lens) const#
-
inline size_t kdims() const#
-
inline std::string name() const#
-
struct convolution_backwards#
- #include <migraphx/op/convolution_backwards.hpp>
Public Functions
-
inline std::string name() const#
-
inline void check_attribute_size() const#
-
inline std::vector<std::size_t> calc_spatial_lens(std::vector<std::size_t> x_lens, std::vector<std::size_t> w_lens) const#
-
inline size_t kdims() const#
-
inline std::string name() const#
-
struct cos : public migraphx::internal::op::unary<cos>#
- #include <migraphx/op/cos.hpp>
Public Functions
-
inline auto apply() const#
-
inline auto apply() const#
-
struct cosh : public migraphx::internal::op::unary<cosh>#
- #include <migraphx/op/cosh.hpp>
Public Functions
-
inline auto apply() const#
-
inline auto apply() const#
-
struct dequantizelinear#
- #include <migraphx/op/dequantizelinear.hpp>
-
struct dimensions_of#
- #include <migraphx/op/dimensions_of.hpp>
Returns the dimensions of the input argument from starting axis to ending axis. Atleast
end
must be set to use this operator (setend
to ndim for default ONNX behavior ofShape
operator) This should only be used for dynamic shapes as this can be simplified to a literal for static shapes.Public Functions
-
inline std::string name() const#
-
inline std::string name() const#
-
struct dot#
- #include <migraphx/op/dot.hpp>
Matrix multiplication of two tensors.
-
struct elu : public migraphx::internal::op::unary<elu>#
- #include <migraphx/op/elu.hpp>
Public Members
-
float alpha = 1#
-
float alpha = 1#
-
struct erf : public migraphx::internal::op::unary<erf>#
- #include <migraphx/op/erf.hpp>
Public Functions
-
inline auto apply() const#
-
inline auto apply() const#
-
struct exp : public migraphx::internal::op::unary<exp>#
- #include <migraphx/op/exp.hpp>
Public Functions
-
inline auto apply() const#
-
inline auto apply() const#
-
struct fill#
- #include <migraphx/op/fill.hpp>
fill(default_value, output_buffer) Fill an output buffer with the given default_value. Note that if the default_value is a literal and the output_buffer has a static shape this operator can be replaced with a literal.
-
struct flatten#
- #include <migraphx/op/flatten.hpp>
Public Functions
-
inline std::string name() const#
Public Members
-
int64_t axis = 1#
-
inline std::string name() const#
-
struct floor : public migraphx::internal::op::unary<floor>#
- #include <migraphx/op/floor.hpp>
Public Functions
-
inline auto apply() const#
-
inline auto apply() const#
-
struct gather#
- #include <migraphx/op/gather.hpp>
Public Functions
-
inline std::string name() const#
Public Members
-
int64_t axis = 0#
-
inline std::string name() const#
-
struct gathernd#
- #include <migraphx/op/gathernd.hpp>
Public Functions
-
inline std::string name() const#
Public Members
-
int batch_dims = 0#
-
inline std::string name() const#
-
struct get_tuple_elem#
- #include <migraphx/op/get_tuple_elem.hpp>
Public Functions
-
inline std::string name() const#
Public Members
-
std::size_t index = 0#
-
inline std::string name() const#
-
struct gqa_parameters#
- #include <migraphx/op/group_query_attention.hpp>
Public Members
-
std::size_t batch_size = 0#
-
std::size_t sequence_length = 0#
-
std::size_t head_size = 0#
-
std::size_t rotary_embedding_dim = 0#
-
std::size_t num_heads = 0#
-
std::size_t max_sequence_length = 0#
-
std::size_t head_stride = 0#
-
std::size_t seq_stride = 0#
-
std::size_t batch_stride = 0#
-
bool position_ids_use_batch = false#
-
std::size_t seqlen_present_kv_cache = 0#
-
std::size_t batch_size = 0#
-
struct group_query_attention#
- #include <migraphx/op/group_query_attention.hpp>
Public Functions
-
inline std::string name() const#
-
template<class T>
inline void run_rotary_embedding(T input, T cos_cache, T sin_cache, T output, bool interleaved, const std::size_t *pos_ids, gqa_parameters parameters) const#
-
template<class T>
inline void pack_v_into_rotary_qkv(gqa_parameters parameters, const T input, T output) const#
-
template<typename T>
inline T concat_state_chunk(const T past, const T chunk, T present, std::size_t present_buff_chunk_length, std::size_t past_buff_chunk_length, std::size_t past_chunk_length, std::size_t new_chunk_length, bool is_prompt, bool past_present_share_buffer, std::ptrdiff_t i) const#
-
template<class T, class U>
inline void calculate_attention_probs(T attention_probs, T query, T key, U seqlens_k, T past_key, T present_key, shape::type_t dtype, gqa_parameters params) const#
-
template<class T, class U, class W>
inline void calculate_attention_score(T output, const W attention_probs, const T val, const U seqlens_k, const T past_value, T present_value, shape::type_t dtype, gqa_parameters params) const#
-
inline std::string name() const#
-
struct gru#
- #include <migraphx/op/gru.hpp>
Public Functions
-
inline std::string name() const#
Public Members
-
rnn_direction direction = rnn_direction::forward#
-
float clip = 0.0f#
-
int linear_before_reset = 0#
-
inline std::string name() const#
-
struct highest#
- #include <migraphx/op/reduce_op.hpp>
-
struct identity#
- #include <migraphx/op/identity.hpp>
-
struct layout : public migraphx::internal::op::unary<layout>#
- #include <migraphx/op/layout.hpp>
Public Functions
-
inline auto apply() const#
Public Members
-
std::vector<int64_t> permutation#
-
inline auto apply() const#
-
struct leaky_relu : public migraphx::internal::op::unary<leaky_relu>#
- #include <migraphx/op/leaky_relu.hpp>
Public Functions
-
inline std::string point_op() const#
-
inline std::string name() const#
-
inline auto apply() const#
Public Members
-
float alpha = 0.01#
-
inline std::string point_op() const#
-
struct load#
- #include <migraphx/op/load.hpp>
-
struct log : public migraphx::internal::op::unary<log>#
- #include <migraphx/op/log.hpp>
Public Functions
-
inline auto apply() const#
-
inline auto apply() const#
-
struct log2 : public migraphx::internal::op::unary<log2>#
- #include <migraphx/op/log2.hpp>
Public Functions
-
inline auto apply() const#
-
inline auto apply() const#
-
struct logical_and : public migraphx::internal::op::binary<logical_and>#
- #include <migraphx/op/logical_and.hpp>
-
struct logical_or : public migraphx::internal::op::binary<logical_or>#
- #include <migraphx/op/logical_or.hpp>
-
struct logical_xor : public migraphx::internal::op::binary<logical_xor>#
- #include <migraphx/op/logical_xor.hpp>
-
struct loop#
- #include <migraphx/op/loop.hpp>
Public Functions
-
inline std::string name() const#
-
struct ref_loop#
- #include <migraphx/op/loop.hpp>
Public Functions
-
inline void append(const std::vector<argument> &iter_state, const std::vector<argument> &concatenated_outputs, const std::vector<int64_t> &scan_output_dirs, int64_t curr_iter, int64_t num_iters) const#
-
inline std::unordered_map<std::string, int> get_output_params(const module&) const#
Public Members
-
int64_t max_iterations = 0#
-
inline void append(const std::vector<argument> &iter_state, const std::vector<argument> &concatenated_outputs, const std::vector<int64_t> &scan_output_dirs, int64_t curr_iter, int64_t num_iters) const#
-
inline std::string name() const#
-
struct lowest#
- #include <migraphx/op/reduce_op.hpp>
-
struct lstm#
- #include <migraphx/op/lstm.hpp>
Public Functions
-
inline std::string name() const#
Public Members
-
rnn_direction direction = rnn_direction::forward#
-
float clip = 0.0f#
-
int input_forget = 0#
-
inline std::string name() const#
-
struct multibroadcast#
- #include <migraphx/op/multibroadcast.hpp>
Broadcast multiple dimensions between two tensors. Two versions of this operator: 1 input and 2+ inputs. One input version uses output_lens attribute and broadcasts to it. 2+ inputs version broadcasts first input to the common shape at evaluation time.
Public Functions
-
inline std::string name() const#
Public Members
-
std::vector<std::size_t> output_lens = {}#
-
inline std::string name() const#
-
struct multinomial#
- #include <migraphx/op/multinomial.hpp>
Public Functions
-
inline std::string name() const#
-
inline std::string name() const#
-
struct nearbyint : public migraphx::internal::op::unary<nearbyint>#
- #include <migraphx/op/nearbyint.hpp>
Public Functions
-
inline auto apply() const#
-
inline auto apply() const#
-
struct nonmaxsuppression#
- #include <migraphx/op/nonmaxsuppression.hpp>
Public Functions
-
inline std::string name() const#
-
template<class T>
inline std::vector<std::pair<double, int64_t>> filter_boxes_by_score(T scores_start, std::size_t num_boxes, double score_threshold) const#
-
inline std::string name() const#
-
struct nonzero#
- #include <migraphx/op/nonzero.hpp>
-
struct one#
- #include <migraphx/op/reduce_op.hpp>
-
struct onehot#
- #include <migraphx/op/onehot.hpp>
Produces a one-hot tensor. Called with
axis
attribute that defaults to the last output axis Constant depth:onehot(indices, values), depth attribute must be set; Variable depth:
onehot(indices, depth, values);
indiciesas a N rank tensor of indices where value is
on_valuescalar with the number of classes for the one-hot dimension
values[off_value, on_value]which axis to add the one-hot dimension to For axis = 0 and rank(indices) = 2: output is A[indicies[j, k], j, k] = on_value; A[i, j, k] = off_value otherwise Can be simplified to other operators when
indiceshas a static shape and
depth` is constant at compile-time.Public Functions
-
inline std::string name() const#
-
inline std::string name() const#
-
template<class Derived>
struct op_name# - #include <migraphx/op/name.hpp>
Create name from class.
Subclassed by migraphx::internal::op::binary< add >, migraphx::internal::op::binary< bitwise_and >, migraphx::internal::op::binary< div >, migraphx::internal::op::binary< equal >, migraphx::internal::op::binary< fmod >, migraphx::internal::op::binary< greater >, migraphx::internal::op::binary< less >, migraphx::internal::op::binary< logical_and >, migraphx::internal::op::binary< logical_or >, migraphx::internal::op::binary< logical_xor >, migraphx::internal::op::binary< max >, migraphx::internal::op::binary< min >, migraphx::internal::op::binary< mod >, migraphx::internal::op::binary< mul >, migraphx::internal::op::binary< pow >, migraphx::internal::op::binary< prelu >, migraphx::internal::op::binary< sqdiff >, migraphx::internal::op::binary< sub >, migraphx::internal::op::prefix_scan_op< prefix_scan_sum >, migraphx::internal::op::reduce_op< reduce_all >, migraphx::internal::op::reduce_op< reduce_any >, migraphx::internal::op::reduce_op< reduce_max >, migraphx::internal::op::reduce_op< reduce_mean >, migraphx::internal::op::reduce_op< reduce_min >, migraphx::internal::op::reduce_op< reduce_prod >, migraphx::internal::op::reduce_op< reduce_sum >, migraphx::internal::op::scatter_op< scatter_add >, migraphx::internal::op::scatter_op< scatter_max >, migraphx::internal::op::scatter_op< scatter_min >, migraphx::internal::op::scatter_op< scatter_mul >, migraphx::internal::op::scatter_op< scatter_none >, migraphx::internal::op::scatternd_op< scatternd_add >, migraphx::internal::op::scatternd_op< scatternd_max >, migraphx::internal::op::scatternd_op< scatternd_min >, migraphx::internal::op::scatternd_op< scatternd_mul >, migraphx::internal::op::scatternd_op< scatternd_none >, migraphx::internal::op::unary< abs >, migraphx::internal::op::unary< acos >, migraphx::internal::op::unary< acosh >, migraphx::internal::op::unary< asin >, migraphx::internal::op::unary< asinh >, migraphx::internal::op::unary< atan >, migraphx::internal::op::unary< atanh >, migraphx::internal::op::unary< ceil >, migraphx::internal::op::unary< convert >, migraphx::internal::op::unary< cos >, migraphx::internal::op::unary< cosh >, migraphx::internal::op::unary< elu >, migraphx::internal::op::unary< erf >, migraphx::internal::op::unary< exp >, migraphx::internal::op::unary< floor >, migraphx::internal::op::unary< isinf >, migraphx::internal::op::unary< isnan >, migraphx::internal::op::unary< layout >, migraphx::internal::op::unary< leaky_relu >, migraphx::internal::op::unary< log >, migraphx::internal::op::unary< log2 >, migraphx::internal::op::unary< nearbyint >, migraphx::internal::op::unary< neg >, migraphx::internal::op::unary< recip >, migraphx::internal::op::unary< relu >, migraphx::internal::op::unary< rsqrt >, migraphx::internal::op::unary< sigmoid >, migraphx::internal::op::unary< sign >, migraphx::internal::op::unary< sin >, migraphx::internal::op::unary< sinh >, migraphx::internal::op::unary< sqrt >, migraphx::internal::op::unary< tan >, migraphx::internal::op::unary< tanh >, migraphx::internal::op::unary< unary_not >, migraphx::internal::op::binary< Derived >, migraphx::internal::op::prefix_scan_op< Derived >, migraphx::internal::op::reduce_op< Derived >, migraphx::internal::op::scatter_op< Derived >, migraphx::internal::op::scatternd_op< Derived >, migraphx::internal::op::unary< Derived >
Public Functions
-
inline std::string name() const#
-
inline std::string name() const#
-
struct outline#
- #include <migraphx/op/outline.hpp>
Public Functions
-
inline std::string name() const#
-
inline std::string name() const#
-
struct pack_int4#
- #include <migraphx/op/pack_int4.hpp>
Public Functions
-
inline std::string name() const#
Public Members
-
int64_t axis = -1#
-
inline std::string name() const#
-
struct pad#
- #include <migraphx/op/pad.hpp>
Public Types
-
struct pointwise#
- #include <migraphx/op/pointwise.hpp>
Public Functions
-
inline std::string name() const#
-
inline std::string name() const#
-
struct pooling#
- #include <migraphx/op/pooling.hpp>
Public Functions
-
inline std::string name() const#
-
inline void check_attribute_size() const#
-
inline size_t kdims() const#
-
inline std::size_t dilate_dim(std::size_t dim, std::size_t dilation) const#
-
inline std::vector<std::size_t> calc_spatial_dim_out(const std::vector<std::size_t> &input_lens, std::size_t kdims) const#
Public Members
-
pooling_mode mode = {pooling_mode::average}#
-
std::vector<std::size_t> padding = {0, 0}#
-
std::vector<std::size_t> stride = {1, 1}#
-
std::vector<std::size_t> lengths = {1, 1}#
-
std::vector<std::size_t> dilations = {1, 1}#
-
bool ceil_mode = false#
-
int lp_order = 2#
-
padding_mode_t padding_mode = padding_mode_t::default_#
-
bool dyn_global = false#
-
bool count_include_pad = false#
-
struct avg_pool#
- #include <migraphx/op/pooling.hpp>
-
struct lpnorm_pool#
- #include <migraphx/op/pooling.hpp>
Public Functions
-
lpnorm_pool() = delete#
-
inline explicit lpnorm_pool(int x)#
-
template<class T>
inline double init() const#
-
inline double operator()(double x, double y) const#
-
inline double final(double x, std::size_t) const#
Public Members
-
int p = 0#
-
lpnorm_pool() = delete#
-
struct max_pool#
- #include <migraphx/op/pooling.hpp>
-
inline std::string name() const#
-
struct pow : public migraphx::internal::op::binary<pow>#
- #include <migraphx/op/pow.hpp>
Public Functions
-
inline auto apply() const#
-
inline auto apply() const#
-
template<class Derived>
struct prefix_scan_op : public migraphx::internal::op::op_name<Derived># - #include <migraphx/op/prefix_scan_op.hpp>
Parent struct for prefix scan operations. A prefix scan is equivalent to the C++ std::exclusive_scan or std::inclusive_scan. Given a list of numbers, a prefix scan sum op returns an equal size list of running totals of the values. Other operations besides addition can be supported by their own child ops.
-
enum class normalize_attribute#