• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2023 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_INCLUDE_DEVICE_SYNCHRONIZER_H
18 #define MINDSPORE_CCSRC_INCLUDE_DEVICE_SYNCHRONIZER_H
19 
20 #include <memory>
21 #include <string>
22 #include <cstddef>
23 #include "include/api/format.h"
24 #include "base/user_data.h"
25 #include "include/backend/visible.h"
26 #include "mindapi/base/shape_vector.h"
27 
28 namespace mindspore {
29 namespace device {
30 // This class provides interfaces for synchronizing data between device and host.
31 class BACKEND_EXPORT DeviceSynchronizer {
32  public:
33   DeviceSynchronizer() = default;
34   virtual ~DeviceSynchronizer() = default;
35 
36   // Copy device memory to host side synchronously.
37   virtual bool SyncDeviceToHost(void *host_ptr, const void *device_ptr, size_t size, const std::string &device_name,
38                                 uint32_t device_id, mindspore::Format format, const ShapeVector &shape,
39                                 size_t stream_id, const UserDataPtr &user_data = nullptr) const = 0;
40 
41   // Copy host memory to device side synchronously.
42   virtual bool SyncHostToDevice(void *device_ptr, const void *host_ptr, size_t size, const std::string &device_name,
43                                 uint32_t device_id, mindspore::Format format, const ShapeVector &shape,
44                                 size_t stream_id, const UserDataPtr &user_data = nullptr) const = 0;
45 };
46 using DeviceSynchronizerPtr = std::shared_ptr<DeviceSynchronizer>;
47 }  // namespace device
48 }  // namespace mindspore
49 #endif  // MINDSPORE_CCSRC_INCLUDE_DEVICE_SYNCHRONIZER_H
50