Skip to content
This repository was archived by the owner on May 27, 2021. It is now read-only.

Commit fe9ba9b

Browse files
committed
Remove 265 hacks.
1 parent f014b84 commit fe9ba9b

File tree

4 files changed

+28
-54
lines changed

4 files changed

+28
-54
lines changed

.gitlab-ci.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ variables:
44

55
include:
66
- 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v4/common.yml'
7-
- 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v4/test_v1.1.yml'
8-
- 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v4/test_v1.2.yml'
7+
- 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v4/test_v1.3.yml'
98
- 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v4/test_dev.yml'
10-
- 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v4/coverage_v1.1.yml'
11-
- 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v4/documentation_v1.1.yml'
9+
- 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v4/coverage_v1.3.yml'
10+
- 'https://raw.githubusercontent.com/JuliaGPU/gitlab-ci/master/templates/v4/documentation_v1.3.yml'
1211

1312
test:dev:
1413
allow_failure: true
@@ -30,7 +29,7 @@ pages:
3029

3130
cuarrays:
3231
stage: test
33-
image: "juliagpu/julia:v1.1-cuda"
32+
image: "juliagpu/julia:v1.3-cuda"
3433
script:
3534
- mkdir $JULIA_DEPOT_PATH # Pkg.jl#325
3635
- julia -e 'using Pkg;

src/context.jl

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# contextual dispatch using Cassette.jl
1+
##
2+
# Implements contextual dispatch through Cassette.jl
3+
# Goals:
4+
# - Rewrite common CPU functions to appropriate GPU intrinsics
25
#
36
# TODO:
47
# - error (erf, ...)
@@ -12,50 +15,23 @@
1215

1316
using Cassette
1417

15-
@inline unknowably_false() = Base.llvmcall("ret i8 0", Bool, Tuple{})
18+
function transform(ctx, ref)
19+
CI = ref.code_info
20+
noinline = any(@nospecialize(x) ->
21+
Core.Compiler.isexpr(x, :meta) &&
22+
x.args[1] == :noinline,
23+
CI.code)
24+
CI.inlineable = !noinline
1625

17-
function generate_transform(method_redefinitions)
18-
return function transform(ctx, ref)
19-
CI = ref.code_info
20-
21-
# inline everything
22-
noinline = any(@nospecialize(x) ->
23-
Core.Compiler.isexpr(x, :meta) &&
24-
x.args[1] == :noinline,
25-
CI.code)
26-
CI.inlineable = !noinline
27-
28-
if method_redefinitions
29-
# 265 fix, insert a call to the original method
30-
# that we later will remove with LLVM's DCE
31-
# TODO: We also don't want to compile these functions
32-
unknowably_false = GlobalRef(@__MODULE__, :unknowably_false)
33-
Cassette.insert_statements!(CI.code, CI.codelocs,
34-
(x, i) -> i == 1 ? 4 : nothing,
35-
(x, i) -> i == 1 ? [
36-
Expr(:call, Expr(:nooverdub, unknowably_false)),
37-
Expr(:gotoifnot, Core.SSAValue(i), i+3),
38-
Expr(:call, Expr(:nooverdub, Core.SlotNumber(1)), (Core.SlotNumber(i) for i in 2:ref.method.nargs)...),
39-
x] : nothing)
40-
end
41-
CI.ssavaluetypes = length(CI.code)
42-
43-
#Core.Compiler.validate_code(CI)
44-
return CI
45-
end
26+
CI.ssavaluetypes = length(CI.code)
27+
# Core.Compiler.validate_code(CI)
28+
return CI
4629
end
4730

48-
const StaticPass = Cassette.@pass generate_transform(false)
49-
const InteractivePass = Cassette.@pass generate_transform(true)
31+
const InlinePass = Cassette.@pass transform
5032

5133
Cassette.@context CUDACtx
52-
const StaticCtx = Cassette.disablehooks(CUDACtx(pass = StaticPass))
53-
const InteractiveCtx = Cassette.disablehooks(CUDACtx(pass = InteractivePass))
54-
55-
@inline function contextualize(f::F, interactive) where F
56-
ctx = interactive ? InteractiveCtx : StaticCtx
57-
(args...) -> Cassette.overdub(ctx, f, args...)
58-
end
34+
const cudactx = Cassette.disablehooks(CUDACtx(pass = InlinePass))
5935

6036
###
6137
# Cassette fixes
@@ -95,3 +71,6 @@ for f in (:cos, :cospi, :sin, :sinpi, :tan,
9571
return CUDAnative.$f(x)
9672
end
9773
end
74+
75+
contextualize(f::F) where F = (args...) -> Cassette.overdub(cudactx, f, args...)
76+

src/execution.jl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export @cuda, cudaconvert, cufunction, dynamic_cufunction, nearest_warpsize
88
# split keyword arguments to `@cuda` into ones affecting the macro itself, the compiler and
99
# the code it generates, or the execution
1010
function split_kwargs(kwargs)
11-
macro_kws = [:dynamic, :interactive]
11+
macro_kws = [:dynamic]
1212
compiler_kws = [:minthreads, :maxthreads, :blocks_per_sm, :maxregs, :name]
1313
call_kws = [:cooperative, :blocks, :threads, :config, :shmem, :stream]
1414
macro_kwargs = []
@@ -138,15 +138,11 @@ macro cuda(ex...)
138138

139139
# handle keyword arguments that influence the macro's behavior
140140
dynamic = false
141-
interactive = isinteractive()
142141
for kwarg in macro_kwargs
143142
key,val = kwarg.args
144143
if key == :dynamic
145144
isa(val, Bool) || throw(ArgumentError("`dynamic` keyword argument to @cuda should be a constant value"))
146145
dynamic = val::Bool
147-
elseif key == :interactive
148-
isa(val, Bool) || throw(ArgumentError("`interactive` keyword argument to @cuda should be a constant value"))
149-
interactive = val::Bool
150146
else
151147
throw(ArgumentError("Unsupported keyword argument '$key'"))
152148
end
@@ -163,7 +159,7 @@ macro cuda(ex...)
163159
quote
164160
# we're in kernel land already, so no need to cudaconvert arguments
165161
local kernel_tt = Tuple{$((:(Core.Typeof($var)) for var in var_exprs)...)}
166-
local kernel_f = contextualize($(esc(f)), $interactive)
162+
local kernel_f = contextualize($(esc(f)))
167163
local kernel = dynamic_cufunction(kernel_f, kernel_tt)
168164
kernel($(var_exprs...); $(map(esc, call_kwargs)...))
169165
end)
@@ -177,7 +173,7 @@ macro cuda(ex...)
177173
GC.@preserve $(vars...) begin
178174
local kernel_args = cudaconvert.(($(var_exprs...),))
179175
local kernel_tt = Tuple{Core.Typeof.(kernel_args)...}
180-
local kernel_f = contextualize($(esc(f)), $interactive)
176+
local kernel_f = contextualize($(esc(f)))
181177
local kernel = cufunction(kernel_f, kernel_tt;
182178
$(map(esc, compiler_kwargs)...))
183179
kernel(kernel_args...; $(map(esc, call_kwargs)...))

test/device/execution.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,15 @@ end
308308
return
309309
end
310310

311-
@cuda interactive=true kernel(convert(CuPtr{Int}, arr.buf))
311+
@cuda kernel(convert(CuPtr{Int}, arr.buf))
312312
@test Array(arr)[] == 1
313313

314314
function kernel(ptr)
315315
unsafe_store!(ptr, 2)
316316
return
317317
end
318318

319-
@cuda interactive=true kernel(convert(CuPtr{Int}, arr.buf))
319+
@cuda kernel(convert(CuPtr{Int}, arr.buf))
320320
@test Array(arr)[] == 2
321321
end
322322

0 commit comments

Comments
 (0)