Have a try Julia v1.4.2 for arm32bit

  • Since Julia for arm32bit (e.g. RaspberryPi series) reduced toTier3, https://julialang.org/downloads/ does not provide, binary Julia 1.4.2. :sob:

  • Good news! I’m happy to announce the release of recipe (technically Dockerfile) that builds Julia v1.4.2 for RaspberryPi series.

  • You can enjoy Julia on your Raspberry Pi 3 or 4 even Zero :smile:

  • Does Julia packages runs on Raspberry Pi ?

    • As far as I know, Example.jl, PyCall.jl, PyPlot.jl, SymPy.jl, IJulia.jl, Interact.jl, Images.jl, UnicodePlots.jl, ImageInTerminal.jl, VideoIO.jl, MPI.jl etc… runs on RaspberryPi3 or 4. By using PackageCompiler.jl, you can reduce the latency of loading modules e.g. Plots.jl which is really useful for Raspberry Pi users.
    • If your package (including its dependencies) is written in 100% Julia, there is a chance to run not only Pi3/4 but also PiZero.
  • Is there any application we can use on Raspberry Pi ?

    • Here you are: CameraApp.jl.
    • If you have a USB camera or the official Raspberry Pi camera, you can take photo or movie from it and display the result on your terminal based on ImageInTerminal.jl which means there is a chance to implement IoT application with Julia.
    • Also checkout HelloX.jl which is a simple Hello World Application that will be generated via PackageCompiler. It should run on your PiZero.
  • Is Julia fast ?

Have a try !!!

16 Likes

What a great post! Thank you for sharing!

2 Likes

Hi @terasakisatoshi!

Very nice work! Can you please tell me if they can build correctly in the Pi Zero? Do I need any special configuration? Like a big SD card for swap or something?

1 Like

Hi, @Ronis_BR Thanks for taking the time to look at this post.

2 Likes

Oh, very nice! I think it is not necessary to build Julia locally if the cross-compilation is working fine. The Zero should get here soon. I will test your binary version and let you know :slight_smile:

EDIT: One question, since you already have a binary package for the Pi, is it possible to put it somewhere so that we can download without using docker?

From my RPI4:

$ apt-cache policy julia
julia:
  Installed: (none)
  Candidate: 1.4.1+dfsg-1+rpi1
  Version table:
     1.4.1+dfsg-1+rpi1 500
        500 http://raspbian.raspberrypi.org/raspbian testing/main armhf Packages
     1.0.3+dfsg-4+rpi1 500
        500 http://raspbian.raspberrypi.org/raspbian buster/main armhf Packages

So it seems raspbian already includes julia in testing, if you are ok with 1.4.1 version.

2 Likes

Thanks for your work! I installed and it works flawlessly in Raspbian. In Arch Linux I got many libraries problems.

With respect to Julia, how I wish we could cache the compilation between executions… Julia is fast, but the first call to the function on the Pi Zero is very long. For example, summing to SVectors has performance comparable to C, but the first sum takes almost 20s here.

  • Why don’t you try using PackageCompiler.jl?

PackageCompiler is a Julia package with two main purposes:

  1. Creating custom sysimages for reduced latency when working locally with packages that has a high startup time.
  2. Creating “apps” which are a bundle of files including an executable that can be sent and run on other machines without Julia being installed on that machine.

I’ve made a Dockerfile that testout PackageCompiler.jl works on PiZero with a little modification of functions defined inside of PackageCompiler.jl .

FROM terasakisatoshi/jlcross:rpizero-v1.4.2

RUN julia -e 'using Pkg; \
    Pkg.add(["PackageCompiler", "StaticArrays"]); \
    # precompile pacakges; \
    using PackageCompiler, StaticArrays'

RUN mkdir /sysimages
RUN julia -e '\
using PackageCompiler; \
import PackageCompiler:march, default_app_cpu_target; \
# To specialize in Raspberry Pi zero, \
# we will override `march` and `default_app_cpu_target` \
march()=nothing; \
default_app_cpu_target() = "arm1176jzf-s"; \
create_sysimage([:StaticArrays], sysimage_path="/sysimages/sarrays.so"); \
'

Usage:

  • Let’s build a Docker image: You can run it on your PC (i.e. you do not have to run on Pi Zero)
$ docker build -t sample .

Running Julia with a default sysimage.

$ docker run -it sample bash
# root@8a376904e61e:~# julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.4.2 (2020-05-23)
 _/ |\__'_|_|_|\__'_|  |
|__/                   |

julia> @time using StaticArrays
  8.570656 seconds (2.63 M allocations: 97.142 MiB) 
julia> # Yeah ... Its so slow

Running Julia with /sysimages/sarrays.so

root@8a376904e61e:~# julia -J/sysimages/sarrays.so
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.4.2 (2020-05-23)
 _/ |\__'_|_|_|\__'_|  |
|__/                   |

julia> @time using StaticArrays
  0.018823 seconds (528 allocations: 17.688 KiB)
julia> # Yeah !!!

I think this is exactly what you want.

3 Likes

Wow! Thanks, you’re awesome!

Can you please test the time it takes there to create the first SVector in both configurations? Just something like SVector{3}(0.0,0.0,0.0). I am current struggling with docker on macOS to build this image :sweat_smile:

Yep

              _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.4.2 (2020-05-23)
 _/ |\__'_|_|_|\__'_|  |
|__/                   |

julia> @time using StaticArrays
  8.681726 seconds (2.63 M allocations: 97.372 MiB)

julia> @time s1=SVector{3}(rand(3)...)
  4.732088 seconds (527.81 k allocations: 23.473 MiB, 0.43% gc time)
3-element SArray{Tuple{3},Float64,1,3} with indices SOneTo(3):
 0.6251627489660037
 0.906300457096751
 0.15755352263915

julia> @time s2=SVector{3}(rand(3)...);
  0.000386 seconds (6 allocations: 224 bytes)

julia> @time s1+s2
  3.152563 seconds (262.98 k allocations: 9.889 MiB, 3.56% gc time)
3-element SArray{Tuple{3},Float64,1,3} with indices SOneTo(3):
 1.0164078910097523
 1.3066583615381162
 0.9318514291842892
root@322ab6dcb7f2:/home/pi/work# julia -J/sysimages/sarrays
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.4.2 (2020-05-23)
 _/ |\__'_|_|_|\__'_|  |
|__/                   |

julia> @time using StaticArrays
  0.033259 seconds (528 allocations: 17.688 KiB)

julia> @time s1=SVector{3}(rand(3)...)
  0.995602 seconds (89.46 k allocations: 3.633 MiB)
3-element SArray{Tuple{3},Float64,1,3} with indices SOneTo(3):
 0.7940274815713029
 0.33778859425558583
 0.8802788022203052

julia> @time s2=SVector{3}(rand(3)...)
  0.000409 seconds (6 allocations: 224 bytes)
3-element SArray{Tuple{3},Float64,1,3} with indices SOneTo(3):
 0.6341863302172961
 0.8197629384451275
 0.535413927058944

julia> @time s1+s2
  2.648152 seconds (201.26 k allocations: 7.491 MiB, 0.31% gc time)
3-element SArray{Tuple{3},Float64,1,3} with indices SOneTo(3):
 1.428213811788599
 1.1575515327007133
 1.4156927292792492
  • I’ve updated the Dockerfile above by adding keyword argumnet precompile_execution_file.
    It will improve performance.

See https://julialang.github.io/PackageCompiler.jl/dev/examples/plots/ fore more information.

FROM terasakisatoshi/jlcross:rpizero-v1.4.2

RUN julia -e 'using Pkg; \
    Pkg.add(["PackageCompiler", "StaticArrays"]); \
    # precompile pacakges; \
    using PackageCompiler, StaticArrays'

RUN mkdir /sysimages

RUN echo 'using StaticArrays; s1=SVector{3}(0.0,0.0,0.0); s2=SVector{3}(rand(3)...); s1+s2' >> /home/pi/executionfile.jl
RUN julia /home/pi/executionfile.jl

RUN julia -e '\
using PackageCompiler; \
import PackageCompiler:march, default_app_cpu_target; \
# To specialize in Raspberry Pi zero, \
# we will override `march` and `default_app_cpu_target` \
march()=nothing; \
default_app_cpu_target() = "arm1176jzf-s"; \
create_sysimage([:StaticArrays], precompile_execution_file="/home/pi/executionfile.jl", sysimage_path="/sysimages/sarrays.so"); \
'

RUN julia -e '\
@time using StaticArrays; \
@time s1=SVector{3}(rand(3)...); \
@time s2=SVector{3}(rand(3)...); \
@time s1+s2;\
'

RUN julia -J/sysimages/sarrays.so -e '\
@time using StaticArrays; \
@time s1=SVector{3}(rand(3)...); \
@time s2=SVector{3}(rand(3)...); \
@time s1+s2;\
'
$ docker build -t sample .

will output …

...
...
...
Step 7/8 : RUN julia -e '@time using StaticArrays; @time s1=SVector{3}(rand(3)...); @time s2=SVector{3}(rand(3)...); @time s1+s2;'
 ---> Running in 04803b0cf08e
  8.666841 seconds (2.63 M allocations: 97.241 MiB)
  4.802351 seconds (527.82 k allocations: 23.474 MiB, 0.66% gc time)
  0.000365 seconds (6 allocations: 224 bytes)
  2.840873 seconds (275.62 k allocations: 10.468 MiB, 0.30% gc time)
Removing intermediate container 04803b0cf08e
 ---> d272f875c9e9
Step 8/8 : RUN julia -J/sysimages/sarrays.so -e '@time using StaticArrays; @time s1=SVector{3}(rand(3)...); @time s2=SVector{3}(rand(3)...); @time s1+s2;'
 ---> Running in 9b1244590691
  0.014529 seconds (528 allocations: 17.688 KiB)
  0.242853 seconds (253 allocations: 32.297 KiB)
  0.000339 seconds (6 allocations: 224 bytes)
  0.000107 seconds (1 allocation: 32 bytes)
Removing intermediate container 9b1244590691
 ---> d0b825ef3d9d
Successfully built d0b825ef3d9d
2 Likes

Thank you very much! I think I can do the same approach, precompile everything in the startup. It should work :slight_smile:

1 Like

Also checkout https://github.com/terasakisatoshi/HelloX.jl :smiley:

1 Like

Just a tip for people that want to try Julia in RPi zero W. REPL is very, very slow. When I run the script, then I see Julia is working pretty well. However, everything in REPL is very slow. Maybe because there is a lot of functions being compiled during typing and running. Hence, do not think Julia is slow if you are using REPL.

BTW @terasakisatoshi, I am working in a package to access GPIO/SPI without any external libraries. Using only /dev/spidev0.Xand /dev/gpiomem. This is necessary because PiGPIO uses a daemon (pigpio) and communicates with it using sockets. I will never allowed to put this kind of thing inside a CubeSat. If I keep everything as baremetal as possible, maybe I can achieve the latency I need :slight_smile:

1 Like

Just an information, using the amazing guides provided by @terasakisatoshi, I could built Julia for Archlinux ARMV6. If anyone wants, I can share the package. In this case, I build every single dependency (inclusion openBLAS, lapack, etc.), so that it stays more or less disconnected from the system libraries. Otherwise, we may have some problems with Arch rolling release system (or not, if the API of those libraries does not change that much).

Hi folks, Have a try 1.5.0-rc1.

6 Likes

This PR is merged.