class habana::v1::HpuKernelContext
On this Page
class habana::v1::HpuKernelContext¶
Overview¶
Context containing all the necessary information to define TPC bound to HpuKernel. More…
#include <hpu_kernel_context.h> class HpuKernelContext { public: // construction virtual ~HpuKernelContext(); // methods virtual tensorflow::Status InputInfo(int idx, TensorInfo& input_info) const = 0; virtual tensorflow::Status OutputInfo(int idx, TensorInfo& output_info) const = 0; virtual int NumInputs() const = 0; virtual int NumOutputs() const = 0; virtual const tensorflow::Tensor* HostMemoryInput(int idx) const = 0; virtual const tensorflow::NodeDef& NodeDef() const = 0; template <class T> tensorflow::Status GetAttr(tensorflow::StringPiece attr_name, T* value) const; virtual tensorflow::Status DefineOutputInfo(int idx, const TensorInfo& info) = 0; virtual tensorflow::Status DefineNode(const NodeDesc& node_desc, const std::vector<int>& input_indices, const std::vector<int>& output_indices) = 0; virtual tensorflow::Status DefineNode(const NodeDesc& node_desc, const std::vector<int>& input_indices, const std::vector<TensorInfo>& output_infos) = 0; virtual void SetStatus(const tensorflow::Status& status) = 0; virtual const tensorflow::Status& Status() const = 0; virtual void CtxFailure(const tensorflow::Status& s) = 0; virtual void CtxFailureWithWarning(const tensorflow::Status& s) = 0; virtual void CtxFailure(const char* file, int line, const tensorflow::Status& s) = 0; virtual void CtxFailureWithWarning(const char* file, int line, const tensorflow::Status& s) = 0; virtual const tensorflow::OpKernelContext* OpKernelContext() const = 0; };
Detailed Documentation¶
Context containing all the necessary information to define TPC bound to HpuKernel.
Within HpuKernelContext, user is responsible to define output information as well as define TPC kernel to be invoked. If there is any error, while working with HpuKernelContext, SetStatus() method with error should be called, and function should return.
Methods¶
virtual tensorflow::Status InputInfo(int idx, TensorInfo& input_info) const = 0
Returns success status, if input for a given index exists.
If successful, input_info is updated with information about input tensorflow::Tensor connected to the HpuKernel at given index.
virtual tensorflow::Status OutputInfo(int idx, TensorInfo& output_info) const = 0
Returns success status, if output for a given index exists.
If successful, output_info is updated with information about output tensorflow::Tensor connected to the HpuKernel at given index. In order for this function to work, outputs must be populated with DefineOutputInfo().
virtual int NumInputs() const = 0
Returns number of inputs of HpuKernel.
virtual int NumOutputs() const = 0
Returns number of outputs of HpuKernel.
virtual const tensorflow::Tensor* HostMemoryInput(int idx) const = 0
Returns valid pointer, if there is HostMemory tensorflow::Tensor at a given input index.
In case of invalid index for HostMemory input, nullptr is returned.
virtual const tensorflow::NodeDef& NodeDef() const = 0
Returns NodeDef for a given OpKernel associated with HpuKernelContext.
template <class T> tensorflow::Status GetAttr(tensorflow::StringPiece attr_name, T* value) const
Returns selected attribute of the Kernel.
Function borrowed from OpKernelConstruction class. If the T type does match the type found under attr_name, error status is returned.
Parameters:
attr_name |
name of attribute in Op in TF Graph |
value |
pointer to object to be filled with data. |
Returns:
status of the operation
virtual tensorflow::Status DefineOutputInfo(int idx, const TensorInfo& info) = 0
Defines single output info within HpuKernelContext.
Multiple calls with same index will result in error status returned
Parameters:
idx |
output index. Should be less than NumOutputs() |
info |
tensorflow::Tensor info for given output |
Returns:
status of the operation
virtual tensorflow::Status DefineNode(const NodeDesc& node_desc, const std::vector<int>& input_indices, const std::vector<int>& output_indices) = 0
Defines single TPC kernel within HpuKernelContext.
Multiple calls to this function will result in error status returned
In order to connect outputs to TPC kernel, DefineOutputInfo() must be called before for each output.
Parameters:
node_desc |
definition of TPC kernel |
input_indices |
ordered indices of input TensorInfos from HpuKernelContext that should be connected to TPC kernel |
output_indices |
indices of output TensorInfos from HpuKernelContext that should be connected to TPC kernel Example: Op with 3 outputs (0, 1, 2), TPC with 3 outputs needed in different order (1, 0, 2) This implies output_indices={1, 0, 2} (indices of OutputInfos in HpuKernelContex) |
Returns:
status of the operation
virtual tensorflow::Status DefineNode(const NodeDesc& node_desc, const std::vector<int>& input_indices, const std::vector<TensorInfo>& output_infos) = 0
Defines single TPC kernel within HpuKernelContext with in-place outputs definition.
Multiple calls to this function will result in error status returned
DefineOutputInfo() cannot be called before. If it was, this function will return error.
Parameters:
node_desc |
definition of TPC kernel |
input_indices |
ordered indices of input TensorInfos from HpuKernelContext that should be connected to TPC kernel |
output_infos |
ordered list of output infos that should be connected to TPC kernel Received output infos will automatically be added (in order) to HpuKernelContext. |
Returns:
status of the operation
virtual void SetStatus(const tensorflow::Status& status) = 0
SetStatus() should be called, if HpuKernelContext encounters an error.
Any method returning tensorflow::Status is not updating Status on HpuKernelContext. It is caller’s responsibility to do it.
virtual const tensorflow::Status& Status() const = 0
Getter for current status of HpuKernelContext.
virtual void CtxFailure(const tensorflow::Status& s) = 0
Helper routine for the OP_REQUIRES macros.
virtual void CtxFailureWithWarning(const tensorflow::Status& s) = 0
Helper routine for the OP_REQUIRES macros.
virtual void CtxFailure(const char* file, int line, const tensorflow::Status& s) = 0
Helper routine for the OP_REQUIRES macros.
virtual void CtxFailureWithWarning(const char* file, int line, const tensorflow::Status& s) = 0
Helper routine for the OP_REQUIRES macros.
virtual const tensorflow::OpKernelContext* OpKernelContext() const = 0
Getter for pointer to tensorflow::OpKernelContext. Use rarely.