• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2020 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_PS_PS_CACHE_ASCEND_ASCEND_PS_CACHE_H_
18 #define MINDSPORE_CCSRC_PS_PS_CACHE_ASCEND_ASCEND_PS_CACHE_H_
19 
20 #include <string>
21 #include <vector>
22 #include <memory>
23 #include <utility>
24 #include "ps/ps_cache/ps_cache_basic.h"
25 #include "backend/kernel_compiler/aicpu/aicpu_kernel_mod.h"
26 #include "ir/dtype.h"
27 #include "runtime/base.h"
28 
29 namespace mindspore {
30 namespace ps {
31 namespace ascend {
32 struct KernelNodeInfo {
KernelNodeInfoKernelNodeInfo33   KernelNodeInfo(const std::string &op_name, std::vector<std::vector<size_t>> input_data_shape,
34                  std::vector<TypeId> input_data_type, std::vector<std::vector<size_t>> output_data_shape,
35                  std::vector<TypeId> output_data_type)
36       : op_name_(op_name) {
37     input_data_shape_.swap(input_data_shape);
38     input_data_type_.swap(input_data_type);
39     output_data_shape_.swap(output_data_shape);
40     output_data_type_.swap(output_data_type);
41   }
42   std::string op_name_;
43   std::vector<std::vector<size_t>> input_data_shape_;
44   std::vector<TypeId> input_data_type_;
45   std::vector<std::vector<size_t>> output_data_shape_;
46   std::vector<TypeId> output_data_type_;
47 };
48 
49 class AscendPsCache : public PsCacheBasic {
50  public:
51   AscendPsCache() = default;
52   ~AscendPsCache() override = default;
53   bool InitDevice(uint32_t device_id, const void *context) override;
54   void *MallocMemory(size_t size) override;
55   bool MallocConstantMemory(size_t cache_vocab_size) override;
56   bool RecordEvent() override;
57   bool SynchronizeEvent() override;
58   bool SynchronizeStream() override;
59   bool CopyHostMemToDevice(void *dst, const void *src, size_t size) override;
60   bool CopyDeviceMemToHost(void *dst, const void *src, size_t size) override;
61   bool HashSwapOut(void *hash_table_addr, void *swap_out_value_addr, void *swap_out_index_addr, size_t cache_vocab_size,
62                    size_t embedding_size, size_t swap_out_size) override;
63   bool HashSwapIn(void *hash_table_addr, void *swap_in_value_addr, void *swap_in_index_addr, size_t cache_vocab_size,
64                   size_t embedding_size, size_t swap_in_size) override;
65 
66  private:
67   int *offset_addr_{nullptr};
68   int *cache_vocab_size_addr_{nullptr};
69   std::unique_ptr<rtEvent_t> event_;
70 };
71 }  // namespace ascend
72 }  // namespace ps
73 }  // namespace mindspore
74 #endif  // MINDSPORE_CCSRC_PS_PS_CACHE_ASCEND_ASCEND_PS_CACHE_H_
75