Data types#
2024-02-27
25 min read time
shape#
-
struct shape#
Public Types
-
enum type_t#
Values:
-
enumerator bool_type#
-
enumerator half_type#
-
enumerator float_type#
-
enumerator double_type#
-
enumerator uint8_type#
-
enumerator int8_type#
-
enumerator uint16_type#
-
enumerator int16_type#
-
enumerator int32_type#
-
enumerator int64_type#
-
enumerator uint32_type#
-
enumerator uint64_type#
-
enumerator fp8e4m3fnuz_type#
-
enumerator tuple_type#
-
enumerator bool_type#
Public Functions
-
shape()#
-
shape(type_t t, std::vector<dynamic_dimension> dims)#
-
shape(type_t t, std::vector<std::size_t> mins, std::vector<std::size_t> maxes, std::vector<std::set<std::size_t>> optimals_list)#
-
const std::vector<std::size_t> &lens() const#
-
const std::vector<std::size_t> &strides() const#
-
std::size_t ndim() const#
The number of dimensions in the shape, either static or dynamic. Same as the number of indices required to get a data value.
-
std::size_t elements() const#
Return the number of elements in the tensor.
-
std::size_t bytes() const#
Return the number of total bytes used for storage of the tensor data; includes subshapes. For dynamic shape, returns the maximum number of bytes presuming a packed shape.
-
std::size_t type_size() const#
Return the size of the type of the main shape. Returns 0 if there are subshapes.
-
const std::vector<dynamic_dimension> &dyn_dims() const#
-
std::vector<std::size_t> min_lens() const#
Minimum lengths for dynamic shape. lens() for static shape.
-
std::vector<std::size_t> max_lens() const#
Maximum lengths for dynamic shape. lens() for static shape.
-
std::vector<std::set<std::size_t>> opt_lens() const#
Optimum lengths for dynamic shape. Empty for static shape.
-
std::size_t index(std::initializer_list<std::size_t> l) const#
Map multiple indices to space index.
-
std::size_t index(const std::vector<std::size_t> &l) const#
Map multiple indices to space index.
-
template<class Iterator>
inline std::size_t index(Iterator start, Iterator last) const# Map multiple indices from a range of iterator to a space index.
-
std::size_t index(std::size_t i) const#
Map element index to space index.
-
std::vector<std::size_t> multi(std::size_t idx) const#
Map element index to multi-dimensional index.
-
void multi_copy(std::size_t idx, std::size_t *start, const std::size_t *end) const#
Map element index to multi-dimensional index and put them them into location provided by pointers
-
bool packed() const#
Returns true if the shape is packed (number of elements and buffer size the same) with no padding
-
bool transposed() const#
Returns true if the shape has been transposed. That is the strides are not in descending order
-
bool broadcasted() const#
Returns true if the shape is broadcasting a dimension. That is, one of the strides are zero.
-
bool standard() const#
Returns true if the shape is in its standard format. That is, the shape is both packed and not transposed.
-
bool scalar() const#
Returns true if all strides are equal to 0 (scalar tensor)
-
bool dynamic() const#
Return true if the shape is dynamic.
-
bool any_of_dynamic() const#
Return true if this shape or any of the sub_shapes are dynamic.
-
std::string type_string() const#
-
std::size_t element_space() const#
Returns the number of elements in the data buffer. For a dynamic shape, returns the maximum number of elements of the data buffer and assumes it is packed. Will clip to the maximum of size_t if overflows for dynamic shapes.
Public Static Functions
-
static shape from_permutation(type_t t, const std::vector<std::size_t> &l, const std::vector<int64_t> &perm)#
Creates an output shape with dimensions equal to the input lengths and strides determined by the permutation argument such that find_permutation() of the output shape returns the inputted permuation.
2D example: parameters: l = [2, 3], perm = [1, 0] therefore: “original” shape = {lens = [3, 2], strides = [2, 1]} output_shape = {lens = [2, 3], strides = [1, 2]
3D example: parameters: l = [2, 3, 4], perm = [1, 2, 0] therefore: “original” shape = {lens = [3, 4, 2], strides = [8, 2, 1]} output_shape = {lens = [2, 3, 4], strides = [1, 8, 2]}
-
template<class Visitor, class TupleVisitor>
static inline void visit(type_t t, Visitor v, TupleVisitor tv)#
Friends
-
template<class T>
struct as#
-
struct dynamic_dimension#
Public Functions
-
bool is_fixed() const#
-
bool has_optimal() const#
-
dynamic_dimension &operator+=(const std::size_t &x)#
-
dynamic_dimension &operator-=(const std::size_t &x)#
Friends
-
friend bool operator==(const dynamic_dimension &x, const dynamic_dimension &y)#
-
friend bool operator!=(const dynamic_dimension &x, const dynamic_dimension &y)#
-
friend std::ostream &operator<<(std::ostream &os, const dynamic_dimension &x)#
-
friend bool operator==(const dynamic_dimension &x, const std::size_t &y)#
-
friend bool operator==(const std::size_t &x, const dynamic_dimension &y)#
-
friend bool operator!=(const dynamic_dimension &x, const std::size_t &y)#
-
friend bool operator!=(const std::size_t &x, const dynamic_dimension &y)#
-
friend dynamic_dimension operator+(const dynamic_dimension &x, const std::size_t &y)#
-
friend dynamic_dimension operator+(const std::size_t &x, const dynamic_dimension &y)#
-
friend dynamic_dimension operator-(const dynamic_dimension &x, const std::size_t &y)#
-
bool is_fixed() const#
-
template<class T, class = void>
struct get_type# Subclassed by migraphx::internal::shape::get_type< const T >
-
template<class T>
struct get_type<double, T> : public std::integral_constant<type_t, double_type>#
-
template<class T>
struct get_type<float, T> : public std::integral_constant<type_t, float_type>#
-
template<class T>
struct get_type<int16_t, T> : public std::integral_constant<type_t, int16_type>#
-
template<class T>
struct get_type<int32_t, T> : public std::integral_constant<type_t, int32_type>#
-
template<class T>
struct get_type<int64_t, T> : public std::integral_constant<type_t, int64_type>#
- template<class T> fp8e4m3fnuz, T > : public std::integral_constant< type_t, fp8e4m3fnuz_type >
-
template<class T>
struct get_type<uint16_t, T> : public std::integral_constant<type_t, uint16_type>#
-
template<class T>
struct get_type<uint32_t, T> : public std::integral_constant<type_t, uint32_type>#
-
template<class T>
struct get_type<uint64_t, T> : public std::integral_constant<type_t, uint64_type>#
-
template<class T>
struct get_type<uint8_t, T> : public std::integral_constant<type_t, uint8_type>#
-
enum type_t#
literal#
-
struct literal : public migraphx::internal::raw_data<literal>#
Represents a raw literal.
This stores the literal has a raw buffer that is owned by this class
Public Functions
-
inline literal()#
-
template<class U, class T = deduce<U>, shape::type_t ShapeType = shape::get_type<T>{}>
inline literal(U x)#
-
template<class T, long PrivateRequires__LINE__ = __LINE__, typename std::enable_if<(PrivateRequires__LINE__ == __LINE__ && (migraphx::and_<sizeof(T) == 1>{})), int>::type = 0>
inline literal(const shape &s, T *x)#
-
inline bool empty() const#
Whether data is available.
-
inline const char *data() const#
Provides a raw pointer to the data.
-
inline literal()#
argument#
-
struct argument : public migraphx::internal::raw_data<argument>#
Arguments passed to instructions.
An
argument
can represent a raw buffer of data that either be referenced from another element or it can be owned by the argument.Public Functions
-
argument() = default#
-
template<class F, long PrivateRequires__LINE__ = __LINE__, typename std::enable_if<(PrivateRequires__LINE__ == __LINE__ && (migraphx::and_<std::is_pointer<decltype(std::declval<F>()())>{}>{})), int>::type = 0>
inline argument(shape s, F d)#
-
char *data() const#
Provides a raw pointer to the data.
-
bool empty() const#
Whether data is available.
Make copy of the argument that is always sharing the data.
-
argument() = default#
raw_data#
-
template<class Derived>
struct raw_data : public migraphx::internal::raw_data_base# Provides a base class for common operations with raw buffer.
For classes that handle a raw buffer of data, this will provide common operations such as equals, printing, and visitors. To use this class the derived class needs to provide a
data()
method to retrieve a raw pointer to the data, andget_shape
method that provides the shape of the data.Public Functions
-
template<class Visitor>
inline void visit_at(Visitor v, std::size_t n = 0) const# Visits a single data element at a certain index.
- Parameters:
v – A function which will be called with the type of data
n – The index to read from
-
template<class Visitor, class TupleVisitor>
inline void visit(Visitor v, TupleVisitor tv) const#
-
template<class Visitor>
inline void visit(Visitor v) const# Visits the data.
This will call the visitor function with a
tensor_view<T>
based on the shape of the data.- Parameters:
v – A function to be called with
tensor_view<T>
-
inline bool single() const#
Returns true if the raw data is only one element.
-
template<class T>
inline T at(std::size_t n = 0) const# Retrieves a single element of data.
- Parameters:
n – The index to retrieve the data from
- Template Parameters:
T – The type of data to be retrieved
- Returns:
The element as
T
-
template<class T>
inline tensor_view<T> get() const# Get a tensor_view to the data.
-
inline std::string to_string() const#
-
struct auto_cast#
Public Types
-
template<class T>
using is_data_ptr = bool_c<(std::is_void<T>{} or std::is_same<char, std::remove_cv_t<T>>{} or std::is_same<unsigned char, std::remove_cv_t<T>>{})>#
-
template<class T>
using get_data_type = std::conditional_t<is_data_ptr<T>{}, float, T>#
Public Functions
-
template<class T>
inline bool matches() const#
-
template<class T>
-
template<class Visitor>
-
template<class T, class ...Ts>
auto migraphx::internal::visit_all(T &&x, Ts&&... xs)# Visits every object together.
This will visit every object, but assumes each object is the same type. This can reduce the deeply nested visit calls. Returns a function that takes the visitor callback. Calling syntax is
visit_all(xs...)([](auto... ys) {})
wherexs...
andys...
are the same number of parameters.- Parameters:
x – A raw data object
xs – Many raw data objects.
- Returns:
A function to be called with the visitor
-
template<class T>
auto migraphx::internal::visit_all(const std::vector<T> &x)# Visits every object together.
This will visit every object, but assumes each object is the same type. This can reduce the deeply nested visit calls. Returns a function that takes the visitor callback.
- Parameters:
x – A vector of raw data objects. Types must all be the same.
- Returns:
A function to be called with the visitor
tensor_view#
-
template<class T>
struct tensor_view# Public Types
-
using iterator = basic_iota_iterator<tensor_view_iterator_read<tensor_view<T>>, std::size_t>#
-
using const_iterator = basic_iota_iterator<tensor_view_iterator_read<const tensor_view<T>>, std::size_t>#
Public Functions
-
inline tensor_view()#
-
inline bool empty() const#
-
inline std::size_t size() const#
-
template<class ...Ts, long PrivateRequires__LINE__ = __LINE__, typename std::enable_if<(PrivateRequires__LINE__ == __LINE__ && (migraphx::and_<std::is_integral<Ts>{}...>{})), int>::type = 0>
inline const T &operator()(Ts... xs) const#
-
template<class ...Ts, long PrivateRequires__LINE__ = __LINE__, typename std::enable_if<(PrivateRequires__LINE__ == __LINE__ && (migraphx::and_<std::is_integral<Ts>{}...>{})), int>::type = 0>
inline T &operator()(Ts... xs)#
-
template<class Iterator, long PrivateRequires__LINE__ = __LINE__, typename std::enable_if<(PrivateRequires__LINE__ == __LINE__ && (migraphx::and_<not std::is_integral<Iterator>{}>{})), int>::type = 0>
inline const T &operator()(Iterator start, Iterator last) const#
-
template<class Iterator, long PrivateRequires__LINE__ = __LINE__, typename std::enable_if<(PrivateRequires__LINE__ == __LINE__ && (migraphx::and_<not std::is_integral<Iterator>{}>{})), int>::type = 0>
inline T &operator()(Iterator start, Iterator last)#
-
inline const_iterator begin() const#
-
inline const_iterator end() const#
Friends
-
inline friend std::ostream &operator<<(std::ostream &os, const tensor_view<T> &x)#
-
using iterator = basic_iota_iterator<tensor_view_iterator_read<tensor_view<T>>, std::size_t>#