From 1550ab806519b92d8782eb9cf604011e4d3c4ab6 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Thu, 13 Feb 2025 09:54:44 +0100 Subject: [PATCH 1/2] Use invariant.load for ldg --- src/device/pointer.jl | 52 ++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/src/device/pointer.jl b/src/device/pointer.jl index 0be5b0d4f4..c9d514c81e 100644 --- a/src/device/pointer.jl +++ b/src/device/pointer.jl @@ -15,29 +15,41 @@ const Local = 5 end -## ldg +@inline @generated function pointerref_ldg(ptr::LLVMPtr{T,A}, i::I, ::Val{align}) where {T,A,I,align} + sizeof(T) == 0 && return T.instance + LLVM.@dispose ctx=LLVM.Context() begin + eltyp = convert(LLVM.LLVMType, T) -const LDGTypes = (UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64, - Float32, Float64) + T_idx = convert(LLVM.LLVMType, I) + T_ptr = convert(LLVM.LLVMType, ptr) -# TODO: this functionality should throw Date: Thu, 13 Feb 2025 09:58:14 +0100 Subject: [PATCH 2/2] fixup! Use invariant.load for ldg --- src/device/pointer.jl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/device/pointer.jl b/src/device/pointer.jl index c9d514c81e..baa7709f04 100644 --- a/src/device/pointer.jl +++ b/src/device/pointer.jl @@ -78,9 +78,5 @@ end export unsafe_cached_load -unsafe_cached_load(p::LLVMPtr{<:Union{LDGTypes...},AS.Global}, i::Integer=1, align::Val=Val(1)) = - pointerref_ldg(p, i, align) -# NOTE: fall back to normal unsafe_load for unsupported types. we could be smarter here, -# e.g. destruct/load/reconstruct, but that's too complicated for what it's worth. unsafe_cached_load(p::LLVMPtr, i::Integer=1, align::Val=Val(1)) = - unsafe_load(p, i, align) + pointerref_ldg(p, i, align)