# MethodError: no method matching getrf! when I try to use GPU to training a universal differential equation with ForwardDiff.jl

**URL:** https://discourse.julialang.org/t/methoderror-no-method-matching-getrf-when-i-try-to-use-gpu-to-training-a-universal-differential-equation-with-forwarddiff-jl/91062
**Category:** Optimization (Mathematical)
**Tags:** question
**Created:** [November 30, 2022, 6:56pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-getrf-when-i-try-to-use-gpu-to-training-a-universal-differential-equation-with-forwarddiff-jl/91062 "2022-11-30T18:56:50Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Ronaldo\_Nogueira](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronaldo_nogueira/32/44773_2.png) [@Ronaldo\_Nogueira](https://discourse.julialang.org/u/Ronaldo_Nogueira)
#### Post date: [November 30, 2022, 6:56pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-getrf-when-i-try-to-use-gpu-to-training-a-universal-differential-equation-with-forwarddiff-jl/91062/1 "2022-11-30T18:56:50Z")

</div>

Hi, thank you for your attention. So, I’m trying to make use of GPU to train a universal differential equation but, when I run the code to make the optimization with Optimization.jl I got this error below. I already tried to search for similar problems but none of them helped me to solve mine. Someone had this issue?

```julia
MethodError: no method matching getrf!(::CuArray{ForwardDiff.Dual{ForwardDiff.Tag{ODEFunction{true, SciMLBase.AutoSpecialize, typeof(nn_dynamics!), UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing, Nothing}, Float32}, Float32, 11}, 2, CUDA.Mem.DeviceBuffer})
Closest candidates are:
  getrf!(::StridedCuMatrix{Float32}) at ~/.julia/packages/CUDA/DfvRa/lib/cusolver/dense.jl:120
  getrf!(::StridedCuMatrix{Float64}) at ~/.julia/packages/CUDA/DfvRa/lib/cusolver/dense.jl:120
  getrf!(::StridedCuMatrix{ComplexF32}) at ~/.julia/packages/CUDA/DfvRa/lib/cusolver/dense.jl:120
  ...

```

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [December 1, 2022, 1:25am UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-getrf-when-i-try-to-use-gpu-to-training-a-universal-differential-equation-with-forwarddiff-jl/91062/2 "2022-12-01T01:25:48Z")

</div>

If you use Zygote you shouldn’t hit this. You can open an issue in CUDA.jl to implement a generic `getrf!` kernel, but just avoiding the need for a generic kernel is probably a better way here.

---

<div class="post-metadata">

### Author: ![Ronaldo\_Nogueira](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronaldo_nogueira/32/44773_2.png) [@Ronaldo\_Nogueira](https://discourse.julialang.org/u/Ronaldo_Nogueira)
#### Post date: [December 1, 2022, 1:36pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-getrf-when-i-try-to-use-gpu-to-training-a-universal-differential-equation-with-forwarddiff-jl/91062/3 "2022-12-01T13:36:01Z")

</div>

Thank you so much for your answear. I changed the AD type to `AutoZygote` and I had to change the sensealg to `QuadratureAdjoint` when calling `solve` function. Well, now I am facing the `Performing scalar indexing on task Task` problem, even though I used the `CUDA.allowscalar() do ..... end` on the ODE function. Maybe I will have to spend some time vectorizing the operations. Do you know any tutorial about using GPU to train UDE model (mechanistic model coupled with neural network)?

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [December 1, 2022, 8:52pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-getrf-when-i-try-to-use-gpu-to-training-a-universal-differential-equation-with-forwarddiff-jl/91062/4 "2022-12-01T20:52:18Z")

</div>

> [@Ronaldo\_Nogueira](#):
>
> Do you know any tutorial about using GPU to train UDE model (mechanistic model coupled with neural network)?

I haven’t found a case where it was actually beneficial do GPU the NN because they usually end up too small, so we went the other direction and created SimpleChains.jl for a lot of the UDE use cases.

> **[Doing small network scientific machine learning in Julia 5x faster than PyTorch](https://julialang.org/blog/2022/04/simple-chains/)**
>
> Doing small network scientific machine learning in Julia 5x faster than PyTorch ...

The climate and Fisher-KPP examples did have GPU codes at one time though,

> <https://github.com/ChrisRackauckas/universal_differential_equations/blob/master/Climate/NeuralPDE/npde.jl>

not quite sure where those went, but I need to update those codes to proper tutorials anyways (“soon”). But even then, the NN wasn’t really the bottleneck in those cases to the point where GPU kernel speed matters. The issue is that if the other equations are not highly structured (like a PDE), then the prior knowledge portion needs to be done on CPU (because then it’s not good structured for SIMD), and so you have some form of data transfer in the steps, which then makes the cutoff point a lot higher.

That said, UDE on a PDE with a ROCK method is probably the best place to find an example where it works out.

---

<div class="post-metadata">

### Author: ![Ronaldo\_Nogueira](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronaldo_nogueira/32/44773_2.png) [@Ronaldo\_Nogueira](https://discourse.julialang.org/u/Ronaldo_Nogueira)
#### Post date: [December 6, 2022, 12:17pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-getrf-when-i-try-to-use-gpu-to-training-a-universal-differential-equation-with-forwarddiff-jl/91062/5 "2022-12-06T12:17:14Z")

</div>

Thank you for your reply. I will take a look at the links you sent, I’m very grateful for that. In my case I use ODE coupled with NN, my setup is an ODE with 11 states or chemical species and an NN with 11 inputs and 7 outputs but this model is just a cut out of a big one and I’m trying to see if the NN would predict the missing signals from the cutout model. So, my goal is to run the training with different initial vectors and I thought to use GPU to accelerate the experiment. But, I think I will let this for a moment and use just the CPU. If you have any advice, you are welcome. Thank you again 😃

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [December 6, 2022, 3:50pm UTC](https://discourse.julialang.org/t/methoderror-no-method-matching-getrf-when-i-try-to-use-gpu-to-training-a-universal-differential-equation-with-forwarddiff-jl/91062/6 "2022-12-06T15:50:07Z")

</div>

> [@Ronaldo\_Nogueira](#):
>
> my setup is an ODE with 11 states or chemical species and an NN with 11 inputs and 7 outputs but this model is just a cut out of a big one and I’m trying to see if the NN would predict the missing signals from the cutout model

Yeah that’s a CPU case.
