Skip to content

Commit 06469fa

Browse files
authored
Merge pull request #140 from JuliaGPU/codetyped_interactive
@ka_code_typed interactive mode
2 parents 20e3bb6 + f87bcf1 commit 06469fa

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
1111
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
1212
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
1313
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
14+
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
1415

1516
[compat]
1617
Adapt = "0.4, 1.0, 2.0"

src/reflection.jl

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import InteractiveUtils
22
export @ka_code_typed
33
using CUDA
44

5-
function ka_code_typed(kernel, argtypes; ndrange=nothing, workgroupsize=nothing, dependencies=nothing, kwargs...)
5+
using UUIDs
6+
const Cthulhu = Base.PkgId(UUID("f68482b8-f384-11e8-15f7-abe071a5a75f"), "Cthulhu")
7+
8+
function ka_code_typed(kernel, argtypes; ndrange=nothing, workgroupsize=nothing, dependencies=nothing, interactive=false, kwargs...)
69
# get the iterspace and dynamic of a kernel
710
ndrange, workgroupsize, iterspace, dynamic = KernelAbstractions.launch_config(kernel, ndrange, workgroupsize)
811

@@ -19,7 +22,15 @@ function ka_code_typed(kernel, argtypes; ndrange=nothing, workgroupsize=nothing,
1922
argtypes = argtypes.parameters
2023
end
2124
# use code_typed
22-
return InteractiveUtils.code_typed(KernelAbstractions.Cassette.overdub, (typeof(ctx), typeof(kernel.f), argtypes...); kwargs...)
25+
if interactive
26+
# call Cthulhu without introducing a dependency on Cthulhu
27+
mod = Base.get(Base.loaded_modules, Cthulhu, nothing)
28+
mod===nothing && error("Interactive code reflection requires Cthulhu; please install and load this package first.")
29+
descend_code_typed = getfield(mod, :descend_code_typed)
30+
return descend_code_typed(KernelAbstractions.Cassette.overdub, (typeof(ctx), typeof(kernel.f), argtypes...); kwargs...)
31+
else
32+
return InteractiveUtils.code_typed(KernelAbstractions.Cassette.overdub, (typeof(ctx), typeof(kernel.f), argtypes...); kwargs...)
33+
end
2334
end
2435

2536

@@ -32,6 +43,10 @@ Get the typed IR for a kernel
3243
@ka_code_typed kernel(args. ndrange=... workgroupsize=...)
3344
@ka_code_typed optimize=false kernel(args. ndrange=...)
3445
```
46+
To use interactive mode (with Cthulhu), call
47+
```
48+
@ka_code_typed interactive=true kernel(args. ndrange=...)
49+
```
3550
If ndrange is statically defined, then you could call
3651
```
3752
@ka_code_typed kernel(args.)

0 commit comments

Comments
 (0)