ONE - On-device Neural Engine
Loading...
Searching...
No Matches
PALBatchMatMul.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef LUCI_INTERPRETER_PAL_BATCHMATMUL_H
18#define LUCI_INTERPRETER_PAL_BATCHMATMUL_H
19
20#include <tensorflow/lite/kernels/internal/reference/batch_matmul.h>
21
23{
24inline void BatchMatMul(const tflite::RuntimeShape &lhs_shape, const float *lhs_data,
25 const tflite::RuntimeShape &rhs_shape, const float *rhs_data,
26 const tflite::RuntimeShape &output_shape, float *output_data)
27{
28 tflite::reference_ops::BatchMatMul(lhs_shape, lhs_data, rhs_shape, rhs_data, output_shape,
29 output_data);
30}
31
32static inline void SetupScratchpadTensor(luci_interpreter::Tensor *lhs_scratchpad,
33 luci_interpreter::Tensor *rhs_scratchpad,
34 const tflite::RuntimeShape &lhs_shape,
35 const tflite::RuntimeShape &rhs_shape)
36{
37 // Scratchpad for transposed LHS
38 {
39 auto lhs_rank = lhs_shape.DimensionsCount();
40 luci_interpreter::Shape scratchpad_size(lhs_rank);
41 for (int i = 0; i < lhs_rank - 2; ++i)
42 {
43 scratchpad_size.dim(i) = lhs_shape.Dims(i);
44 }
45 scratchpad_size.dim(lhs_rank - 2) = lhs_shape.Dims(lhs_rank - 1);
46 scratchpad_size.dim(lhs_rank - 1) = lhs_shape.Dims(lhs_rank - 2);
47
48 lhs_scratchpad->resize(scratchpad_size);
49 }
50 // Scratchpad for transposed RHS
51 {
52 auto rhs_rank = rhs_shape.DimensionsCount();
53 luci_interpreter::Shape scratchpad_size(rhs_rank);
54 for (int i = 0; i < rhs_rank - 2; ++i)
55 {
56 scratchpad_size.dim(i) = rhs_shape.Dims(i);
57 }
58 scratchpad_size.dim(rhs_rank - 2) = rhs_shape.Dims(rhs_rank - 1);
59 scratchpad_size.dim(rhs_rank - 1) = rhs_shape.Dims(rhs_rank - 2);
60
61 rhs_scratchpad->resize(scratchpad_size);
62 }
63}
64
65} // namespace luci_interpreter_pal
66
67#endif // LUCI_INTERPRETER_PAL_BATCHMATMUL_H
void resize(const Shape &new_shape)
Definition Tensor.cpp:56
const luci_interpreter::RuntimeShape output_shape
void BatchMatMul(const tflite::RuntimeShape &lhs_shape, const float *lhs_data, const tflite::RuntimeShape &rhs_shape, const float *rhs_data, const tflite::RuntimeShape &output_shape, float *output_data)