Skip to content

Commit 3a77121

Browse files
committed
use kprod with -1 instead of kneg for negation
1 parent c0bcffb commit 3a77121

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

core/conversion/converters/impl/bitwise.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ auto bitwisenot TORCHTRT_UNUSED =
1919

2020
if(in->getType() == nvinfer1::DataType::kINT32) {
2121
// Integer case
22-
auto one = torch::tensor({1}, util::TRTDataTypeToScalarType(in->getType()));
23-
auto one_const = tensor_to_const(ctx, one);
24-
auto neg = ctx->net->addUnary(*in, nvinfer1::UnaryOperation::kNEG);
25-
TORCHTRT_CHECK(neg, "Unable to create neg unary layer from node: " << *n);
22+
auto neg_one = torch::tensor({-1}, util::TRTDataTypeToScalarType(in->getType()));
23+
auto neg_one_const = tensor_to_const(ctx, neg_one);
24+
auto neg = add_elementwise(
25+
ctx, nvinfer1::ElementWiseOperation::kPROD, in,
26+
neg_one_const, util::node_info(n) + std::string("_Negation"));
27+
TORCHTRT_CHECK(neg, "Unable to create prod layer from node: " << *n);
2628
out = add_elementwise(
27-
ctx, nvinfer1::ElementWiseOperation::kSUB, neg->getOutput(0),
28-
one_const, util::node_info(n));
29-
TORCHTRT_CHECK(out, "Unable to create sub layer from node: " << *n);
29+
ctx, nvinfer1::ElementWiseOperation::kSUM, neg->getOutput(0),
30+
neg_one_const, util::node_info(n) + std::string("_SubOne"));
31+
TORCHTRT_CHECK(out, "Unable to create sum layer from node: " << *n);
3032
} else if(in->getType() == nvinfer1::DataType::kBOOL) {
3133
// Boolean case
3234
out = ctx->net->addUnary(*in, nvinfer1::UnaryOperation::kNOT);

0 commit comments

Comments
 (0)