Skip to content

[RFC][VM] Failing to legalize arith.extf from f32 to f64 #20022

Closed

Description

@zjgarvey

I'm debugging some issues in the iree-test-suites onnx_ops tests, which uses the flag --iree-input-demote-f64-to-f32=false. See #17345 (comment) for some context.

The issue is that, in some torch-mlir conversions, we are comparing a runtime-generated f32 scalar value to a torch.constant.float (which is stored as f64). E.g., generating IR like:

module {
  func.func @is_zero(%arg0: f32) -> i1 {
    %cst = arith.constant 0.000000e+00 : f64
    %0 = arith.extf %arg0 : f32 to f64
    %1 = arith.cmpf ueq, %cst, %0 : f64
    return %1 : i1
  }
}

This fails to compile (for any backend) with --iree-input-demote-f64-to-f32=false.

My request for comment is with regards to a solution:

  • Can I simply add a VM conversion for f32->f64, or is there an intentional reason why this doesn't exist already?
  • If it doesn't make sense to add a VM conversion, are there ways to demote f64 to f32 just for host-code (keeping the higher-precision for dispatches)?

Versions:

iree-base-compiler 3.3.0rc20250218
iree-base-runtime  3.3.0rc20250218

Activity

  1. benvanik commented on Feb 18, 2025

    @benvanik
    Collaborator

    it's expected that should work - so I'd look for why it isn't. arith.extf should become vm.ext.f32.f64 and arith.cmpf ueq should become vm.cmp.eq.f64.u.

  2. zjgarvey commented on Feb 19, 2025

    @zjgarvey
    ContributorAuthor

    It looks like both of those are missing from ArithToVm (although the op codes are already defined). I'll go ahead and add the conversions.

    I figured there might be a specific reason why they weren't supported.

  3. self-assigned this
    on Feb 19, 2025
  4. benvanik commented on Feb 19, 2025

    @benvanik
    Collaborator

    yay, that's the best situation :P
    you're probably hitting these for the first time as nearly everyone runs in f32.
    it'll be nice to have the full coverage - if you spot anymore missing patterns while you're digging in there feel free to add them too - if you're using f64 you're likely to hit them at some point!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions