• 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_MINDDATA_DATASET_ENGINE_GNN_GRAPH_SHARED_MEMORY_H_
17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_GNN_GRAPH_SHARED_MEMORY_H_
18 
19 #include <sys/ipc.h>
20 #include <sys/shm.h>
21 #include <mutex>
22 #include <string>
23 
24 #include "minddata/dataset/util/status.h"
25 
26 namespace mindspore {
27 namespace dataset {
28 namespace gnn {
29 
30 const int kGnnSharedMemoryId = 65;
31 
32 class GraphSharedMemory {
33  public:
34   explicit GraphSharedMemory(int64_t memory_size, key_t memory_key);
35   explicit GraphSharedMemory(int64_t memory_size, const std::string &mr_file);
36 
37   ~GraphSharedMemory();
38 
39   // @param uint8_t** shared_memory - shared memory address
40   // @return Status - the status code
41   Status CreateSharedMemory();
42 
43   // @param uint8_t** shared_memory - shared memory address
44   // @return Status - the status code
45   Status GetSharedMemory();
46 
47   Status DeleteSharedMemory();
48 
49   Status InsertData(const uint8_t *data, int64_t len, int64_t *offset);
50 
51   Status GetData(uint8_t *data, int64_t data_len, int64_t offset, int64_t get_data_len);
52 
memory_key()53   key_t memory_key() { return memory_key_; }
54 
memory_size()55   int64_t memory_size() { return memory_size_; }
56 
57  private:
58   Status SharedMemoryImpl(const int &shmflg);
59 
60   std::string mr_file_;
61   int64_t memory_size_;
62   key_t memory_key_;
63   std::string memory_key_str_;
64   uint8_t *memory_ptr_;
65   int64_t memory_offset_;
66   std::mutex mutex_;
67   bool is_new_create_;
68 };
69 }  // namespace gnn
70 }  // namespace dataset
71 }  // namespace mindspore
72 #endif  // MINDSPORE_CCSRC_MINDDATA_DATASET_ENGINE_GNN_GRAPH_SHARED_MEMORY_H_
73