Skip to content

t to z start ops | add dim order sanity check #4328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions kernels/portable/cpu/op_t_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ Tensor& t_copy_out(RuntimeContext& ctx, const Tensor& in, Tensor& out) {
return out;
}

ET_KERNEL_CHECK(
ctx, tensors_have_same_dim_order(in, out), InvalidArgument, out);

ET_KERNEL_CHECK(ctx, tensor_is_default_dim_order(in), InvalidArgument, out);

Tensor::SizesType expected_out_size[kTensorDimensionLimit];
size_t expected_out_dim = 0;
get_transpose_out_target_size(in, 1, 0, expected_out_size, &expected_out_dim);
Expand Down
5 changes: 5 additions & 0 deletions kernels/portable/cpu/op_to_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ Tensor& to_copy_out(
InvalidArgument,
out);

ET_KERNEL_CHECK(
ctx, tensors_have_same_dim_order(self, out), InvalidArgument, out);

ET_KERNEL_CHECK(ctx, tensor_is_default_dim_order(self), InvalidArgument, out);

ET_SWITCH_REALHBBF16_TYPES(self.scalar_type(), ctx, "to_copy", CTYPE_IN, [&] {
ET_SWITCH_REALHBBF16_TYPES(
out.scalar_type(), ctx, "to_copy", CTYPE_OUT, [&] {
Expand Down
3 changes: 3 additions & 0 deletions kernels/portable/cpu/op_transpose_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ Tensor& transpose_copy_int_out(
InvalidArgument,
out);

ET_KERNEL_CHECK(
ctx, tensors_have_same_dim_order(in, out), InvalidArgument, out);

ET_SWITCH_ALL_TYPES(in.scalar_type(), ctx, __func__, CTYPE, [&] {
transpose_tensors<CTYPE>(in, dim0, dim1, out);
});
Expand Down
5 changes: 5 additions & 0 deletions kernels/portable/cpu/op_tril.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ Tensor& tril_out(
InvalidArgument,
out);

ET_KERNEL_CHECK(
ctx, tensors_have_same_dim_order(self, out), InvalidArgument, out);

ET_KERNEL_CHECK(ctx, tensor_is_default_dim_order(self), InvalidArgument, out);

if (self.numel() == 0) {
return out;
}
Expand Down
7 changes: 7 additions & 0 deletions kernels/portable/cpu/op_unbind_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ void unbind_copy_int_out(
ET_KERNEL_CHECK(
ctx, check_unbind_copy_args(input, dim, out), InvalidArgument, );

for (int i = 0; i < out.size(); ++i) {
ET_KERNEL_CHECK(
ctx, tensors_have_same_dim_order(input, out[i]), InvalidArgument, );
}

ET_KERNEL_CHECK(ctx, tensor_is_default_dim_order(input), InvalidArgument, );

if (input.numel() == 0) {
return;
}
Expand Down
5 changes: 5 additions & 0 deletions kernels/portable/cpu/op_unsqueeze_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ Tensor& unsqueeze_copy_out(
ET_KERNEL_CHECK(ctx, self.dim() + 1 == out.dim(), InvalidArgument, out);
ET_KERNEL_CHECK(ctx, dim <= self.dim(), InvalidArgument, out);

ET_KERNEL_CHECK(
ctx, tensors_have_same_dim_order(self, out), InvalidArgument, out);

ET_KERNEL_CHECK(ctx, tensor_is_default_dim_order(self), InvalidArgument, out);

for (size_t i = 0; i < out.dim(); ++i) {
if (i < dim) {
expected_output_size[i] = self.size(i);
Expand Down
5 changes: 5 additions & 0 deletions kernels/portable/cpu/op_var.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ Tensor& var_out(
ET_KERNEL_CHECK(ctx, tensor_is_floating_type(in), InvalidArgument, out);
ET_KERNEL_CHECK(ctx, tensor_is_floating_type(out), InvalidArgument, out);

ET_KERNEL_CHECK(
ctx, tensors_have_same_dim_order(in, out), InvalidArgument, out);

ET_KERNEL_CHECK(ctx, tensor_is_default_dim_order(in), InvalidArgument, out);

ET_KERNEL_CHECK(
ctx,
resize_reduction_out(in, dim_list, keepdim, out) == Error::Ok,
Expand Down
5 changes: 5 additions & 0 deletions kernels/portable/cpu/op_view_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ Tensor& view_copy_out(
out,
"Failed to resize output tensor.");

ET_KERNEL_CHECK(
ctx, tensors_have_same_dim_order(self, out), InvalidArgument, out);

ET_KERNEL_CHECK(ctx, tensor_is_default_dim_order(self), InvalidArgument, out);

ET_KERNEL_CHECK(
ctx, check_view_copy_args(self, size_int64_t, out), InvalidArgument, out);

Expand Down
3 changes: 3 additions & 0 deletions kernels/portable/cpu/op_where.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ Tensor& where_out(
InvalidArgument,
out);

ET_KERNEL_CHECK(
ctx, tensors_have_same_dim_order(cond, a, b, out), InvalidArgument, out);

constexpr auto name = "where.self_out";

ET_CHECK_MSG(
Expand Down
Loading