Uploaded image for project: 'Data Management'
  1. Data Management
  2. DM-17147

SAL numpy array data corruption

    XMLWordPrintable

    Details

      Description

      While trying to collect data from SAL with python I uncovered an issue with the numpy arrays. If you cache the array directly from the data structure (for example, to get an average of the data) you will get bad numbers. The issue appears to relate to garbage collection and the SAL data structure being collected while something else still holds a reference to the numpy arrays contained by that data structure.

      Attached is an example python file that has 3 ways of caching the data.

      I also tried a change in which I print the min/max of the first data cached while adding more data to the cache. What I found is the min / max of the first set of data cached changes. I have attached an image of it.

        Attachments

          Issue Links

            Activity

            Hide
            dmills Dave Mills added a comment -

            Did you try adding a small sleep so that you are not in a python cpu-locked loop.
            You should never call SAL methods in a python cpu bound loop as the GIL may not
            be able to schedule things correctly.

            Show
            dmills Dave Mills added a comment - Did you try adding a small sleep so that you are not in a python cpu-locked loop. You should never call SAL methods in a python cpu bound loop as the GIL may not be able to schedule things correctly.
            Hide
            ccontaxis Christopher Contaxis [X] (Inactive) added a comment -

            I did, even if you do a 0.1 second sleep it does not change the behavior.

            Show
            ccontaxis Christopher Contaxis [X] (Inactive) added a comment - I did, even if you do a 0.1 second sleep it does not change the behavior.
            Hide
            dmills Dave Mills added a comment -

            And what happens if you just create the myData before entering the loop and keep reusing the same object ?

            Show
            dmills Dave Mills added a comment - And what happens if you just create the myData before entering the loop and keep reusing the same object ?
            Hide
            ccontaxis Christopher Contaxis [X] (Inactive) added a comment - - edited

            If you keep reusing the same data structure then the old data you are attempting to cache is overwritten by new data.

            This is expected behavior given that you aren't instantiating new memory for the new data to be placed into.

            Show
            ccontaxis Christopher Contaxis [X] (Inactive) added a comment - - edited If you keep reusing the same data structure then the old data you are attempting to cache is overwritten by new data. This is expected behavior given that you aren't instantiating new memory for the new data to be placed into.
            Hide
            rowen Russell Owen added a comment -

            I think this is caused by the fact that the SALPY pybind11 is clever about how it wraps arrays and shares memory instead of copying the elements. If we can afford the small performance hit I think copying the data (as pybind11 does by default) would be much better because it would avoid issues like this.

            Show
            rowen Russell Owen added a comment - I think this is caused by the fact that the SALPY pybind11 is clever about how it wraps arrays and shares memory instead of copying the elements. If we can afford the small performance hit I think copying the data (as pybind11 does by default) would be much better because it would avoid issues like this.
            Hide
            dmills Dave Mills added a comment -

            Multiple other methods are available to avoid this

            Show
            dmills Dave Mills added a comment - Multiple other methods are available to avoid this

              People

              Assignee:
              dmills Dave Mills
              Reporter:
              ccontaxis Christopher Contaxis [X] (Inactive)
              Watchers:
              Christopher Contaxis [X] (Inactive), Dave Mills, Rob Bovill, Russell Owen
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Start date:
                End date:

                  Jenkins

                  No builds found.