File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,15 @@ struct ThreadSafeVarInfo{V<:AbstractVarInfo,L} <: AbstractVarInfo
9
9
logps:: L
10
10
end
11
11
function ThreadSafeVarInfo (vi:: AbstractVarInfo )
12
+ # In ThreadSafeVarInfo we use threadid() to index into the array of logp
13
+ # fields. This is not good practice --- see
14
+ # https://github.com/TuringLang/DynamicPPL.jl/issues/924 for a full
15
+ # explanation --- but it has worked okay so far.
16
+ # The use of nthreads()*2 here ensures that threadid() doesn't exceed
17
+ # the length of the logps array. Ideally, we would use maxthreadid(),
18
+ # but Mooncake can't differentiate through that. Empirically, nthreads()*2
19
+ # seems to provide an upper bound to maxthreadid(), so we use that here.
20
+ # See https://github.com/TuringLang/DynamicPPL.jl/pull/936
12
21
return ThreadSafeVarInfo (
13
22
vi, [Ref (zero (getlogp (vi))) for _ in 1 : (Threads. nthreads () * 2 )]
14
23
)
You can’t perform that action at this time.
0 commit comments