Skip to content

Commit 4ee5b78

Browse files
committed
fix formatting
1 parent eb57cb1 commit 4ee5b78

File tree

6 files changed

+310
-232
lines changed

6 files changed

+310
-232
lines changed

src/pocl/compiler/compilation.jl

+11-9
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22

33
struct OpenCLCompilerParams <: AbstractCompilerParams end
44
const OpenCLCompilerConfig = CompilerConfig{SPIRVCompilerTarget, OpenCLCompilerParams}
5-
const OpenCLCompilerJob = CompilerJob{SPIRVCompilerTarget,OpenCLCompilerParams}
5+
const OpenCLCompilerJob = CompilerJob{SPIRVCompilerTarget, OpenCLCompilerParams}
66

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

99
GPUCompiler.method_table(::OpenCLCompilerJob) = method_table
1010

1111
# filter out OpenCL built-ins
1212
# TODO: eagerly lower these using the translator API
1313
GPUCompiler.isintrinsic(job::OpenCLCompilerJob, fn::String) =
14-
invoke(GPUCompiler.isintrinsic,
15-
Tuple{CompilerJob{SPIRVCompilerTarget}, typeof(fn)},
16-
job, fn) ||
14+
invoke(
15+
GPUCompiler.isintrinsic,
16+
Tuple{CompilerJob{SPIRVCompilerTarget}, typeof(fn)},
17+
job, fn
18+
) ||
1719
in(fn, opencl_builtins)
1820

1921

@@ -42,14 +44,14 @@ function compiler_config(dev::cl.Device; kwargs...)
4244
end
4345
return config
4446
end
45-
@noinline function _compiler_config(dev; kernel=true, name=nothing, always_inline=false, kwargs...)
47+
@noinline function _compiler_config(dev; kernel = true, name = nothing, always_inline = false, kwargs...)
4648
supports_fp16 = "cl_khr_fp16" in dev.extensions
4749
supports_fp64 = "cl_khr_fp64" in dev.extensions
4850

4951
# create GPUCompiler objects
5052
target = SPIRVCompilerTarget(; supports_fp16, supports_fp64, kwargs...)
5153
params = OpenCLCompilerParams()
52-
CompilerConfig(target, params; kernel, name, always_inline)
54+
return CompilerConfig(target, params; kernel, name, always_inline)
5355
end
5456

5557
# compile to executable machine code
@@ -59,7 +61,7 @@ function compile(@nospecialize(job::CompilerJob))
5961
GPUCompiler.compile(:obj, job)
6062
end
6163

62-
(;obj, entry=LLVM.name(meta.entry))
64+
return (; obj, entry = LLVM.name(meta.entry))
6365
end
6466

6567
# link into an executable kernel
@@ -70,5 +72,5 @@ function link(@nospecialize(job::CompilerJob), compiled)
7072
error("Your device does not support SPIR-V, which is currently required for native execution.")
7173
end
7274
cl.build!(prog)
73-
cl.Kernel(prog, compiled.entry)
75+
return cl.Kernel(prog, compiled.entry)
7476
end

src/pocl/compiler/execution.jl

+36-30
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const LAUNCH_KWARGS = [:global_size, :local_size, :queue]
99

1010
macro opencl(ex...)
1111
call = ex[end]
12-
kwargs = map(ex[1:end-1]) do kwarg
12+
kwargs = map(ex[1:(end - 1)]) do kwarg
1313
if kwarg isa Symbol
1414
:($kwarg = $kwarg)
1515
elseif Meta.isexpr(kwarg, :(=))
@@ -31,14 +31,14 @@ macro opencl(ex...)
3131
macro_kwargs, compiler_kwargs, call_kwargs, other_kwargs =
3232
split_kwargs(kwargs, MACRO_KWARGS, COMPILER_KWARGS, LAUNCH_KWARGS)
3333
if !isempty(other_kwargs)
34-
key,val = first(other_kwargs).args
34+
key, val = first(other_kwargs).args
3535
throw(ArgumentError("Unsupported keyword argument '$key'"))
3636
end
3737

3838
# handle keyword arguments that influence the macro's behavior
3939
launch = true
4040
for kwarg in macro_kwargs
41-
key,val = kwarg.args
41+
key, val = kwarg.args
4242
if key == :launch
4343
isa(val, Bool) || throw(ArgumentError("`launch` keyword argument to @opencl should be a constant value"))
4444
launch = val::Bool
@@ -56,7 +56,8 @@ macro opencl(ex...)
5656

5757
# convert the arguments, call the compiler and launch the kernel
5858
# while keeping the original arguments alive
59-
push!(code.args,
59+
push!(
60+
code.args,
6061
quote
6162
$f_var = $f
6263
GC.@preserve $(vars...) $f_var begin
@@ -69,13 +70,16 @@ macro opencl(ex...)
6970
end
7071
$kernel
7172
end
72-
end)
73+
end
74+
)
7375

74-
return esc(quote
75-
let
76-
$code
76+
return esc(
77+
quote
78+
let
79+
$code
80+
end
7781
end
78-
end)
82+
)
7983
end
8084

8185

@@ -101,21 +105,23 @@ end
101105
# Base.RefValue isn't GPU compatible, so provide a compatible alternative
102106
# TODO: port improvements from CUDA.jl
103107
struct CLRefValue{T} <: Ref{T}
104-
x::T
108+
x::T
105109
end
106110
Base.getindex(r::CLRefValue) = r.x
107111
Adapt.adapt_structure(to::KernelAdaptor, r::Base.RefValue) = CLRefValue(adapt(to, r[]))
108112

109113
# broadcast sometimes passes a ref(type), resulting in a GPU-incompatible DataType box.
110114
# avoid that by using a special kind of ref that knows about the boxed type.
111115
struct CLRefType{T} <: Ref{DataType} end
112-
Base.getindex(r::CLRefType{T}) where T = T
113-
Adapt.adapt_structure(to::KernelAdaptor, r::Base.RefValue{<:Union{DataType,Type}}) =
116+
Base.getindex(r::CLRefType{T}) where {T} = T
117+
Adapt.adapt_structure(to::KernelAdaptor, r::Base.RefValue{<:Union{DataType, Type}}) =
114118
CLRefType{r[]}()
115119

116120
# case where type is the function being broadcasted
117-
Adapt.adapt_structure(to::KernelAdaptor,
118-
bc::Broadcast.Broadcasted{Style, <:Any, Type{T}}) where {Style, T} =
121+
Adapt.adapt_structure(
122+
to::KernelAdaptor,
123+
bc::Broadcast.Broadcasted{Style, <:Any, Type{T}}
124+
) where {Style, T} =
119125
Broadcast.Broadcasted{Style}((x...) -> T(x...), adapt(to, bc.args), bc.axes)
120126

121127
"""
@@ -131,29 +137,30 @@ register methods for the the `OpenCL.KernelAdaptor` type.
131137
The `pointers` argument is used to collect pointers to indirect SVM buffers, which need to
132138
be registered with OpenCL before invoking the kernel.
133139
"""
134-
function clconvert(arg, pointers::Vector{Ptr{Cvoid}}=Ptr{Cvoid}[])
135-
adapt(KernelAdaptor(pointers), arg)
140+
function clconvert(arg, pointers::Vector{Ptr{Cvoid}} = Ptr{Cvoid}[])
141+
return adapt(KernelAdaptor(pointers), arg)
136142
end
137143

138144

139-
140145
## abstract kernel functionality
141146

142-
abstract type AbstractKernel{F,TT} end
147+
abstract type AbstractKernel{F, TT} end
143148

144-
@inline @generated function (kernel::AbstractKernel{F,TT})(args...;
145-
call_kwargs...) where {F,TT}
149+
@inline @generated function (kernel::AbstractKernel{F, TT})(
150+
args...;
151+
call_kwargs...
152+
) where {F, TT}
146153
sig = Tuple{F, TT.parameters...} # Base.signature_type with a function type
147-
args = (:(kernel.f), (:( clconvert(args[$i], svm_pointers) ) for i in 1:length(args))...)
154+
args = (:(kernel.f), (:(clconvert(args[$i], svm_pointers)) for i in 1:length(args))...)
148155

149156
# filter out ghost arguments that shouldn't be passed
150157
predicate = dt -> GPUCompiler.isghosttype(dt) || Core.Compiler.isconstType(dt)
151158
to_pass = map(!predicate, sig.parameters)
152-
call_t = Type[x[1] for x in zip(sig.parameters, to_pass) if x[2]]
153-
call_args = Union{Expr,Symbol}[x[1] for x in zip(args, to_pass) if x[2]]
159+
call_t = Type[x[1] for x in zip(sig.parameters, to_pass) if x[2]]
160+
call_args = Union{Expr, Symbol}[x[1] for x in zip(args, to_pass) if x[2]]
154161

155162
# replace non-isbits arguments (they should be unused, or compilation would have failed)
156-
for (i,dt) in enumerate(call_t)
163+
for (i, dt) in enumerate(call_t)
157164
if !isbitstype(dt)
158165
call_t[i] = Ptr{Any}
159166
call_args[i] = :C_NULL
@@ -163,17 +170,16 @@ abstract type AbstractKernel{F,TT} end
163170
# finalize types
164171
call_tt = Base.to_tuple_type(call_t)
165172

166-
quote
173+
return quote
167174
svm_pointers = Ptr{Cvoid}[]
168175
$cl.clcall(kernel.fun, $call_tt, $(call_args...); svm_pointers, call_kwargs...)
169176
end
170177
end
171178

172179

173-
174180
## host-side kernels
175181

176-
struct HostKernel{F,TT} <: AbstractKernel{F,TT}
182+
struct HostKernel{F, TT} <: AbstractKernel{F, TT}
177183
f::F
178184
fun::cl.Kernel
179185
end
@@ -183,7 +189,7 @@ end
183189

184190
const clfunction_lock = ReentrantLock()
185191

186-
function clfunction(f::F, tt::TT=Tuple{}; kwargs...) where {F,TT}
192+
function clfunction(f::F, tt::TT = Tuple{}; kwargs...) where {F, TT}
187193
ctx = context()
188194
dev = device()
189195

@@ -200,10 +206,10 @@ function clfunction(f::F, tt::TT=Tuple{}; kwargs...) where {F,TT}
200206
kernel = get(_kernel_instances, h, nothing)
201207
if kernel === nothing
202208
# create the kernel state object
203-
kernel = HostKernel{F,tt}(f, fun)
209+
kernel = HostKernel{F, tt}(f, fun)
204210
_kernel_instances[h] = kernel
205211
end
206-
return kernel::HostKernel{F,tt}
212+
return kernel::HostKernel{F, tt}
207213
end
208214
end
209215

src/pocl/compiler/reflection.jl

+7-6
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,28 @@ for method in (:code_typed, :code_warntype, :code_llvm, :code_native)
2424
args = method == :code_typed ? (:job,) : (:io, :job)
2525

2626
@eval begin
27-
function $method(io::IO, @nospecialize(func), @nospecialize(types);
28-
kernel::Bool=false, kwargs...)
27+
function $method(
28+
io::IO, @nospecialize(func), @nospecialize(types);
29+
kernel::Bool = false, kwargs...
30+
)
2931
compiler_kwargs, kwargs = split_kwargs_runtime(kwargs, COMPILER_KWARGS)
3032
source = methodinstance(typeof(func), Base.to_tuple_type(types))
3133
config = compiler_config(device(); kernel, compiler_kwargs...)
3234
job = CompilerJob(source, config)
33-
GPUCompiler.$method($(args...); kwargs...)
35+
return GPUCompiler.$method($(args...); kwargs...)
3436
end
3537
$method(@nospecialize(func), @nospecialize(types); kwargs...) =
3638
$method(stdout, func, types; kwargs...)
3739
end
3840
end
3941

4042

41-
4243
#
4344
# @device_code_* functions
4445
#
4546

4647
export @device_code_lowered, @device_code_typed, @device_code_warntype, @device_code_llvm,
47-
@device_code_native, @device_code
48+
@device_code_native, @device_code
4849

4950
# forward to GPUCompiler
5051
@eval $(Symbol("@device_code_lowered")) = $(getfield(GPUCompiler, Symbol("@device_code_lowered")))
@@ -70,5 +71,5 @@ function return_type(@nospecialize(func), @nospecialize(tt))
7071
job = CompilerJob(source, config)
7172
interp = GPUCompiler.get_interpreter(job)
7273
sig = Base.signature_type(func, tt)
73-
Core.Compiler.return_type(interp, sig)
74+
return Core.Compiler.return_type(interp, sig)
7475
end

0 commit comments

Comments
 (0)