Skip to content

Support native fma on riscv64 #57043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Support native fma on riscv64 #57043

wants to merge 3 commits into from

Conversation

giordano
Copy link
Member

@giordano giordano commented Jan 14, 2025

This is an attempt to support native fma on riscv64, but I'm quite confused because with this PR I get at the same time

julia> Core.Intrinsics.have_fma(Float64)
false

julia> code_llvm(fma, NTuple{3,Float64}; debuginfo=:none)
; Function Signature: fma(Float64, Float64, Float64)
define double @julia_fma_1141(double %"x::Float64", double %"y::Float64", double %"z::Float64") #0 {
common.ret:
    #dbg_value(double %"x::Float64", !2, !DIExpression(), !16)
    #dbg_value(double %"y::Float64", !14, !DIExpression(), !16)
    #dbg_value(double %"z::Float64", !15, !DIExpression(), !16)
  %0 = call double @llvm.fma.f64(double %"x::Float64", double %"y::Float64", double %"z::Float64")
  ret double %0
}

Core.Intrinsics.have_fma claims native FMA instructions aren't available, but fma now uses @llvm.fma.f64 instead of going through the emulated path, as it does on master:

julia> code_llvm(fma, NTuple{3,Float64}; debuginfo=:none)
; Function Signature: fma(Float64, Float64, Float64)
define double @julia_fma_1023(double %"x::Float64", double %"y::Float64", double %"z::Float64") #0 {
common.ret:
    #dbg_value(double %"x::Float64", !3, !DIExpression(), !17)
    #dbg_value(double %"y::Float64", !15, !DIExpression(), !17)
    #dbg_value(double %"z::Float64", !16, !DIExpression(), !17)
  %0 = call double @j_fma_emulated_1026(double %"x::Float64", double %"y::Float64", double %"z::Float64")
  ret double %0
}

@gbaraldi any idea of what's going on?

@giordano giordano added maths Mathematical functions system:riscv Support for Risc-V cpus labels Jan 14, 2025
@giordano giordano mentioned this pull request Jan 14, 2025
@giordano giordano requested a review from vchuravy January 14, 2025 14:45
@gbaraldi
Copy link
Member

@giordano the runtime version of this needs to also check it correctly. Also how are we passing the runtime features?

@giordano
Copy link
Member Author

the runtime version of this needs to also check it correctly.

You mean I need to complement a function like

julia/src/processor_x86.cpp

Lines 1094 to 1102 in 6cf2b14

JL_DLLEXPORT jl_value_t *jl_cpu_has_fma(int bits)
{
TargetData<feature_sz> target = jit_targets.front();
FeatureList<feature_sz> features = target.en.features;
if ((bits == 32 || bits == 64) && (test_nbit(features, Feature::fma) || test_nbit(features, Feature::fma4)))
return jl_true;
else
return jl_false;
}
for riscv64?

Also how are we passing the runtime features?

Not sure what you mean.

@oscardssmith
Copy link
Member

You mean I need to complement a function like

yes. The part you've done so far is the version for where have_fma is figured out at compile time, but the other implementation is for when it is done as a runtime check.

@giordano
Copy link
Member Author

I think that overlaps quite a bit with #57049?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maths Mathematical functions system:riscv Support for Risc-V cpus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants