OutputShapeDependOnCompute
Function
Identifies whether the output shape of an operator depends on computation. For NonZero (counting the number of non-zero values in a tensor), the output shape information of the operator cannot be obtained before the computation is complete. When defining the prototype of this type of operator, you need to use the OutputShapeDependOnCompute API to identify the operator, and write the actual output shape to the output parameters in the operator kernel function so that the framework can manage the output memory based on the information. For details about the implementation on the kernel, see Implementing Operator Whose Output Shape Depends on Computation on the Kernel.
Prototype
1
|
OpParamDef &OutputShapeDependOnCompute() |
Parameters
None
Returns
OpParamDef operator definition. For details, see OpParamDef.
Constraints
- It can only be used to identify the operator output.
- The custom operator project generated based on the CANN package of an earlier version (which does not support the OutputShapeDependOnCompute feature) is incompatible with the OutputShapeDependOnCompute API. When using a custom operator project generated based on the CANN package of a non-current version, pay special attention to compatibility issues. You can check whether the current project supports this feature by checking whether the output_shape_depend_on_compute field exists in the cmake/util/ascendc_impl_build.py file in the custom operator project. If the field is not found, you need to regenerate the custom operator project to enable the OutputShapeDependOnCompute feature.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 |
this->Input("x1") .ParamType(REQUIRED) .DataType({ge::DT_FLOAT, ge::DT_FLOAT}) .Format({ge::FORMAT_ND, ge::FORMAT_ND}); this->Input("x2") .ParamType(REQUIRED) .DataType({ge::DT_FLOAT, ge::DT_FLOAT}) .Format({ge::FORMAT_ND, ge::FORMAT_ND}); this->Output("y1") .ParamType(REQUIRED) .DataType({ge::DT_FLOAT, ge::DT_FLOAT}) .Format({ge::FORMAT_ND, ge::FORMAT_ND}) .OutputShapeDependOnCompute(); |
Parent topic: OpParamDef