# Solve linear systems inside CUDA kernel function

**URL:** <https://discourse.julialang.org/t/solve-linear-systems-inside-cuda-kernel-function/110202>\
**Category:** GPU\
**Created:** [February 14, 2024, 8:52am UTC](https://discourse.julialang.org/t/solve-linear-systems-inside-cuda-kernel-function/110202 "2024-02-14T08:52:59Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![trahflow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/trahflow/32/30585_2.png) [@trahflow](https://discourse.julialang.org/u/trahflow)\
**Post date:** [February 14, 2024, 1:58pm UTC](https://discourse.julialang.org/t/solve-linear-systems-inside-cuda-kernel-function/110202/6 "2024-02-14T13:58:08Z")

</div>

> [@FR13ndSDP](#):
>
> In my case, AAA and bbb will be constructed inside the kernel, so they have to be mutable.

That’s very unlikely to work. You cannot dynamically allocate memory inside a GPU kernel (see also this recent post: [Modifying a thread-local vector within CUDA Dynamic Parallelism - #2 by vchuravy](https://discourse.julialang.org/t/modifying-a-thread-local-vector-within-cuda-dynamic-parallelism/110110/2)).

What should work though is to allocate all CuArrays outside the kernel, then inside the kernel convert the relevant `view`s into your arrays into `SMatrix`/`SVector`s and do the solve on StaticArrays only. (I don’t have access to a GPU atm to check)

---

_[View the full topic](https://discourse.julialang.org/t/solve-linear-systems-inside-cuda-kernel-function/110202)._
