From af957b1535c28e3bb51398035f14678362df2294 Mon Sep 17 00:00:00 2001 From: iabhi4 Date: Sun, 15 Mar 2026 21:16:45 -0400 Subject: [PATCH] #4486 - Reconstruct Ceil and Round ops for DLA compatibility Ceil and Round map to IUnaryLayer which only supports kABS on DLA. Reconstruct Ceil as -floor(-x) and Round as floor(x+0.5) using IUnaryLayer(kFLOOR) and IElementWiseLayer, both DLA-native. Add test_round to onnx_backend_test.py. Signed-off-by: iabhi4 --- onnxOpImporters.cpp | 25 +++++++++++++++++++++++-- onnx_backend_test.py | 1 + 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/onnxOpImporters.cpp b/onnxOpImporters.cpp index 5f39005d..b32bb5be 100644 --- a/onnxOpImporters.cpp +++ b/onnxOpImporters.cpp @@ -584,7 +584,19 @@ DEFINE_BUILTIN_OP_IMPORTER(CastLike) DEFINE_BUILTIN_OP_IMPORTER(Ceil) { - return unaryHelper(ctx, node, nodeIdx, inputs.at(0), nvinfer1::UnaryOperation::kCEIL); + nvinfer1::ITensor& input = convertToTensor(inputs.at(0), ctx); + nvinfer1::IConstantLayer* negOne + = addConstantScalar(ctx, -1.f, ::ONNX_NAMESPACE::TensorProto_DataType_FLOAT, getNbDims(&input)); + nvinfer1::IElementWiseLayer* negInput + = N_CHECK(ctx->network()->addElementWise(input, *negOne->getOutput(0), nvinfer1::ElementWiseOperation::kPROD)); + ctx->registerLayer(negInput, node); + nvinfer1::IUnaryLayer* floorNegInput + = N_CHECK(ctx->network()->addUnary(*negInput->getOutput(0), nvinfer1::UnaryOperation::kFLOOR)); + ctx->registerLayer(floorNegInput, node); + nvinfer1::IElementWiseLayer* result = N_CHECK(ctx->network()->addElementWise( + *floorNegInput->getOutput(0), *negOne->getOutput(0), nvinfer1::ElementWiseOperation::kPROD)); + ctx->registerLayer(result, node); + return {{result->getOutput(0)}}; } DEFINE_BUILTIN_OP_IMPORTER(Celu) @@ -5043,7 +5055,16 @@ DEFINE_BUILTIN_OP_IMPORTER(Sign) DEFINE_BUILTIN_OP_IMPORTER(Round) { - return unaryHelper(ctx, node, nodeIdx, inputs.at(0), nvinfer1::UnaryOperation::kROUND); + nvinfer1::ITensor& input = convertToTensor(inputs.at(0), ctx); + nvinfer1::IConstantLayer* half + = addConstantScalar(ctx, 0.5f, ::ONNX_NAMESPACE::TensorProto_DataType_FLOAT, getNbDims(&input)); + nvinfer1::IElementWiseLayer* addHalf + = N_CHECK(ctx->network()->addElementWise(input, *half->getOutput(0), nvinfer1::ElementWiseOperation::kSUM)); + ctx->registerLayer(addHalf, node); + nvinfer1::IUnaryLayer* result + = N_CHECK(ctx->network()->addUnary(*addHalf->getOutput(0), nvinfer1::UnaryOperation::kFLOOR)); + ctx->registerLayer(result, node); + return {{result->getOutput(0)}}; } DEFINE_BUILTIN_OP_IMPORTER(Resize) diff --git a/onnx_backend_test.py b/onnx_backend_test.py index f62004ad..fe0c0a1a 100644 --- a/onnx_backend_test.py +++ b/onnx_backend_test.py @@ -107,6 +107,7 @@ backend_test.include(r'.*test_reduce.*') backend_test.include(r'.*test_ReLU*') backend_test.include(r'.*test_relu.*') +backend_test.include(r'.*test_round.*') backend_test.include(r'.*test_selu.*') backend_test.include(r'.*test_shape.*') backend_test.include(r'.*test_Sigmoid*')