Class Kernel

Class Documentation

class Kernel

The Kernel class is used to define a MindSpore Kernel.

Public Functions

inline Kernel(const std::vector<mindspore::MSTensor> &inputs, const std::vector<mindspore::MSTensor> &outputs, const schema::Primitive *primitive, const mindspore::Context *ctx)

Constructor.

Parameters
  • inputs[in] define the input tensors for kernel.

  • outputs[in] define the output tensors for kernel.

  • primitive[in] define the primitive of kernel generated by flatbuffers.

  • ctx[in] define the context for kernel.

virtual ~Kernel() = default

Destructor.

virtual int Prepare() = 0

prepare for executing kernel.

Returns

result code.

virtual int Execute() = 0

execute the kernel.

Returns

result code.

virtual int ReSize() = 0

resize the kernel input shape, memory need to refresh.

Returns

result code.

inline virtual void set_inputs(const std::vector<mindspore::MSTensor> &in_tensors)

set kernel’s input tensors.

Parameters

in_tensors[in] define the input tensors.

inline virtual void set_input(mindspore::MSTensor in_tensor, int index)

set kernel’s input tensor.

Parameters
  • in_tensor[in] define the input tensor.

  • index[in] define the index of the input tensor.

inline virtual void set_outputs(const std::vector<mindspore::MSTensor> &out_tensors)

set kernel’s output tensors.

Parameters

out_tensors[in] define the output tensors.

inline virtual void set_output(mindspore::MSTensor out_tensor, int index)

set kernel’s output tensor.

Parameters
  • out_tensor[in] define the output tensor.

  • index[in] define the index of the output tensor.

inline virtual const std::vector<mindspore::MSTensor> &inputs()

obtain kernel’s input tensors.

Returns

input tensors.

inline virtual const std::vector<mindspore::MSTensor> &outputs()

obtain kernel’s output tensors.

Returns

output tensors.

inline std::string name() const

obtain kernel’s name.

Returns

kernel’s name.

inline void set_name(const std::string &name)

set kernel’s name.

Parameters

name[in] define the kernel’s name.

inline const mindspore::Context *context() const

obtain kernel’s context.

Returns

kernel’s context.

inline virtual schema::PrimitiveType type() const

obtain kernel’s type.

Returns

kernel’s type.

inline const schema::Primitive *primitive() const

obtain the primitive of kernel generated by flatbuffers.

Returns

the primitive of kernel generated by flatbuffers.

inline std::string GetAttr(const std::string &key) const

get kernel’s attribute

Parameters

key[in] define the kernel’s attribute key.