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

Add a CPU lowering pass #1

Closed
wants to merge 2 commits into from

Conversation

shintaro-iwasaki
Copy link
Owner

@shintaro-iwasaki shintaro-iwasaki commented Oct 27, 2023

This demonstrates how triton-shared can potentially run its lowered linalg + its friends on CPU as a reference.

  1. We don't need any changes in the Triton runtime
  2. A very basic empty kernel runs, and it succeeds
  3. Unfortunately I could not make the standard MLIR lowering passes work for triton-shared generated code (it causes SEGV).

Recently Triton updated its test suite to specify the device type iirc, so we can naturally run test_core.py using a reference CPU backend if the problem above will be solved. Would it be something interesting?

@shintaro-iwasaki
Copy link
Owner Author

examples.yml runs Triton code using GitHub Actions.

Choose a reason for hiding this comment

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

when i ran this locally there's a warning from Python using is operator in this situation. I'm definitely not Python programmer but i think the correct code you want might be something more like this:

def _get_triton_shared_opt_path():
    path = os.getenv("TRITON_SHARED_OPT_PATH", "")
    if path == "":
        raise Exception("TRITON_SHARED_OPT_PATH is not set.")
    return path


def _get_llvm_bin_path(bin_name: str):
    path = os.getenv("LLVM_BINARY_DIR", "")
    if path == "":
        raise Exception("LLVM_BINARY_DIR is not set.")
    return f"{path}/{bin_name}"

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thank you! I don't remember why I used is, but I fixed the issue in the latest commit.

Choose a reason for hiding this comment

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

keep gettting this error on latest version on triton which odd since Intel's XPU backend does the same thing

/triton/python/triton/third_party/cpu/__init__.py", line 13, in <module>
    from triton.runtime.jit import version_key  # noqa:E402
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: cannot import name 'version_key' from 'triton.runtime.jit' 

Choose a reason for hiding this comment

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

@danikhan632 i'm pretty sure there's some kind of versioning mismatch going on as the code around this changed recently.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thanks for taking a look at this PR!

  • From a reproducibility perspective, it worked at least on GitHub Actions below, so if you follow exactly the same way as what it does, it should work.
  • If you are using the very latest Triton (not the version specified by ".github/workflows/integration-tests.yml"), maybe the upstream has reorganized files and function names etc. I will investigate it when the version is updated.

Choose a reason for hiding this comment

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

was working on a similar thing, do you plan on making the compiler with gcc/clang?
worked on the intel extenison so most of my experience building a launcher comes from that

Copy link
Owner Author

Choose a reason for hiding this comment

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

I might not fully understand your question, but this PR uses the following binaries.

  • Triton's default LLVM binaries (llc and mlir-opt)
  • The default C++ compiler for the pybind logic and linking etc; now it uses g++ (hardcoded, but can be changed).

Choose a reason for hiding this comment

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

Which triton commit hash are you using?s till running into the same issue

Copy link
Owner Author

Choose a reason for hiding this comment

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

See .github/workflows/integration-tests.yml. It uses 05dc28be0e72dd496300a31b99a21a5a5118f8e9.
Please also check the installation method written in the GitHub Action script.

Choose a reason for hiding this comment

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

missed that, thank you

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