Skip to content

Can't compare Float32 with Rational on Metal #550

@efaulhaber

Description

@efaulhaber
julia> map(y -> y < 3 // 2, Metal.zeros(1))
ERROR: InvalidIRError: compiling MethodInstance for (::Metal.var"#broadcast_linear#204")(::MtlDeviceVector{…}, ::Base.Broadcast.Broadcasted{…}) resulted in invalid LLVM IR
Reason: unsupported call to an unknown function (call to gpu_malloc)
Stacktrace:
  [1] malloc
    @ ~/.julia/packages/GPUCompiler/AQezv/src/runtime.jl:85
  [2] macro expansion
    @ ~/.julia/packages/GPUCompiler/AQezv/src/runtime.jl:180
  [3] macro expansion
    @ ./none:0
  [4] box
    @ ./none:0
  [5] box_int64
    @ ~/.julia/packages/GPUCompiler/AQezv/src/runtime.jl:209
  [6] ndigits0z
    @ ./intfuncs.jl:701
  [7] <
    @ ./rational.jl:470
  [8] #76
    @ ./REPL[24]:1
  [9] _broadcast_getindex_evalf
    @ ./broadcast.jl:678
 [10] _broadcast_getindex
    @ ./broadcast.jl:651
 [11] getindex
    @ ./broadcast.jl:610
 [12] broadcast_linear
    @ ~/.julia/packages/Metal/N2ABH/src/broadcast.jl:89
Reason: unsupported use of i128 value
Stacktrace:
  [1] toInt128
    @ ./boot.jl:823
  [2] Int128
    @ ./boot.jl:893
  [3] convert
    @ ./number.jl:7
  [4] widen
    @ ./operators.jl:900
  [5] widemul
    @ ./number.jl:277
  [6] <
    @ ./rational.jl:460
  [7] #76
    @ ./REPL[24]:1
  [8] _broadcast_getindex_evalf
    @ ./broadcast.jl:678
  [9] _broadcast_getindex
    @ ./broadcast.jl:651
 [10] getindex
    @ ./broadcast.jl:610
 [11] broadcast_linear
    @ ~/.julia/packages/Metal/N2ABH/src/broadcast.jl:89
[...]

Julia is apparently converting things to Int128 to compare a Float32 with 3 // 2.

julia> Metal.versioninfo()
macOS 15.1.1, Darwin 24.3.0

Toolchain:
- Julia: 1.11.3
- LLVM: 16.0.6

Julia packages: 
- Metal.jl: 1.5.1
- GPUArrays: 11.2.2
- GPUCompiler: 1.1.1
- KernelAbstractions: 0.9.33
- ObjectiveC: 3.4.0
- LLVM: 9.2.0
- LLVMDowngrader_jll: 0.6.0+0

1 device:
- Apple M2 Pro (72.219 MiB allocated)

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomerskernelsThings about kernels and how they are compiled.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions