Skip to content

Commit 878bcba

Browse files
hsharma35facebook-github-bot
authored andcommitted
Allow zero-element tensors for shared inputs. (#13935)
Summary: Adds support for the case where method inputs are zero-element. Similar to #13623, but adds support for shared input instead. Reviewed By: JacobSzwejbka, DrJessop Differential Revision: D81653487
1 parent 56d5186 commit 878bcba

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

runtime/core/exec_aten/util/tensor_util_portable.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,17 @@ Error share_tensor_data(
147147
t_dst.nbytes(),
148148
t_src.nbytes());
149149

150+
// Either the t_src is empty or contains valid data.
150151
ET_CHECK_OR_RETURN_ERROR(
151-
t_src.mutable_data_ptr() != nullptr,
152+
t_src.mutable_data_ptr() != nullptr || t_src.nbytes() == 0,
152153
InvalidArgument,
153154
"Source tensor should have data_ptr not being nullptr.");
155+
156+
// Setting data_ptr to nullptr explicitly when t_src is empty.
157+
void* t_src_data_ptr =
158+
t_src.numel() == 0 ? nullptr : t_src.mutable_data_ptr();
154159
// Assign internal data_ptr as the one in forwarded tensor
155-
t_dst.unsafeGetTensorImpl()->set_data(t_src.mutable_data_ptr());
160+
t_dst.unsafeGetTensorImpl()->set_data(t_src_data_ptr);
156161

157162
return Error::Ok;
158163
}

0 commit comments

Comments
 (0)