1/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15#ifndef TENSORFLOW_LITE_TOCO_ALLOCATE_TRANSIENT_ARRAYS_H_
16#define TENSORFLOW_LITE_TOCO_ALLOCATE_TRANSIENT_ARRAYS_H_
17
18#include "tensorflow/lite/toco/model.h"
19
20namespace toco {
21
22// We align the allocated sizes to the next multiple of a cache line,
23// to get simple performance characteristics without side effects of
24// accesses to one buffer on accesses to another buffer.
25// That also takes care of data type alignment for any reasonable type
26// (no reasonable data type should have alignment greater than a cache line).
27// Here we make CPU-centric assumptions, in particular, we assume 64-byte cache
28// lines. Getting this wrong by a factor of 2x (if this ever changes) wouldn't
29// be terrible.
30// Embedded architectures may use a different value for alignment.
31constexpr std::size_t kDefaultTransientDataAlignment = 64;
32
33// Rounds up dividend to a value divisible by divisor.
34inline std::size_t RoundUpToNextMultipleOf(std::size_t dividend,
35 std::size_t divisor) {
36 return ((dividend + divisor - 1) / divisor) * divisor;
37}
38
39void AllocateTransientArrays(Model* model,
40 std::size_t transient_data_alignment);
41
42} // namespace toco
43
44#endif // TENSORFLOW_LITE_TOCO_ALLOCATE_TRANSIENT_ARRAYS_H_
45