Skip to content

Conversation

maleadt
Copy link
Member

@maleadt maleadt commented Oct 7, 2025

Here I've added yet another interface method to intercept the module before optimization, but after deferred codegen. I use that to postpone the Metal kernel conversions until all modules are collected, making it possible to link deferred modules that use intrinsics rewritten by said conversions.

I'm considering doing this for more back-ends, because it saves us from rewriting the module multiple times. This would mean that more back-ends would start relying on the julia.kernel metadata to discover kernels in the linked module, rather than the interface method being called multiple times with each time a different entry::LLVM.Function being passed.

cc @vchuravy

@simeonschaub: this is so that initialize_rng_state can simply call intrinsics like thread_position_in_threadgroup_1d() instead of having to do the ugly argument decoding.

Copy link
Contributor

github-actions bot commented Oct 7, 2025

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/driver.jl b/src/driver.jl
index 950ea27..7808667 100644
--- a/src/driver.jl
+++ b/src/driver.jl
@@ -284,7 +284,7 @@ const __llvm_initialized = Ref(false)
             end
 
             # minimal optimization to convert the inttoptr/call into a direct call
-            @dispose pb=NewPMPassBuilder() begin
+            @dispose pb = NewPMPassBuilder() begin
                 add!(pb, NewPMFunctionPassManager()) do fpm
                     add!(fpm, InstCombinePass())
                 end
@@ -355,7 +355,7 @@ const __llvm_initialized = Ref(false)
                     # which also need to happen _after_ regular optimization.
                     # XXX: make these part of the optimizer pipeline?
                     if has_deferred_jobs
-                        @dispose pb=NewPMPassBuilder() begin
+                        @dispose pb = NewPMPassBuilder() begin
                             add!(pb, NewPMFunctionPassManager()) do fpm
                                 add!(fpm, InstCombinePass())
                             end
diff --git a/src/irgen.jl b/src/irgen.jl
index 2d36315..39e2e54 100644
--- a/src/irgen.jl
+++ b/src/irgen.jl
@@ -950,6 +950,7 @@ function add_input_arguments!(@nospecialize(job::CompilerJob), mod::LLVM.Module,
                     error("Don't know how to check uses of $candidate. Please file an issue.")
                 end
             end
+            return
         end
         for f in worklist
             scan_uses(f)

@maleadt maleadt changed the title Net interface: process_linked_module! New interface: process_linked_module! Oct 7, 2025
simeonschaub added a commit to JuliaGPU/OpenCL.jl that referenced this pull request Oct 7, 2025
simeonschaub added a commit to JuliaGPU/OpenCL.jl that referenced this pull request Oct 7, 2025
@simeonschaub
Copy link
Member

This looks great, thanks! I can make use of this in JuliaGPU/OpenCL.jl#365 as well and simplify some things

@maleadt
Copy link
Member Author

maleadt commented Oct 7, 2025

The whole set of interfaces is becoming a bit of a mess though. Probably warrants a breaking release at some point to clean some things up, but seeing how this PR is nonbreaking I propose we do that another time.

Copy link

codecov bot commented Oct 7, 2025

Codecov Report

❌ Patch coverage is 98.43750% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 73.73%. Comparing base (aab6333) to head (1722ae3).
⚠️ Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
src/irgen.jl 94.11% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #727      +/-   ##
==========================================
- Coverage   75.00%   73.73%   -1.28%     
==========================================
  Files          24       24              
  Lines        3613     3636      +23     
==========================================
- Hits         2710     2681      -29     
- Misses        903      955      +52     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maleadt maleadt merged commit 070406e into master Oct 7, 2025
34 checks passed
@maleadt maleadt deleted the tb/linked_module branch October 7, 2025 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants