GPUCompiler.jl icon indicating copy to clipboard operation
GPUCompiler.jl copied to clipboard

Imaging-mode PLT codegen and relocatable TLS

Open joelreymont opened this issue 1 month ago • 5 comments

  • Enable imaging-mode PLT lookups only on Julia versions that expose use_jlplt, preserving older compat.
  • Make StaticCompiler host targets emit relocatable TLS getters by rewriting intrinsic and inttoptr forms and ensuring the pass runs after upstream transforms.
  • Update docs and fix the native ccall test message match.
  • Tests: julia --project -q -e 'using Pkg; Pkg.test()'.

These changes are required for runtime-linked StaticCompiler targets. Without these GPUCompiler patches, executables that link the Julia runtime would bake absolute TLS addresses and crash at startup.

joelreymont avatar Nov 23 '25 06:11 joelreymont

Your PR requires formatting changes to meet the project's style guidelines. Please consider running Runic (git runic master) to apply these changes.

Click here to view the suggested changes.
diff --git a/src/execution.jl b/src/execution.jl
index 22dd592..c37f264 100644
--- a/src/execution.jl
+++ b/src/execution.jl
@@ -280,11 +280,11 @@ end
                 error(
                     """Did not find CodeInstance for $job.
 
-                    Pleaase make sure that the `compiler` function passed to `cached_compilation`
-                    invokes GPUCompiler with exactly the same configuration as passed to the API.
+                                        Pleaase make sure that the `compiler` function passed to `cached_compilation`
+                                        invokes GPUCompiler with exactly the same configuration as passed to the API.
 
-                    Note that you should do this by calling `GPUCompiler.compile`, and not by
-                    using reflection functions (which alter the compiler configuration)."""
+                                        Note that you should do this by calling `GPUCompiler.compile`, and not by
+                                        using reflection functions (which alter the compiler configuration)."""
                 )
             end
             key = (ci, cfg)
diff --git a/src/ptx.jl b/src/ptx.jl
index 0a340b9..f4ae4bd 100644
--- a/src/ptx.jl
+++ b/src/ptx.jl
@@ -459,8 +459,8 @@ function nvvm_reflect!(fun::LLVM.Function)
             end
             if !isa(sym, LLVM.GlobalVariable)
                 @safe_error """Unrecognized format of __nvvm_reflect call:
-                $(string(call))
-                Operand should be a global variable, got a $(typeof(sym)). Please file an issue."""
+                                $(string(call))
+                                Operand should be a global variable, got a $(typeof(sym)). Please file an issue."""
                 continue
             end
             sym_op = operands(sym)[1]
diff --git a/test/helpers/test.jl b/test/helpers/test.jl
index 8e9c996..432e246 100644
--- a/test/helpers/test.jl
+++ b/test/helpers/test.jl
@@ -22,17 +22,17 @@ end
 @inline @generated function sink(i::T, ::Val{addrspace} = Val(0)) where {T <: Union{Int32, UInt32}, addrspace}
     as_str = addrspace > 0 ? " addrspace($addrspace)" : ""
     llvmcall_str = """%slot = alloca i32$(addrspace > 0 ? ", addrspace($addrspace)" : "")
-    store volatile i32 %0, i32$(as_str)* %slot
-    %value = load volatile i32, i32$(as_str)* %slot
-    ret i32 %value"""
+        store volatile i32 %0, i32$(as_str)* %slot
+        %value = load volatile i32, i32$(as_str)* %slot
+        ret i32 %value"""
     return :(Base.llvmcall($llvmcall_str, T, Tuple{T}, i))
 end
 @inline @generated function sink(i::T, ::Val{addrspace} = Val(0)) where {T <: Union{Int64, UInt64}, addrspace}
     as_str = addrspace > 0 ? " addrspace($addrspace)" : ""
     llvmcall_str = """%slot = alloca i64$(addrspace > 0 ? ", addrspace($addrspace)" : "")
-    store volatile i64 %0, i64$(as_str)* %slot
-    %value = load volatile i64, i64$(as_str)* %slot
-    ret i64 %value"""
+        store volatile i64 %0, i64$(as_str)* %slot
+        %value = load volatile i64, i64$(as_str)* %slot
+        ret i64 %value"""
     return :(Base.llvmcall($llvmcall_str, T, Tuple{T}, i))
 end
 
@@ -112,10 +112,10 @@ module FileCheck
             seekstart(output_io)
             filecheck_io = Pipe()
             cmd = ```$(filecheck_exe())
-            --color
-            --allow-unused-prefixes
-            --check-prefixes $(join(prefixes, ','))
-            $path```
+                        --color
+                        --allow-unused-prefixes
+                        --check-prefixes $(join(prefixes, ','))
+                        $path```
             proc = run(pipeline(ignorestatus(cmd); stdin = output_io, stdout = filecheck_io, stderr = filecheck_io); wait = false)
             close(filecheck_io.in)
 
diff --git a/test/native.jl b/test/native.jl
index c6d9916..db8418b 100644
--- a/test/native.jl
+++ b/test/native.jl
@@ -388,15 +388,15 @@ end
             Base.llvmcall(
                 (
                     """
-                    declare void @barrier() #1
+                                        declare void @barrier() #1
 
-                    define void @entry() #0 {
-                        call void @barrier()
-                        ret void
-                    }
+                                        define void @entry() #0 {
+                                            call void @barrier()
+                                            ret void
+                                        }
 
-                    attributes #0 = { alwaysinline }
-                    attributes #1 = { convergent }""", "entry",
+                                        attributes #0 = { alwaysinline }
+                                        attributes #1 = { convergent }""", "entry",
                 ),
                 Nothing, Tuple{}
             )

github-actions[bot] avatar Nov 23 '25 06:11 github-actions[bot]

Could you for review undo the formatting commit? We haven't transitioned the entire repo and so there are lots of unrelated stuff that makes it harder to review your actual changes.

vchuravy avatar Nov 24 '25 16:11 vchuravy

I wonder if this is an AI-generated pull request, without human review. This is based on their other pull requests to many different projects.

See say https://github.com/ocaml/ocaml/pull/14369#issuecomment-3557328285

matkoniecz avatar Nov 27 '25 19:11 matkoniecz

See also https://github.com/tshort/StaticCompiler.jl/pull/180

gdalle avatar Nov 28 '25 08:11 gdalle

Yes, that Julia PR requires this one.

joelreymont avatar Nov 28 '25 09:11 joelreymont