MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / ExamplePrepack

Function ExamplePrepack

tensorflow/lite/experimental/ruy/example_advanced.cc:36–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34};
35
36void 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
80int main() {
81 ruy::Context context;

Callers 1

mainFunction · 0.85

Calls 2

MakeSimpleLayoutFunction · 0.85
AllocateBytesMethod · 0.45

Tested by

no test coverage detected