Skip to content

Commit

Permalink
Made some small changes
Browse files Browse the repository at this point in the history
- deleted old MATTTODOs

- fixed some backend function names

- enabled get_partition for some grid types
  • Loading branch information
mattloulou committed Jul 24, 2024
1 parent 50c500d commit 9830465
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 78 deletions.
2 changes: 1 addition & 1 deletion libNeonPy/include/Neon/py/bGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extern "C" auto bGrid_bField_partition_size(
Neon::bGrid::Partition<int, 0>* 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;
Expand Down
8 changes: 4 additions & 4 deletions libNeonPy/include/Neon/py/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */,
Expand All @@ -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;
2 changes: 1 addition & 1 deletion libNeonPy/include/Neon/py/mGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion libNeonPy/src/Neon/py/bGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions libNeonPy/src/Neon/py/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion libNeonPy/src/Neon/py/mGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
38 changes: 13 additions & 25 deletions py_neon/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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')
56 changes: 27 additions & 29 deletions py_neon/block/bField.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions py_neon/block/bGrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
3 changes: 0 additions & 3 deletions py_neon/multires/mField.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 9830465

Please sign in to comment.