cpu_context.h 1.5 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
#include <memory>

19 20
#include "paddle/phi/backends/cpu/forwards.h"
#include "paddle/phi/core/device_context.h"
W
Wilber 已提交
21

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

25
namespace phi {
W
Wilber 已提交
26

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

W
Wilber 已提交
37 38 39 40
 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 已提交
41 42 43
  void SetEigenDevice(Eigen::DefaultDevice* device);

 private:
W
Wilber 已提交
44 45
  struct Impl;
  std::unique_ptr<Impl> impl_;
W
Wilber 已提交
46 47
};

48
}  // namespace phi