forked from iraikov/neuroh5
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request iraikov#10 from iraikov/feature/shared_array
Support for shared memory arrays
- Loading branch information
Showing
13 changed files
with
611 additions
and
349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
|
||
set(NEUROH5_IO_SRCS | ||
"iomodule.cc" | ||
"iomodule.cc" | ||
) | ||
|
||
include_directories(${MPI_C_INCLUDE_DIRS}) | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
|
||
#include "shared_array.hh" | ||
|
||
// Function to create shared numpy array | ||
static PyObject* create_shared_array(PyObject* self, PyObject* args) | ||
{ | ||
Py_ssize_t size; | ||
const char* dtype_str; | ||
|
||
// Parse size and dtype arguments | ||
if (!PyArg_ParseTuple(args, "ns", &size, &dtype_str)) { | ||
return nullptr; | ||
} | ||
|
||
// Map dtype string to appropriate creation function | ||
std::string dtype(dtype_str); | ||
if (dtype == "float32" || dtype == "float") { | ||
return create_typed_shared_array<float>(size); | ||
} | ||
else if (dtype == "int32") { | ||
return create_typed_shared_array<int32_t>(size); | ||
} | ||
else if (dtype == "int16") { | ||
return create_typed_shared_array<int16_t>(size); | ||
} | ||
else if (dtype == "int8") { | ||
return create_typed_shared_array<int8_t>(size); | ||
} | ||
else if (dtype == "uint32") { | ||
return create_typed_shared_array<uint32_t>(size); | ||
} | ||
else if (dtype == "uint16") { | ||
return create_typed_shared_array<uint16_t>(size); | ||
} | ||
else if (dtype == "uint8") { | ||
return create_typed_shared_array<uint8_t>(size); | ||
} | ||
|
||
PyErr_SetString(PyExc_ValueError, "Unsupported dtype"); | ||
return nullptr; | ||
} | ||
|
||
// Module method definition | ||
static PyMethodDef ModuleMethods[] = { | ||
{"create_shared_array", create_shared_array, METH_VARARGS, | ||
"Create a numpy array that shares memory with C++ array. Args: size, dtype"}, | ||
{nullptr, nullptr, 0, nullptr} | ||
}; | ||
|
||
// Module definition structure | ||
static struct PyModuleDef moduledef = { | ||
PyModuleDef_HEAD_INIT, | ||
"shared_array_module", | ||
"Module that provides shared memory array between C++ and Python", | ||
-1, | ||
ModuleMethods | ||
}; | ||
|
||
// Module initialization function | ||
PyMODINIT_FUNC PyInit_shared_array_module(void) { | ||
import_array(); // Initialize numpy C-API | ||
|
||
PyObject* module = PyModule_Create(&moduledef); | ||
if (!module) { | ||
return nullptr; | ||
} | ||
|
||
return module; | ||
} |
Oops, something went wrong.