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 lib/intrinsics/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SPIRVIntrinsics"
uuid = "71d1d633-e7e8-4a92-83a1-de8814b09ba8"
authors = ["Tim Besard <tim.besard@gmail.com>"]
version = "1.6.1"
version = "1.6.2"

[deps]
GPUToolbox = "096a3bc2-3ced-46d0-87f4-dd12716f4bfc"
Expand Down
6 changes: 5 additions & 1 deletion lib/intrinsics/src/work_item.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ end
# back-end lowers to a load and an extract of the component. the declaration gets the
# attributes LLVM gives its own work-item intrinsics (e.g. `llvm.nvvm.read.ptx.sreg.tid.x`):
# Enzyme only differentiates through calls of `nofree` declarations, and `speculatable` lets
# the optimizer hoist calls out of conditionals.
# the optimizer hoist calls out of conditionals. The `enzyme_type` return attribute tells
# Enzyme that the result is an integer, as it knows for those intrinsics: when the result
# only reaches integer code through a `trunc` (e.g. with 32-bit indices), Enzyme otherwise
# can't rule out a pointer, and fails to differentiate the call in reverse mode.
@llvmgenerated builder function builtin_vector_variable(::Val{name}, idx::Int32)::UInt where {name}
ft = LLVM.FunctionType(convert(LLVMType, UInt), [idx.value_type])
f = LLVM.Function(current_module(builder), String(name), ft)
Expand All @@ -27,6 +30,7 @@ end
push!(f.function_attributes, EnumAttribute(:nosync))
push!(f.function_attributes, EnumAttribute(:speculatable))
f.memory_effects = MemoryEffects(:none)
push!(f.return_attributes, StringAttribute("enzyme_type", "{[-1]:Integer}"))
call!(builder, ft, f, [idx])
end

Expand Down
2 changes: 2 additions & 0 deletions test/intrinsics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ builtin_attributes_kernel(a) = (@inbounds a[get_global_id(1)] = get_group_id(1);
@test attrs !== nothing
group = match(Regex("attributes #$(attrs[1]) = \\{([^}]*)\\}"), ir)[1]
@test issubset(["nofree", "nosync", "nounwind", "speculatable", "willreturn"], split(group))
# Enzyme's type analysis needs to know the result is an integer
@test occursin(r"declare \"enzyme_type\"=\"\{\[-1\]:Integer\}\" i64 @_Z26__spirv_BuiltInWorkgroupIdi", ir)
end

# truncating the 3-D builtins used to produce loads of vector types SPIR-V doesn't have
Expand Down