[jit] Reduce refcounting of Types (#65345)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/65345

FooType::get() can return a const reference. Inconveniently, converting shared_ptr<FooType> to shared_ptr<Type> requires a copy & refcount bump, so to properly take advantage of this in unshapedType() we need to take a const Type& in isSubtypeOf(), which is good practice anyway -- don't require a shared_ptr if you don't need to take ownership.
ghstack-source-id: 140044165

Test Plan:
CI

perf says c10::unshapedType time decreased from 2.8% to 2.2% during static runtime startup, though I expect this to be generally beneficial.

Reviewed By: hlu1

Differential Revision: D31027361

fbshipit-source-id: 676feb81db9f74ad7b8651d8774f4ecb4cfa6ab8
This commit is contained in:
Scott Wolchok
2021-10-08 09:01:42 -07:00
committed by Facebook GitHub Bot
parent 1ae468a484
commit 2d885ab73d
69 changed files with 421 additions and 405 deletions

View File

@ -348,9 +348,9 @@ c10::intrusive_ptr<OwnerRRef> RRefContext::getOrCreateOwnerRRef(
// since Tensor can only get specialized with a previous run of local
// JIT function, and we shouldn't preserve the specialized SubTensorType
// information on other workers because it's only information only.
if (type->isSubtypeOf(TensorType::get())) {
if (type->isSubtypeOf(*TensorType::get())) {
TORCH_INTERNAL_ASSERT(
ownerRRef->type()->isSubtypeOf(TensorType::get()),
ownerRRef->type()->isSubtypeOf(*TensorType::get()),
"Expect OwnerRRef to be a sub-type of TensorType, but got ",
ownerRRef->type()->repr_str());
} else {