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

Reland non-splat tensor.from_elements to flow #18049

Merged
merged 3 commits into from
Jul 31, 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
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,13 @@
"onnx/node/generated/test_castlike_STRING_to_FLOAT_expanded",
"onnx/node/generated/test_center_crop_pad_crop",
"onnx/node/generated/test_center_crop_pad_crop_and_pad",
"onnx/node/generated/test_center_crop_pad_crop_and_pad_expanded",
"onnx/node/generated/test_center_crop_pad_crop_axes_chw",
"onnx/node/generated/test_center_crop_pad_crop_axes_chw_expanded",
"onnx/node/generated/test_center_crop_pad_crop_axes_hwc",
"onnx/node/generated/test_center_crop_pad_crop_axes_hwc_expanded",
"onnx/node/generated/test_center_crop_pad_crop_expanded",
"onnx/node/generated/test_center_crop_pad_crop_negative_axes_hwc",
"onnx/node/generated/test_center_crop_pad_crop_negative_axes_hwc_expanded",
"onnx/node/generated/test_center_crop_pad_pad",
"onnx/node/generated/test_center_crop_pad_pad_expanded",
"onnx/node/generated/test_col2im",
"onnx/node/generated/test_col2im_5d",
"onnx/node/generated/test_col2im_dilations",
Expand Down
13 changes: 5 additions & 8 deletions build_tools/pkgci/external_test_suite/onnx_gpu_cuda.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
"--device=cuda"
],
"skip_compile_tests": [
"onnx/node/generated/test_dequantizelinear"
"onnx/node/generated/test_dequantizelinear",
"onnx/node/generated/test_group_normalization_example_expanded",
"onnx/node/generated/test_group_normalization_epsilon_expanded",
],
"skip_run_tests": [
"onnx/node/generated/test_gather_elements_negative_indices",
"onnx/node/generated/test_gridsample_zeros_padding",
"onnx/node/generated/test_scatter_elements_with_negative_indices",
"onnx/node/generated/test_resize_downsample_scales_linear_align_corners",
"onnx/node/generated/test_resize_downsample_scales_linear_half_pixel_symmetric"
"onnx/node/generated/test_resize_downsample_scales_linear_half_pixel_symmetric",
"onnx/node/generated/test_scatter_elements_with_negative_indices"
],
"expected_compile_failures": [
"onnx/node/generated/test_adagrad",
Expand Down Expand Up @@ -92,16 +94,13 @@
"onnx/node/generated/test_castlike_STRING_to_FLOAT_expanded",
"onnx/node/generated/test_center_crop_pad_crop",
"onnx/node/generated/test_center_crop_pad_crop_and_pad",
"onnx/node/generated/test_center_crop_pad_crop_and_pad_expanded",
"onnx/node/generated/test_center_crop_pad_crop_axes_chw",
"onnx/node/generated/test_center_crop_pad_crop_axes_chw_expanded",
"onnx/node/generated/test_center_crop_pad_crop_axes_hwc",
"onnx/node/generated/test_center_crop_pad_crop_axes_hwc_expanded",
"onnx/node/generated/test_center_crop_pad_crop_expanded",
"onnx/node/generated/test_center_crop_pad_crop_negative_axes_hwc",
"onnx/node/generated/test_center_crop_pad_crop_negative_axes_hwc_expanded",
"onnx/node/generated/test_center_crop_pad_pad",
"onnx/node/generated/test_center_crop_pad_pad_expanded",
"onnx/node/generated/test_col2im",
"onnx/node/generated/test_col2im_5d",
"onnx/node/generated/test_col2im_dilations",
Expand Down Expand Up @@ -158,9 +157,7 @@
"onnx/node/generated/test_gridsample_volumetric_nearest_align_corners_0",
"onnx/node/generated/test_gridsample_volumetric_nearest_align_corners_1",
"onnx/node/generated/test_group_normalization_epsilon",
"onnx/node/generated/test_group_normalization_epsilon_expanded",
"onnx/node/generated/test_group_normalization_example",
"onnx/node/generated/test_group_normalization_example_expanded",
"onnx/node/generated/test_gru_batchwise",
"onnx/node/generated/test_gru_defaults",
"onnx/node/generated/test_gru_seq_length",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"--device=hip"
],
"skip_compile_tests": [
"onnx/node/generated/test_dequantizelinear"
"onnx/node/generated/test_dequantizelinear",
"onnx/node/generated/test_group_normalization_epsilon_expanded",
"onnx/node/generated/test_group_normalization_example_expanded"
],
"skip_run_tests": [],
"expected_compile_failures": [
Expand Down Expand Up @@ -87,16 +89,13 @@
"onnx/node/generated/test_castlike_STRING_to_FLOAT_expanded",
"onnx/node/generated/test_center_crop_pad_crop",
"onnx/node/generated/test_center_crop_pad_crop_and_pad",
"onnx/node/generated/test_center_crop_pad_crop_and_pad_expanded",
"onnx/node/generated/test_center_crop_pad_crop_axes_chw",
"onnx/node/generated/test_center_crop_pad_crop_axes_chw_expanded",
"onnx/node/generated/test_center_crop_pad_crop_axes_hwc",
"onnx/node/generated/test_center_crop_pad_crop_axes_hwc_expanded",
"onnx/node/generated/test_center_crop_pad_crop_expanded",
"onnx/node/generated/test_center_crop_pad_crop_negative_axes_hwc",
"onnx/node/generated/test_center_crop_pad_crop_negative_axes_hwc_expanded",
"onnx/node/generated/test_center_crop_pad_pad",
"onnx/node/generated/test_center_crop_pad_pad_expanded",
"onnx/node/generated/test_col2im",
"onnx/node/generated/test_col2im_5d",
"onnx/node/generated/test_col2im_dilations",
Expand Down Expand Up @@ -153,9 +152,7 @@
"onnx/node/generated/test_gridsample_volumetric_nearest_align_corners_0",
"onnx/node/generated/test_gridsample_volumetric_nearest_align_corners_1",
"onnx/node/generated/test_group_normalization_epsilon",
"onnx/node/generated/test_group_normalization_epsilon_expanded",
"onnx/node/generated/test_group_normalization_example",
"onnx/node/generated/test_group_normalization_example_expanded",
"onnx/node/generated/test_gru_batchwise",
"onnx/node/generated/test_gru_defaults",
"onnx/node/generated/test_gru_seq_length",
Expand Down
11 changes: 5 additions & 6 deletions build_tools/pkgci/external_test_suite/onnx_gpu_vulkan.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
"--device=vulkan"
],
"skip_compile_tests": [
"onnx/node/generated/test_dequantizelinear"
],
"skip_run_tests": [
"onnx/node/generated/test_det_nd"
"onnx/node/generated/test_dequantizelinear",
"onnx/node/generated/test_det_nd",
"onnx/node/generated/test_group_normalization_epsilon_expanded",
"onnx/node/generated/test_group_normalization_example_expanded"
],
"skip_run_tests": [],
"expected_compile_failures": [
"onnx/node/generated/test_adagrad",
"onnx/node/generated/test_adagrad_multiple",
Expand Down Expand Up @@ -187,9 +188,7 @@
"onnx/node/generated/test_gridsample_volumetric_nearest_align_corners_1",
"onnx/node/generated/test_gridsample_zeros_padding",
"onnx/node/generated/test_group_normalization_epsilon",
"onnx/node/generated/test_group_normalization_epsilon_expanded",
"onnx/node/generated/test_group_normalization_example",
"onnx/node/generated/test_group_normalization_example_expanded",
"onnx/node/generated/test_gru_batchwise",
"onnx/node/generated/test_gru_defaults",
"onnx/node/generated/test_gru_seq_length",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,33 @@ struct ConvertTensorFromElementsPattern
}
auto tensorType = op.getType();
if (!tensorType.hasRank()) {
return failure();
return rewriter.notifyMatchFailure(op,
"unranked result type not supported");
}

// Check that all the dimensions are 1.
if (!llvm::all_of(tensorType.getShape(),
[](int64_t dim) { return dim == 1; })) {
return failure();
if (op.getNumOperands() == 1) {
rewriter.replaceOpWithNewOp<IREE::Flow::TensorSplatOp>(
op, tensorType, op.getOperand(0), ValueRange());
return success();
}

rewriter.replaceOpWithNewOp<IREE::Flow::TensorSplatOp>(
op, tensorType, op.getOperand(0), ValueRange());
const int64_t rank = tensorType.getRank();
Value result = rewriter.create<tensor::EmptyOp>(
op.getLoc(), tensorType.getShape(), tensorType.getElementType());
SmallVector<Value> ivs(rank);
for (int i = 0, s = op.getNumOperands(); i < s; ++i) {
int64_t index = i;
for (int j = rank - 1; j >= 0; --j) {
int64_t iv = index % tensorType.getDimSize(j);
index = index / tensorType.getDimSize(j);
ivs[j] = rewriter.create<arith::ConstantIndexOp>(op.getLoc(), iv);
}

result = rewriter.create<Flow::TensorStoreOp>(
op.getLoc(), op.getOperand(i), result, ivs);
}

rewriter.replaceOp(op, result);
return success();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@ util.func public @tensor.from_elements__to__flow.tensor.splat(%arg0: i8) -> (i8)
util.return %1 : i8
}

// -----
// CHECK: util.func public @tensor.from_elements__not_convertible(%[[arg0:.*]]: i8)
util.func public @tensor.from_elements__not_convertible(%arg0: i8) -> (i8) {
// CHECK: %[[c0:.*]] = arith.constant 0
%c0 = arith.constant 0 : index
// CHECK: %[[res:.*]] = tensor.from_elements %[[arg0]], %[[arg0]] : tensor<2xi8>
%0 = tensor.from_elements %arg0, %arg0 : tensor<2xi8>
// CHECK: flow.tensor.load %[[res]][%[[c0]]]
%1 = flow.tensor.load %0[%c0] : tensor<2xi8>
util.return %1 : i8
}

// -----
util.func public @tensor.from_elements__within_dispatch_workgroups_not_converted() -> tensor<f32> {
%x = arith.constant 100 : index
Expand All @@ -44,3 +32,21 @@ util.func public @tensor.from_elements_0D(%arg0 : f32) -> tensor<f32> {
// CHECK-SAME: %[[ARG0:.+]]: f32
// CHECK: %[[SPLAT:.+]] = flow.tensor.splat %[[ARG0]] : tensor<f32>
// CHECK: util.return %[[SPLAT]]

// -----

// CHECK-LABEL: util.func public @tensor.from_elements_2D
util.func @tensor.from_elements_2D(%arg0 : f32, %arg1 : f32, %arg2 : f32, %arg3 : f32, %arg4 : f32, %arg5 : f32) -> tensor<2x3xf32> {
%0 = tensor.from_elements %arg0, %arg1, %arg2, %arg3, %arg4, %arg5 : tensor<2x3xf32>
// CHECK-DAG: %[[C2:.+]] = arith.constant 2 : index
// CHECK-DAG: %[[C1:.+]] = arith.constant 1 : index
// CHECK-DAG: %[[C0:.+]] = arith.constant 0 : index
// CHECK: %[[EMPTY:.+]] = tensor.empty() : tensor<2x3xf32>
// CHECK: %[[STORE0:.+]] = flow.tensor.store %arg0, %[[EMPTY]][%[[C0]], %[[C0]]] : tensor<2x3xf32>
// CHECK: %[[STORE1:.+]] = flow.tensor.store %arg1, %[[STORE0]][%[[C0]], %[[C1]]] : tensor<2x3xf32>
// CHECK: %[[STORE2:.+]] = flow.tensor.store %arg2, %[[STORE1]][%[[C0]], %[[C2]]] : tensor<2x3xf32>
// CHECK: %[[STORE3:.+]] = flow.tensor.store %arg3, %[[STORE2]][%[[C1]], %[[C0]]] : tensor<2x3xf32>
// CHECK: %[[STORE4:.+]] = flow.tensor.store %arg4, %[[STORE3]][%[[C1]], %[[C1]]] : tensor<2x3xf32>
// CHECK: %[[STORE5:.+]] = flow.tensor.store %arg5, %[[STORE4]][%[[C1]], %[[C2]]] : tensor<2x3xf32>
util.return %0 : tensor<2x3xf32>
}
Loading