Avoid refcount when looking up dispatch key
authorSebastian Messmer <messmer@fb.com>
Fri, 22 Mar 2019 21:05:50 +0000 (14:05 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 22 Mar 2019 21:09:20 +0000 (14:09 -0700)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/18294

Reviewed By: ezyang

Differential Revision: D14512979

fbshipit-source-id: 45e548974f06184c375c2bb8339e3049a4ebd880

aten/src/ATen/core/dispatch/DispatchTable.h

index 08e43c4..78b048b 100644 (file)
@@ -184,12 +184,13 @@ private:
         reverse_index_of_first_tensor_arg_
       );
       if (first_tensor_arg_is_tensor_list_) {
-        auto tensor_list = first_tensor_arg.toTensorList();
-        if (tensor_list->elements().size() == 0) {
+        const auto& tensor_list = first_tensor_arg.toTensorListRef();
+        if (tensor_list.size() == 0) {
           throw std::runtime_error("Tried to dispatch based on an empty tensor list. When the first tensor argument of an operator is a tensor list, then it must not be empty.");
         }
-        return tensor_list->elements()[0].type_id();
+        return tensor_list[0].type_id();
       } else {
+        // TODO Avoid bumping the refcounter
         return first_tensor_arg.toTensor().type_id();
       }
     }