| 34 | }; |
| 35 | |
| 36 | void ExamplePrepack(ruy::Context* context) { |
| 37 | const float lhs_data[] = {1, 2, 3, 4}; |
| 38 | const float rhs_data[] = {1, 2, 3, 4}; |
| 39 | float dst_data[4]; |
| 40 | |
| 41 | // Set up the matrix layouts and spec. |
| 42 | ruy::Matrix<float> lhs; |
| 43 | ruy::MakeSimpleLayout(2, 2, ruy::Order::kRowMajor, &lhs.layout); |
| 44 | ruy::Matrix<float> rhs; |
| 45 | ruy::MakeSimpleLayout(2, 2, ruy::Order::kColMajor, &rhs.layout); |
| 46 | ruy::Matrix<float> dst; |
| 47 | ruy::MakeSimpleLayout(2, 2, ruy::Order::kColMajor, &dst.layout); |
| 48 | ruy::BasicSpec<float, float> spec; |
| 49 | |
| 50 | SimpleAllocator allocator; |
| 51 | auto alloc_fn = [&allocator](std::size_t num_bytes) -> void* { |
| 52 | return allocator.AllocateBytes(num_bytes); |
| 53 | }; |
| 54 | |
| 55 | // In this example, we pre-pack only the RHS, but either will work. |
| 56 | // Note that we only need to set the data pointer for the matrix we are |
| 57 | // pre-packing. |
| 58 | ruy::PrepackedMatrix prepacked_rhs; |
| 59 | rhs.data = rhs_data; |
| 60 | ruy::PrePackForMul<ruy::kAllPaths>(lhs, rhs, spec, context, &dst, |
| 61 | /*prepacked_lhs=*/nullptr, &prepacked_rhs, |
| 62 | alloc_fn); |
| 63 | |
| 64 | // No data will be read from the RHS input matrix when using a pre-packed RHS. |
| 65 | rhs.data = nullptr; |
| 66 | lhs.data = lhs_data; |
| 67 | dst.data = dst_data; |
| 68 | ruy::MulWithPrepacked<ruy::kAllPaths>(lhs, rhs, spec, context, &dst, |
| 69 | /*prepacked_lhs=*/nullptr, |
| 70 | &prepacked_rhs); |
| 71 | rhs.data = rhs_data; |
| 72 | |
| 73 | // Print out the results. |
| 74 | std::cout << "Example Mul with pre-packing RHS, float:\n"; |
| 75 | std::cout << "LHS:\n" << lhs; |
| 76 | std::cout << "RHS:\n" << rhs; |
| 77 | std::cout << "Result:\n" << dst << "\n"; |
| 78 | } |
| 79 | |
| 80 | int main() { |
| 81 | ruy::Context context; |
no test coverage detected