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

L2_NORM resorts to scalar indexing on GPU ComponentArray #524

Open
vpuri3 opened this issue Jan 2, 2025 · 3 comments
Open

L2_NORM resorts to scalar indexing on GPU ComponentArray #524

vpuri3 opened this issue Jan 2, 2025 · 3 comments
Labels
bug Something isn't working

Comments

@vpuri3
Copy link
Member

vpuri3 commented Jan 2, 2025

julia> using CUDA, NonlinearSolve; CUDA.allowscalar(false)                                         
                                                 
julia> x = ComponentArray(; x = ones(2), y = ones(2)) |> cu              
ComponentVector{Float32, CuArray{Float32, 1, CUDA.DeviceMemory}, Tuple{Axis{(x = 1:2, y = 3:4)}}}(x = Float32[1.0, 1.0], y = Float32[1.0, 1.0])                                                       
                                                                                                   
julia> NonlinearSolveBase.L2_NORM(x)                                                               
ERROR: Scalar indexing is disallowed.                                                              
Invocation of getindex resulted in scalar indexing of a GPU array.                                 
This is typically caused by calling an iterating implementation of a method.                       
Such implementations *do not* execute on the GPU, but very slowly on the CPU,
and therefore should be avoided.

Need a ComponentArray extension with L2_NORM(x::CA) = L2_NORM(getdata(x)).

@vpuri3 vpuri3 added the bug Something isn't working label Jan 2, 2025
@avik-pal
Copy link
Member

avik-pal commented Jan 2, 2025

does NonlinearSolve work with a CA initial guess (even on CPU)?

@vpuri3
Copy link
Member Author

vpuri3 commented Jan 4, 2025

I've been using NonlinearSolve.jl to optimize neural networks (written in Lux with ComponentArrays) here. Haven't had an issue before, though this is the first time I'm testing it since the reorg.

@vpuri3
Copy link
Member Author

vpuri3 commented Jan 9, 2025

This solved the issue for me. https://github.com/vpuri3/NeuralROMs.jl/blob/master/experiments_SNFROM/compare.jl#L28-L30

# https://github.com/SciML/NonlinearSolve.jl/issues/524                                       
using NonlinearSolve, ComponentArrays                                                         
NonlinearSolveBase.L2_NORM(u::ComponentArray) = NonlinearSolveBase.L2_NORM(getdata(u))        

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants