# Best practices to reduce startup time for CUDA.jl?

**URL:** <https://discourse.julialang.org/t/best-practices-to-reduce-startup-time-for-cuda-jl/92102>\
**Category:** GPU\
**Tags:** performance\
**Created:** [December 25, 2022, 7:24am UTC](https://discourse.julialang.org/t/best-practices-to-reduce-startup-time-for-cuda-jl/92102 "2022-12-25T07:24:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![parthe](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@parthe](https://discourse.julialang.org/u/parthe)\
**Post date:** [December 25, 2022, 7:24am UTC](https://discourse.julialang.org/t/best-practices-to-reduce-startup-time-for-cuda-jl/92102/1 "2022-12-25T07:24:13Z")

</div>

[Github Discussion](https://github.com/JuliaGPU/CUDA.jl/discussions/1706)

Hi,

I am looking for best practices to load the `CUDA.jl` package and the first usage of methods such as `CUDA.randn` from this package.

I am running CUDA.jl on a cluster node. I am not sure if I am using the package correctly.  
When I run the following code, I see a long recompilation time. However the package was precompiled when it was installed.

```julia
@time using CUDA
# 3.247396 seconds (9.32 M allocations: 628.931 MiB, 3.77% gc time, 14.07% compilation time: 59% of which was recompilation)
for i in 1:5
    @time x=CUDA.randn(1000,10);
end
# 14.033213 seconds (26.59 M allocations: 1.350 GiB, 3.78% gc time, 38.45% compilation time)
# 0.000127 seconds (57 allocations: 2.578 KiB)
# 0.000069 seconds (57 allocations: 2.578 KiB)
# 0.000027 seconds (57 allocations: 2.578 KiB)
# 0.000021 seconds (57 allocations: 2.578 KiB)

```

---

<div class="post-metadata">

**Author:** ![jmair](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmair/32/35117_2.png) [@jmair](https://discourse.julialang.org/u/jmair)\
**Post date:** [December 25, 2022, 9:44am UTC](https://discourse.julialang.org/t/best-practices-to-reduce-startup-time-for-cuda-jl/92102/2 "2022-12-25T09:44:37Z")

</div>

For improving TTFX issues, people usually recommend creating a sysimage using `PackageCompiler.jl` ([link here](https://julialang.github.io/PackageCompiler.jl/dev/sysimages.html)). However, I’ve had issues with getting a custom sysimage to work specifically with `CUDA.jl`, but it’s been a while since I last tried, so it may be worth it to try it out.

Also, which version of Julia are you using?

---

<div class="post-metadata">

**Author:** ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)\
**Post date:** [December 25, 2022, 9:54am UTC](https://discourse.julialang.org/t/best-practices-to-reduce-startup-time-for-cuda-jl/92102/3 "2022-12-25T09:54:47Z")

</div>

CUDA.jl is known to have a large TTFX because it essentially needs to re-compile the Julia compiler (which is specialized on an AbstractInterpreter argument). Recent advances in precompilation support in base Julia will make it possible to precompile this.
