diff options
author | Benoit Jacob <benoitjacob@google.com> | 2020-12-21 12:39:19 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2020-12-21 12:39:38 -0800 |
commit | 177062d283a4bb14b414bc2f101a2103aee4fb71 (patch) | |
tree | 5e35e6838883d2119f7860924936653927bb04a4 | |
parent | 4790797d11a81f96baf24f3731fd3ca44c2c5f8b (diff) | |
download | ruy-177062d283a4bb14b414bc2f101a2103aee4fb71.tar.gz |
Move the example out of the ruy/ruy directory, and add an example returning raw
int32 accumulators.
PiperOrigin-RevId: 348511323
-rw-r--r-- | example/BUILD (renamed from ruy/example/BUILD) | 0 | ||||
-rw-r--r-- | example/README.md (renamed from ruy/example/README.md) | 26 | ||||
-rw-r--r-- | example/example.cc (renamed from ruy/example/example.cc) | 26 |
3 files changed, 40 insertions, 12 deletions
diff --git a/ruy/example/BUILD b/example/BUILD index aa85701..aa85701 100644 --- a/ruy/example/BUILD +++ b/example/BUILD diff --git a/ruy/example/README.md b/example/README.md index ec9a8fd..e29ee12 100644 --- a/ruy/example/README.md +++ b/example/README.md @@ -1,12 +1,14 @@ -## Introduction
-These are some examples about how to use RUY.
-
-## BUILD
-Build the example with bazel commands:
-```
-bazel build //ruy/example:example
-```
-You can find the generated target under directory:
-```
-./bazel-bin/ruy/example
-```
+## Introduction + +These are some examples about how to use RUY. + +## BUILD + +Build the example with bazel commands: +``` +bazel build //ruy/example:example +``` +You can find the generated target under directory: +``` +./bazel-bin/ruy/example +``` diff --git a/ruy/example/example.cc b/example/example.cc index 6752d2a..4e81304 100644 --- a/ruy/example/example.cc +++ b/example/example.cc @@ -126,6 +126,31 @@ void ExampleMulInt8PerChannelQuantized(ruy::Context *context) { std::cout << "RHS:\n" << rhs; std::cout << "Result:\n" << dst << "\n"; } +void ExampleMulInt8PerChannelGetRawAccumulators(ruy::Context *context) { + const std::int8_t lhs_data[] = {1, 2, 3, 4}; + const std::int8_t rhs_data[] = {1, 2, 3, 4}; + std::int32_t dst_data[4]; + + ruy::Matrix<std::int8_t> lhs; + ruy::MakeSimpleLayout(2, 2, ruy::Order::kRowMajor, lhs.mutable_layout()); + lhs.set_data(lhs_data); + ruy::Matrix<std::int8_t> rhs; + ruy::MakeSimpleLayout(2, 2, ruy::Order::kColMajor, rhs.mutable_layout()); + rhs.set_data(rhs_data); + ruy::Matrix<std::int32_t> dst; + ruy::MakeSimpleLayout(2, 2, ruy::Order::kColMajor, dst.mutable_layout()); + dst.set_data(dst_data); + + // When Dst is int32, mul_params is unused. + ruy::MulParams<std::int32_t, std::int32_t> mul_params; + ruy::Mul(lhs, rhs, mul_params, context, &dst); + + std::cout << "Example Mul, int8 quantized with per-channel multipliers, " + "returning raw int32 accumulators:\n"; + std::cout << "LHS:\n" << lhs; + std::cout << "RHS:\n" << rhs; + std::cout << "Result:\n" << dst << "\n"; +} int main() { ruy::Context context; @@ -133,4 +158,5 @@ int main() { ExampleMulFloatWithBiasAddAndClamp(&context); ExampleMulUint8AsymmetricQuantized(&context); ExampleMulInt8PerChannelQuantized(&context); + ExampleMulInt8PerChannelGetRawAccumulators(&context); } |