[myelin][onnx] Assertion failuers on logical operator (seems buffer overwritten by downstream node?)
Description
Either logical_op followed by reshape or reshape followed by logical_op may trigger an error. They look similar so I'm filing in the same issue.
See my next comment. It looks like it's because logical operators are not operating on the right tensor buffer; or their buffers are overwritten by downstream nodes.
logical_op->reshape
When a boolean tensor is reshaped and the target shape happens to be the same, any further operations (even identity_op) on the before-reshape tensor will trigger assertion failures [TensorRT] ERROR: 2: [myelinCopyLayer.cpp::addCopy::14] Error Code 2: Internal Error (Assertion node.params.origin == CopyOrigin::kIDENTITY failed.). Below is the minimal reproducible onnx model:
import numpy as np
import torch
inputs = {
'i3': np.random.rand(2, 48).astype(np.float32),
}
class Model(torch.nn.Module):
def __init__(self) -> None:
super().__init__()
@torch.no_grad()
def forward(self, i3):
g = i3 > 0
a = g.reshape(2, 48)
# a = g.reshape(1, 48 * 2) # this would be fine however
# any of the following crashes TensorRT
b = g
# b = torch.all(g)
# b = g.to(torch.int32)
# b = torch.sum(g)
# but fine with any of the following
# b = torch.all(a)
# b = a.to(torch.int32)
# b = torch.sum(a)
return (a, b)
model = Model()
model.eval()
torch_inp = {k: torch.from_numpy(v) for k, v in inputs.items()}
torch.onnx.export(
model, tuple(torch_inp.values()),
"output.onnx", input_names=list(inputs.keys()),
verbose=False, opset_version=14)

My best guess is that the Reshape op is getting optimized to an no-op, but that somehow changed the tensor buffer in place, but the logical op still needs the original buffer.
reshape->logical_op
Interestingly, in a slightly different model with their order switched, it still triggers an error, though different: python: /root/gpgpu/MachineLearning/myelin/src/compiler/.././compiler/kernel_gen/cuda_codegen/cuda_codegen.hpp:285: const string& myelin::kgen::cuda_codegen_t::crd_t::operator[](size_t) const: Assertion `i < crds_.size()' failed. Below are the model and the code
import numpy as np
import torch
inputs = {
'i3': np.random.rand(1, 3, 48, 48).astype(np.float32),
}
class Model(torch.nn.Module):
def __init__(self) -> None:
super().__init__()
@torch.no_grad()
def forward(self, i3):
r = i3.reshape(4, 1, 1728, 1)
a = torch.sqrt(r) # other ops seem fine
a = torch.squeeze(a, 1)
g = r > 0
# any of the following crashes TensorRT
b = g
# b = torch.all(g)
# b = g.to(torch.int32)
# b = torch.sum(g)
return (a, b)
model = Model()
model.eval()
torch_inp = {k: torch.from_numpy(v) for k, v in inputs.items()}
torch.onnx.export(
model, tuple(torch_inp.values()),
"output.onnx", input_names=list(inputs.keys()),
output_names=['o0'],
verbose=False, opset_version=14)

This one is more criptic. I don't have any guess for it.
Environment
TensorRT Version: 8003 NVIDIA GPU: RTX 2080 NVIDIA Driver Version: 495.29.05 CUDA Version: 11.5 CUDNN Version: 8.3.0 Operating System: Ubuntu 18.04 Python Version (if applicable): 3.8.10 Tensorflow Version (if applicable): PyTorch Version (if applicable): 1.10.1 Baremetal or Container (if so, version): Container
Relevant Files
output of first model
&&&& RUNNING TensorRT.trtexec [TensorRT v8003] # trtexec --onnx=./model-1.onnx --verbose
[02/06/2022-04:07:57] [I] === Model Options ===
[02/06/2022-04:07:57] [I] Format: ONNX
[02/06/2022-04:07:57] [I] Model: ./model-1.onnx
[02/06/2022-04:07:57] [I] Output:
[02/06/2022-04:07:57] [I] === Build Options ===
[02/06/2022-04:07:57] [I] Max batch: explicit
[02/06/2022-04:07:57] [I] Workspace: 16 MiB
[02/06/2022-04:07:57] [I] minTiming: 1
[02/06/2022-04:07:57] [I] avgTiming: 8
[02/06/2022-04:07:57] [I] Precision: FP32
[02/06/2022-04:07:57] [I] Calibration:
[02/06/2022-04:07:57] [I] Refit: Disabled
[02/06/2022-04:07:57] [I] Sparsity: Disabled
[02/06/2022-04:07:57] [I] Safe mode: Disabled
[02/06/2022-04:07:57] [I] Restricted mode: Disabled
[02/06/2022-04:07:57] [I] Save engine:
[02/06/2022-04:07:57] [I] Load engine:
[02/06/2022-04:07:57] [I] NVTX verbosity: 0
[02/06/2022-04:07:57] [I] Tactic sources: Using default tactic sources
[02/06/2022-04:07:57] [I] timingCacheMode: local
[02/06/2022-04:07:57] [I] timingCacheFile:
[02/06/2022-04:07:57] [I] Input(s)s format: fp32:CHW
[02/06/2022-04:07:57] [I] Output(s)s format: fp32:CHW
[02/06/2022-04:07:57] [I] Input build shapes: model
[02/06/2022-04:07:57] [I] Input calibration shapes: model
[02/06/2022-04:07:57] [I] === System Options ===
[02/06/2022-04:07:57] [I] Device: 0
[02/06/2022-04:07:57] [I] DLACore:
[02/06/2022-04:07:57] [I] Plugins:
[02/06/2022-04:07:57] [I] === Inference Options ===
[02/06/2022-04:07:57] [I] Batch: Explicit
[02/06/2022-04:07:57] [I] Input inference shapes: model
[02/06/2022-04:07:57] [I] Iterations: 10
[02/06/2022-04:07:57] [I] Duration: 3s (+ 200ms warm up)
[02/06/2022-04:07:57] [I] Sleep time: 0ms
[02/06/2022-04:07:57] [I] Streams: 1
[02/06/2022-04:07:57] [I] ExposeDMA: Disabled
[02/06/2022-04:07:57] [I] Data transfers: Enabled
[02/06/2022-04:07:57] [I] Spin-wait: Disabled
[02/06/2022-04:07:57] [I] Multithreading: Disabled
[02/06/2022-04:07:57] [I] CUDA Graph: Disabled
[02/06/2022-04:07:57] [I] Separate profiling: Disabled
[02/06/2022-04:07:57] [I] Time Deserialize: Disabled
[02/06/2022-04:07:57] [I] Time Refit: Disabled
[02/06/2022-04:07:57] [I] Skip inference: Disabled
[02/06/2022-04:07:57] [I] Inputs:
[02/06/2022-04:07:57] [I] === Reporting Options ===
[02/06/2022-04:07:57] [I] Verbose: Enabled
[02/06/2022-04:07:57] [I] Averages: 10 inferences
[02/06/2022-04:07:57] [I] Percentile: 99
[02/06/2022-04:07:57] [I] Dump refittable layers:Disabled
[02/06/2022-04:07:57] [I] Dump output: Disabled
[02/06/2022-04:07:57] [I] Profile: Disabled
[02/06/2022-04:07:57] [I] Export timing to JSON file:
[02/06/2022-04:07:57] [I] Export output to JSON file:
[02/06/2022-04:07:57] [I] Export profile to JSON file:
[02/06/2022-04:07:57] [I]
[02/06/2022-04:07:57] [I] === Device Information ===
[02/06/2022-04:07:57] [I] Selected Device: NVIDIA GeForce RTX 2080
[02/06/2022-04:07:57] [I] Compute Capability: 7.5
[02/06/2022-04:07:57] [I] SMs: 46
[02/06/2022-04:07:57] [I] Compute Clock Rate: 1.71 GHz
[02/06/2022-04:07:57] [I] Device Global Memory: 7982 MiB
[02/06/2022-04:07:57] [I] Shared Memory per SM: 64 KiB
[02/06/2022-04:07:57] [I] Memory Bus Width: 256 bits (ECC disabled)
[02/06/2022-04:07:57] [I] Memory Clock Rate: 7 GHz
[02/06/2022-04:07:57] [I]
[02/06/2022-04:07:57] [I] TensorRT version: 8003
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::GridAnchor_TRT version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::GridAnchorRect_TRT version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::NMS_TRT version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::Reorg_TRT version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::Region_TRT version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::Clip_TRT version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::LReLU_TRT version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::PriorBox_TRT version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::Normalize_TRT version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::ScatterND version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::RPROI_TRT version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::BatchedNMS_TRT version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::BatchedNMSDynamic_TRT version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::FlattenConcat_TRT version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::CropAndResize version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::DetectionLayer_TRT version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::EfficientNMS_ONNX_TRT version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::EfficientNMS_TRT version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::Proposal version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::ProposalLayer_TRT version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::PyramidROIAlign_TRT version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::ResizeNearest_TRT version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::Split version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::SpecialSlice_TRT version 1
[02/06/2022-04:07:57] [V] [TRT] Registered plugin creator - ::InstanceNormalization_TRT version 1
[02/06/2022-04:07:58] [I] [TRT] [MemUsageChange] Init CUDA: CPU +328, GPU +0, now: CPU 335, GPU 271 (MiB)
[02/06/2022-04:07:58] [I] Start parsing network model
[02/06/2022-04:07:58] [I] [TRT] ----------------------------------------------------------------
[02/06/2022-04:07:58] [I] [TRT] Input filename: ./model-1.onnx
[02/06/2022-04:07:58] [I] [TRT] ONNX IR version: 0.0.7
[02/06/2022-04:07:58] [I] [TRT] Opset version: 14
[02/06/2022-04:07:58] [I] [TRT] Producer name: pytorch
[02/06/2022-04:07:58] [I] [TRT] Producer version: 1.10
[02/06/2022-04:07:58] [I] [TRT] Domain:
[02/06/2022-04:07:58] [I] [TRT] Model version: 0
[02/06/2022-04:07:58] [I] [TRT] Doc string:
[02/06/2022-04:07:58] [I] [TRT] ----------------------------------------------------------------
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::GridAnchor_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::GridAnchorRect_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::NMS_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::Reorg_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::Region_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::Clip_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::LReLU_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::PriorBox_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::Normalize_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::ScatterND version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::RPROI_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::BatchedNMS_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::BatchedNMSDynamic_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::FlattenConcat_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::CropAndResize version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::DetectionLayer_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::EfficientNMS_ONNX_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::EfficientNMS_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::Proposal version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::ProposalLayer_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::PyramidROIAlign_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::ResizeNearest_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::Split version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::SpecialSlice_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Plugin creator already registered - ::InstanceNormalization_TRT version 1
[02/06/2022-04:07:58] [V] [TRT] Adding network input: i3 with dtype: float32, dimensions: (2, 48)
[02/06/2022-04:07:58] [V] [TRT] Registering tensor: i3 for ONNX tensor: i3
[02/06/2022-04:07:58] [V] [TRT] Parsing node: Constant_0 [Constant]
[02/06/2022-04:07:58] [V] [TRT] Constant_0 [Constant] inputs:
[02/06/2022-04:07:58] [V] [TRT] Constant_0 [Constant] outputs: [1 -> ()[FLOAT]],
[02/06/2022-04:07:58] [V] [TRT] Parsing node: Greater_1 [Greater]
[02/06/2022-04:07:58] [V] [TRT] Searching for input: i3
[02/06/2022-04:07:58] [V] [TRT] Searching for input: 1
[02/06/2022-04:07:58] [V] [TRT] Greater_1 [Greater] inputs: [i3 -> (2, 48)[FLOAT]], [1 -> ()[FLOAT]],
[02/06/2022-04:07:58] [V] [TRT] Registering layer: 1 for ONNX node: 1
[02/06/2022-04:07:58] [V] [TRT] Registering layer: Greater_1 for ONNX node: Greater_1
[02/06/2022-04:07:58] [V] [TRT] Registering tensor: 2_0 for ONNX tensor: 2
[02/06/2022-04:07:58] [V] [TRT] Greater_1 [Greater] outputs: [2 -> (2, 48)[BOOL]],
[02/06/2022-04:07:58] [V] [TRT] Parsing node: Constant_2 [Constant]
[02/06/2022-04:07:58] [V] [TRT] Constant_2 [Constant] inputs:
[02/06/2022-04:07:58] [W] [TRT] onnx2trt_utils.cpp:362: Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32.
[02/06/2022-04:07:58] [V] [TRT] Constant_2 [Constant] outputs: [3 -> (2)[INT32]],
[02/06/2022-04:07:58] [V] [TRT] Parsing node: Reshape_3 [Reshape]
[02/06/2022-04:07:58] [V] [TRT] Searching for input: 2
[02/06/2022-04:07:58] [V] [TRT] Searching for input: 3
[02/06/2022-04:07:58] [V] [TRT] Reshape_3 [Reshape] inputs: [2 -> (2, 48)[BOOL]], [3 -> (2)[INT32]],
[02/06/2022-04:07:58] [V] [TRT] Registering layer: Reshape_3 for ONNX node: Reshape_3
[02/06/2022-04:07:58] [V] [TRT] Registering tensor: 4_1 for ONNX tensor: 4
[02/06/2022-04:07:58] [V] [TRT] Reshape_3 [Reshape] outputs: [4 -> (2, 48)[BOOL]],
[02/06/2022-04:07:58] [V] [TRT] Marking 4_1 as output: 4
[02/06/2022-04:07:58] [V] [TRT] Marking 2_0 as output: 2
[02/06/2022-04:07:58] [I] Finish parsing network model
[02/06/2022-04:07:58] [I] [TRT] [MemUsageChange] Init CUDA: CPU +0, GPU +0, now: CPU 335, GPU 271 (MiB)
[02/06/2022-04:07:58] [I] [TRT] [MemUsageSnapshot] Builder begin: CPU 335 MiB, GPU 271 MiB
[02/06/2022-04:07:58] [V] [TRT] Applying generic optimizations to the graph for inference.
[02/06/2022-04:07:58] [V] [TRT] Original: 4 layers
[02/06/2022-04:07:58] [V] [TRT] After dead-layer removal: 4 layers
[02/06/2022-04:07:58] [V] [TRT] ConstShuffleFusion: Fusing 1 with (Unnamed Layer* 1) [Shuffle]
[02/06/2022-04:07:58] [V] [TRT] Removing Reshape_3
[02/06/2022-04:07:58] [V] [TRT] After Myelin optimization: 1 layers
[02/06/2022-04:07:58] [V] [TRT] After scale fusion: 1 layers
[02/06/2022-04:07:58] [V] [TRT] After vertical fusions: 1 layers
[02/06/2022-04:07:58] [V] [TRT] After dupe layer removal: 1 layers
[02/06/2022-04:07:58] [V] [TRT] After final dead-layer removal: 1 layers
[02/06/2022-04:07:58] [V] [TRT] After tensor merging: 1 layers
[02/06/2022-04:07:58] [V] [TRT] After concat removal: 1 layers
[02/06/2022-04:07:58] [V] [TRT] Graph construction and optimization completed in 0.000603092 seconds.
[02/06/2022-04:07:58] [V] [TRT] Using cublasLt a tactic source
[02/06/2022-04:07:58] [I] [TRT] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +508, GPU +222, now: CPU 843, GPU 493 (MiB)
[02/06/2022-04:07:58] [V] [TRT] Using cuDNN as a tactic source
[02/06/2022-04:07:58] [I] [TRT] [MemUsageChange] Init cuDNN: CPU +114, GPU +52, now: CPU 957, GPU 545 (MiB)
[02/06/2022-04:07:58] [W] [TRT] Detected invalid timing cache, setup a local cache instead
[02/06/2022-04:07:58] [V] [TRT] Constructing optimization profile number 0 [1/1].
[02/06/2022-04:07:58] [V] [TRT] *************** Autotuning format combination: Float(48,1) -> Bool(48,1), Bool(48,1) ***************
[02/06/2022-04:07:58] [V] [TRT] --------------- Timing Runner: {ForeignNode[1 + (Unnamed Layer* 1) [Shuffle]...Reshape_3]} (Myelin)
[02/06/2022-04:07:58] [I] [TRT] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +0, GPU +0, now: CPU 957, GPU 527 (MiB)
[02/06/2022-04:07:58] [E] Error[2]: [myelinCopyLayer.cpp::addCopy::14] Error Code 2: Internal Error (Assertion node.params.origin == CopyOrigin::kIDENTITY failed.)
[02/06/2022-04:07:58] [E] Error[2]: [builder.cpp::buildSerializedNetwork::417] Error Code 2: Internal Error (Assertion enginePtr != nullptr failed.)
output of the second model
&&&& RUNNING TensorRT.trtexec [TensorRT v8003] # trtexec --onnx=./model-2.onnx --verbose
[02/06/2022-04:08:10] [I] === Model Options ===
[02/06/2022-04:08:10] [I] Format: ONNX
[02/06/2022-04:08:10] [I] Model: ./model-2.onnx
[02/06/2022-04:08:10] [I] Output:
[02/06/2022-04:08:10] [I] === Build Options ===
[02/06/2022-04:08:10] [I] Max batch: explicit
[02/06/2022-04:08:10] [I] Workspace: 16 MiB
[02/06/2022-04:08:10] [I] minTiming: 1
[02/06/2022-04:08:10] [I] avgTiming: 8
[02/06/2022-04:08:10] [I] Precision: FP32
[02/06/2022-04:08:10] [I] Calibration:
[02/06/2022-04:08:10] [I] Refit: Disabled
[02/06/2022-04:08:10] [I] Sparsity: Disabled
[02/06/2022-04:08:10] [I] Safe mode: Disabled
[02/06/2022-04:08:10] [I] Restricted mode: Disabled
[02/06/2022-04:08:10] [I] Save engine:
[02/06/2022-04:08:10] [I] Load engine:
[02/06/2022-04:08:10] [I] NVTX verbosity: 0
[02/06/2022-04:08:10] [I] Tactic sources: Using default tactic sources
[02/06/2022-04:08:10] [I] timingCacheMode: local
[02/06/2022-04:08:10] [I] timingCacheFile:
[02/06/2022-04:08:10] [I] Input(s)s format: fp32:CHW
[02/06/2022-04:08:10] [I] Output(s)s format: fp32:CHW
[02/06/2022-04:08:10] [I] Input build shapes: model
[02/06/2022-04:08:10] [I] Input calibration shapes: model
[02/06/2022-04:08:10] [I] === System Options ===
[02/06/2022-04:08:10] [I] Device: 0
[02/06/2022-04:08:10] [I] DLACore:
[02/06/2022-04:08:10] [I] Plugins:
[02/06/2022-04:08:10] [I] === Inference Options ===
[02/06/2022-04:08:10] [I] Batch: Explicit
[02/06/2022-04:08:10] [I] Input inference shapes: model
[02/06/2022-04:08:10] [I] Iterations: 10
[02/06/2022-04:08:10] [I] Duration: 3s (+ 200ms warm up)
[02/06/2022-04:08:10] [I] Sleep time: 0ms
[02/06/2022-04:08:10] [I] Streams: 1
[02/06/2022-04:08:10] [I] ExposeDMA: Disabled
[02/06/2022-04:08:10] [I] Data transfers: Enabled
[02/06/2022-04:08:10] [I] Spin-wait: Disabled
[02/06/2022-04:08:10] [I] Multithreading: Disabled
[02/06/2022-04:08:10] [I] CUDA Graph: Disabled
[02/06/2022-04:08:10] [I] Separate profiling: Disabled
[02/06/2022-04:08:10] [I] Time Deserialize: Disabled
[02/06/2022-04:08:10] [I] Time Refit: Disabled
[02/06/2022-04:08:10] [I] Skip inference: Disabled
[02/06/2022-04:08:10] [I] Inputs:
[02/06/2022-04:08:10] [I] === Reporting Options ===
[02/06/2022-04:08:10] [I] Verbose: Enabled
[02/06/2022-04:08:10] [I] Averages: 10 inferences
[02/06/2022-04:08:10] [I] Percentile: 99
[02/06/2022-04:08:10] [I] Dump refittable layers:Disabled
[02/06/2022-04:08:10] [I] Dump output: Disabled
[02/06/2022-04:08:10] [I] Profile: Disabled
[02/06/2022-04:08:10] [I] Export timing to JSON file:
[02/06/2022-04:08:10] [I] Export output to JSON file:
[02/06/2022-04:08:10] [I] Export profile to JSON file:
[02/06/2022-04:08:10] [I]
[02/06/2022-04:08:10] [I] === Device Information ===
[02/06/2022-04:08:10] [I] Selected Device: NVIDIA GeForce RTX 2080
[02/06/2022-04:08:10] [I] Compute Capability: 7.5
[02/06/2022-04:08:10] [I] SMs: 46
[02/06/2022-04:08:10] [I] Compute Clock Rate: 1.71 GHz
[02/06/2022-04:08:10] [I] Device Global Memory: 7982 MiB
[02/06/2022-04:08:10] [I] Shared Memory per SM: 64 KiB
[02/06/2022-04:08:10] [I] Memory Bus Width: 256 bits (ECC disabled)
[02/06/2022-04:08:10] [I] Memory Clock Rate: 7 GHz
[02/06/2022-04:08:10] [I]
[02/06/2022-04:08:10] [I] TensorRT version: 8003
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::GridAnchor_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::GridAnchorRect_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::NMS_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::Reorg_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::Region_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::Clip_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::LReLU_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::PriorBox_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::Normalize_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::ScatterND version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::RPROI_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::BatchedNMS_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::BatchedNMSDynamic_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::FlattenConcat_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::CropAndResize version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::DetectionLayer_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::EfficientNMS_ONNX_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::EfficientNMS_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::Proposal version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::ProposalLayer_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::PyramidROIAlign_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::ResizeNearest_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::Split version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::SpecialSlice_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Registered plugin creator - ::InstanceNormalization_TRT version 1
[02/06/2022-04:08:10] [I] [TRT] [MemUsageChange] Init CUDA: CPU +328, GPU +0, now: CPU 335, GPU 271 (MiB)
[02/06/2022-04:08:10] [I] Start parsing network model
[02/06/2022-04:08:10] [I] [TRT] ----------------------------------------------------------------
[02/06/2022-04:08:10] [I] [TRT] Input filename: ./model-2.onnx
[02/06/2022-04:08:10] [I] [TRT] ONNX IR version: 0.0.7
[02/06/2022-04:08:10] [I] [TRT] Opset version: 14
[02/06/2022-04:08:10] [I] [TRT] Producer name: pytorch
[02/06/2022-04:08:10] [I] [TRT] Producer version: 1.10
[02/06/2022-04:08:10] [I] [TRT] Domain:
[02/06/2022-04:08:10] [I] [TRT] Model version: 0
[02/06/2022-04:08:10] [I] [TRT] Doc string:
[02/06/2022-04:08:10] [I] [TRT] ----------------------------------------------------------------
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::GridAnchor_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::GridAnchorRect_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::NMS_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::Reorg_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::Region_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::Clip_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::LReLU_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::PriorBox_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::Normalize_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::ScatterND version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::RPROI_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::BatchedNMS_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::BatchedNMSDynamic_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::FlattenConcat_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::CropAndResize version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::DetectionLayer_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::EfficientNMS_ONNX_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::EfficientNMS_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::Proposal version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::ProposalLayer_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::PyramidROIAlign_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::ResizeNearest_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::Split version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::SpecialSlice_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Plugin creator already registered - ::InstanceNormalization_TRT version 1
[02/06/2022-04:08:10] [V] [TRT] Adding network input: i3 with dtype: float32, dimensions: (1, 3, 48, 48)
[02/06/2022-04:08:10] [V] [TRT] Registering tensor: i3 for ONNX tensor: i3
[02/06/2022-04:08:10] [V] [TRT] Parsing node: Constant_0 [Constant]
[02/06/2022-04:08:10] [V] [TRT] Constant_0 [Constant] inputs:
[02/06/2022-04:08:10] [W] [TRT] onnx2trt_utils.cpp:362: Your ONNX model has been generated with INT64 weights, while TensorRT does not natively support INT64. Attempting to cast down to INT32.
[02/06/2022-04:08:10] [V] [TRT] Constant_0 [Constant] outputs: [1 -> (4)[INT32]],
[02/06/2022-04:08:10] [V] [TRT] Parsing node: Reshape_1 [Reshape]
[02/06/2022-04:08:10] [V] [TRT] Searching for input: i3
[02/06/2022-04:08:10] [V] [TRT] Searching for input: 1
[02/06/2022-04:08:10] [V] [TRT] Reshape_1 [Reshape] inputs: [i3 -> (1, 3, 48, 48)[FLOAT]], [1 -> (4)[INT32]],
[02/06/2022-04:08:10] [V] [TRT] Registering layer: Reshape_1 for ONNX node: Reshape_1
[02/06/2022-04:08:10] [V] [TRT] Registering tensor: 2 for ONNX tensor: 2
[02/06/2022-04:08:10] [V] [TRT] Reshape_1 [Reshape] outputs: [2 -> (4, 1, 1728, 1)[FLOAT]],
[02/06/2022-04:08:10] [V] [TRT] Parsing node: Sqrt_2 [Sqrt]
[02/06/2022-04:08:10] [V] [TRT] Searching for input: 2
[02/06/2022-04:08:10] [V] [TRT] Sqrt_2 [Sqrt] inputs: [2 -> (4, 1, 1728, 1)[FLOAT]],
[02/06/2022-04:08:10] [V] [TRT] Registering layer: Sqrt_2 for ONNX node: Sqrt_2
[02/06/2022-04:08:10] [V] [TRT] Registering tensor: 3 for ONNX tensor: 3
[02/06/2022-04:08:10] [V] [TRT] Sqrt_2 [Sqrt] outputs: [3 -> (4, 1, 1728, 1)[FLOAT]],
[02/06/2022-04:08:10] [V] [TRT] Parsing node: Constant_3 [Constant]
[02/06/2022-04:08:10] [V] [TRT] Constant_3 [Constant] inputs:
[02/06/2022-04:08:10] [V] [TRT] Constant_3 [Constant] outputs: [4 -> (1)[INT32]],
[02/06/2022-04:08:10] [V] [TRT] Parsing node: Squeeze_4 [Squeeze]
[02/06/2022-04:08:10] [V] [TRT] Searching for input: 3
[02/06/2022-04:08:10] [V] [TRT] Searching for input: 4
[02/06/2022-04:08:10] [V] [TRT] Squeeze_4 [Squeeze] inputs: [3 -> (4, 1, 1728, 1)[FLOAT]], [4 -> (1)[INT32]],
[02/06/2022-04:08:10] [V] [TRT] Original shape: (4, 1, 1728, 1), squeezing to: (4, 1728, 1)
[02/06/2022-04:08:10] [V] [TRT] Registering layer: Squeeze_4 for ONNX node: Squeeze_4
[02/06/2022-04:08:10] [V] [TRT] Registering tensor: o0_0 for ONNX tensor: o0
[02/06/2022-04:08:10] [V] [TRT] Squeeze_4 [Squeeze] outputs: [o0 -> (4, 1728, 1)[FLOAT]],
[02/06/2022-04:08:10] [V] [TRT] Parsing node: Constant_5 [Constant]
[02/06/2022-04:08:10] [V] [TRT] Constant_5 [Constant] inputs:
[02/06/2022-04:08:10] [V] [TRT] Constant_5 [Constant] outputs: [6 -> ()[FLOAT]],
[02/06/2022-04:08:10] [V] [TRT] Parsing node: Greater_6 [Greater]
[02/06/2022-04:08:10] [V] [TRT] Searching for input: 2
[02/06/2022-04:08:10] [V] [TRT] Searching for input: 6
[02/06/2022-04:08:10] [V] [TRT] Greater_6 [Greater] inputs: [2 -> (4, 1, 1728, 1)[FLOAT]], [6 -> ()[FLOAT]],
[02/06/2022-04:08:10] [V] [TRT] Registering layer: 6 for ONNX node: 6
[02/06/2022-04:08:10] [V] [TRT] Registering layer: Greater_6 for ONNX node: Greater_6
[02/06/2022-04:08:10] [V] [TRT] Registering tensor: 7_1 for ONNX tensor: 7
[02/06/2022-04:08:10] [V] [TRT] Greater_6 [Greater] outputs: [7 -> (4, 1, 1728, 1)[BOOL]],
[02/06/2022-04:08:10] [V] [TRT] Marking o0_0 as output: o0
[02/06/2022-04:08:10] [V] [TRT] Marking 7_1 as output: 7
[02/06/2022-04:08:10] [I] Finish parsing network model
[02/06/2022-04:08:10] [I] [TRT] [MemUsageChange] Init CUDA: CPU +0, GPU +0, now: CPU 335, GPU 271 (MiB)
[02/06/2022-04:08:10] [I] [TRT] [MemUsageSnapshot] Builder begin: CPU 335 MiB, GPU 271 MiB
[02/06/2022-04:08:10] [V] [TRT] Applying generic optimizations to the graph for inference.
[02/06/2022-04:08:10] [V] [TRT] Original: 6 layers
[02/06/2022-04:08:10] [V] [TRT] After dead-layer removal: 6 layers
[02/06/2022-04:08:10] [V] [TRT] ConstShuffleFusion: Fusing 6 with (Unnamed Layer* 4) [Shuffle]
[02/06/2022-04:08:10] [V] [TRT] After Myelin optimization: 1 layers
[02/06/2022-04:08:10] [V] [TRT] After scale fusion: 1 layers
[02/06/2022-04:08:10] [V] [TRT] After vertical fusions: 1 layers
[02/06/2022-04:08:10] [V] [TRT] After dupe layer removal: 1 layers
[02/06/2022-04:08:10] [V] [TRT] After final dead-layer removal: 1 layers
[02/06/2022-04:08:10] [V] [TRT] After tensor merging: 1 layers
[02/06/2022-04:08:10] [V] [TRT] After concat removal: 1 layers
[02/06/2022-04:08:10] [V] [TRT] Graph construction and optimization completed in 0.000609018 seconds.
[02/06/2022-04:08:11] [V] [TRT] Using cublasLt a tactic source
[02/06/2022-04:08:11] [I] [TRT] [MemUsageChange] Init cuBLAS/cuBLASLt: CPU +508, GPU +222, now: CPU 843, GPU 493 (MiB)
[02/06/2022-04:08:11] [V] [TRT] Using cuDNN as a tactic source
[02/06/2022-04:08:11] [I] [TRT] [MemUsageChange] Init cuDNN: CPU +114, GPU +52, now: CPU 957, GPU 545 (MiB)
[02/06/2022-04:08:11] [W] [TRT] Detected invalid timing cache, setup a local cache instead
[02/06/2022-04:08:11] [V] [TRT] Constructing optimization profile number 0 [1/1].
[02/06/2022-04:08:11] [V] [TRT] *************** Autotuning format combination: Float(6912,2304,48,1) -> Bool(1728,1728,1,1), Float(1728,1,1) ***************
[02/06/2022-04:08:11] [V] [TRT] --------------- Timing Runner: {ForeignNode[Reshape_1...Squeeze_4]} (Myelin)
trtexec: /root/gpgpu/MachineLearning/myelin/src/compiler/.././compiler/kernel_gen/cuda_codegen/cuda_codegen.hpp:285: const string& myelin::kgen::cuda_codegen_t::crd_t::operator[](size_t) const: Assertion `i < crds_.size()' failed.
Steps To Reproduce
trtexec --onnx=./model-1.onnx --verbose and trtexec --onnx=./model-2.onnx --verbose. See models.zip for model-1.onnx and model-2.onnx.
So after some investigation it really seems that the logical operator is not operating on the buffer or on a buffer overwritten by some downstream op. For example,
import numpy as np
import torch
inputs = {
'i3': np.random.uniform(0, 1, size=(20, 20)).astype(np.float32),
}
class Model(torch.nn.Module):
def __init__(self) -> None:
super().__init__()
self.relu = torch.nn.ReLU()
@torch.no_grad()
def forward(self, i3):
a = self.relu(i3)
b = a.min(1).values
return (b, a >= -1)
model = Model()
model.eval()
torch_inp = {k: torch.from_numpy(v) for k, v in inputs.items()}
torch.onnx.export(
model, tuple(torch_inp.values()),
"output.onnx", input_names=list(inputs.keys()),
output_names=['red_min', 'bool'],
verbose=False, opset_version=14)

The output of the bool tensor should always be True everywhere, but turns out the command trtexec --onnx=output.onnx --dumpOutput gives
...
[02/06/2022-06:32:07] [I] Output Tensors:
[02/06/2022-06:32:07] [I] bool: (20x20)
[02/06/2022-06:32:07] [I] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[02/06/2022-06:32:07] [I] red_min: (20)
[02/06/2022-06:32:07] [I] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
&&&& PASSED TensorRT.trtexec [TensorRT v8003] # trtexec --onnx=output.onnx --dumpOutput
where bool tensor is only partially True, likely polluted by the reduce_min op. This error won't show after commenting out the reduce_min line.
Model file: output.onnx.zip