From 8c833a834c11b90c2167ce3adc204ac4a652d18c Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Tue, 17 Jun 2025 12:04:56 +0200 Subject: [PATCH 1/3] Use stacked method tables --- Project.toml | 4 ++++ src/compiler/compilation.jl | 2 +- src/oneAPI.jl | 30 ++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 3699e4d9..e9290542 100644 --- a/Project.toml +++ b/Project.toml @@ -49,3 +49,7 @@ oneAPI_Support_jll = "0.8" [extras] libigc_jll = "94295238-5935-5bd7-bb0f-b00942e9bdd5" + +[sources] +GPUCompiler = {url="https://github.com/JuliaGPU/GPUCompiler.jl", rev="vc/mtv"} +SPIRVIntrinsics = {url="https://github/JuliaGPU/OpenCL.jl", rev="vc/mtv", subdir="lib/intrinsics"} \ No newline at end of file diff --git a/src/compiler/compilation.jl b/src/compiler/compilation.jl index 5fbcb9c9..823cb4fd 100644 --- a/src/compiler/compilation.jl +++ b/src/compiler/compilation.jl @@ -6,7 +6,7 @@ const oneAPICompilerJob = CompilerJob{SPIRVCompilerTarget,oneAPICompilerParams} GPUCompiler.runtime_module(::oneAPICompilerJob) = oneAPI -GPUCompiler.method_table(::oneAPICompilerJob) = method_table +GPUCompiler.method_table_view(job::oneAPICompilerJob) = GPUCompiler.StackedMethodTable(job.world, method_table, spirv_method_table) # filter out OpenCL built-ins # TODO: eagerly lower these using the translator API diff --git a/src/oneAPI.jl b/src/oneAPI.jl index afb9bc15..efe7381a 100644 --- a/src/oneAPI.jl +++ b/src/oneAPI.jl @@ -25,10 +25,40 @@ include("../lib/level-zero/oneL0.jl") using .oneL0 functional() = oneL0.functional[] + +## device overrides + +# local method table for device functions +Base.Experimental.@MethodTable(method_table) + +macro device_override(ex) + esc(quote + Base.Experimental.@overlay($method_table, $ex) + end) +end + +macro device_function(ex) + ex = macroexpand(__module__, ex) + def = ExprTools.splitdef(ex) + + # generate a function that errors + def[:body] = quote + error("This function is not intended for use on the CPU") + end + + esc(quote + $(ExprTools.combinedef(def)) + @device_override $ex + end) +end + # device functionality import SPIRVIntrinsics SPIRVIntrinsics.@import_all SPIRVIntrinsics.@reexport_public + +const spirv_method_table = SPIRVIntrinsics.method_table + include("device/runtime.jl") include("device/array.jl") include("device/quirks.jl") From 357c4d3062c587431945e321e17e14b908777f30 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Tue, 17 Jun 2025 12:12:00 +0200 Subject: [PATCH 2/3] fixup! Use stacked method tables --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index e9290542..f79f0b33 100644 --- a/Project.toml +++ b/Project.toml @@ -52,4 +52,4 @@ libigc_jll = "94295238-5935-5bd7-bb0f-b00942e9bdd5" [sources] GPUCompiler = {url="https://github.com/JuliaGPU/GPUCompiler.jl", rev="vc/mtv"} -SPIRVIntrinsics = {url="https://github/JuliaGPU/OpenCL.jl", rev="vc/mtv", subdir="lib/intrinsics"} \ No newline at end of file +SPIRVIntrinsics = {url="https://github.com/JuliaGPU/OpenCL.jl", rev="vc/mtv", subdir="lib/intrinsics"} From 154774547525ff01b7c0afcae5381be24725cff4 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Fri, 11 Jul 2025 10:22:49 +0200 Subject: [PATCH 3/3] cleanup --- Project.toml | 8 ++------ src/compiler/compilation.jl | 2 +- src/oneAPI.jl | 30 ++---------------------------- src/oneAPIKernels.jl | 2 +- 4 files changed, 6 insertions(+), 36 deletions(-) diff --git a/Project.toml b/Project.toml index f79f0b33..c2aa0b5b 100644 --- a/Project.toml +++ b/Project.toml @@ -33,13 +33,13 @@ Adapt = "4" CEnum = "0.4, 0.5" ExprTools = "0.1" GPUArrays = "11.2.1" -GPUCompiler = "1.5" +GPUCompiler = "1.6" GPUToolbox = "0.1, 0.2" KernelAbstractions = "0.9.1" LLVM = "6, 7, 8, 9" NEO_jll = "=24.26.30049" Preferences = "1" -SPIRVIntrinsics = "0.2" +SPIRVIntrinsics = "0.4" SPIRV_LLVM_Translator_jll = "20" SpecialFunctions = "1.3, 2" StaticArrays = "1" @@ -49,7 +49,3 @@ oneAPI_Support_jll = "0.8" [extras] libigc_jll = "94295238-5935-5bd7-bb0f-b00942e9bdd5" - -[sources] -GPUCompiler = {url="https://github.com/JuliaGPU/GPUCompiler.jl", rev="vc/mtv"} -SPIRVIntrinsics = {url="https://github.com/JuliaGPU/OpenCL.jl", rev="vc/mtv", subdir="lib/intrinsics"} diff --git a/src/compiler/compilation.jl b/src/compiler/compilation.jl index 823cb4fd..9593ad73 100644 --- a/src/compiler/compilation.jl +++ b/src/compiler/compilation.jl @@ -6,7 +6,7 @@ const oneAPICompilerJob = CompilerJob{SPIRVCompilerTarget,oneAPICompilerParams} GPUCompiler.runtime_module(::oneAPICompilerJob) = oneAPI -GPUCompiler.method_table_view(job::oneAPICompilerJob) = GPUCompiler.StackedMethodTable(job.world, method_table, spirv_method_table) +GPUCompiler.method_table_view(job::oneAPICompilerJob) = GPUCompiler.StackedMethodTable(job.world, method_table, SPIRVIntrinsics.method_table) # filter out OpenCL built-ins # TODO: eagerly lower these using the translator API diff --git a/src/oneAPI.jl b/src/oneAPI.jl index efe7381a..ab4da365 100644 --- a/src/oneAPI.jl +++ b/src/oneAPI.jl @@ -26,38 +26,12 @@ using .oneL0 functional() = oneL0.functional[] -## device overrides - -# local method table for device functions -Base.Experimental.@MethodTable(method_table) - -macro device_override(ex) - esc(quote - Base.Experimental.@overlay($method_table, $ex) - end) -end - -macro device_function(ex) - ex = macroexpand(__module__, ex) - def = ExprTools.splitdef(ex) - - # generate a function that errors - def[:body] = quote - error("This function is not intended for use on the CPU") - end - - esc(quote - $(ExprTools.combinedef(def)) - @device_override $ex - end) -end - # device functionality import SPIRVIntrinsics SPIRVIntrinsics.@import_all SPIRVIntrinsics.@reexport_public - -const spirv_method_table = SPIRVIntrinsics.method_table +# local method table for device functions +Base.Experimental.@MethodTable(method_table) include("device/runtime.jl") include("device/array.jl") diff --git a/src/oneAPIKernels.jl b/src/oneAPIKernels.jl index 66729b57..cd40d8d9 100644 --- a/src/oneAPIKernels.jl +++ b/src/oneAPIKernels.jl @@ -1,7 +1,7 @@ module oneAPIKernels using ..oneAPI -using ..oneAPI: @device_override +using ..oneAPI: @device_override, method_table import KernelAbstractions as KA