Create an empty array with shared memory given shape and dtype Parameters ---------- name : string The name of the shared memory. It's a file name in Unix. is_create : bool Whether to create the shared memory or use the one created by somewhere else. shape : tu
(name, is_create, shape, dtype="float32")
| 140 | |
| 141 | |
| 142 | def empty_shared_mem(name, is_create, shape, dtype="float32"): |
| 143 | """Create an empty array with shared memory given shape and dtype |
| 144 | |
| 145 | Parameters |
| 146 | ---------- |
| 147 | name : string |
| 148 | The name of the shared memory. It's a file name in Unix. |
| 149 | |
| 150 | is_create : bool |
| 151 | Whether to create the shared memory or use the one created by somewhere else. |
| 152 | |
| 153 | shape : tuple of int |
| 154 | The shape of the array |
| 155 | |
| 156 | dtype : type or str |
| 157 | The data type of the array. |
| 158 | |
| 159 | Returns |
| 160 | ------- |
| 161 | arr : dgl.nd.NDArray |
| 162 | The array dgl supported. |
| 163 | """ |
| 164 | name = ctypes.c_char_p(name.encode("utf-8")) |
| 165 | shape = c_array(dgl_shape_index_t, shape) |
| 166 | ndim = ctypes.c_int(len(shape)) |
| 167 | handle = DGLArrayHandle() |
| 168 | dtype = DGLDataType(dtype) |
| 169 | check_call( |
| 170 | _LIB.DGLArrayAllocSharedMem( |
| 171 | name, |
| 172 | shape, |
| 173 | ndim, |
| 174 | ctypes.c_int(dtype.type_code), |
| 175 | ctypes.c_int(dtype.bits), |
| 176 | ctypes.c_int(dtype.lanes), |
| 177 | is_create, |
| 178 | ctypes.byref(handle), |
| 179 | ) |
| 180 | ) |
| 181 | return _make_array(handle, False) |
| 182 | |
| 183 | |
| 184 | def from_dlpack(dltensor): |
no test coverage detected