Skip to content

Importers should print generic op form by default/exclusively #4441

Closed

Description

@stellaraccident

Currently, the importers print custom op asm form, which limits the ability to interface to/from systems that may not have the dialects linked in, making the pipeline far less hackable.

Example:

from pyiree.compiler2 import xla as xlac
from jaxlib import xla_client
ops = xla_client.ops
builder = xla_client.XlaBuilder("testbuilder")
in_shape = np.array([4, 2, 3], dtype=np.float32)
in_feed = ops.Parameter(builder, 0, xla_client.shape_from_pyval(in_shape))
result = ops.Add(in_feed, ops.Constant(builder, np.float32(1.0)))
xla_computation = builder.Build(result)

# TODO: Should be printing generic op form.
mhlo_text = xlac.compile_str(xla_computation.as_serialized_hlo_module_proto(), import_only=True).decode('utf-8')
print(mhlo_text)

Prints this:

module  {
  func @main(%arg0: tensor<3xf32>) -> tensor<3xf32> {
    %0 = mhlo.constant dense<1.000000e+00> : tensor<f32> loc(#loc1)
    %1 = "mhlo.broadcast_in_dim"(%0) {broadcast_dimensions = dense<> : tensor<0xi64>} : (tensor<f32>) -> tensor<3xf32> loc(#loc2)
    %2 = mhlo.add %arg0, %1 : tensor<3xf32> loc(#loc3)
    return %2 : tensor<3xf32> loc(#loc0)
  } loc(#loc0)
} loc(#loc0)
#loc0 = loc(unknown)
#loc1 = loc("constant.2")
#loc2 = loc("broadcast.3")
#loc3 = loc("add.4")

Since the importer is intended to be part of systematic pipelines, it should be operating in a mode that is the most efficient and accessible. Currently, that means bridging through ASM, but in the future, it will likely involve a more efficient binary IR representation. There is no reason to be going through custom op forms for such tools.

Activity

  1. added
    bindings/python
    on Jan 8, 2021
  2. added a commit that references this issue on Jan 8, 2021
    58f4ae5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bindings/python

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions