Skip to content

Commit fa509d9

Browse files
committed
refactor(//core/conversion/var): Rename Arg -> Var
Signed-off-by: Naren Dasan <[email protected]> Signed-off-by: Naren Dasan <[email protected]>
1 parent ac2b102 commit fa509d9

File tree

4 files changed

+40
-45
lines changed

4 files changed

+40
-45
lines changed

Diff for: core/conversion/arg/BUILD renamed to core/conversion/var/BUILD

+6-7
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@ config_setting(
88
)
99

1010
cc_library(
11-
name = "arg",
11+
name = "var",
1212
hdrs = [
13-
"Arg.h",
14-
"Arg_inl.h"
13+
"Var.h",
14+
"Var_inl.h"
1515
],
1616
srcs = [
17-
"Arg.cpp",
17+
"Var.cpp",
1818
],
1919
deps = [
2020
"@tensorrt//:nvinfer",
2121
"//core/util:prelude",
22-
"//core/conversion/conversionctx",
2322
] + select({
2423
":use_pre_cxx11_abi": ["@libtorch_pre_cxx11_abi//:libtorch"],
2524
"//conditions:default": ["@libtorch//:libtorch"],
@@ -33,7 +32,7 @@ pkg_tar(
3332
name = "include",
3433
package_dir = "core/conversion/arg/",
3534
srcs = [
36-
"Arg.h",
37-
"Arg_inl.h"
35+
"Var.h",
36+
"Var_inl.h"
3837
],
3938
)

Diff for: core/conversion/arg/Arg.cpp renamed to core/conversion/var/Var.cpp

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
#include "core/util/prelude.h"
2-
#include "core/conversion/arg/Arg.h"
2+
#include "core/conversion/var/Var.h"
33

44
namespace trtorch {
55
namespace core {
66
namespace conversion {
77

8-
Arg::Arg() {
8+
Var::Var() {
99
ptr_.none = nullptr;
1010
type_ = Type::kNone;
1111
}
1212

13-
Arg::Arg(const torch::jit::IValue* p)
13+
Var::Var(const torch::jit::IValue* p)
1414
: type_(Type::kIValue) {
1515
ptr_.ivalue = p;
1616
}
1717

18-
Arg::Arg(nvinfer1::ITensor* p)
18+
Var::Var(nvinfer1::ITensor* p)
1919
: type_(Type::kITensor) {
2020
ptr_.tensor = p;
2121
}
2222

23-
Arg::Arg(const Arg& a) {
23+
Var::Var(const Var& a) {
2424
switch(a.type_) {
2525
case Type::kITensor:
2626
ptr_.tensor = a.ptr_.tensor;
@@ -37,7 +37,7 @@ Arg::Arg(const Arg& a) {
3737
}
3838
}
3939

40-
Arg& Arg::operator=(const Arg& a) {
40+
Var& Var::operator=(const Var& a) {
4141
switch(a.type_) {
4242
case Type::kITensor:
4343
ptr_.tensor = a.ptr_.tensor;
@@ -55,23 +55,23 @@ Arg& Arg::operator=(const Arg& a) {
5555
return (*this);
5656
}
5757

58-
Arg& Arg::operator=(const torch::jit::IValue* in) {
58+
Var& Var::operator=(const torch::jit::IValue* in) {
5959
ptr_.ivalue = in;
6060
type_ = Type::kIValue;
6161
return (*this);
6262
}
6363

64-
Arg& Arg::operator=(nvinfer1::ITensor* in) {
64+
Var& Var::operator=(nvinfer1::ITensor* in) {
6565
ptr_.tensor = in;
6666
type_ = Type::kITensor;
6767
return (*this);
6868
}
6969

70-
Arg::Type Arg::type() const {
70+
Var::Type Var::type() const {
7171
return type_;
7272
}
7373

74-
std::string Arg::type_name() const {
74+
std::string Var::type_name() const {
7575
switch(type_) {
7676
case Type::kITensor:
7777
return "nvinfer1::ITensor";
@@ -85,41 +85,41 @@ std::string Arg::type_name() const {
8585
}
8686
}
8787

88-
const torch::jit::IValue* Arg::IValue() const {
89-
TRTORCH_CHECK(isIValue(), "Requested IValue from Arg, however arg type is " << type_name());
88+
const torch::jit::IValue* Var::IValue() const {
89+
TRTORCH_CHECK(isIValue(), "Requested IValue from Var, however Var type is " << type_name());
9090
if (type_ == Type::kIValue) {
9191
return ptr_.ivalue;
9292
} else {
9393
return nullptr;
9494
}
9595
}
9696

97-
nvinfer1::ITensor* Arg::ITensor() const {
98-
TRTORCH_CHECK(isITensor(), "Requested ITensor from Arg, however arg type is " << type_name());
97+
nvinfer1::ITensor* Var::ITensor() const {
98+
TRTORCH_CHECK(isITensor(), "Requested ITensor from Var, however Var type is " << type_name());
9999
if (type_ == Type::kITensor) {
100100
return ptr_.tensor;
101101
} else {
102102
return nullptr;
103103
}
104104
}
105105

106-
bool Arg::isITensor() const {
106+
bool Var::isITensor() const {
107107
if (type_ == Type::kITensor) {
108108
return true;
109109
} else {
110110
return false;
111111
}
112112
}
113113

114-
bool Arg::isIValue() const {
114+
bool Var::isIValue() const {
115115
if (type_ == Type::kIValue) {
116116
return true;
117117
} else {
118118
return false;
119119
}
120120
}
121121

122-
bool Arg::isNone() const {
122+
bool Var::isNone() const {
123123
if (type_ == Type::kNone) {
124124
return true;
125125
} else {

Diff for: core/conversion/arg/Arg.h renamed to core/conversion/var/Var.h

+13-15
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,29 @@
33
#include <string>
44
#include <map>
55

6-
#include "torch/csrc/jit/runtime/custom_operator.h"
7-
#include "ATen/core/function_schema.h"
6+
#include "torch/csrc/jit/ir/ir.h"
87

98
#include "core/util/prelude.h"
10-
#include "core/conversion/conversionctx/ConversionCtx.h"
119

1210
namespace trtorch {
1311
namespace core {
1412
namespace conversion {
1513

16-
class Arg {
14+
class Var : torch::CustomClassHolder {
1715
public:
1816
enum Type {
1917
kITensor,
2018
kIValue,
2119
kNone
2220
};
2321

24-
Arg();
25-
Arg(const torch::jit::IValue* p);
26-
Arg(nvinfer1::ITensor* p);
27-
Arg(const Arg& a);
28-
Arg& operator=(const Arg& a);
29-
Arg& operator=(const torch::jit::IValue* in);
30-
Arg& operator=(nvinfer1::ITensor* in);
22+
Var();
23+
Var(const torch::jit::IValue* p);
24+
Var(nvinfer1::ITensor* p);
25+
Var(const Var& a);
26+
Var& operator=(const Var& a);
27+
Var& operator=(const torch::jit::IValue* in);
28+
Var& operator=(nvinfer1::ITensor* in);
3129
const torch::jit::IValue* IValue() const;
3230
nvinfer1::ITensor* ITensor() const;
3331

@@ -59,21 +57,21 @@ class Arg {
5957
bool isIValue() const;
6058
bool isITensor() const;
6159
bool isNone() const;
62-
Arg::Type type() const;
60+
Var::Type type() const;
6361
std::string type_name() const;
6462
private:
65-
union ArgContainer {
63+
union VarContainer {
6664
const torch::jit::IValue* ivalue;
6765
nvinfer1::ITensor* tensor;
6866
void* none;
6967
};
7068

71-
ArgContainer ptr_;
69+
VarContainer ptr_;
7270
Type type_;
7371
};
7472

7573
} // namespace conversion
7674
} // namespace core
7775
} // namespace trtorch
7876

79-
#include "core/conversion/arg/Arg_inl.h"
77+
#include "core/conversion/var/Var_inl.h"

Diff for: core/conversion/arg/Arg_inl.h renamed to core/conversion/var/Var_inl.h

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
#pragma once
22

3-
//#include "core/conversion/arg/Arg.h"
4-
53
namespace trtorch {
64
namespace core {
75
namespace conversion {
86

97
#define DEFINE_UNWRAP_TO(ival_type, method_variant) \
108
template<> \
11-
inline ival_type Arg::unwrapTo<ival_type>() { \
9+
inline ival_type Var::unwrapTo<ival_type>() { \
1210
TRTORCH_CHECK(isIValue(), "Requested unwrapping of arg assuming it was an IValue, however arg type is " << type_name()); \
1311
auto ivalue = ptr_.ivalue; \
1412
TRTORCH_CHECK(ivalue->is##method_variant(), "Requested unwrapping of arg IValue assuming it was " << typeid(ival_type).name() << " however type is " << *(ptr_.ivalue->type())); \
1513
return ptr_.ivalue->to<ival_type>(); \
1614
} \
1715
template<> \
18-
inline ival_type Arg::unwrapTo(ival_type default_val) { \
16+
inline ival_type Var::unwrapTo(ival_type default_val) { \
1917
try { \
2018
return this->unwrapTo<ival_type>(); \
2119
} catch(trtorch::Error& e) { \
@@ -24,11 +22,11 @@ inline ival_type Arg::unwrapTo(ival_type default_val) { \
2422
} \
2523
} \
2624
\
27-
inline ival_type Arg::unwrapTo##method_variant(ival_type default_val) { \
25+
inline ival_type Var::unwrapTo##method_variant(ival_type default_val) { \
2826
return this->unwrapTo<ival_type>(default_val); \
2927
} \
3028
\
31-
inline ival_type Arg::unwrapTo##method_variant() { \
29+
inline ival_type Var::unwrapTo##method_variant() { \
3230
return this->unwrapTo<ival_type>(); \
3331
}
3432

0 commit comments

Comments
 (0)