Skip to content

Commit

Permalink
Detect intrinsic FP functions (instead of higher-level ones)
Browse files Browse the repository at this point in the history
  • Loading branch information
ffevotte committed Jun 22, 2019
1 parent 439a8cb commit b070980
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions src/overdub.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,37 @@ using Cassette

Cassette.@context CounterCtx;

ops = [
(:add32, +, Float32, Float32),
(:sub32, -, Float32, Float32),
(:mul32, *, Float32, Float32),
(:div32, /, Float32, Float32),
(:add64, +, Float64, Float64),
(:sub64, -, Float64, Float64),
(:mul64, *, Float64, Float64),
(:div64, /, Float64, Float64),
]
const ops = (
(:add32, Core.Intrinsics.add_float, Float32),
(:sub32, Core.Intrinsics.sub_float, Float32),
(:mul32, Core.Intrinsics.mul_float, Float32),
(:div32, Core.Intrinsics.div_float, Float32),
(:add64, Core.Intrinsics.add_float, Float64),
(:sub64, Core.Intrinsics.sub_float, Float64),
(:mul64, Core.Intrinsics.mul_float, Float64),
(:div64, Core.Intrinsics.div_float, Float64),
)

@eval mutable struct Counter
$((:($(op[1]) ::Int) for op in ops)...)
Counter() = new($((0 for _ in 1:length(ops))...))
end

for (name, op, typ1, typ2) in ops
@eval function Cassette.prehook(ctx::CounterCtx, op::typeof($op), a::$typ1, b::$typ2)
ctx.metadata.$name +=1
for typ1 in (Float32, Float64)
@eval function Cassette.prehook(ctx::CounterCtx,
op::Core.IntrinsicFunction,
::$typ1,
::$typ1)
$(Expr(:block,
(map(ops) do (name, op, typ2)
typ1 == typ2 || return :nothing
quote
if op == $op
ctx.metadata.$name += 1
return
end
end
end)...))
end
end

Expand Down

0 comments on commit b070980

Please sign in to comment.