Skip to content

Commit

Permalink
Fix multithreading offsets. Fixes #14.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriselrod committed May 11, 2021
1 parent 687e3fb commit 9ed8406
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "VectorizedRNG"
uuid = "33b4df10-0173-11e9-2a0c-851a7edac40e"
authors = ["Chris Elrod <elrodc@gmail.com>"]
version = "0.2.9"
version = "0.2.10"

[deps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Expand Down
47 changes: 14 additions & 33 deletions src/VectorizedRNG.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,46 +33,27 @@ include("xoshiro.jl")

const GLOBAL_vRNGs = Ref{Ptr{UInt64}}()

local_rng(i) = Xoshift{XREGISTERS}(i*4simd_integer_register_size()*XREGISTERS + GLOBAL_vRNGs[])

const RNG_MEM_SIZE = (5(simd_integer_register_size()*XREGISTERS + 2048*3))
local_rng(i) = Xoshift{XREGISTERS}(i*(RNG_MEM_SIZE) + GLOBAL_vRNGs[])
local_rng() = local_rng(Base.Threads.threadid() - 1)

# include("precompile.jl")
# _precompile_()

# const RANDBUFFER32 = Float32[]
# const RANDNBUFFER32 = Float32[]
# const RANDBUFFER64 = Float64[]
# const RANDNBUFFER64 = Float64[]
# const RANDBUFFERCOUNTER = UInt8[]
# const RANDNBUFFER32COUNTER = UInt8[]
# const RANDBUFFER64COUNTER = UInt8[]
# const RANDNBUFFER64COUNTER = UInt8[]



function __init__()
# ccall(:jl_generating_output, Cint, ()) == 1 && return
nthreads = Base.Threads.nthreads()
nstreams = XREGISTERS * nthreads * simd_integer_register_size()
GLOBAL_vRNGs[] = ptr = VectorizationBase.valloc(5nstreams + 256 * 3nthreads, UInt64)
initXoshift!(ptr, nstreams)

for tid 0:nthreads-1
rng = local_rng(tid)
setrandu64counter!(rng, 0x00)
# setrandn32counter!(rng, 0x00)
setrand64counter!(rng, 0x00)
setrandn64counter!(rng, 0x00)
end
# resize!(RANDBUFFER32, 256nthreads)
# resize!(RANDNBUFFER32, 256nthreads)
# resize!(RANDBUFFER64, 256nthreads)
# resize!(RANDNBUFFER64, 256nthreads)

# resize!(RANDBUFFERCOUNTER, VectorizationBase.CACHELINE_SIZE*nthreads); fill!(RANDBUFFERCOUNTER, 0)
# resize!(RANDNBUFFER32COUNTER, VectorizationBase.CACHELINE_SIZE*nthreads)
# resize!(RANDBUFFER64COUNTER, VectorizationBase.CACHELINE_SIZE*nthreads)
# resize!(RANDNBUFFER64COUNTER, VectorizationBase.CACHELINE_SIZE*nthreads)
nthreads = Base.Threads.nthreads()
GLOBAL_vRNGs[] = ptr = VectorizationBase.valloc((RNG_MEM_SIZE ÷ 8)*nthreads, UInt64)
nstreams = XREGISTERS * nthreads * simd_integer_register_size()
initXoshift!(ptr, nstreams)
for tid 0:nthreads-1
rng = local_rng(tid)
setrandu64counter!(rng, 0x00)
# setrandn32counter!(rng, 0x00)
setrand64counter!(rng, 0x00)
setrandn64counter!(rng, 0x00)
end
end


Expand Down

2 comments on commit 9ed8406

@chriselrod
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/36539

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.10 -m "<description of version>" 9ed8406f7e590dd288997b6ad3340bb1669a37ef
git push origin v0.2.10

Please sign in to comment.