• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2019-2021 Huawei Technologies Co., Ltd
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 MINDSPORE_CCSRC_RUNTIME_DEVICE_GPU_GPU_DEVICE_ADDRESS_H_
18 #define MINDSPORE_CCSRC_RUNTIME_DEVICE_GPU_GPU_DEVICE_ADDRESS_H_
19 
20 #include <string>
21 #include <vector>
22 #include "runtime/device/device_address.h"
23 
24 using ShapeVecotr = std::vector<int>;
25 
26 namespace mindspore {
27 #ifdef ENABLE_DEBUGGER
28 class Debugger;
29 #endif
30 namespace device {
31 namespace gpu {
32 class GPUDeviceAddress : public DeviceAddress {
33  public:
GPUDeviceAddress(void * ptr,size_t size)34   GPUDeviceAddress(void *ptr, size_t size) : DeviceAddress(ptr, size) {}
GPUDeviceAddress(void * ptr,size_t size,const string & format,TypeId type_id)35   GPUDeviceAddress(void *ptr, size_t size, const string &format, TypeId type_id)
36       : DeviceAddress(ptr, size, format, type_id) {}
GPUDeviceAddress(void * ptr,size_t size,const std::string & format,TypeId type_id,const KernelWithIndex & node_index)37   GPUDeviceAddress(void *ptr, size_t size, const std::string &format, TypeId type_id, const KernelWithIndex &node_index)
38       : DeviceAddress(ptr, size, format, type_id, node_index) {}
39   ~GPUDeviceAddress() override;
40 
41   bool SyncDeviceToHost(size_t size, void *host_ptr) const override;
42   bool SyncHostToDevice(size_t size, const void *host_ptr) const override;
43   bool SyncDeviceToHost(const ShapeVector &shape, size_t size, TypeId type, void *host_ptr) const override;
44   bool SyncHostToDevice(const ShapeVector &shape, size_t size, TypeId type, const void *host_ptr,
45                         const std::string &format = "DefaultFormat") const override;
46 
47   void ClearDeviceMemory() override;
set_status(DeviceAddressStatus status)48   void set_status(DeviceAddressStatus status) { status_ = status; }
status()49   DeviceAddressStatus status() const { return status_; }
DeviceType()50   DeviceAddressType DeviceType() const override { return DeviceAddressType::kGPU; }
51 
52 #ifdef ENABLE_DEBUGGER
53   bool LoadMemToHost(const std::string &tensor_name, int execution_order, const std::string &host_fmt,
54                      const ShapeVector &host_shape, TypeId host_type, size_t slot, bool keep_prev) const override;
55 #endif
56 
57  private:
58   DeviceAddressStatus status_{DeviceAddressStatus::kInDevice};
59 };
60 }  // namespace gpu
61 }  // namespace device
62 }  // namespace mindspore
63 
64 #endif  // MINDSPORE_CCSRC_RUNTIME_DEVICE_GPU_GPU_DEVICE_ADDRESS_H_
65