• 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 #ifndef MINDSPORE_CCSRC_PS_PS_CACHE_PS_CACHE_BASIC_H
17 #define MINDSPORE_CCSRC_PS_PS_CACHE_PS_CACHE_BASIC_H
18 
19 #include <utility>
20 #include <memory>
21 
22 namespace mindspore {
23 namespace ps {
24 #define RETURN_IF_FALSE(condition) \
25   do {                             \
26     if (!(condition)) {            \
27       return false;                \
28     }                              \
29   } while (false)
30 
31 class PsCacheBasic {
32  public:
33   PsCacheBasic() = default;
34   virtual ~PsCacheBasic() = default;
35   virtual bool InitDevice(uint32_t device_id, const void *context) = 0;
36   virtual void *MallocMemory(size_t size) = 0;
MallocConstantMemory(size_t cache_vocab_size)37   virtual bool MallocConstantMemory(size_t cache_vocab_size) { return true; }
38   virtual bool RecordEvent() = 0;
39   virtual bool SynchronizeEvent() = 0;
40   virtual bool SynchronizeStream() = 0;
41   virtual bool CopyHostMemToDevice(void *dst, const void *src, size_t size) = 0;
42   virtual bool CopyDeviceMemToHost(void *dst, const void *src, size_t size) = 0;
43   virtual bool HashSwapOut(void *hash_table_addr, void *swap_out_value_addr, void *swap_out_index_addr,
44                            size_t cache_vocab_size, size_t embedding_size, size_t swap_out_size) = 0;
45   virtual bool HashSwapIn(void *hash_table_addr, void *swap_in_value_addr, void *swap_in_index_addr,
46                           size_t cache_vocab_size, size_t embedding_size, size_t swap_in_size) = 0;
47 
48  protected:
49   void *stream_;
50 };
51 }  // namespace ps
52 }  // namespace mindspore
53 #endif  // MINDSPORE_CCSRC_PS_PS_CACHE_PS_CACHE_BASIC_H
54