QNN HTP Op Package - Common Default Package Ops Usage Examples

Add

Add two tensors element-wise

Usage Hint

Syntax

/*
 * In1             -  Input tensor1
 * In2             -  Input tensor2
 */
 Op(FROM_DEFAULT_PACKAGE("Add"), "In1", "In2")

Example

# we can combine a Matmul Op followed by an Add to a new Matmul_bias op
DEF_PACKAGE_OPTIMIZATION(Fraph,
 Op("Add", Op("Matmul", "A", "B"), "Bias"),
 OK,
 Op("Matmul_bias", "A", "B", "Bias")
 )

Reshape

Reshapes a tensor from one dimension to another

Usage Hint

Often used with WITH_SIZE(gen_Shape(X,X,X,X)) to determine the output tensor dimension

Syntax

/*
 * In             -  Input tensor
 *
 */
 Op(FROM_DEFAULT_PACKAGE("Reshape"), "In")

Example

# We can reshape input tensor into seme shape that Relu_1x1x1xd Op like
DEF_PACKAGE_OPTIMIZATION(TILING,
 Op("Relu", "In"),
 OK,
 Op("Relu_1x1x1xd", WITH_SIZE(
   WITH_SIZE(gen_Shape(1,1,1,MUL(DIM_BATCH("In"),DIM_HEIGHT("In"),DIM_WIDTH("In"),DIM_DEPTH("In"))),
     Op(FROM_DEFAULT_PACKAGE("Reshape"),"In")
   )
 )
)