@@ -2,7 +2,10 @@ import InteractiveUtils
2
2
export @ka_code_typed
3
3
using CUDA
4
4
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... )
6
9
# get the iterspace and dynamic of a kernel
7
10
ndrange, workgroupsize, iterspace, dynamic = KernelAbstractions. launch_config (kernel, ndrange, workgroupsize)
8
11
@@ -19,7 +22,15 @@ function ka_code_typed(kernel, argtypes; ndrange=nothing, workgroupsize=nothing,
19
22
argtypes = argtypes. parameters
20
23
end
21
24
# 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
23
34
end
24
35
25
36
@@ -32,6 +43,10 @@ Get the typed IR for a kernel
32
43
@ka_code_typed kernel(args. ndrange=... workgroupsize=...)
33
44
@ka_code_typed optimize=false kernel(args. ndrange=...)
34
45
```
46
+ To use interactive mode (with Cthulhu), call
47
+ ```
48
+ @ka_code_typed interactive=true kernel(args. ndrange=...)
49
+ ```
35
50
If ndrange is statically defined, then you could call
36
51
```
37
52
@ka_code_typed kernel(args.)
0 commit comments