Skip to content

Add BLAS/LAPACK runtime libraries to support Elixir Matrex and Python NumPy/SciPy #46

Description

@toshi0806

Problem

Elixir's Matrex library (and potentially Python's NumPy/SciPy) fail to load NIF (Native Implemented Function) libraries in the runtime stage due to missing BLAS/LAPACK runtime dependencies.

Error Message

Error loading NIF Failed to load NIF library /judge/main/_build/prod/rel/main/lib/matrex-0.6.8/priv/matrix_nifs: 
'libblas.so.3: cannot open shared object file: No such file or directory'

Reproduction

# In container with Full version
cd /root/contest/test_elixir

# Create test file using Matrex
cat > Main.ex << 'EOF'
defmodule Main do
  def main do
    mx = Matrex.new([[1, 2], [3, 4]])
    scaled = Matrex.multiply(mx, 2)
    IO.puts("Result: #{inspect(Matrex.to_list_of_lists(scaled))}")
  end
end
EOF

# Run in strict mode
STRICT_MODE=1 make PROG=elixir run
# Error: libblas.so.3: cannot open shared object file

Root Cause

Builder stage (line 53-54):

libblas-dev \
liblapack-dev \

✅ Development libraries are installed for building

Runtime stage (line 295-337):
❌ Runtime libraries (libblas3, liblapack3) are NOT installed

NIF libraries like Matrex require the runtime shared libraries (.so files) to be available at execution time.

Impact

Currently Affected

  • Elixir Matrex: Matrix operations fail
  • ⚠️ Python NumPy/SciPy: May have similar issues (needs verification)

Currently Working

  • Elixir Nx: Pure Elixir implementation, no native dependencies
  • Elixir Aja: Pure Elixir implementation
  • Elixir EXLA: Not tested yet, but may have similar issues

Proposed Solution

Add runtime BLAS/LAPACK libraries to the runtime stage in both Dockerfile and Dockerfile.lite:

# Runtime stage
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
            # ... existing packages ...
            # BLAS/LAPACK runtime libraries for Matrex and NumPy/SciPy
            libblas3 \
            liblapack3 \
            # ... rest of packages ...

File Locations

  • Dockerfile: Around line 305 (runtime dependencies section)
  • Dockerfile.lite: Around line 215 (runtime dependencies section)

Additional Notes

  1. These are runtime-only libraries (not -dev versions), so they don't significantly increase image size
  2. Ubuntu 24.04 package names: libblas3 and liblapack3
  3. This affects both Full and Lite versions since both include Elixir with mix dependencies

Testing After Fix

# Test Matrex
docker run --rm ghcr.io/smkwlab/atcoder-container:full-latest-amd64 \
  sh -c 'cd /judge/main && echo "defmodule Main do; def main do; mx = Matrex.new([[1,2],[3,4]]); IO.inspect(mx); end; end" > lib/main.ex && MIX_ENV=prod mix release --quiet --overwrite && _build/prod/rel/main/bin/main eval Main.main'

# Test NumPy (verify it still works)
docker run --rm ghcr.io/smkwlab/atcoder-container:full-latest-amd64 \
  python3.13 -c "import numpy; print('NumPy version:', numpy.__version__)"

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions