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

Import matmul/conv/attention tests from iree/tests/e2e/ #2

Open
ScottTodd opened this issue Aug 9, 2024 · 3 comments
Open

Import matmul/conv/attention tests from iree/tests/e2e/ #2

ScottTodd opened this issue Aug 9, 2024 · 3 comments
Assignees

Comments

@ScottTodd
Copy link
Member

Could start with what already exists, including the C++ binaries files and CMake build system:

Or... run the generator scripts and jump straight to a prototype replacement test runner (pytest? other cmake functions?)

The test generators seem to be using mostly upstream dialects (e.g. linalg.conv_2d_nchw_fchw). The build system usage does some fancy things with flags though... should watch out for layering in there. For example:

  COMPILER_FLAGS
    "--iree-opt-data-tiling=false"
    "--iree-llvmcpu-enable-scalable-vectorization"
    "--iree-llvmcpu-target-triple=aarch64-unknown-unknown"
    "--iree-preprocessing-pass-pipeline=builtin.module\(util.func\(iree-preprocessing-transpose-matmul-pass{input=lhs}\)\)"
  LABELS
    "requires-arm-sme"
  TARGET_CPU_FEATURES_VARIANTS
    "arm_64:sme:+sve,+sme"

See this related thread on Discord: https://discord.com/channels/689900678990135345/1270451599231156266

@ScottTodd ScottTodd self-assigned this Aug 9, 2024
@ScottTodd
Copy link
Member Author

Can also draw on code from https://github.com/nod-ai/rocm-gemm-benchmark/. That has test case generators and checked in .mlir files.

@ScottTodd
Copy link
Member Author

Current plan (cc @erman-gurses ):

  1. Land Add e2e test suite for the Attention - CPU Backend iree#17751 for interim coverage of attention on CPU (and possibly ROCm)
  2. Fork C++ and CMake matmul test code to this repo (including all transitive deps, a new CMake project that depends on the runtime, etc.)
  3. Fork C++ and CMake conv and attention test code to this repo
  4. Prototype a new test structure (check in generated files, rework CMake/ctest project or use pytest, etc.)

ScottTodd added a commit that referenced this issue Aug 20, 2024
Progress on #2.

This begins to port the tests from
https://github.com/iree-org/iree/tree/main/tests/e2e/matmul. The changes
here aim to be minimal, but a lot of cleanup is needed to make this
sustainable.

* A new CMake project named `iree-test-suites-matmul` is added. We could
share this with other test suites that need CMake, or let each test
suite create its own. I don't want to overgeneralize yet while so much
is still up in the air.
* The CMake project depends on the IREE runtime libraries and header
files to build a `iree-e2e-matmul-test` binary. This binary handles
preparing inputs, running a compiled program, and comparing outputs
against a reference implementation. That may be split into multiple
libraries or parts of it may move into Python or another test harness.
TBD.
* The CMake project then defines some test cases using
`iree_generated_e2e_runner_test`. This may be split into an offline
generation step and a test runner other than ctest. TBD.

TODO:

- [x] Fix namespace/symbol collisions in `test_utils.h` (fork further)
and include it correctly
- [x] Fix namespace/symbol collisions in
`iree_e2e_generated_runner_test.cmake` (fork further)
- [ ] Add a GitHub Actions workflow running the tests
- [x] Structure the CMake project such that it can be used from
iree-org/iree in place of the current tests
- [ ] Fork or remove dependencies on the upstream CMake helpers used by
`matmul/iree_e2e_generated_runner_test.cmake`?
- [x] Allow pointing at a local IREE, like
https://github.com/ScottTodd/iree/tree/infra-e2e-test-suites which
deletes the in-tree tests and supporting infra
@ScottTodd
Copy link
Member Author

ScottTodd commented Aug 20, 2024

Finding lots to clean up while refactoring the matmul tests. Debating starting fresh or cleaning up in-place.

Notes/ideas:

  • Generate MLIR files for matmul tests. #14 (run the generator offline and check in the test case files)
  • Drop matmul "compilation_info" generator code and test cases. #15
  • Remove the concept of "sizes" from the generator. Generate one file per test case with only a single function / matmul shape.
  • Maintain a list of interesting problem sizes sourced from general sweeps of common sizes and specific sizes used in popular workloads, like in https://github.com/nod-ai/rocm-gemm-benchmark/blob/main/gemmbench/problems.py
  • Come up with some directory structure that gets the number of files / test cases per folder down to under 100-1000 as needed. Maybe group by LHS/RHS data type, with deeper subfolders for transpose variants?
  • Drop the infer_acc_type helper function and make all calls into the generator fully explicit about what data types they want to use for the LHS, RHS, and accumulator
  • Decide on continuing to use iree_generated_e2e_runner_test or writing something new (pytest?). Start with manual testing and see what is needed from the build system / test runner. Compiler and runtime flagfiles could be used instead of plumbing strings through CMake functions 🤔
  • Merge _matmul.mlir and _calls.mlir into a single file for each test case? One entry function to run arbitrary inputs -> outputs, a second function to run with generated inputs and checking provided by the test module? Check optional symbol resolution...

ScottTodd added a commit that referenced this issue Aug 23, 2024
Progress on #2

(This is not yet running on CI anywhere, still refactoring the test
suite before passing it back into developer hands)

This was leaking compiler implementation details into test cases. The
compiler should be selecting a pipeline on its own based on the target
device(s). If a developer wants to try a different pipeline, they can
make a code change, introduce a dedicated flag (global/hacky), or use a
transform dialect script.

I think this drops some of the rocm test suites, which were only added
using explicit compilation_info settings. Leaving adding that back to a
follow-up / further refactoring. Editing the 2000 line `CMakeLists.txt`
file (generated from a 700 line `BUILD.bazel` file) is error-prone
especially with how this file has grown over the years. _If_ we stick to
CMake/CTest, it probably makes sense to start the file over from
scratch.
ScottTodd added a commit that referenced this issue Sep 4, 2024
Progress on #2.

* Renamed top level `matmul/` folder to `linalg_ops/`. We can put
`convolution` (linalg) and `attention` (linalg_ext) tests under here
too. Maybe other named ops or generics too.
* Rebased on the latest IREE code, including flag renames (though we
should drop usage of some flags and prefer to test the main user-facing
options)
* Added a workflow that goes through the instructions in
`linalg_ops/README.md` and configured both workflows to run on `push`
events in addition to the current triggers.
ScottTodd added a commit that referenced this issue Oct 15, 2024
Progress on #2. See
also the long [Discord thread
here](https://discord.com/channels/689900678990135345/1270451599231156266).

## Summaries of changes

### Further decoupled test suites from the core CMake project

* Forked `iree_native_test.cmake` to
`iree_test_suites_native_test.cmake`
* Dropped support (temporarily?) for testing on Android, RISC-V, and ARM
with SME
* Forked `iree_e2e_generated_runner_test.cmake` to
`iree_test_suites_runner_test.cmake`
* Dropped support (temporarily?) for filtering within the build system
which tests are defined and compile .vmfb files
* Now we can set `-DIREE_BUILD_TESTS=OFF` and avoid pulling in IREE's
other tests
* Added a new hand-authored `linalg_ops/matmul/CMakeLists.txt` that runs
tests on each backend using default flags

### Simplified the test generator

* Dropped unused functions
* Folded GPU-specific shapes into generic "small" and "large" shape test
suites

### Ran the `generate_e2e_matmul_tests.py` script offline and checked in
the generated files

* Currently 56 files totaling 1.90MB on disk (~27000 lines of code
according to GitHub)
* Now we can inspect the test cases without needing to run the generator
locally, and I fixed a few formatting issues
* I think this makes test suite management easier, and having the
generated files in this test suites repository doesn't cost the main
repository much (just extra `git checkout` time), but I could see a case
for more tightly coupling the generator with the test runner

## What is left to do?

* I want to iterate some more on the `linalg_ops/matmul/CMakeLists.txt`
file or move to a different test runner somehow. I mainly want to
support XFAIL in some way for both compiling and running.
* We should add back tests using CPU features like AVX512, GPU features
like Vulkan float16 extensions, and other non-default flags somehow.
Either infer what the compiler can from the host / target, or add test
suites explicitly.
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

No branches or pull requests

1 participant