Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions kernels/portable/cpu/op_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ Tensor& copy_out(
// Use direct copy fast path if broadcast is not needed and tensors are
// non-empty
if (internal::sizes_match_ignoring_leading_1s(out.sizes(), src.sizes()) &&
src.numel() > 0) {
src.numel() > 0 && out.nbytes() >= src.nbytes() &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manuelcandales if numel are equal but nbytes isnt then should we be promoting the dtype here? Im not actually sure what copy_ does for mixed dtype?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JacobSzwejbka If nbytes isn't equal, it should go into the else statement, which I think handles different dtypes

tensors_have_same_dtype(src, out)) {
std::memcpy(out.mutable_data_ptr(), src.const_data_ptr(), src.nbytes());
} else {
ET_SWITCH_REALHBBF16_TYPES(in.scalar_type(), ctx, op_name, CTYPE, [&]() {
Expand Down Expand Up @@ -91,8 +92,9 @@ Tensor& copy_(
// Use direct copy fast path if broadcast is not needed and tensors are
// non-empty
if (internal::sizes_match_ignoring_leading_1s(in.sizes(), src.sizes()) &&
src.numel() > 0) {
std::memcpy(in.mutable_data_ptr(), src.const_data_ptr(), in.nbytes());
src.numel() > 0 && in.nbytes() >= src.nbytes() &&
tensors_have_same_dtype(src, in)) {
std::memcpy(in.mutable_data_ptr(), src.const_data_ptr(), src.nbytes());
} else {
ET_SWITCH_REALHBBF16_TYPES(in.scalar_type(), ctx, op_name, CTYPE, [&]() {
utils::apply_bitensor_elementwise_fn<
Expand Down
Loading