Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/emlx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
mix test --warnings-as-errors

macos:
name: macOS (${{ matrix.job.elixir }}, ${{ matrix.job.otp }})
name: macOS ${{ matrix.job.gpu && 'gpu' || 'cpu' }} (${{ matrix.job.elixir }}, ${{ matrix.job.otp }})
runs-on: macos-26
strategy:
fail-fast: false
Expand Down
2 changes: 1 addition & 1 deletion emlx/c_src/emlx_nif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ NIF(to_blob) {
}

uint64_t elem_count(std::vector<int> shape) {
return std::accumulate(shape.begin(), shape.end(), 1, std::multiplies<>{});
return std::accumulate(shape.begin(), shape.end(), uint64_t{1}, std::multiplies<uint64_t>{});
Comment thread
edenamram marked this conversation as resolved.
}

NIF(from_blob) {
Expand Down
17 changes: 17 additions & 0 deletions emlx/test/emlx_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,21 @@ defmodule EMLXTest do
end
end
end

# Regression: elem_count overflowed int32 for shapes whose element count
# exceeds INT32_MAX, causing "Binary size is too small" on valid binaries.
@tag :large_memory
test "from_binary accepts shape whose element count exceeds INT32_MAX" do
# Reshape on BinaryBackend first — Nx.from_binary creates a flat 1D tensor
# whose single dimension would also exceed INT32_MAX.
int_32_max = 2 ** 31
binary = String.duplicate(<<7>>, int_32_max)
shape = {2, div(int_32_max, 2)}

out = Nx.template(shape, :u8)
t = EMLX.Backend.from_binary(out, binary, backend: EMLX.Backend)

assert Nx.shape(t) == shape
assert_equal(Nx.all(Nx.equal(t, 7)), 1)
end
end
2 changes: 1 addition & 1 deletion emlx/test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ distributed_exclude =

gpu_exclude =
case EMLX.NIF.command_queue_new(:gpu) do
{:ok, _} -> []
{:ok, _} -> [:large_memory]
{:error, _} -> [:metal]
end

Expand Down
Loading