Skip to content

end-to-end matmul tests - #7347

Merged
bjacob merged 2 commits into
iree-org:mainfrom
bjacob:e2e-matmul-tests
Oct 21, 2021
Merged

bjacob merged 2 commits into
iree-org:mainfrom
bjacob:e2e-matmul-tests

Conversation

@bjacob

@bjacob bjacob commented Oct 14, 2021 •

Copy link
Copy Markdown
Collaborator

end-to-end matmul tests, meaning: we generate input matrices, perform linalg.matmul's, check that the results are correct.

In an earlier attempt (PR #7154) the test was entirely generated code. That approach was abandoned because it potentially amounted to comparing the compiler's output with itself.

The new approach here is to have a custom C test runner that has its own C reference implementation of matmul and uses it to compare the output of the generated code, which it drives by means of replay-trace. So now each test is not just a .mlir source, but a (.mlir, .yaml) pair where the yaml file is a trace, determining the runtime values of the inputs of the code being tested. Both .mlir and .yaml files are co-generated by a Python script.

A new CMake function iree_trace_runner_test is added. It is a variant of iree_check_test, taking a custom trace runner and trace file, instead of iree_check_test's behavior of just running the module in iree-check-module.

A new CMake function iree_generated_trace_runner_test is added to call the Python script to co-generate the .yaml and the .mlirsource and call iree_trace_runner_test on the resulting files.

One aspect of PR #7154 is retained here: all the above-mentioned CMake functions are generalized also to allow running iree-opt (or an alternate tool) as a pre-processing step on the source .mlir file, before running iree-translate. That is because by default, new MLIR transformations are not necessarily known to iree-translate. In our case, that's the mmt4d-related transformations.

The tests added in this PR share the prefix e2e_matmul (that can be used with ctest -R).

Notes:

  • Android is fully supported.
  • There are both i8 and f32 tests, on equal footing.
  • There are separate tests for "small" and "large" shapes.
  • Tests are currently covering dylib-llvm-aot and vmvx. I haven't tried Vulkan.
  • Both direct lowering of linalg.matmul, and lowering via linalg.mmt4d, are tested in separate tests (look for direct vs mmt4d in the test names). The majority of the tests are mmt4d.
  • The tests are fully reproducible: across runs, across toolchains, across machines, because the pseudorandom numbers are entirely fixed across these dimensions.
  • The tests for each shape start out with simple matrices such as identity matrices before gradually involving more and more random matrices. That should ensure that >80% of the time spent squinting at matrices, is one cases where it's easy to understand what went wrong.

@google-cla google-cla Bot added the cla: yes label Oct 14, 2021
@bjacob
bjacob marked this pull request as ready for review October 15, 2021 04:07
Comment thread build_tools/cmake/iree_check_test.cmake Resolved
Comment thread iree/tools/iree-e2e-matmul-test.c Resolved
Comment thread iree/tools/iree-e2e-matmul-test.c Resolved
Comment thread iree/tools/iree-e2e-matmul-test.c Resolved
Comment thread iree/tools/utils/trace_replay.c Resolved

@GMNGeoffrey GMNGeoffrey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think there's cleanup to do with now-superfluous args and such, but overall I like this a lot better. You probably want to move trace runner out into its own cmake file though.

Comment thread build_tools/cmake/iree_check_test.cmake Resolved
Comment thread build_tools/cmake/iree_check_test.cmake Resolved
@bjacob
bjacob marked this pull request as draft October 19, 2021 03:31
@bjacob
bjacob marked this pull request as ready for review October 19, 2021 20:58

@GMNGeoffrey GMNGeoffrey left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh no, we need yaml for the tests, so need to update docker images. Let me do that. You've done enough.

Comment thread iree/tools/iree-e2e-matmul-test.c Resolved
Comment thread iree/tools/iree-e2e-matmul-test.c Resolved
Comment thread iree/tools/iree-e2e-matmul-test.c Resolved
Comment thread iree/tools/iree-e2e-matmul-test.c Resolved
Comment thread iree/tools/iree-e2e-matmul-test.c Resolved
# ARGS: arguments passed to the test binary.
# DRIVER: If specified, will pass --driver=DRIVER to the test binary and adds
# a driver label to the test.
# TEST_INPUT_FILE_ARG: If specified, the input file will be added to TEST_DATA and

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmmm this is going to be a bit of a problem with translation from Bazel where $location is the natural way to do this and this approach only works for positional arguments. I think it's fine for now, but it will probably be necessary to add this stuff when adding Bazel coverage. We could parse "$(location foo)" or translate that to something more cmake-y and parse that. We can cross that bridge later

@GMNGeoffrey

Copy link
Copy Markdown
Member

You'll also need to fix the Bazel build:

ERROR: Traceback (most recent call last):
	File "/tmpfs/src/github/iree/iree/test/e2e/regression/BUILD", line 13, column 90, in <toplevel>
		load("//build_tools/bazel:iree_check_test.bzl", "iree_check_single_backend_test_suite", "iree_generated_trace_runner_test")
Error: file '//build_tools/bazel:iree_check_test.bzl' does not contain symbol 'iree_generated_trace_runner_test'
ERROR: package contains errors: iree/test/e2e/regression
ERROR: error loading package 'iree/test/e2e/regression': Package 'iree/test/e2e/regression' contains errors

https://source.cloud.google.com/results/invocations/dceaaef7-79df-43f5-90c0-d231ee6d4acc/targets/iree%2Fgcp_ubuntu%2Fbazel%2Flinux%2Fx86-swiftshader%2Fcore%2Fpresubmit/log

Overall approach LGTM

@GMNGeoffrey

Copy link
Copy Markdown
Member

Oh no, we need yaml for the tests, so need to update docker images. Let me do that. You've done enough.

Hopefully #7406 will give you what you need. It became rather more of an adventure than I expected, which honestly should be expected because Docker is always broken in some new and interesting way

@bjacob

bjacob commented Oct 21, 2021

Copy link
Copy Markdown
Collaborator Author

Oh no, we need yaml for the tests, so need to update docker images. Let me do that. You've done enough.

Hopefully #7406 will give you what you need. It became rather more of an adventure than I expected, which honestly should be expected because Docker is always broken in some new and interesting way

Yes, it does fix it! Thanks!

GMNGeoffrey added a commit that referenced this pull request Oct 21, 2021
At this point all of our builds use Python. With
#7347 the last holdouts are growing a
dep on yaml to be able to run traces. So I squashed `cmake-python` into
`cmake` and shortened all the dependents by dropping `python` from their
name.

Some other cleanups, some of which were unfortunately necessary to be able to rebuild our images. Hooray unreproducible builds!
1. The rbe-toolchain image was never actually updated to bump the swiftshader commit in #7117 and
#6859, and the newer commits don't
actually build there so I had to restore the commit in the Dockerfile to
the one that has actually always been the one the image is using. See
#7419.
2. The place we were fetching the Vulkan SDK from is no longer
available, so I had to rebundle it and stash it in our GCS. Upgrading
Vulkan is a huge undertaking that I'm not going to undertake right now.
3. Deleted the `cmake-bazel-frontends-android` image, which is
unused.
@MaheshRavishankar

Copy link
Copy Markdown
Collaborator

(dropping myself from reviewer list. Thanks @bjacob for pushing this)

@MaheshRavishankar
MaheshRavishankar removed their request for review October 21, 2021 16:45
@bjacob
bjacob requested a review from GMNGeoffrey October 21, 2021 16:47
Comment thread build_tools/cmake/iree_check_test.cmake Resolved
Comment thread build_tools/bazel/iree_check_test.bzl Outdated
Comment on lines +202 to +206

def iree_generated_trace_runner_test(**kwargs):
# TODO: implement this. For now, it's only parsed by bazel_to_cmake.py, so
# the iree_generated_check_test's are just omitted in bazel builds.
pass

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is in the other file now

Suggested change
def iree_generated_trace_runner_test(**kwargs):
# TODO: implement this. For now, it's only parsed by bazel_to_cmake.py, so
# the iree_generated_check_test's are just omitted in bazel builds.
pass

Comment thread iree/tools/iree-e2e-matmul-test.c Resolved
@GMNGeoffrey

Copy link
Copy Markdown
Member

Please make sure you squash this when merging. We really don't want all these commits coming into main :-)

@asaadaldien asaadaldien left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! passing it to @benvanik

Comment thread iree/tools/utils/trace_replay.c Resolved
Comment thread iree/tools/utils/trace_replay.c Resolved
Comment thread iree/tools/utils/trace_replay.c Resolved
Comment thread iree/tools/utils/trace_replay.c Resolved
Comment thread iree/tools/utils/trace_replay.c Resolved
@bjacob
bjacob requested a review from benvanik October 21, 2021 20:21

@benvanik benvanik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍

@bjacob
bjacob merged commit 5feef48 into iree-org:main Oct 21, 2021
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.

5 participants