cpu_context.h 1.6 KB
Newer Older
W
Wilber 已提交
1
/* Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

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

W
Wilber 已提交
17 18 19 20 21 22 23
#include <memory>

#include "paddle/pten/backends/cpu/forwards.h"
#include "paddle/pten/core/device_context.h"

// TODO(wilber): Do we need to use place in pten kernel?
#include "paddle/pten/common/place.h"
24 25

namespace pten {
W
Wilber 已提交
26 27 28 29

class CPUContext : public DeviceContext {
 public:
  CPUContext();
W
Wilber 已提交
30 31
  explicit CPUContext(const Place&);
  virtual ~CPUContext();
W
Wilber 已提交
32
  Eigen::DefaultDevice* eigen_device() const;
W
Wilber 已提交
33
  const Place& GetPlace() const override;
W
Wilber 已提交
34 35

 public:
W
Wilber 已提交
36 37 38 39
  // NOTE: DeviceContext hold resources. Used in training scenarios.
  // The interface used by the training scene, DeviceContext will initialize
  // all resources and delete them when destructing.
  void Init();
W
Wilber 已提交
40

W
Wilber 已提交
41 42 43 44
 protected:
  // NOTE: External users manage resources. Used in inference scenarios.
  // The Set interface is for inference only, DeviceContext will mark the
  // resource as external, and will not delete any resource when destructing.
W
Wilber 已提交
45 46 47
  void SetEigenDevice(Eigen::DefaultDevice* device);

 private:
W
Wilber 已提交
48 49
  struct Impl;
  std::unique_ptr<Impl> impl_;
W
Wilber 已提交
50 51
};

52
}  // namespace pten