Skip to content

[AIROCMLIR-612] Lower migraphx.convert into linalg.generic#2302

Merged
Mr-Anyone merged 1 commit intodevelopfrom
pr-migraphx-convert
Apr 7, 2026
Merged

[AIROCMLIR-612] Lower migraphx.convert into linalg.generic#2302
Mr-Anyone merged 1 commit intodevelopfrom
pr-migraphx-convert

Conversation

@Mr-Anyone
Copy link
Copy Markdown
Member

Motivation

There is a nice helper in arith/Utils/Utils.h that converts from type A to type B. In the case of integer, we always assume it is signed. See AIROCMLIR-595

Technical Details

Added a linalg.generic loop elementwise converter that converts type type A to type B. The emitted IR looks like the following:

Starting from

func.func @func_convert_i32_to_f32(%arg0: !migraphx.shaped<4x8xi32, 8x1>) -> !migraphx.shaped<4x8xf32, 8x1> {
  %0 = migraphx.convert %arg0 : <4x8xi32, 8x1> to <4x8xf32, 8x1>
  return %0 : !migraphx.shaped<4x8xf32, 8x1>

to

    %1 = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel", "parallel"]} ins(%expanded : tensor<4x8xi32>) outs(%0 : tensor<4x8xf32>) {
    ^bb0(%in: i32, %out: f32):
      %2 = arith.sitofp %in : i32 to f32
      linalg.yield %2 : f32
    } -> tensor<4x8xf32>

Test Plan

Lit test

Test Result

Passed lit test

Submission Checklist

@Mr-Anyone Mr-Anyone requested a review from causten as a code owner March 18, 2026 14:15
@Mr-Anyone Mr-Anyone marked this pull request as draft March 18, 2026 14:15
@Mr-Anyone Mr-Anyone force-pushed the pr-migraphx-sigmoid branch 2 times, most recently from 1dc37d9 to 1f101bd Compare March 23, 2026 20:20
@Mr-Anyone Mr-Anyone force-pushed the pr-migraphx-convert branch from d8d1cf9 to 93023d1 Compare March 23, 2026 20:25
@Mr-Anyone Mr-Anyone force-pushed the pr-migraphx-sigmoid branch from 1f101bd to 1dc37d9 Compare March 23, 2026 20:26
@Mr-Anyone Mr-Anyone marked this pull request as ready for review March 23, 2026 20:27
@Mr-Anyone Mr-Anyone changed the title Lower migraphx.convert into linalg.generic [AIROCMLIR-612] Lower migraphx.convert into linalg.generic Mar 23, 2026
@Mr-Anyone Mr-Anyone force-pushed the pr-migraphx-sigmoid branch from 1dc37d9 to 83fb455 Compare March 27, 2026 19:48
@Mr-Anyone Mr-Anyone force-pushed the pr-migraphx-convert branch from 93023d1 to 58c43e8 Compare March 27, 2026 19:50
@Mr-Anyone Mr-Anyone force-pushed the pr-migraphx-sigmoid branch from 83fb455 to ce3e8e0 Compare March 30, 2026 14:30
@Mr-Anyone Mr-Anyone force-pushed the pr-migraphx-convert branch from 58c43e8 to 0182077 Compare March 30, 2026 14:30
@Mr-Anyone Mr-Anyone force-pushed the pr-migraphx-sigmoid branch from a4d0c34 to 871820b Compare March 30, 2026 20:17
Base automatically changed from pr-migraphx-sigmoid to develop April 1, 2026 13:03
@Mr-Anyone Mr-Anyone force-pushed the pr-migraphx-convert branch 7 times, most recently from a4312db to 9a6410b Compare April 7, 2026 13:03
@Mr-Anyone Mr-Anyone force-pushed the pr-migraphx-convert branch from 9a6410b to 8640ff4 Compare April 7, 2026 17:04
@Mr-Anyone Mr-Anyone merged commit cdf4447 into develop Apr 7, 2026
8 of 15 checks passed
@Mr-Anyone Mr-Anyone deleted the pr-migraphx-convert branch April 7, 2026 21:40
@dhernandez0
Copy link
Copy Markdown
Contributor

sorry I'm late to the review, We have always rewritten migraphx.convert to tosa.cast, so migraphx expects tosa's way of casting. We are having some issues on rocmlirTriton (https://github.com/ROCm/rocmlirTriton/pull/125) related to this. We use tosa spec for converting (tosa.cast), so the logic they follow is not as simple as arith::FPToUIOp. https://github.com/ROCm/rocmlirTriton/pull/125#discussion_r3043866753

@dhernandez0
Copy link
Copy Markdown
Contributor

we probably want to sync with migraphx team if we really want to follow tosa's spec for casting. My intuition is that it's better to follow what ONNX/pytorch do instead (which might be the same as tosa or not).

umangyadav pushed a commit that referenced this pull request Apr 9, 2026
Lower migraphx.convert into linalg.generic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants