KernelRunContextHolder Structure Definition

Function Description

This structure is the final construction result of the ContextBuilder class. You can obtain the internal operator information or objects of the KernelContext class by using specified APIs.

Prototype

struct KernelRunContextHolder {
    KernelRunContextHolder();
    ~KernelRunContextHolder();
    template<typename T>
    T *GetContext() const
    {
        return reinterpret_cast<T*>(context);
    }
    gert::ComputeNodeInfo *MutableComputeNodeInfo()
    {
        return reinterpret_cast<gert::ComputeNodeInfo *>(computeNodeExtendHolder.get());
    }
    std::unique_ptr<ValueHolderImpl> valueHolder;
    std::unique_ptr<uint8_t[]> computeNodeExtendHolder;
    KernelRunContext *context {nullptr};
};

Function Usage

Table 1 Function description

Function Name

Input Parameter Description

Meaning

GetContext

None

Obtains the context member variable and converts it to the pointer to template T, where T can be either KernelContext or its subclasses such as TilingContext.

MutableComputeNodeInfo

None

Returns the constructed gert::ComputeNodeInfo class pointer.

Table 2 Variable description

Variable Name

Meaning

valueHolder

Smart pointer that ensures that the internal value of KernelRunContextHolder is not destructed.

computeNodeExtendHolder

Smart pointer that can be converted into the ComputeNodeInfo class.

context

Pointer to the KernelRunContext class.

Precautions

None

Example

auto holder = context_ascendc::ContextBuilder().Inputs().Outputs().BuildKernelRunContext();
if (holder != nullptr) {
    gert::KernelContext* tilingParseContext = holder->GetContext<gert::KernelContext>();
    gert::ComputeNodeInfo* info = holder->MutableComputeNodeInfo();
}