Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[native] linalg implementations deep copy input arrays #202

Open
max-hillsidetec opened this issue Mar 5, 2024 · 2 comments
Open

[native] linalg implementations deep copy input arrays #202

max-hillsidetec opened this issue Mar 5, 2024 · 2 comments
Labels
native An issue/PR related to Native perf An issue/PR related to performance

Comments

@max-hillsidetec
Copy link

Hi guys,

I saw functions in NativeLinAlgEx in multi-openblas deep copy the input arrays. Some of the examples are shown below.

 override fun <T : Number, D : Dim2> solve(a: MultiArray<T, D2>, b: MultiArray<T, D>): NDArray<Double, D> =
    solveCommon(a.toType(CopyStrategy.MEANINGFUL), b.toType(CopyStrategy.MEANINGFUL))`

 override fun <D : Dim2> solveF(a: MultiArray<Float, D2>, b: MultiArray<Float, D>): NDArray<Float, D> =
    solveCommon(a.deepCopy(), b.deepCopy())`

 override fun <T : Complex, D : Dim2> solveC(a: MultiArray<T, D2>, b: MultiArray<T, D>): NDArray<T, D> =
    solveCommon(a.deepCopy(), b.deepCopy())

I wonder whether deep copy is in fact needed. In our use cases, we slice a matrix many times and pass the sub-matrices to the solver. Deep copying them is suboptimal.

Thanks in advance for your help!

Best,
Max

@devcrocod
Copy link
Collaborator

Hi Max!

We are not always able to work directly with "views", which necessitates us to copy arrays for sgesv / dgesv. The copying does not involve the entire original matrix but only the part indicated by the strides.
Nonetheless, I will take a closer look at this area to see if there's potential for performance improvement.

@devcrocod devcrocod added perf An issue/PR related to performance native An issue/PR related to Native labels Mar 19, 2024
@max-hillsidetec
Copy link
Author

Hi Pavel,

Thanks very much for taking a look! It looks like if an NDArray is consistent, then deep copy may not be necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
native An issue/PR related to Native perf An issue/PR related to performance
Projects
None yet
Development

No branches or pull requests

2 participants