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.
PackageCompiler is a Julia package with two main purposes:
Creating custom sysimages for reduced latency when working locally with packages that has a high startup time.
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
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
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
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
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).
I’ve tried to compile on my Mac (Mojave) using the rpi3/rpi3-v1.5.0 image, with the hopes of running Julia on both a RPi 3B+ and a 4 (both running Buster). (Will images in rpi3 also build for a RPi 4?)
After running docker build -t jl4rpi3 -f Dockerfile-v1.5.0 . as per instructions, it crashes with an error:
Step 3/11 : RUN apt-get update && apt-get install -y build-essential libatomic1 python gfortran perl wget m4 cmake pkg-config git && apt-get clean && rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/*
---> Running in 86d10a034862
standard_init_linux.go:211: exec user process caused "exec format error"
The command '/bin/sh -c apt-get update && apt-get install -y build-essential libatomic1 python gfortran perl wget m4 cmake pkg-config git && apt-get clean && rm -rf /var/cache/apt/archives/* /var/lib/apt/lists/*' returned a non-zero code: 1
Any suggestions? I am probably making a naive mistake; I’ve never tried to cross-compile something using Docker before.
Thanks for the help. I’m on the latest Docker, but can’t upgrade the OS to Catalina at the moment. Here’s what happened:
Build again with --no-cache option
Same error.
Try to run docker image that I built
This crashes immediately with standard_init_linux.go:211: exec user process caused "exec format error" without doing anything else.
Try to run with another Dockerfile e.g. Dockerfile-v1.4.2
Same as the original error.
The first thing I tried is to build Julia 1.5.0 locally (on my 3B+ with a fresh Buster install; I haven’t set up the 4 yet), using the JuliaBerry instructions. That compiled for a while but then crashed:
CC src/llvm-api.o
CC src/llvm-remove-addrspaces.o
CC src/llvm-remove-ni.o
LINK usr/lib/libjulia.so.1.5
/usr/bin/ld: ./gc.o: in function `combine_thread_gc_counts':
/home/pi/julia/src/gc.c:998: undefined reference to `__atomic_load_8'
/usr/bin/ld: /home/pi/julia/src/gc.c:999: undefined reference to `__atomic_load_8'
/usr/bin/ld: /home/pi/julia/src/gc.c:1000: undefined reference to `__atomic_load_8'
/usr/bin/ld: /home/pi/julia/src/gc.c:1001: undefined reference to `__atomic_load_8'
/usr/bin/ld: /home/pi/julia/src/gc.c:1002: undefined reference to `__atomic_load_8'
/usr/bin/ld: ./gc.o:/home/pi/julia/src/gc.c:1003: more undefined references to `__atomic_load_8' follow
/usr/bin/ld: ./gc.o: in function `jl_gc_collect':
/home/pi/julia/src/gc.c:3079: undefined reference to `__atomic_fetch_add_8'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:333: /home/pi/julia/usr/lib/libjulia.so.1.5] Error 1
make: *** [Makefile:75: julia-src-release] Error 2
I’ve tried to build Julia v1.5.1 and v1.5.0 locally and found it failed.
In stead of building v.1.5.x, I’ve succeeded to build Julia 1.6-DEV (today’s master branch).
Here is my bash script to build Julia on RPI4 locally (i.e. without using Docker). I hope @nurban can do as well.
#! /bin/bash
# Usage:
# 1. Copy this file to your raspberry pi e.g. /home/pi
# 2. Run this file `bash build_locally.sh`
# 3. Tested on Raspberry Pi4 with 4 or 8 GB
sudo apt-get update && sudo apt-get install -y \
build-essential libatomic1 python gfortran perl wget m4 cmake pkg-config \
git
JL_VERSION=master
JL_BUILD_DIR=build-julia-${JL_VERSION}
JL_COMMIT_HASH=3d04d15c31
JL_BUILD_DIR=build-julia-${JL_VERSION}-${JL_COMMIT_HASH}
git clone https://github.com/JuliaLang/julia.git $JL_BUILD_DIR && \
cd ${JL_BUILD_DIR} && git checkout ${JL_COMMIT_HASH} && cd ..
cat > ${JL_BUILD_DIR}/Make.user << EOF
CXXFLAGS=-D_GLIBCXX_USE_CXX11_ABI=0
prefix=/home/pi/julia-${JL_VERSION}-${JL_COMMIT_HASH}
USE_BINARYBUILDER=0
LDFLAGS=-latomic
CFLAGS += "-mfpu=neon-vfpv4"
CXXFLAGS += "-mfpu=neon-vfpv4"
MARCH="armv7-a"
JULIA_CPU_TARGET="armv7-a\;armv7-a,neon\;armv7-a,neon,vfp4"
EOF
cd ${JL_BUILD_DIR} && make -j `nproc` && sudo make install && cd ..
Is it possible for you to ship these with sysimages for stuff like JSServe, AbstractPlotting, WGLMakie, LibSerialPort, maybe even Images? It’s just that these packages take ages to load and use on the RPI and are very useful for project involving the Pi Cam and server-related tasks… Just a thought!
They do work, so that’s good. PackageCompiler is the way to go for sure, I was just thinking that while you’re shipping these docker images, you could bake into them sysimages that already include these packages precompiled. My point is, that it would be very useful for people using these docker images to already have these packages precompiled, especially on an RPI, since the use-cases for them would be wide.