diff --git a/libNeonPy/include/Neon/py/bGrid.h b/libNeonPy/include/Neon/py/bGrid.h index c525cb71..512f578e 100644 --- a/libNeonPy/include/Neon/py/bGrid.h +++ b/libNeonPy/include/Neon/py/bGrid.h @@ -65,7 +65,7 @@ extern "C" auto bGrid_bField_partition_size( Neon::bGrid::Partition* partitionPtr) -> int; -extern "C" auto bGrid_get_properties( /* TODOMATT verify what the return of this method should be */ +extern "C" auto bGrid_get_properties( uint64_t& gridHandle, const Neon::index_3d* idx) -> int; diff --git a/libNeonPy/include/Neon/py/backend.h b/libNeonPy/include/Neon/py/backend.h index 6c7ba563..87366dc5 100644 --- a/libNeonPy/include/Neon/py/backend.h +++ b/libNeonPy/include/Neon/py/backend.h @@ -5,7 +5,7 @@ /** * */ -extern "C" auto dBackend_new( +extern "C" auto backend_new( uint64_t& handle, int runtime /*! Type of runtime to use */, int numDecices /*! Number of devices */, @@ -15,10 +15,10 @@ extern "C" auto dBackend_new( /** * Delete a backend object on the heap. */ -extern "C" auto dBackend_delete( +extern "C" auto backend_delete( uint64_t& handle) -> int; -extern "C" auto dBackend_get_string(uint64_t& handle) -> const char*; +extern "C" auto backend_get_string(uint64_t& handle) -> const char*; -extern "C" auto dBackend_sync(uint64_t& handle) -> int; +extern "C" auto backend_sync(uint64_t& handle) -> int; diff --git a/libNeonPy/include/Neon/py/mGrid.h b/libNeonPy/include/Neon/py/mGrid.h index b633d2bd..c674a882 100644 --- a/libNeonPy/include/Neon/py/mGrid.h +++ b/libNeonPy/include/Neon/py/mGrid.h @@ -5,7 +5,7 @@ /** * Initialize a new grid object on the heap. * NOTE: some parameters are still not exposed - */ /* TODOMATT fix the constructor to have correct arguments */ + */ extern "C" auto mGrid_new( uint64_t& handle, uint64_t& backendPtr, diff --git a/libNeonPy/src/Neon/py/bGrid.cpp b/libNeonPy/src/Neon/py/bGrid.cpp index 30759578..fd5856e2 100644 --- a/libNeonPy/src/Neon/py/bGrid.cpp +++ b/libNeonPy/src/Neon/py/bGrid.cpp @@ -224,7 +224,7 @@ auto bGrid_bField_partition_size( return sizeof(*partitionPtr); } -auto bGrid_get_properties( /* TODOMATT verify what the return of this method should be */ +auto bGrid_get_properties( uint64_t& gridHandle, const Neon::index_3d* idx) -> int diff --git a/libNeonPy/src/Neon/py/backend.cpp b/libNeonPy/src/Neon/py/backend.cpp index 406ce47f..622eeaf2 100644 --- a/libNeonPy/src/Neon/py/backend.cpp +++ b/libNeonPy/src/Neon/py/backend.cpp @@ -4,8 +4,8 @@ #include "Neon/Neon.h" void backend_constructor_prologue(uint64_t& handle) { - std::cout << "dBackend_new - BEGIN" << std::endl; - std::cout << "dBackend handle" << handle << std::endl; + std::cout << "backend_new - BEGIN" << std::endl; + std::cout << "backend handle" << handle << std::endl; } int backend_constructor_epilogue(uint64_t& handle, Neon::Backend* backendPtr) { @@ -19,7 +19,7 @@ int backend_constructor_epilogue(uint64_t& handle, Neon::Backend* backendPtr) { return 0; } -auto dBackend_new( +auto backend_new( uint64_t& handle, int runtime, int numDevices, @@ -37,11 +37,11 @@ auto dBackend_new( return backend_constructor_epilogue(handle, backendPtr); } -auto dBackend_delete( +auto backend_delete( uint64_t& handle) -> int { - std::cout << "dBackend_delete - BEGIN" << std::endl; + std::cout << "backend_delete - BEGIN" << std::endl; std::cout << "backendHandle " << handle << std::endl; using Backend = Neon::Backend; @@ -52,11 +52,11 @@ auto dBackend_delete( AllocationCounter::Deallocation(); } handle = 0; - std::cout << "dBackend_delete - END" << std::endl; + std::cout << "backend_delete - END" << std::endl; return 0; } -auto dBackend_get_string(uint64_t& handle) -> const char* { +auto backend_get_string(uint64_t& handle) -> const char* { std::cout << "get_string - BEGIN" << std::endl; std::cout << "backendHandle " << handle << std::endl; @@ -70,8 +70,8 @@ auto dBackend_get_string(uint64_t& handle) -> const char* { std::cout << "get_string - END" << std::endl; } -auto dBackend_sync(uint64_t& handle) -> int { - std::cout << "dBackend_sync - BEGIN" << std::endl; +auto backend_sync(uint64_t& handle) -> int { + std::cout << "backend_sync - BEGIN" << std::endl; std::cout << "backendHandle " << handle << std::endl; using Backend = Neon::Backend; @@ -82,5 +82,5 @@ auto dBackend_sync(uint64_t& handle) -> int { backendPtr->syncAll(); return 0; - std::cout << "dBackend_sync - END" << std::endl; + std::cout << "backend_sync - END" << std::endl; } diff --git a/libNeonPy/src/Neon/py/mGrid.cpp b/libNeonPy/src/Neon/py/mGrid.cpp index 093ce32e..f8da2f57 100644 --- a/libNeonPy/src/Neon/py/mGrid.cpp +++ b/libNeonPy/src/Neon/py/mGrid.cpp @@ -237,7 +237,7 @@ auto mGrid_mField_partition_size( return sizeof(*partitionPtr); } -auto mGrid_get_properties( /* TODOMATT verify what the return of this method should be */ +auto mGrid_get_properties( uint64_t& gridHandle, uint64_t grid_level, const Neon::index_3d* idx) diff --git a/py_neon/backend.py b/py_neon/backend.py index d7780615..0dcc29bd 100644 --- a/py_neon/backend.py +++ b/py_neon/backend.py @@ -6,8 +6,6 @@ from py_neon import Py_neon -# TODOMATT why are these functions called dBackend_XXX, it should just be Backend_XXX - class Backend(object): class Runtime(Enum): none = 0 @@ -41,34 +39,24 @@ def __del__(self): def _help_load_api(self): - # # backend_new - # self.py_neon.lib.dBackend_new1.argtypes = [self.py_neon.handle_type] - # self.py_neon.lib.dBackend_new1.restype = ctypes.c_int - # - # # backend_new - # self.py_neon.lib.dBackend_new2.argtypes = [self.py_neon.handle_type, - # ctypes.c_int, - # ctypes.c_int] - # self.py_neon.lib.dBackend_new2.restype = ctypes.c_int - # backend_new - self.py_neon.lib.dBackend_new.argtypes = [self.py_neon.handle_type, + self.py_neon.lib.backend_new.argtypes = [self.py_neon.handle_type, ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_int)] - self.py_neon.lib.dBackend_new.restype = ctypes.c_int + self.py_neon.lib.backend_new.restype = ctypes.c_int # backend_delete - self.py_neon.lib.dBackend_delete.argtypes = [self.py_neon.handle_type] - self.py_neon.lib.dBackend_delete.restype = ctypes.c_int + self.py_neon.lib.backend_delete.argtypes = [self.py_neon.handle_type] + self.py_neon.lib.backend_delete.restype = ctypes.c_int # backend_get_string - self.py_neon.lib.dBackend_get_string.argtypes = [self.py_neon.handle_type] - self.py_neon.lib.dBackend_get_string.restype = ctypes.c_char_p + self.py_neon.lib.backend_get_string.argtypes = [self.py_neon.handle_type] + self.py_neon.lib.backend_get_string.restype = ctypes.c_char_p - self.py_neon.lib.dBackend_sync.argtypes = [self.py_neon.handle_type] - self.py_neon.lib.dBackend_sync.restype = ctypes.c_int + self.py_neon.lib.backend_sync.argtypes = [self.py_neon.handle_type] + self.py_neon.lib.backend_sync.restype = ctypes.c_int # TODOMATT get num devices # TODOMATT get device type @@ -78,7 +66,7 @@ def _help_backend_new(self, n_dev: int, dev_idx_list: List[int]): if self.handle.value != ctypes.c_uint64(0).value: - raise Exception(f'DBackend: Invalid handle {self.handle}') + raise Exception(f'backend: Invalid handle {self.handle}') if n_dev > len(dev_idx_list): dev_idx_list = list(range(n_dev)) @@ -88,22 +76,22 @@ def _help_backend_new(self, dev_idx_np = np.array(dev_idx_list, dtype=int) dev_idx_ptr = dev_idx_np.ctypes.data_as(ctypes.POINTER(ctypes.c_int)) - res = self.py_neon.lib.dBackend_new(ctypes.byref(self.handle), + res = self.py_neon.lib.backend_new(ctypes.byref(self.handle), runtime.value, n_dev, dev_idx_ptr) if res != 0: - raise Exception('DBackend: Failed to initialize backend') + raise Exception('backend: Failed to initialize backend') def help_backend_delete(self): if self.handle == 0: return - res = self.py_neon.lib.dBackend_delete(self.handle) + res = self.py_neon.lib.backend_delete(self.handle) if res != 0: raise Exception('Failed to delete backend') def sync(self): - return self.py_neon.lib.dBackend_sync(ctypes.byref(self.handle)) + return self.py_neon.lib.backend_sync(ctypes.byref(self.handle)) def __str__(self): return ctypes.cast(self.py_neon.lib.get_string(self.handle), ctypes.c_char_p).value.decode('utf-8') diff --git a/py_neon/block/bField.py b/py_neon/block/bField.py index 9d114b01..ce293e29 100644 --- a/py_neon/block/bField.py +++ b/py_neon/block/bField.py @@ -94,35 +94,33 @@ def help_delete(self): if res != 0: raise Exception('Failed to delete field') - # TODOMATT ask Max how to reconcile our new partitions with the wpne partitions - # def get_partition(self, - # execution: NeExecution, - # c: ctypes.c_int, - # data_view: NeDataView - # ) -> Wpne_NeonDensePartitionInt: - - # if self.handle == 0: - # raise Exception('bField: Invalid handle') - - # partition = NeBPartitionInt() - - # res = self.py_neon.lib.bGrid_bField_get_partition(self.handle, - # partition, - # execution, - # c, - # data_view) - # if res != 0: - # raise Exception('Failed to get span') - - # ccp_size = self.py_neon.lib.bGrid_bField_partition_size(partition) - # ctypes_size = ctypes.sizeof(partition) - - # if ccp_size != ctypes_size: - # raise Exception(f'Failed to get span: cpp_size {ccp_size} != ctypes_size {ctypes_size}') - - # print(f"Partition {partition}") - # wpne_partition = Wpne_NeonDensePartitionInt(partition) - # return wpne_partition + def get_partition(self, + execution: NeExecution, + c: ctypes.c_int, + data_view: NeDataView + ) -> NeBPartitionInt: + + if self.handle == 0: + raise Exception('bField: Invalid handle') + + partition = NeBPartitionInt() + + res = self.py_neon.lib.bGrid_bField_get_partition(self.handle, + partition, + execution, + c, + data_view) + if res != 0: + raise Exception('Failed to get span') + + ccp_size = self.py_neon.lib.bGrid_bField_partition_size(partition) + ctypes_size = ctypes.sizeof(partition) + + if ccp_size != ctypes_size: + raise Exception(f'Failed to get span: cpp_size {ccp_size} != ctypes_size {ctypes_size}') + + print(f"Partition {partition}") + return partition def read(self, idx: Index_3d, cardinality: ctypes.c_int): return self.py_neon.lib.bGrid_bField_read(ctypes.byref(self.handle), idx, cardinality) diff --git a/py_neon/block/bGrid.py b/py_neon/block/bGrid.py index c006b161..80da888a 100644 --- a/py_neon/block/bGrid.py +++ b/py_neon/block/bGrid.py @@ -37,9 +37,8 @@ def __init__(self, backend = None, dim = None, sparsity_pattern: np.ndarray = No self._help_grid_new() def __del__(self): - if self.handle == 0: - return - self._help_grid_delete() + if self.handle != 0: + self._help_grid_delete() def _help_load_api(self): diff --git a/py_neon/multires/mField.py b/py_neon/multires/mField.py index 11680f7d..f8cc7470 100644 --- a/py_neon/multires/mField.py +++ b/py_neon/multires/mField.py @@ -9,9 +9,6 @@ from py_neon.py_ne import Py_neon as NePy_neon from py_neon.index_3d import Index_3d -# TODOMATT ask Max how to reconcile our new partitions with the wpne partitions -# from wpne.dense.partition import NeonDensePartitionInt as Wpne_NeonDensePartitionInt - class mField(object): def __init__(self, grid_handle: ctypes.c_uint64,