@@ -11,15 +11,15 @@ namespace core {
11
11
namespace conversion {
12
12
13
13
// Defined in core/conversion/conversion_blacklist.cpp
14
- bool isNodeConversionBlacklisted (torch::jit::Node* n);
14
+ bool isNodeConversionBlacklisted (const torch::jit::Node* n);
15
15
16
16
bool OpSupported (const torch::jit::Node* n) {
17
17
bool evalable = evaluators::shouldEvalAtConversionTime (n);
18
18
bool convertable = converters::node_is_convertable (n);
19
19
return evalable || convertable;
20
20
}
21
21
22
- c10::optional<torch::jit::IValue> EvaluateNode (ConversionCtx* ctx, torch::jit::Node* n, int level=0 , int limit=10 ) {
22
+ c10::optional<torch::jit::IValue> EvaluateNode (ConversionCtx* ctx, const torch::jit::Node* n, int level=0 , int limit=10 ) {
23
23
// Check to see if you can just go through and eval all of these AOT (saves the recursion)
24
24
// Also probably a better way to deal with the two error cases;
25
25
TRTORCH_CHECK (level < limit, " Failed to evaluate node: " << *n \
@@ -55,7 +55,7 @@ c10::optional<torch::jit::IValue> EvaluateNode(ConversionCtx* ctx, torch::jit::N
55
55
return eval;
56
56
}
57
57
58
- bool AddLayer (ConversionCtx* ctx, torch::jit::Node* n) {
58
+ bool AddLayer (ConversionCtx* ctx, const torch::jit::Node* n) {
59
59
LOG_INFO (ctx->logger ,
60
60
" Adding Layer " << util::node_info (n) << " (ctx.AddLayer)" );
61
61
converters::args node_args;
@@ -114,11 +114,11 @@ bool AddLayer(ConversionCtx* ctx, torch::jit::Node* n) {
114
114
}
115
115
116
116
bool AddInputs (ConversionCtx* ctx,
117
- at::ArrayRef<torch::jit::Value*> inputs,
117
+ at::ArrayRef<const torch::jit::Value*> inputs,
118
118
std::vector<InputRange>& input_dims) {
119
119
120
120
auto type_lut = torch::jit::script::string_to_type_lut ();
121
- std::vector<torch::jit::Value*> input_tensors;
121
+ std::vector<const torch::jit::Value*> input_tensors;
122
122
for (auto in : inputs) {
123
123
// Disregarding inputs that are not tensors
124
124
//
@@ -163,7 +163,7 @@ bool AddInputs(ConversionCtx* ctx,
163
163
return true ;
164
164
}
165
165
166
- bool MarkOutputs (ConversionCtx* ctx, at::ArrayRef<torch::jit::Value*> outputs) {
166
+ bool MarkOutputs (ConversionCtx* ctx, at::ArrayRef<const torch::jit::Value*> outputs) {
167
167
for (auto out : outputs) {
168
168
ctx->net ->markOutput (*(ctx->value_tensor_map [out]));
169
169
LOG_INFO (ctx->logger ,
@@ -178,7 +178,7 @@ void AddParamsToCtxValueMap(ConversionCtx* ctx, GraphParams& params) {
178
178
}
179
179
}
180
180
181
- void ConvertBlockToNetDef (ConversionCtx* ctx, torch::jit::Block* b, ExtraInfo build_info, GraphParams& static_params) {
181
+ void ConvertBlockToNetDef (ConversionCtx* ctx, const torch::jit::Block* b, ExtraInfo build_info, GraphParams& static_params) {
182
182
LOG_INFO (ctx->logger , " Converting Block" );
183
183
184
184
auto inputs = b->inputs ();
@@ -188,7 +188,6 @@ void ConvertBlockToNetDef(ConversionCtx* ctx, torch::jit::Block* b, ExtraInfo bu
188
188
auto nodes = b->nodes ();
189
189
190
190
for (const auto n : nodes) {
191
-
192
191
bool to_eval = evaluators::shouldEvalAtConversionTime (n);
193
192
bool blacklisted = isNodeConversionBlacklisted (n);
194
193
if (!to_eval && !blacklisted) {
@@ -220,13 +219,41 @@ void ConvertBlockToNetDef(ConversionCtx* ctx, torch::jit::Block* b, ExtraInfo bu
220
219
// a serialized TensorRT engine that can be deserialized and run
221
220
222
221
// Probably should consolidate these two functions
223
- std::string ConvertBlockToEngine (torch::jit::Block* b, ExtraInfo build_info, GraphParams& static_params) {
222
+ std::string ConvertBlockToEngine (const torch::jit::Block* b, ExtraInfo build_info, GraphParams& static_params) {
224
223
ConversionCtx ctx (build_info.engine_settings );
225
224
ConvertBlockToNetDef (&ctx, b, build_info, static_params);
226
225
std::string engine = ctx.SerializeEngine ();
227
226
return engine;
228
227
}
229
228
229
+ bool VerifyConverterSupportForBlock (const torch::jit::Block* b) {
230
+ bool supported = true ;
231
+ std::set<std::string> unsupported_ops;
232
+ for (const auto n : b->nodes ()) {
233
+ if (!OpSupported (n)) {
234
+ auto schema = n->maybeSchema ();
235
+ TRTORCH_CHECK (schema, " Unable to get schema for Node " << util::node_info (n) \
236
+ << " (conversion.AddLayer)" );
237
+ std::stringstream ss;
238
+ ss << *schema;
239
+ unsupported_ops.insert (ss.str ());
240
+ supported = false ;
241
+ }
242
+ }
243
+
244
+ if (!supported) {
245
+ std::stringstream unsupported_msg;
246
+ unsupported_msg << " Method requested cannot be compiled by TRTorch.\n Unsupported operators listed below:" << std::endl;
247
+ for (auto s : unsupported_ops) {
248
+ unsupported_msg << " - " << s << std::endl;
249
+ }
250
+ unsupported_msg << " You can either implement converters for these ops in your application or file a bug" << std::endl;
251
+ unsupported_msg << " https://www.github.com/nvidia/TRTorch/issues" << std::endl;
252
+ LOG_ERROR (unsupported_msg.str ());
253
+ }
254
+ return supported;
255
+ }
256
+
230
257
} // namespace conversion
231
258
} // namespace core
232
259
} // namespace trtorch
0 commit comments