Skip to content

Commit 20df1a2

Browse files
manuelcandalesfacebook-github-bot
authored andcommitted
Fix op t_copy (#790)
Summary: Pull Request resolved: #790 ghstack-source-id: 203476469 exported-using-ghexport Reviewed By: digantdesai Differential Revision: D50109849 fbshipit-source-id: 8ce4058f797193e92d04ccfa69eb4f5b32b5910d
1 parent 2628c0e commit 20df1a2

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

kernels/portable/cpu/op_t_copy.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,13 @@ Tensor& t_copy_out(RuntimeContext& ctx, const Tensor& in, Tensor& out) {
3636
ET_KERNEL_CHECK(
3737
ctx, resize_tensor(out, in.sizes()) == Error::Ok, InvalidArgument, out);
3838

39-
ET_SWITCH_ALL_TYPES(in_type, ctx, __func__, CTYPE, [&]() {
40-
const CTYPE* in_data = in.const_data_ptr<CTYPE>();
41-
CTYPE* out_data = out.mutable_data_ptr<CTYPE>();
42-
memcpy(out_data, in_data, in.nbytes());
43-
});
39+
if (in.numel() > 0) {
40+
ET_SWITCH_ALL_TYPES(in_type, ctx, __func__, CTYPE, [&]() {
41+
const CTYPE* in_data = in.const_data_ptr<CTYPE>();
42+
CTYPE* out_data = out.mutable_data_ptr<CTYPE>();
43+
memcpy(out_data, in_data, in.nbytes());
44+
});
45+
}
4446

4547
return out;
4648
}

0 commit comments

Comments
 (0)