# Understanding JULIA\_CPU\_TARGET

**URL:** <https://discourse.julialang.org/t/understanding-julia-cpu-target/116774>\
**Category:** New to Julia\
**Tags:** precompilation\
**Created:** [July 8, 2024, 2:15pm UTC](https://discourse.julialang.org/t/understanding-julia-cpu-target/116774 "2024-07-08T14:15:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![amanif0ld](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@amanif0ld](https://discourse.julialang.org/u/amanif0ld)\
**Post date:** [July 8, 2024, 2:15pm UTC](https://discourse.julialang.org/t/understanding-julia-cpu-target/116774/1 "2024-07-08T14:15:41Z")

</div>

I am trying to generate precompiled files for packages that are reusable across a number of computers that share a common DEPOT\_PATH through a shared filesystem. I would ideally want to precompile package .so and .ji files only once, and reuse those files for all julia installations.

Although my clusters are fairly homogeneous architecture wise, I do have a small number of instruction set architectures that have to coexist.

According to [the docs](https://docs.julialang.org/en/v1/devdocs/sysimg/#Specifying-multiple-system-image-targets) and this post [Repeated precompilation on a cluster makes life difficult](https://discourse.julialang.org/t/repeated-precompilation-on-a-cluster-makes-life-difficult/94194), setting the JULIA\_CPU\_TARGET to generic or some other variant should do the trick.

According to the docs, you can target a number of different targets separated by semicolons, and if I understood correctly, the host machine will take the most suitable ISA inside that precompiled file.

My question is regarding how to set an appropriate value for JULIA\_CPU\_TARGET. I don’t understand the exact function of all the flags mentioned in the sysimage documentation, such as rdrnd, haswell base(n) and so on.

It appears that the [LLVM](https://llvm.org/docs/LangRef.html) might be helpful, but as someone without a formal cs background, I’m feel a little bit lost in that document. Do you know any other documents that may explain the basics of LLVM flags for Julia, so as to decide which set of flags has to be put (if at all, maybe just generic may work but I have to test that), and how to determine the compatibility tree of the different instruction set architectures available through JULIA\_CPU\_TARGET?

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [July 8, 2024, 2:34pm UTC](https://discourse.julialang.org/t/understanding-julia-cpu-target/116774/2 "2024-07-08T14:34:48Z")

</div>

Check `Sys.CPU_NAME` for the hosts that you want to precompile for, and use these as the targets. Add `generic` as a fallback.

---

<div class="post-metadata">

**Author:** ![amanif0ld](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@amanif0ld](https://discourse.julialang.org/u/amanif0ld)\
**Post date:** [July 8, 2024, 2:41pm UTC](https://discourse.julialang.org/t/understanding-julia-cpu-target/116774/3 "2024-07-08T14:41:38Z")

</div>

Thanks for your response! Can I add as many hosts as I want? Do you know if these will impact the size of the precompiled objects?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [July 8, 2024, 3:21pm UTC](https://discourse.julialang.org/t/understanding-julia-cpu-target/116774/4 "2024-07-08T15:21:58Z")

</div>

> [@amanif0ld](#):
>
> Can I add as many hosts as I want? Do you know if these will impact the size of the precompiled objects?

Yes and yes (more = larger size)

---

<div class="post-metadata">

**Author:** ![Sevi](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@Sevi](https://discourse.julialang.org/u/Sevi)\
**Post date:** [July 8, 2024, 8:51pm UTC](https://discourse.julialang.org/t/understanding-julia-cpu-target/116774/5 "2024-07-08T20:51:53Z")

</div>

Just wanted to leave this link here in case it’s helpful. I had similar questions (but about the automatic package precompilation, not with sysimages, but the process is “similar” 😉 )

> [@Julia 1.9, same depot with different machines?](https://discourse.julialang.org/t/julia-1-9-same-depot-with-different-machines/103463):
>
> Hi! I’m using Julia 1.9 on an HPC cluster and ran into a strange error on some of the machines. I have a hunch that it’s related to native code caching and the fact that I currently use the same depot for all machines, but I’m a bit stuck investigating the actual issue and finding a good solution. Problem Running certain code on the affected machines gives an Illegal instruction error. So far I could only trigger the error when using Cthulhu.jl, but I’m not sure if it’s really related to that p…

The upshot is that I also ended up using `generic` followed by the CPU architectures returned from `Sys.CPU_NAME` which I crawled on our cluster with a short script, so something like

`generic;sandybridge;icelake-server;znver2;haswell;broadwell;znver1;skylake-avx512;znver3;cascadelake`

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [July 9, 2024, 3:42am UTC](https://discourse.julialang.org/t/understanding-julia-cpu-target/116774/6 "2024-07-09T03:42:38Z")

</div>

You might want to add `,clone_all` to all variants except the first. Without it, specific variants will one be compiled if they are necessary or estimated to be superior to a generic one. With it, everything will be duplicated for all architectures.

See [System Image Building · The Julia Language](https://docs.julialang.org/en/v1/devdocs/sysimg/#Specifying-multiple-system-image-targets).
