@@ -11,15 +11,15 @@ namespace core {
1111namespace conversion {
1212
1313// Defined in core/conversion/conversion_blacklist.cpp
14- bool isNodeConversionBlacklisted (torch::jit::Node* n);
14+ bool isNodeConversionBlacklisted (const torch::jit::Node* n);
1515
1616bool OpSupported (const torch::jit::Node* n) {
1717 bool evalable = evaluators::shouldEvalAtConversionTime (n);
1818 bool convertable = converters::node_is_convertable (n);
1919 return evalable || convertable;
2020}
2121
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 ) {
2323 // Check to see if you can just go through and eval all of these AOT (saves the recursion)
2424 // Also probably a better way to deal with the two error cases;
2525 TRTORCH_CHECK (level < limit, " Failed to evaluate node: " << *n \
@@ -55,7 +55,7 @@ c10::optional<torch::jit::IValue> EvaluateNode(ConversionCtx* ctx, torch::jit::N
5555 return eval;
5656}
5757
58- bool AddLayer (ConversionCtx* ctx, torch::jit::Node* n) {
58+ bool AddLayer (ConversionCtx* ctx, const torch::jit::Node* n) {
5959 LOG_INFO (ctx->logger ,
6060 " Adding Layer " << util::node_info (n) << " (ctx.AddLayer)" );
6161 converters::args node_args;
@@ -114,11 +114,11 @@ bool AddLayer(ConversionCtx* ctx, torch::jit::Node* n) {
114114}
115115
116116bool AddInputs (ConversionCtx* ctx,
117- at::ArrayRef<torch::jit::Value*> inputs,
117+ at::ArrayRef<const torch::jit::Value*> inputs,
118118 std::vector<InputRange>& input_dims) {
119119
120120 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;
122122 for (auto in : inputs) {
123123 // Disregarding inputs that are not tensors
124124 //
@@ -163,7 +163,7 @@ bool AddInputs(ConversionCtx* ctx,
163163 return true ;
164164}
165165
166- bool MarkOutputs (ConversionCtx* ctx, at::ArrayRef<torch::jit::Value*> outputs) {
166+ bool MarkOutputs (ConversionCtx* ctx, at::ArrayRef<const torch::jit::Value*> outputs) {
167167 for (auto out : outputs) {
168168 ctx->net ->markOutput (*(ctx->value_tensor_map [out]));
169169 LOG_INFO (ctx->logger ,
@@ -178,7 +178,7 @@ void AddParamsToCtxValueMap(ConversionCtx* ctx, GraphParams& params) {
178178 }
179179}
180180
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) {
182182 LOG_INFO (ctx->logger , " Converting Block" );
183183
184184 auto inputs = b->inputs ();
@@ -188,7 +188,6 @@ void ConvertBlockToNetDef(ConversionCtx* ctx, torch::jit::Block* b, ExtraInfo bu
188188 auto nodes = b->nodes ();
189189
190190 for (const auto n : nodes) {
191-
192191 bool to_eval = evaluators::shouldEvalAtConversionTime (n);
193192 bool blacklisted = isNodeConversionBlacklisted (n);
194193 if (!to_eval && !blacklisted) {
@@ -220,13 +219,41 @@ void ConvertBlockToNetDef(ConversionCtx* ctx, torch::jit::Block* b, ExtraInfo bu
220219// a serialized TensorRT engine that can be deserialized and run
221220
222221// 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) {
224223 ConversionCtx ctx (build_info.engine_settings );
225224 ConvertBlockToNetDef (&ctx, b, build_info, static_params);
226225 std::string engine = ctx.SerializeEngine ();
227226 return engine;
228227}
229228
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+
230257} // namespace conversion
231258} // namespace core
232259} // namespace trtorch
0 commit comments