Skip to content

Add RISC-V benchmark configs - #9218

Merged
pzread merged 4 commits into
iree-org:mainfrom
pzread:riscv-pipeline
Jun 2, 2022
Merged

pzread merged 4 commits into
iree-org:mainfrom
pzread:riscv-pipeline

Conversation

@pzread

@pzread pzread commented May 25, 2022 •

Copy link
Copy Markdown
Contributor

Add benchmark configs for RV64 and RV32 architecture.

Currently we don't mean to run these benchmarks, they are just for compiling the modules for now, so we can collect the compilation statistics. However we keep them in the same format as other benchmarks, as we will run them eventually.

There are some changes to be done in iree_benchmark_suite to generate the statistics with some special parameters (--iree-llvm-debug-symbols=false and --iree-vm-emit-polyglot-zip). They will be done in the follow-up changes.

@pzread
pzread requested a review from dcaballe May 25, 2022 18:07
@pzread pzread changed the title Add example RISCV benchmarks Add RISC-V benchmark configs May 25, 2022
@pzread

pzread commented May 25, 2022

Copy link
Copy Markdown
Contributor Author

@dcaballe I drafted the benchmark configs for RISC-V. They will generate the RISC-V modules when we build with --target iree-benchmark-suites.

I'm not familiar with RISC-V, so I have questions about

  1. What CPU features do we want to use in the benchmarks?
  2. Is there a specific microarchitecture we want to target?
  3. Not sure about the name of the architecture, should we use RISC-V64 instead of RISCV64?
  4. Do we want to include both RISC-V64 and RISC-V32?

@dcaballe

Copy link
Copy Markdown
Contributor

I'm not familiar with RISC-V, so I have questions about

  1. What CPU features do we want to use in the benchmarks?
  2. Is there a specific microarchitecture we want to target?

For the 64-bit configuration, you can try:

tools/iree-compile \
  --iree-mlir-to-vm-bytecode-module \
  --iree-hal-target-backends=dylib-llvm-aot \
  --iree-llvm-target-triple=riscv64 \
  --iree-llvm-target-cpu=generic-rv64 \
  --iree-llvm-target-abi=lp64d \
  --iree-llvm-target-cpu-features="+m,+a,+f,+d,+v" \
  --riscv-v-vector-bits-min=512 --riscv-v-fixed-length-vector-lmul-max=8 \
  iree_input.mlir -o mobilenet-dylib.vmfb

You can find further information here: https://google.github.io/iree/building-from-source/riscv/#optional-configuration

For the 32-bit configuration, I think @hcindyl should be able to help but it should be something like:

iree-compile --iree-mlir-to-vm-bytecode-module --iree-hal-target-backends=dylib-llvm-aot --iree-llvm-target-triple=riscv32-pc-linux-elf -iree-llvm-target-cpu=generic-rv32 -iree-llvm-target-abi=ilp32 --iree-llvm-target-cpu-features=+m,+a,+f,+zvl512b,+zve32x --riscv-v-vector-bits-min=512 --riscv-v-fixed-length-vector-lmul-max=8 --iree-llvm-debug-symbols=false --iree-llvm-link-embedded=true --iree-llvm-embedded-linker-path=lld
  1. Not sure about the name of the architecture, should we use RISC-V64 instead of RISCV64?

I would use RV64 and RV32 so that it's the same as in the flags.

  1. Do we want to include both RISC-V64 and RISC-V32?

Yes but we only need rv32 for person detection, for now.

@dcaballe
dcaballe requested a review from hcindyl May 26, 2022 18:29

@hcindyl hcindyl 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.

We need a benchmark config to invoke codegen only and add embedded library code size check.

Comment thread benchmarks/TFLite/linux-riscv.cmake Outdated
"--iree-llvm-target-cpu-features=+m,+a,+f,+d,+c"
)

# CPU, Dylib-Sync, RISCV64, full-inference

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.

We can't run the inference from the iree-benchmark-module because the runtime binary needs to be built with RV64 compiler and the binary needs to be run under an emulator.

This should be codegen only and the benchmark should be about the codegen time and the embedded dispatch library size.

@pzread pzread May 26, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Currently the benchmark framework doesn't support only compiling modules, but there is no harm to have runtime configs here, since we don't run them in the pipeline. The rules I add here are just for compiling the RV64 modules.

I'm adding the script to collect compilation time and binary size and it will work with the module generated from these rules (#9227).

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.

I see from #9227 we only get the module size. However, I wonder if we should report both the bytecode module size as well as the embedded workload library size.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think it is a good idea to also track the embedded library size. The issue is I don't think our current infra can handle that many metrics well. So if the module size is good enough for now, I'd prefer to postpone the embedded library size.

I'm working on a new benchmark infra design and we should be able to support much more metrics with it. Happy to chat offline if you are interested in it : )

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.

See the reply in #9218 (comment). I didn't mean to try the size for every dispatch library, but the total size of the .so would be sufficient, so that's two numbers in total, bytecode size and .so size.

@pzread pzread May 26, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

SGTM : ) I think we can work on the bytecode size (total module size), as it is more straightforward. The .so size can be added later (with --iree-vm-emit-polyglot-zip as you suggested or other ways, but they require some extra changes in the build system).

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.

Sorry, I saw this after submitting #9218 (comment). Yes, please, let's focus on just one metric for now, either the .so size of the bytecode size would work. Whatever is simpler.

Comment thread benchmarks/TFLite/linux-riscv.cmake Resolved
Comment thread benchmarks/TFLite/linux-riscv.cmake Outdated
"--iree-llvm-target-triple=riscv64"
"--iree-llvm-target-cpu=generic-rv64"
"--iree-llvm-target-abi=lp64d"
"--iree-llvm-target-cpu-features=+m,+a,+f,+d,+c"

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.

@pzread pzread May 26, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is there a big difference between counting .vmfb vs. the embedded dynamic library? The vmfb should include all the embedded dynamic libraries and I assume usually we deploy .vmfb (according to https://google.github.io/iree/building-from-source/riscv/#optional-configuration).

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.

If we intend to generate the full bytecode module, we should consider to add --iree-llvm-debug-symbols=false to avoid the overhead of including the symbols in the workload library.

If we add --iree-vm-emit-polyglot-zip flag then the workload library can be extracted from the bytecode module with zipinfo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do we want to track the total size of workload libraries or each of them (there are usually 70~90 libraries in a model)?

The number of workload libraries (dispatches) are frequently changed when we change the fuse, so it will be an issue to track the history of their sizes. Also our dashboard can't handle that many metrics well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My idea is if we mainly distribute the full bytecode module (I assume), then tracking the size of bytecode module is quite important, as It tells us the final binary size that will be distributed.

This size includes the VM code, workload libraries, and maybe other unexpected things. It can be unclear which part is wrong when we see the size is increased, but it also covers every part.

The next step can count the size of each part separately, which provides better insights. But it is still valuable to track the total binary size as it is the actual binary size.

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.

Is there a big difference between counting .vmfb vs. the embedded dynamic library? The vmfb should include all the embedded dynamic libraries and I assume usually we deploy .vmfb (according to https://google.github.io/iree/building-from-source/riscv/#optional-configuration).

.vmfb includes the VM flatbuffer control and the embedded dynamic library, and the LLVM target triple should only affect the latter, but the former should affect the delta for improvement/regression. For example, person detect bytecode module built for x86_64 has the size of 729kB, but 480kB is the LLVM-target-dependent workload (model_linked_llvm_embedded_elf_x86_64.so). We want to present those two numbers separably to identify the improvement/regression.

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.

Indeed, all that fine-grained information could be very useful in the future but the goal for this quarter is to just track the size of the full model from the .so file without symbols/debug information. I expect to use this to quickly detect major changes in code size, such us the one related to tosa.apply_scale (one order of magnitude), and get an overall long-term view but not to scrutinize/root-cause every small increase because increases will happen. For that purpose, just tracking the full model size would be enough. We can iterate and gather more information once we have something working. Let's keep it simple for now.

@benvanik provided some flags to keep the temporary files around here.

@pzread
pzread marked this pull request as ready for review May 26, 2022 23:31
@pzread

pzread commented May 26, 2022

Copy link
Copy Markdown
Contributor Author

Updated the config with the suggestions in #9218 (comment). @dcaballe @hcindyl Let me know if those compilation options make sense to you : )

Also I refer the "microarchitecture" (defined here) of this config as "Generic", not sure if that is a correct name.

Comment thread benchmarks/TFLite/linux-riscv.cmake Resolved
Comment thread benchmarks/TFLite/linux-riscv.cmake Resolved
Comment thread benchmarks/TFLite/linux-riscv.cmake Resolved
Comment thread benchmarks/TFLite/linux-riscv.cmake Resolved

@antiagainst antiagainst 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.

LGTM regarding general structure; I'll leave others to check RISC-V specific stuff. :)

Just two general points that we'd like to watch out and improve in the future:

  1. I see we are generating more and more permutations for different targets. The benchmark suite tarball uploaded to buildkite right now contains everything. It's growingly large (at 1.27GB right now). Given that these targets are for different scenarios, we should consider split the benchmark tarball and build different subsets on different pipelines, e.g., only building ARM CPU / Adreno GPU / Mali GPU targets in android benchmarking pipeline, only building x86-64 / RISC-V / CUDA targets in cloud benchmarking pipeline. This reduces building time, reduces tarball generating / uploading time, and it also reduces time to download those tarballs (esp. for RPI4s driving those Android phones). This can be done e.g., by registering more pseudo targets like iree-benchmark-suites-x86-64 etc. and make CMake targets generating x86-64 artifacts a dependency.
  2. As an inline comment.

Comment thread benchmarks/TFLite/CMakeLists.txt Outdated
################################################################################
# Add benchmarks for all platforms. #
################################################################################
include(linux-riscv.cmake)

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.

We'd want to move the configurations for mobile CPU/GPU in the above to its separate files and include here to be consistent. Don't need to happen in this patch though.

@pzread

pzread commented May 27, 2022

Copy link
Copy Markdown
Contributor Author

LGTM regarding general structure; I'll leave others to check RISC-V specific stuff. :)

Just two general points that we'd like to watch out and improve in the future:

  1. I see we are generating more and more permutations for different targets. The benchmark suite tarball uploaded to buildkite right now contains everything. It's growingly large (at 1.27GB right now). Given that these targets are for different scenarios, we should consider split the benchmark tarball and build different subsets on different pipelines, e.g., only building ARM CPU / Adreno GPU / Mali GPU targets in android benchmarking pipeline, only building x86-64 / RISC-V / CUDA targets in cloud benchmarking pipeline. This reduces building time, reduces tarball generating / uploading time, and it also reduces time to download those tarballs (esp. for RPI4s driving those Android phones). This can be done e.g., by registering more pseudo targets like iree-benchmark-suites-x86-64 etc. and make CMake targets generating x86-64 artifacts a dependency.
  2. As an inline comment.

Definitely agree with target split for benchmark suites. I was planning to do this later but decided to do it first as it's not too complicated #9237.

Comment thread benchmarks/TFLite/linux-riscv.cmake Resolved
"${DEEPLABV3_FP32_MODULE}"
"${MOBILESSD_FP32_MODULE}"
"${POSENET_FP32_MODULE}"
"${MOBILEBERT_FP32_MODULE}"

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As #9218 (comment), we only add MobileBert in this change.

@dcaballe dcaballe 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.

It looks good! Just a couple of comments! Thanks!

Comment thread benchmarks/TFLite/linux-riscv.cmake Resolved
Comment thread benchmarks/TFLite/linux-riscv.cmake Outdated
"${POSENET_FP32_MODULE}"
"${MOBILEBERT_FP32_MODULE}"
"${MOBILENET_V2_MODULE}"
"${MOBILENET_V3SMALL_MODULE}"

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.

We should only be tracking MobileNetV1 (rv64, fp32), MobileBert (rv64, fp32), DeepLabV3 (rv64, fp32) and Person Detection (rv32, quantized) for now (see #9167) but we don't have to add them all as part of this PR. I would add just one for now. We can add the rest incrementally and consider more for rv32, but first we have to figure out if they are still compiling successfully for RISC-V (we are not tracking any of this) and know more about the limitations to run them on an FPGA or any other mean. I don't think we can have a large number of models for the time being due to execution constraints.

@pzread pzread Jun 1, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I only keep MOBILEBERT_FP32_MODULE in this change as an example. It is a good idea to add the rest modules in the follow-up PRs.

@pzread
pzread requested review from dcaballe and hcindyl June 1, 2022 13:25

@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'm worried about how far we're going down this CMake complexity path and how many different benchmark configurations we're adding. Each one is "just one more", but

GTp65Dn8AwnH

@ScottTodd

Copy link
Copy Markdown
Member

I'm worried about how far we're going down this CMake complexity path and how many different benchmark configurations we're adding.

The configs themselves don't concern me, but I am worried about growing complexity in https://github.com/google/iree/blob/main/build_tools/cmake/iree_benchmark_suite.cmake as we add more types of "benchmarking" and more platforms. At some point we might want to pull pieces of that into standalone python/bash scripts, to decouple from the build system.

@pzread

pzread commented Jun 1, 2022 •

Copy link
Copy Markdown
Contributor Author

I'm worried about how far we're going down this CMake complexity path and how many different benchmark configurations we're adding.

The configs themselves don't concern me, but I am worried about growing complexity in https://github.com/google/iree/blob/main/build_tools/cmake/iree_benchmark_suite.cmake as we add more types of "benchmarking" and more platforms. At some point we might want to pull pieces of that into standalone python/bash scripts, to decouple from the build system.

I'm planning to do a big refactoring of the current benchmark framework in the following months, including replacing some cmake rules with python scripts. Originally I wouldn't do these changes before the new benchmark framework, but as it will take some time to happen and we want to have these features (x86, risc-v, cuda pipeline, binary sizes) now, I think it is fine as long as we don't stretch this too much.

Pipelines for more architectures and collecting binary sizes are basically the boundary I would push to. Beyond that is too complicated for our current framework.

@antiagainst

Copy link
Copy Markdown
Member

+1 to reducing the complexity in iree_benchmark_suite.cmake!

@dcaballe

dcaballe commented Jun 1, 2022

Copy link
Copy Markdown
Contributor

Thank you so much for accommodating our needs! We understand that adding support for these metrics is a stretch and that's why I'm pushing to keep it as minimalistic as possible. We currently don't have any way to test/track anything related to RISC-V, which makes our RISC-V users the first line of testing, with all the negative implications of that. The fact that we don't have hardware to run on makes the situation even more complicated. I hope that with these metrics we can at least catch some major issues before hitting the user. I also think that once these metrics are more generally used in the pipelines and we can enable execution on RISC-V, the infra implementation should be more uniform and require less special casing. At this point, I'm not aware of any other metrics or configurations that we may urgently need in the short term (@hcindyl, please, correct me if I'm wrong) other than enabling execution for RISC-V (probably in Q3). Hopefully, this provides some clarity on the short- and mid-term needs.

@dcaballe dcaballe 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.

The RISC-V aspect of it looks good to me. Thanks!

@pzread
pzread enabled auto-merge (squash) June 2, 2022 00:11
@pzread
pzread merged commit 2187016 into iree-org:main Jun 2, 2022
@GMNGeoffrey GMNGeoffrey added infrastructure Relating to build systems, CI, or testing infrastructure/benchmark Relating to benchmarking infrastructure labels Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

infrastructure/benchmark Relating to benchmarking infrastructure infrastructure Relating to build systems, CI, or testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants