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

Do not require scalar for memref set value #101

Merged
merged 2 commits into from
Oct 14, 2024

Conversation

hunhoffe
Copy link
Contributor

Hello!

I'm not sure if this fits entirely with the mlir-python-extras philosophy (and I'm not sure how to test mlir-python-extras beyond how I am using it), but a local modification I made was to infer the type of an inserted element into a MemRef based on the dtype of MemRef. While this does allow one to shoot themselves in the foot more easily, it does make some of the resulting code in my examples look a bit cleaner as I'm trying to avoid using the constant() function if the dtype can be reasonably inferred some other way.

As a side note, if this PR is accepted, I believe mlir-aie has a clear path forward for using mlir-python-extras as an external library (Xilinx/mlir-aie#1828). We would be using the commit at main, so AFAIK the aie branch is no longer needed.

The reason I am attempting to upstream this particular change, and why I feel it is an important step in using mlir-python-extras as a library, is because using the mlir-python-extras memref module is more or less an all-or-nothing endeavor because the following can only be called once:

@register_value_caster(MemRefType.static_typeid)

So I can't use other pieces of the mlir-python-extras memref module while overriding a small portion of the memref module myself locally. If this PR is not accepted, my options are to either:

  • Keep my own copy of memref with my minor change
  • Something else I haven't thought of?

Let me know your thoughts!

Copy link
Owner

@makslevental makslevental left a comment

Choose a reason for hiding this comment

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

I'll approve after you commit/make the small change.

mlir/extras/dialects/ext/memref.py Show resolved Hide resolved
@makslevental
Copy link
Owner

makslevental commented Oct 12, 2024

and I'm not sure how to test mlir-python-extras beyond how I am using it

There's a fairly large pytest test suite (which you can run by doing pytest tests).

so AFAIK the aie branch is no longer needed.

That's not how that works - this package/project/repo (mlir-python-extras) requires host bindings that have to be specified at install time (see the install instructions in the README). That branch simply hardcodes HOST_MLIR_PYTHON_PACKAGE_PREFIX so you will still need it (and I'm happy to bump that branch for you when you need it).

Sorry I went and looked at your PR and saw that you do actually have HOST_MLIR_PYTHON_PACKAGE_PREFIX=aie. In that case sure yea that branch isn't necessary anymore.

because the following can only be called once

That's not correct - you can pass replace=True there like so

@register_value_caster(MemRefType.static_typeid, replace=True)

Co-authored-by: Maksim Levental <maksim.levental@gmail.com>
@hunhoffe
Copy link
Contributor Author

hunhoffe commented Oct 14, 2024

Ah, thank you for the information! I've committed the requested change (and thanks for pointing that out).

I have installed the requirements from requirements.txt and I've tried to run pytest tests but I get the following errors:

ImportError while importing test module '.../mlir-python-extras/tests/test_vector.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.10/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test_vector.py:6: in <module>
    from mlir.dialects import builtin
E   ModuleNotFoundError: No module named 'mlir'

I'm not sure what else is needed in my env for this, but I suppose I'll just trust the CI in the meantime!

@makslevental makslevental enabled auto-merge (squash) October 14, 2024 16:51
@makslevental makslevental merged commit b2b8d72 into makslevental:main Oct 14, 2024
30 checks passed
@hunhoffe hunhoffe deleted the memref-index-with-pyint branch October 14, 2024 18:10
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.

2 participants