Skip to content

Commit

Permalink
use Const to mark readonly arguments, so that we can use __ldg on t…
Browse files Browse the repository at this point in the history
…he GPU
  • Loading branch information
vchuravy committed Feb 6, 2018
1 parent bac8ce2 commit 6894fe4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/ad/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ forward!(i::BroadcastInstruction{<:Tuple{typeof(*),Any,Any}}) = invoke(forward!,
# multiple dispatch selects this implementation for fused benchmarks

function forward!(i::BroadcastInstruction)
f, input_values = first(i.input), value.(i.input[2:end])
f, _input_values = first(i.input), value.(i.input[2:end])
input_values = map(readonly, _input_values)
if isa(i.output, Tuple) # we have pre-cached memory we can reuse
output_variable, output_duals = i.output
dual_eval_broadcast!(f, output_duals, value(output_variable), input_values)
Expand Down Expand Up @@ -188,8 +189,9 @@ end

function backward!(i::BroadcastInstruction)
f, args = first(i.input), i.input[2:end]
output, output_duals = i.output
output_deriv = deriv(output)
output, _output_duals = i.output
output_duals = readonly(_output_duals)
output_deriv = readonly(deriv(output))
for (i, arg) in enumerate(args)
isa(arg, Variable) || continue
arg_deriv = deriv(arg)
Expand Down

0 comments on commit 6894fe4

Please sign in to comment.