Skip to content
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

i32 index fixes #180

Open
wants to merge 3 commits into
base: mlir
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
Empty file added src/cmake/123
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ struct ConvertGather {
auto empty_add = builder.create<tensor::EmptyOp>(loc, indices_expanded.getType(), dynamic_index_dims);
auto add = builder.create<linalg::AddOp>(loc, mlir::ValueRange{cast.getResult(), indices_expanded}, mlir::ValueRange{empty_add});
auto select = builder.create<linalg::SelectOp>(loc, mlir::ValueRange{cmpi.getResult(), add.getResult(0), indices_expanded}, mlir::ValueRange{empty_add});
auto index_type = RankedTensorType::get(ArrayRef(importShape(ov_output_shape)), builder.getIndexType());
auto cast2 = builder.create<arith::IndexCastOp>(loc, index_type, mlir::ValueRange{select.getResult(0)});

auto gather_node = std::dynamic_pointer_cast<ov::op::util::GatherBase>(node);
assert(gather_node && "Expected a gather node");
int64_t axis = gather_node->get_axis();

llvm::SmallVector<int64_t> gather_dims{axis};
auto gather = builder.create<tensor::GatherOp>(loc, out_type, input, select.getResult(0), gather_dims, false);
auto gather = builder.create<tensor::GatherOp>(loc, out_type, input, cast2, gather_dims, false);
context.addOutputs(node, gather);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,19 @@ struct ConvertTranspose {
const auto ov_output_shape = node->get_output_partial_shape(0);
auto out_type = importTensor(context.context, ov_output_shape, ov_output_element_type);
auto dynamic_dimensions = context.get_dynamic_dimension_values(ov_output_shape);
const auto ov_order_element_type = node->get_input_element_type(1);

auto const_order = dynamic_cast<ov::op::v0::Constant*>(node->get_input_node_ptr(1));
assert(const_order && "non-const order not supported");
ov::Coordinate coords = const_order->get_coordinate_val();
SmallVector<int64_t> order(coords.begin(), coords.end());
SmallVector<int64_t> order;
if (ov_order_element_type == ov::element::i64) {
ov::Coordinate coords = const_order->get_coordinate_val();
Copy link
Owner

@slyalin slyalin Dec 19, 2024

Choose a reason for hiding this comment

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

Indices in const_order as the second input of Transpose cannot be negative, so you can just use const_order->cast_vector<uint64_t>() and leave negative indices as UB.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, I tried that, but got only partial result for some reason. Half of the values were correct, others - zeroes.

Copy link
Owner

Choose a reason for hiding this comment

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

Make sure that you used cast_vector, not get_vector.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, I see

order.assign(coords.begin(), coords.end());
} else {
assert(ov_order_element_type == ov::element::i32);
std::vector<int32_t> coords = const_order->get_vector<int32_t>();
order.assign(coords.begin(), coords.end());
}

auto empty = builder.create<tensor::EmptyOp>(loc, out_type, dynamic_dimensions);
auto transpose = builder.create<linalg::TransposeOp>(loc, input, empty, order);
Expand Down
Loading