Skip to content

Commit

Permalink
Merge pull request #1025 from slaclab/pre-release
Browse files Browse the repository at this point in the history
Release Candidate v6.4.2
  • Loading branch information
ruck314 authored Oct 16, 2024
2 parents eb0d921 + 3986b15 commit ef54a60
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 35 deletions.
51 changes: 35 additions & 16 deletions python/pyrogue/_Root.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ def decrement(self):
self._check()

def _check(self):
if len(self._list) != 0 and (self._count == 0 or (self._period != 0 and (time.time() - self._last) > self._period)):
#print(f"Update fired {time.time()}")
self._last = time.time()
self._q.put(self._list)
self._list = {}
if self._count == 0 or (self._period != 0 and (time.time() - self._last) > self._period):
if len(self._list) != 0:
#print(f"Update fired {time.time()}")
self._last = time.time()
self._q.put(self._list)
self._list = {}

def update(self,var):
"""
Expand Down Expand Up @@ -482,19 +483,19 @@ def updateGroup(self, period=0):
tid = threading.get_ident()

# At with call
with self._updateLock:
if tid not in self._updateTrack:
self._updateTrack[tid] = UpdateTracker(self._updateQueue)

try:
self._updateTrack[tid].increment(period)
except Exception:
with self._updateLock:
self._updateTrack[tid] = UpdateTracker(self._updateQueue)
self._updateTrack[tid].increment(period)

try:
yield
finally:

# After with is done
with self._updateLock:
self._updateTrack[tid].decrement()
self._updateTrack[tid].decrement()

@contextmanager
def pollBlock(self):
Expand Down Expand Up @@ -1000,10 +1001,19 @@ def _queueUpdates(self,var):
"""
tid = threading.get_ident()

with self._updateLock:
if tid not in self._updateTrack:
self._updateTrack[tid] = UpdateTracker(self._updateQueue)
try:
self._updateTrack[tid].update(var)
except Exception:
with self._updateLock:
self._updateTrack[tid] = UpdateTracker(self._updateQueue)
self._updateTrack[tid].update(var)

# Recursively add listeners to update list
def _recurseAddListeners(self, nvars, var):
for vl in var._listeners:
nvars[vl.path] = vl

self._recurseAddListeners(nvars, vl)

# Worker thread
def _updateWorker(self):
Expand All @@ -1022,10 +1032,19 @@ def _updateWorker(self):
# Process list
elif len(uvars) > 0:
self._log.debug(F'Process update group. Length={len(uvars)}. Entry={list(uvars.keys())[0]}')

# Copy list and add listeners
nvars = uvars.copy()
for p,v in uvars.items():
self._recurseAddListeners(nvars, v)

# Process the new list
for p,v in nvars.items():

# Process updates
val = v._doUpdate()

# Call listener functions,
# Call root listener functions,
with self._varListenLock:
for func,doneFunc,incGroups,excGroups in self._varListeners:
if v.filterByGroup(incGroups, excGroups):
Expand All @@ -1040,7 +1059,7 @@ def _updateWorker(self):
else:
pr.logException(self._log,e)

# Finalize listeners
# Finalize root listeners
with self._varListenLock:
for func,doneFunc,incGroups,excGroups in self._varListeners:
if doneFunc is not None:
Expand Down
3 changes: 0 additions & 3 deletions python/pyrogue/_Variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,9 +860,6 @@ def _queueUpdate(self):
""" """
self._root._queueUpdates(self)

for var in self._listeners:
var._queueUpdate()

def _doUpdate(self):
""" """
val = VariableValue(self)
Expand Down
62 changes: 46 additions & 16 deletions src/rogue/interfaces/memory/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ void rim::Block::setUIntPy(bp::object& value, rim::Variable* var, int32_t index)
PyArrayObject* arr = reinterpret_cast<decltype(arr)>(value.ptr());
npy_intp ndims = PyArray_NDIM(arr);
npy_intp* dims = PyArray_SHAPE(arr);
npy_intp* strides = PyArray_STRIDES(arr);

if (ndims != 1)
throw(rogue::GeneralError::create("Block::setUIntPy",
Expand All @@ -920,11 +921,17 @@ void rim::Block::setUIntPy(bp::object& value, rim::Variable* var, int32_t index)
var->name_.c_str()));

if (PyArray_TYPE(arr) == NPY_UINT64) {
uint64_t* src = reinterpret_cast<uint64_t*>(PyArray_DATA(arr));
for (x = 0; x < dims[0]; x++) setUInt(src[x], var, index + x);
uint64_t* src = reinterpret_cast<uint64_t*>(PyArray_DATA(arr));
npy_intp stride = strides[0] / sizeof(uint64_t);
for (x = 0; x < dims[0]; x++) {
setUInt(src[x * stride], var, index + x);
}
} else if (PyArray_TYPE(arr) == NPY_UINT32) {
uint32_t* src = reinterpret_cast<uint32_t*>(PyArray_DATA(arr));
for (x = 0; x < dims[0]; x++) setUInt(src[x], var, index + x);
uint32_t* src = reinterpret_cast<uint32_t*>(PyArray_DATA(arr));
npy_intp stride = strides[0] / sizeof(uint32_t);
for (x = 0; x < dims[0]; x++) {
setUInt(src[x * stride], var, index + x);
}
} else {
throw(rogue::GeneralError::create("Block::setUIntPy",
"Passed nparray is not of type (uint64 or uint32) for %s",
Expand Down Expand Up @@ -1061,6 +1068,7 @@ void rim::Block::setIntPy(bp::object& value, rim::Variable* var, int32_t index)
PyArrayObject* arr = reinterpret_cast<decltype(arr)>(value.ptr());
npy_intp ndims = PyArray_NDIM(arr);
npy_intp* dims = PyArray_SHAPE(arr);
npy_intp* strides = PyArray_STRIDES(arr);

if (ndims != 1)
throw(rogue::GeneralError::create("Block::setIntPy",
Expand All @@ -1078,11 +1086,17 @@ void rim::Block::setIntPy(bp::object& value, rim::Variable* var, int32_t index)
var->name_.c_str()));

if (PyArray_TYPE(arr) == NPY_INT64) {
int64_t* src = reinterpret_cast<int64_t*>(PyArray_DATA(arr));
for (x = 0; x < dims[0]; x++) setInt(src[x], var, index + x);
int64_t* src = reinterpret_cast<int64_t*>(PyArray_DATA(arr));
npy_intp stride = strides[0] / sizeof(int64_t);
for (x = 0; x < dims[0]; x++) {
setInt(src[x * stride], var, index + x);
}
} else if (PyArray_TYPE(arr) == NPY_INT32) {
int32_t* src = reinterpret_cast<int32_t*>(PyArray_DATA(arr));
for (x = 0; x < dims[0]; x++) setInt(src[x], var, index + x);
int32_t* src = reinterpret_cast<int32_t*>(PyArray_DATA(arr));
npy_intp stride = strides[0] / sizeof(int32_t);
for (x = 0; x < dims[0]; x++) {
setInt(src[x * stride], var, index + x);
}
} else {
throw(rogue::GeneralError::create("Block::setIntPy",
"Passed nparray is not of type (int64 or int32) for %s",
Expand Down Expand Up @@ -1223,6 +1237,7 @@ void rim::Block::setBoolPy(bp::object& value, rim::Variable* var, int32_t index)
PyArrayObject* arr = reinterpret_cast<decltype(arr)>(value.ptr());
npy_intp ndims = PyArray_NDIM(arr);
npy_intp* dims = PyArray_SHAPE(arr);
npy_intp* strides = PyArray_STRIDES(arr);

if (ndims != 1)
throw(rogue::GeneralError::create("Block::setBoolPy",
Expand All @@ -1240,8 +1255,11 @@ void rim::Block::setBoolPy(bp::object& value, rim::Variable* var, int32_t index)
var->name_.c_str()));

if (PyArray_TYPE(arr) == NPY_BOOL) {
bool* src = reinterpret_cast<bool*>(PyArray_DATA(arr));
for (x = 0; x < dims[0]; x++) setBool(src[x], var, index + x);
bool* src = reinterpret_cast<bool*>(PyArray_DATA(arr));
npy_intp stride = strides[0] / sizeof(bool);
for (x = 0; x < dims[0]; x++) {
setBool(src[x * stride], var, index + x);
}
} else {
throw(rogue::GeneralError::create("Block::setBoolPy",
"Passed nparray is not of type (bool) for %s",
Expand Down Expand Up @@ -1431,6 +1449,7 @@ void rim::Block::setFloatPy(bp::object& value, rim::Variable* var, int32_t index
PyArrayObject* arr = reinterpret_cast<decltype(arr)>(value.ptr());
npy_intp ndims = PyArray_NDIM(arr);
npy_intp* dims = PyArray_SHAPE(arr);
npy_intp* strides = PyArray_STRIDES(arr);

if (ndims != 1)
throw(rogue::GeneralError::create("Block::setFloatPy",
Expand All @@ -1448,8 +1467,11 @@ void rim::Block::setFloatPy(bp::object& value, rim::Variable* var, int32_t index
var->name_.c_str()));

if (PyArray_TYPE(arr) == NPY_FLOAT32) {
float* src = reinterpret_cast<float*>(PyArray_DATA(arr));
for (x = 0; x < dims[0]; x++) setFloat(src[x], var, index + x);
float* src = reinterpret_cast<float*>(PyArray_DATA(arr));
npy_intp stride = strides[0] / sizeof(float);
for (x = 0; x < dims[0]; x++) {
setFloat(src[x * stride], var, index + x);
}
} else {
throw(rogue::GeneralError::create("Block::setFLoatPy",
"Passed nparray is not of type (float32) for %s",
Expand Down Expand Up @@ -1576,6 +1598,7 @@ void rim::Block::setDoublePy(bp::object& value, rim::Variable* var, int32_t inde
PyArrayObject* arr = reinterpret_cast<decltype(arr)>(value.ptr());
npy_intp ndims = PyArray_NDIM(arr);
npy_intp* dims = PyArray_SHAPE(arr);
npy_intp* strides = PyArray_STRIDES(arr);

if (ndims != 1)
throw(rogue::GeneralError::create("Block::setDoublePy",
Expand All @@ -1593,8 +1616,11 @@ void rim::Block::setDoublePy(bp::object& value, rim::Variable* var, int32_t inde
var->name_.c_str()));

if (PyArray_TYPE(arr) == NPY_FLOAT64) {
double* src = reinterpret_cast<double*>(PyArray_DATA(arr));
for (x = 0; x < dims[0]; x++) setDouble(src[x], var, index + x);
double* src = reinterpret_cast<double*>(PyArray_DATA(arr));
npy_intp stride = strides[0] / sizeof(double);
for (x = 0; x < dims[0]; x++) {
setDouble(src[x * stride], var, index + x);
}
} else {
throw(rogue::GeneralError::create("Block::setFLoatPy",
"Passed nparray is not of type (double) for %s",
Expand Down Expand Up @@ -1721,6 +1747,7 @@ void rim::Block::setFixedPy(bp::object& value, rim::Variable* var, int32_t index
PyArrayObject* arr = reinterpret_cast<decltype(arr)>(value.ptr());
npy_intp ndims = PyArray_NDIM(arr);
npy_intp* dims = PyArray_SHAPE(arr);
npy_intp* strides = PyArray_STRIDES(arr);

if (ndims != 1)
throw(rogue::GeneralError::create("Block::setFixedPy",
Expand All @@ -1738,8 +1765,11 @@ void rim::Block::setFixedPy(bp::object& value, rim::Variable* var, int32_t index
var->name_.c_str()));

if (PyArray_TYPE(arr) == NPY_FLOAT64) {
double* src = reinterpret_cast<double*>(PyArray_DATA(arr));
for (x = 0; x < dims[0]; x++) setFixed(src[x], var, index + x);
double* src = reinterpret_cast<double*>(PyArray_DATA(arr));
npy_intp stride = strides[0] / sizeof(double);
for (x = 0; x < dims[0]; x++) {
setFixed(src[x * stride], var, index + x);
}
} else {
throw(rogue::GeneralError::create("Block::setFixedPy",
"Passed nparray is not of type (double) for %s",
Expand Down
24 changes: 24 additions & 0 deletions tests/test_list_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,30 @@ def test_memory():
# Test value shift
_ = resA[0] >> 5

root.ListDevice.UInt32List.set(UInt32ListA[::2])
root.ListDevice.Int32List.set(Int32ListA[::2])

resA = root.ListDevice.UInt32List.get()
resB = root.ListDevice.Int32List.get()

for i in range(16):

if resA[i] != UInt32ListA[::2][i]:
raise AssertionError(f'Stripe Verification Failure for UInt32ListA at position {i}')

if resB[i] != Int32ListA[::2][i]:
raise AssertionError(f'Stripe Verification Failure for Int32ListA at position {i}')

for i in range(16, 32):

if resA[i] != UInt32ListA[i]:
raise AssertionError(f'Stripe Verification Failure for UInt32ListA at position {i}')

if resB[i] != Int32ListA[i]:
raise AssertionError(f'Stripe Verification Failure for Int32ListA at position {i}')



def run_gui():
import pyrogue.pydm

Expand Down
15 changes: 15 additions & 0 deletions tests/test_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import time
import hwcounter

#import cProfile, pstats, io
#from pstats import SortKey

#rogue.Logging.setLevel(rogue.Logging.Debug)
#import logging
#logger = logging.getLogger('pyrogue')
Expand Down Expand Up @@ -105,6 +108,9 @@ def __init__(self):

def test_rate():

#pr = cProfile.Profile()
#pr.enable()

with DummyTree() as root:
count = 100000
resultRate = {}
Expand Down Expand Up @@ -178,5 +184,14 @@ def test_rate():
if passed is False:
raise AssertionError('Rate check failed')


#pr.disable()

#s = io.StringIO()
#sortby = SortKey.CUMULATIVE
#ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
#ps.print_stats()
#print(s.getvalue())

if __name__ == "__main__":
test_rate()

0 comments on commit ef54a60

Please sign in to comment.