-
Notifications
You must be signed in to change notification settings - Fork 10
/
metadata.R
58 lines (40 loc) · 1.73 KB
/
metadata.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
library(Rllvm)
m = Module()
fc = Function("foo", VoidType, list(a = FloatType), m)
setMetadata(m, "nvvm.annotation", list(fc, "kernel", 1L))
md = getMetadata(m, "nvvm.annotation")
o = getOperands(md)
els = getOperands(o[[1]])
names(els)
# just exploring. These mean nothing.
#XXX These don't work - using a list()
message("These are not working properly")
setMetadata(m, "Rtypes", list("numeric", "integer", "logical"))
setMetadata(m, "Rvectors", list("numeric", 200L, "integer", 200L, "logical", 1L))
setMetadata(m, "Rvectors", list("abc", 2)) # numeric
# But when the value is a string, it does.
setMetadata(m, "Rtypes", 'numeric,integer,logical')
m
if(TRUE) {
library(RLLVMCompile)
Dnorm = function(x, mu = 0, sd = 1)
1/sqrt(2 * pi * sd^2) * exp( - .5*( (x-mu)/sd ) ^2)
fc = compileFunction(Dnorm, DoubleType, list(DoubleType, DoubleType, DoubleType), optimize = FALSE)
m = as(fc, "Module")
}
# The version that creates MDNode first and then calls addOperand segfaults.
# Probably something with the ArrayRef and it being released.
#################################################
# The rest is just as we were developing setMetadata() above.
if(FALSE) {
mdNode = getMetadata(m, "nvvm.annotation")
ctx = getContext(m)
setMetadata(m, mdNode, list(fc, "kernel", 1L), ctx)
mdNode = .Call("R_getOrInsertNamedMetadata", m, "nvvm.annotation")
ctx = getContext(m)
mdNode = .Call("R_getOrInsertNamedMetadata", m, "nvvm.annotation")
# Set directly
.Call("R_NamedMDNode_addOperand1", mdNode, list(fc, Rllvm:::mdString("kernel", ctx), createIntegerConstant(1L, ctx)), ctx)
vals = .Call("R_MDNode_get", ctx, list(fc, Rllvm:::mdString("kernel", ctx), createIntegerConstant(1L, ctx)))
.Call("R_NamedMDNode_addOperand", mdNode, vals)
}