Skip to content

Use stacked method tables #615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ pocl_jll = "7"
EnzymeCore = "f151be2c-9106-41f4-ab19-57ee4f262869"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[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"}
4 changes: 2 additions & 2 deletions src/pocl/compiler/compilation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const OpenCLCompilerJob = CompilerJob{SPIRVCompilerTarget, OpenCLCompilerParams}

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

GPUCompiler.method_table(::OpenCLCompilerJob) = method_table
GPUCompiler.method_table_view(job::OpenCLCompilerJob) = GPUCompiler.StackedMethodTable(job.world, method_table, spirv_method_table)

# filter out OpenCL built-ins
# TODO: eagerly lower these using the translator API
Expand Down Expand Up @@ -50,7 +50,7 @@ end


# create GPUCompiler objects
target = SPIRVCompilerTarget(; supports_fp16, supports_fp64, version = v"1.2", kwargs...)
target = SPIRVCompilerTarget(; supports_fp16, supports_fp64, validate = true, kwargs...)
params = OpenCLCompilerParams()
return CompilerConfig(target, params; kernel, name, always_inline)
end
Expand Down
32 changes: 32 additions & 0 deletions src/pocl/pocl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,42 @@ using GPUCompiler
import LLVM
using Adapt

## device overrides

# local method table for device functions
Base.Experimental.@MethodTable(method_table)

macro device_override(ex)
return 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

return esc(
quote
$(ExprTools.combinedef(def))
@device_override $ex
end
)
end

import SPIRVIntrinsics
SPIRVIntrinsics.@import_all
SPIRVIntrinsics.@reexport_public

const spirv_method_table = SPIRVIntrinsics.method_table

include("compiler/compilation.jl")
include("compiler/execution.jl")
include("compiler/reflection.jl")
Expand Down
Loading