Skip to content

Commit 3325e3e

Browse files
committed
Use stacked method tables
1 parent 60a17b5 commit 3325e3e

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

Project.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@ pocl_jll = "7"
5353
EnzymeCore = "f151be2c-9106-41f4-ab19-57ee4f262869"
5454
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
5555
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
56+
57+
[sources]
58+
GPUCompiler = {url="https://github.com/JuliaGPU/GPUCompiler.jl", rev="vc/mtv"}
59+
SPIRVIntrinsics = {url="https://github/JuliaGPU/OpenCL.jl", rev="vc/mtv", subdir="lib/intrinsics"}

src/pocl/compiler/compilation.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const OpenCLCompilerJob = CompilerJob{SPIRVCompilerTarget, OpenCLCompilerParams}
66

77
GPUCompiler.runtime_module(::CompilerJob{<:Any, OpenCLCompilerParams}) = POCL
88

9-
GPUCompiler.method_table(::OpenCLCompilerJob) = method_table
9+
GPUCompiler.method_table_view(job::OpenCLCompilerJob) = GPUCompiler.StackedMethodTable(job.world, method_table, spirv_method_table)
1010

1111
# filter out OpenCL built-ins
1212
# TODO: eagerly lower these using the translator API
@@ -50,7 +50,7 @@ end
5050

5151

5252
# create GPUCompiler objects
53-
target = SPIRVCompilerTarget(; supports_fp16, supports_fp64, version = v"1.2", kwargs...)
53+
target = SPIRVCompilerTarget(; supports_fp16, supports_fp64, validate = true, kwargs...)
5454
params = OpenCLCompilerParams()
5555
return CompilerConfig(target, params; kernel, name, always_inline)
5656
end

src/pocl/pocl.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,42 @@ using GPUCompiler
4444
import LLVM
4545
using Adapt
4646

47+
## device overrides
48+
49+
# local method table for device functions
50+
Base.Experimental.@MethodTable(method_table)
51+
52+
macro device_override(ex)
53+
return esc(
54+
quote
55+
Base.Experimental.@overlay($method_table, $ex)
56+
end
57+
)
58+
end
59+
60+
macro device_function(ex)
61+
ex = macroexpand(__module__, ex)
62+
def = ExprTools.splitdef(ex)
63+
64+
# generate a function that errors
65+
def[:body] = quote
66+
error("This function is not intended for use on the CPU")
67+
end
68+
69+
return esc(
70+
quote
71+
$(ExprTools.combinedef(def))
72+
@device_override $ex
73+
end
74+
)
75+
end
76+
4777
import SPIRVIntrinsics
4878
SPIRVIntrinsics.@import_all
4979
SPIRVIntrinsics.@reexport_public
5080

81+
const spirv_method_table = SPIRVIntrinsics.method_table
82+
5183
include("compiler/compilation.jl")
5284
include("compiler/execution.jl")
5385
include("compiler/reflection.jl")

0 commit comments

Comments
 (0)