Skip to content

Bug: Metal bfloat kernel crash when using Swift package #10205

Closed
@jmousseau

Description

@jmousseau

What happened?

I encountered a crash in ggml_metal_init when the first bfloat kernel is added. Below is an explanation of what I believe is happening. My device is running macOS 15.0.1 and has an M3 Max.

Because the macOS platform version in Package.swift is .v12, the condition to disable bfloat, __METAL_VERSION__ < 310, will always be true. However, at runtime the device family is used to set has_bfloat. As a result, there can be a bfloat mismatch between the Swift package's compiled Metal library and the runtime flag. This leads to a crash when adding bfloat Metal kernels as they don't exist.

Some ideas:

  1. Consider bumping the macOS platform version to .v14 so consumers of the Swift package can use bfloat.
  2. Set has_bfloat by also checking for the existence of an empty kernel in the MTLLibrary that will only exist if the library was compiled with bfloat support.

Name and Version

version: 4043 (60e17ce)
built with Apple clang version 16.0.0 (clang-1600.0.26.4) for arm64-apple-darwin24.0.0

What operating system are you seeing the problem on?

Mac

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug-unconfirmedcritical severityUsed to report critical severity bugs in llama.cpp (e.g. Crashing, Corrupted, Dataloss)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions