Skip to content

Commit 48c6bf9

Browse files
Merge pull request #512 from sivasathyaseeelan/gpu-pois_rand
GPU-compatible Poisson sampling
2 parents 200b54f + 361677d commit 48c6bf9

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

ext/JumpProcessesKernelAbstractionsExt.jl

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module JumpProcessesKernelAbstractionsExt
33
using JumpProcesses, SciMLBase
44
using KernelAbstractions, Adapt
55
using StaticArrays
6+
using PoissonRandom, Random
67

78
function SciMLBase.__solve(ensembleprob::SciMLBase.AbstractEnsembleProblem,
89
alg::SimpleTauLeaping,
@@ -131,7 +132,7 @@ end
131132

132133
# Poisson sampling
133134
@inbounds for k in 1:num_jumps
134-
counts[k] = poisson_rand(rate_cache[k])
135+
counts[k] = pois_rand(PoissonRandom.PassthroughRNG(), rate_cache[k])
135136
end
136137

137138
# Apply changes
@@ -208,16 +209,4 @@ function vectorized_solve(probs, prob::JumpProblem, alg::SimpleTauLeaping;
208209
return ts, us
209210
end
210211

211-
# GPU-compatible Poisson sampling
212-
@inline function poisson_rand(lambda::T) where {T}
213-
L = exp(-lambda)
214-
k = 0
215-
p = 1.0
216-
while p > L
217-
k += 1
218-
p *= rand(T)
219-
end
220-
return k - 1
221-
end
222-
223212
end

0 commit comments

Comments
 (0)