C++ API reference

Contents

C++ API reference#

Applies to Linux

2024-09-30

19 min read time

shape#

enum migraphx_shape_datatype_t#

An enum to represent the different data type inputs.

Values:

enumerator migraphx_shape_tuple_type#
enumerator migraphx_shape_bool_type#
enumerator migraphx_shape_half_type#
enumerator migraphx_shape_float_type#
enumerator migraphx_shape_double_type#
enumerator migraphx_shape_uint8_type#
enumerator migraphx_shape_int8_type#
enumerator migraphx_shape_uint16_type#
enumerator migraphx_shape_int16_type#
enumerator migraphx_shape_int32_type#
enumerator migraphx_shape_int64_type#
enumerator migraphx_shape_uint32_type#
enumerator migraphx_shape_uint64_type#
enumerator migraphx_shape_fp8e4m3fnuz_type#
enumerator migraphx_shape_fp8e4m3fn_type#
enumerator migraphx_shape_fp8e5m2_type#
template<class Lens, class Strides>
struct shape : public migraphx::handle_base<>, public migraphx::equality_comparable<shape<Lens, Strides>>#

Describe shape of tensor.

A shape consists of a data type, lengths of multi-dimension tensor, and strides

Public Types

using shape_type = shape#
using index_array = typename Lens::base_array#

Public Functions

inline shape()#
inline shape(const migraphx_shape *p)#
template<class HandleType, class Lifetime, class = typename std::enable_if<std::is_convertible<HandleType*, handle_type*>{}>::type>
inline shape(HandleType *p, Lifetime lifetime)#
inline shape(migraphx_shape_datatype_t type)#

Construct a scalar shape.

inline shape(migraphx_shape_datatype_t type, std::vector<size_t> plengths)#

Construct a shape with its type and lengths. The strides are automatically computed assumming a packed layout.

inline shape(migraphx_shape_datatype_t t, std::initializer_list<std::size_t> d)#
inline shape(migraphx_shape_datatype_t type, std::vector<size_t> plengths, std::vector<size_t> pstrides)#
inline shape(migraphx_shape_datatype_t type, const dynamic_dimensions &dyn_dims)#
inline std::vector<size_t> lengths() const#
inline std::vector<size_t> strides() const
inline dynamic_dimensions dyn_dims() const#

Get the dynamic dimensions of the shape.

inline migraphx_shape_datatype_t type() const#
inline size_t elements() const#
inline size_t bytes() const#
inline bool standard() const#
inline bool dynamic() const#

Is the shape dynamic.

inline size_t index(size_t i) const#
constexpr shape() = default
inline constexpr shape(Lens l, Strides s)#
inline constexpr auto elements() const
inline constexpr auto element_space() const#
inline constexpr auto packed() const#
inline constexpr auto broadcasted() const#
inline constexpr auto transposed() const#
inline constexpr auto skips() const#
inline constexpr auto standard() const
inline constexpr index_int index(index_array x) const#
inline constexpr index_int index(index_int i) const#
inline constexpr index_int compute_index(index_int i) const#
inline constexpr index_array multi(index_int idx) const#

Convert single index into a multi-index.

inline constexpr index_int single(index_array idx) const#

Convert multi-index into a single index.

inline constexpr shape get_shape() const#

Public Members

Lens lens = {}#
Strides strides = {}#

Friends

inline friend bool operator==(const shape &px, const shape &py)#
inline friend bool operator!=(const shape &px, const shape &py)#
template<class ...Ts>
inline friend constexpr bool operator==(const shape &x, const shape<Ts...> &y)#
template<class Stream>
inline friend constexpr const Stream &operator<<(const Stream &ss, const shape &s)#

argument#

struct argument : public migraphx::handle_base<>#

Arguments to be passed to an migraphx arguments.

An argument represents a raw buffer of data with a shape.

Public Functions

inline argument()#
template<class HandleType, class Lifetime, class = typename std::enable_if<std::is_convertible<HandleType*, handle_type*>{}>::type>
inline argument(HandleType *p, Lifetime lifetime)#
inline argument(const migraphx_argument *p)#
inline argument(shape pshape)#
inline argument(shape pshape, void *pbuffer)#
inline shape get_shape() const#
inline char *data() const#
template<typename T>
inline std::vector<T> as_vector() const#

Public Static Functions

static inline argument generate(shape ps, size_t pseed = 0)#

Generate an argument using random data.

Friends

inline friend bool operator==(const argument &px, const argument &py)#
inline friend bool operator!=(const argument &px, const argument &py)#

target#

struct target : public migraphx::handle_base<>#

A target for compilation.

Public Functions

inline target()#
template<class HandleType, class Lifetime, class = typename std::enable_if<std::is_convertible<HandleType*, handle_type*>{}>::type>
inline target(HandleType *p, Lifetime lifetime)#
inline target(const char *name)#

Construct a target from its name.

program#

struct program_parameter_shapes : public migraphx::handle_base<>#

Public Functions

inline program_parameter_shapes()#
template<class HandleType, class Lifetime, class = typename std::enable_if<std::is_convertible<HandleType*, handle_type*>{}>::type>
inline program_parameter_shapes(HandleType *p, Lifetime lifetime)#
inline size_t size() const#
inline shape operator[](const char *pname) const#
inline std::vector<const char*> names() const#
struct program_parameters : public migraphx::handle_base<>#

A class to construct the inputs parameters for a program.

Public Functions

template<class HandleType, class Lifetime, class = typename std::enable_if<std::is_convertible<HandleType*, handle_type*>{}>::type>
inline program_parameters(HandleType *p, Lifetime lifetime)#
inline program_parameters(migraphx_program_parameters *p)#
inline program_parameters()#
inline program_parameters(std::initializer_list<std::pair<std::string, argument>> l)#

Construct the parameters from initializer_list.

inline void add(const char *pname, const argument &pargument) const#

Add a new parameter.

struct migraphx_compile_options#

Public Functions

template<class ...Ts>
inline migraphx_compile_options(Ts&&... xs)#

Public Members

migraphx::compile_options object#
struct program : public migraphx::handle_base<>#

A program represents the all computation graphs to be compiled and executed.

Public Functions

inline program()#
template<class HandleType, class Lifetime, class = typename std::enable_if<std::is_convertible<HandleType*, handle_type*>{}>::type>
inline program(HandleType *p, Lifetime lifetime)#
inline void compile(const target &ptarget, const compile_options &poptions) const#

Compile the program for a specific target to be ran on.

inline void compile(const target &ptarget) const#

Compile the program for a specific target to be ran on.

inline program_parameter_shapes get_parameter_shapes() const#

Return the shapes for the input parameters.

inline shapes get_output_shapes() const#

Get the shapes of all the outputs returned by this program.

inline arguments eval(const program_parameters &pparams) const#

Run the program using the inputs passed in.

template<class Stream>
inline arguments run_async(const program_parameters &pparams, Stream *s) const#

Overloaded to allow for execution_environment input.

inline void print() const#
inline program sort()#
call &migraphx_program_get_main_module()#
inline context experimental_get_context()#
call & migraphx_program_create_module (), name.data()

Public Members

return module   = {p_modu, this->share_handle()}

Friends

inline friend bool operator==(const program &px, const program &py)#
inline friend bool operator!=(const program &px, const program &py)#

quantize#

struct quantize_op_names : public migraphx::handle_base<>#

Public Functions

inline quantize_op_names()#
template<class HandleType, class Lifetime, class = typename std::enable_if<std::is_convertible<HandleType*, handle_type*>{}>::type>
inline quantize_op_names(HandleType *p, Lifetime lifetime)#
inline void add(const std::string &name)#
inline void migraphx::quantize_fp16(const program &prog)#

Quantize program to use fp16.

inline void migraphx::quantize_fp16(const program &prog, const quantize_op_names &names)#

Quantize program to use fp16.

struct quantize_int8_options : public migraphx::handle_base<>#

Options to be passed when quantizing for int8.

Public Functions

inline quantize_int8_options()#
template<class HandleType, class Lifetime, class = typename std::enable_if<std::is_convertible<HandleType*, handle_type*>{}>::type>
inline quantize_int8_options(HandleType *p, Lifetime lifetime)#
inline void add_op_name(const std::string &name)#

Add an operator that should be quantized.

inline void add_calibration_data(const program_parameters &pp)#

Add calibrartion data to be used for quantizing.

Public Members

std::vector<parameter_map> calibration = {}#
std::unordered_set<std::string> op_names = {}#

parse_onnx#

struct onnx_options : public migraphx::handle_base<>#

Options for parsing onnx options.

Public Functions

inline onnx_options()#
template<class HandleType, class Lifetime, class = typename std::enable_if<std::is_convertible<HandleType*, handle_type*>{}>::type>
inline onnx_options(HandleType *p, Lifetime lifetime)#
inline void set_input_parameter_shape(const std::string &name, std::vector<std::size_t> dim)#

Make onnx parser treat an inputs with a certain dimensions.

inline void set_dyn_input_parameter_shape(const std::string &name, const dynamic_dimensions &dyn_dims)#
inline void set_default_dim_value(unsigned int value)#

When there is a dimension parameter, then use this default value.

inline void set_default_dyn_dim_value(const dynamic_dimension &dd)#
inline void set_default_loop_iterations(int64_t value)#

Set default max iteration number for the loop operator.

inline void set_limit_loop_iterations(int64_t value)#

Set max iteration limit for the loop operator.

inline void set_external_data_path(const std::string &external_data_path)#

Set absolute path for external data files.

inline program migraphx::parse_onnx(const char *filename)#

Parse an onnx file into a migraphx program.

inline program migraphx::parse_onnx(const char *filename, const migraphx::onnx_options &options)#

Parse an onnx file into a migraphx program.

inline program migraphx::parse_onnx_buffer(const std::string &buffer)#

Parse a buffer of memory as an onnx file.

inline program migraphx::parse_onnx_buffer(const std::string &buffer, const migraphx::onnx_options &options)#

Parse a buffer of memory as an onnx file.

inline program migraphx::parse_onnx_buffer(const void *data, size_t size)#

Parse a buffer of memory as an onnx file.

inline program migraphx::parse_onnx_buffer(const void *data, size_t size, const migraphx::onnx_options &options)#

Parse a buffer of memory as an onnx file.

load#

struct file_options : public migraphx::handle_base<>#

Public Functions

template<class HandleType, class Lifetime, class = typename std::enable_if<std::is_convertible<HandleType*, handle_type*>{}>::type>
inline file_options(HandleType *p, Lifetime lifetime)#
inline file_options()#
inline void set_file_format(const char *format)#
inline program migraphx::load(const char *filename)#

Load a saved migraphx program from a file.

inline program migraphx::load(const char *filename, const file_options &options)#

Load a saved migraphx program from a file.

save#

inline void migraphx::save(const program &p, const char *filename)#

Save a program to a file.

inline void migraphx::save(const program &p, const char *filename, const file_options &options)#

Save a program to a file.