layer.name = name
return layer.get_output(0)
+def add_matrix_multiply_layer(network, input_val, other_val, name):
+ """ Adds a matrix multiply layer to the TensorRT network
+ Args:
+ network: TensorRT Network
+ input_val: input matrix/vector TensorRT ITensor
+ other_val: another input matrix/vector TensorRT ITensor
+ name: Name of the matrix multiply layer
+ Returns:
+ output TensorRT ITensor from the matrix multiply layer
+ """
+ input_matrix_op = other_matrix_op = trt.MatrixOperation.NONE
+ preset_diff = 0
+
+ if len(input_val.shape) == 1:
+ preset_diff -= 1
+ input_matrix_op = trt.MatrixOperation.VECTOR
+
+ if len(other_val.shape) == 1:
+ preset_diff += 1
+ other_matrix_op = trt.MatrixOperation.VECTOR
+
+ input_val, other_val = broadcast(network, input_val, other_val, f"{name}_input", f"{name}_other", preset_diff)
+ layer = network.add_matrix_multiply(input_val, input_matrix_op, other_val, other_matrix_op)
+ layer.name = name
+ return layer.get_output(0)
def process_attr(val, num_elem):
if not isinstance(val, tuple):
f"matmul received input {i} that is not part " "of the TensorRT region!"
)
- input_matrix_op = other_matrix_op = trt.MatrixOperation.NONE
- preset_diff = 0
-
- if len(input_val.shape) == 1:
- preset_diff -= 1
- input_matrix_op = trt.MatrixOperation.VECTOR
-
- if len(other_val.shape) == 1:
- preset_diff += 1
- other_matrix_op = trt.MatrixOperation.VECTOR
-
- input_val, other_val = broadcast(
- network, input_val, other_val, f"{name}_input", f"{name}_other", preset_diff
- )
- layer = network.add_matrix_multiply(
- input_val, input_matrix_op, other_val, other_matrix_op
- )
- layer.name = name
- return layer.get_output(0)
-
+ return add_matrix_multiply_layer(network, input_val, other_val, name)
@tensorrt_converter(acc_ops.sigmoid)
def acc_ops_sigmoid(network, target, args, kwargs, name):