Skip to content
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

[Metal] Add sincos intrinsic LLVM annotations #663

Open
christiangnrd opened this issue Feb 4, 2025 · 0 comments
Open

[Metal] Add sincos intrinsic LLVM annotations #663

christiangnrd opened this issue Feb 4, 2025 · 0 comments
Labels
metal Stuff about the Apple metal back-end.

Comments

@christiangnrd
Copy link
Member

declare half @air.sincos.f16(half, half* nocapture writeonly)

vs

declare half @air.sincos.f16(half, i64)

So the problem is we aren't passing a pointer, but an i64. This can be fixed by using @typed_ccall from LLVM.jl instead of plain ccall.

It's also probably useful to add those annotations to

GPUCompiler.jl/src/metal.jl

Lines 1161 to 1203 in 47a4a8b

function annotate_air_intrinsics!(@nospecialize(job::CompilerJob), mod::LLVM.Module)
changed = false
for f in functions(mod)
isdeclaration(f) || continue
fn = LLVM.name(f)
attrs = function_attributes(f)
function add_attributes(names...)
for name in names
if LLVM.version() >= v"16" && name in ["argmemonly", "inaccessiblememonly",
"inaccessiblemem_or_argmemonly",
"readnone", "readonly", "writeonly"]
# XXX: workaround for changes from https://reviews.llvm.org/D135780
continue
end
push!(attrs, EnumAttribute(name, 0))
end
changed = true
end
# synchronization
if fn == "air.wg.barrier" || fn == "air.simdgroup.barrier"
add_attributes("nounwind", "convergent")
# atomics
elseif match(r"air.atomic.(local|global).load", fn) !== nothing
# TODO: "memory(argmem: read)" on LLVM 16+
add_attributes("argmemonly", "readonly", "nounwind")
elseif match(r"air.atomic.(local|global).store", fn) !== nothing
# TODO: "memory(argmem: write)" on LLVM 16+
add_attributes("argmemonly", "writeonly", "nounwind")
elseif match(r"air.atomic.(local|global).(xchg|cmpxchg)", fn) !== nothing
# TODO: "memory(argmem: readwrite)" on LLVM 16+
add_attributes("argmemonly", "nounwind")
elseif match(r"^air.atomic.(local|global).(add|sub|min|max|and|or|xor)", fn) !== nothing
# TODO: "memory(argmem: readwrite)" on LLVM 16+
add_attributes("argmemonly", "nounwind")
end
end
return changed
end

Originally posted by @maleadt in #530

@maleadt maleadt added the metal Stuff about the Apple metal back-end. label Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
metal Stuff about the Apple metal back-end.
Projects
None yet
Development

No branches or pull requests

2 participants