context.h 1.7 KB
Newer Older
H
backup  
hjchen2 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#pragma once

17 18 19 20
#if _OPENMP
#include <omp.h>
#endif

21 22
#include <vector>
#include "framework/tensor.h"
H
backup  
hjchen2 已提交
23 24

namespace paddle_mobile {
25
namespace framework {
H
backup  
hjchen2 已提交
26

27
struct CPUContext {
H
backup  
hjchen2 已提交
28
 private:
29
  CPUContext();
30 31 32 33
  virtual ~CPUContext() {}

 public:
  static CPUContext* Context() {
34 35 36 37
    static CPUContext* ctx = nullptr;
    if (ctx == nullptr) {
      ctx = new CPUContext();
    }
H
backup  
hjchen2 已提交
38 39 40
    return ctx;
  }

41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
  void set_thread_num(int thread_num,
                      PowerMode power_mode = PERFORMANCE_PRIORITY);
  int get_thread_num();
  PowerMode get_power_mode() const { return _power_mode; }
  int get_cache_size(int level);
  int get_l1_cache_size() { return get_cache_size(1); }
  int get_l2_cache_size() { return get_cache_size(2); }
  int get_l3_cache_size() { return get_cache_size(3); }
  void* get_work_space(int size_in_byte);

  int _cpu_num;
  PowerMode _power_mode;
  std::vector<int> _big_core_ids;
  std::vector<int> _little_core_ids;
  std::vector<int> _l1_cache_sizes;
  std::vector<int> _l2_cache_sizes;
  std::vector<int> _l3_cache_sizes;
  Tensor _workspace;
H
backup  
hjchen2 已提交
59 60
};

61
}  // namespace framework
H
backup  
hjchen2 已提交
62
}  // namespace paddle_mobile