Skip to content

Speed-up rand: Tausworthe RNG with shared random state. #788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ steps:
- label: "CUDA 11.2"
plugins:
- JuliaCI/julia#v1:
version: 1.6
version: 1.6-nightly
- JuliaCI/julia-test#v1:
test_args: "--thorough"
- JuliaCI/julia-coverage#v1:
Expand All @@ -79,7 +79,7 @@ steps:
- label: "CUDA 11.1"
plugins:
- JuliaCI/julia#v1:
version: 1.6
version: 1.6-nightly
- JuliaCI/julia-test#v1:
test_args: "--thorough"
- JuliaCI/julia-coverage#v1:
Expand All @@ -101,7 +101,7 @@ steps:
- label: "CUDA 11.0"
plugins:
- JuliaCI/julia#v1:
version: 1.6
version: 1.6-nightly
- JuliaCI/julia-test#v1:
test_args: "--thorough"
- JuliaCI/julia-coverage#v1:
Expand All @@ -123,7 +123,7 @@ steps:
- label: "CUDA 10.2"
plugins:
- JuliaCI/julia#v1:
version: 1.6
version: 1.6-nightly
- JuliaCI/julia-test#v1:
test_args: "--thorough"
- JuliaCI/julia-coverage#v1:
Expand All @@ -145,7 +145,7 @@ steps:
- label: "CUDA 10.1"
plugins:
- JuliaCI/julia#v1:
version: 1.6
version: 1.6-nightly
- JuliaCI/julia-test#v1:
test_args: "--thorough"
- JuliaCI/julia-coverage#v1:
Expand Down
7 changes: 7 additions & 0 deletions perf/kernel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ function checked_indexing_kernel(dest, src)
return
end
group["indexing_checked"] = @async_benchmarkable @cuda threads=size(src,1) blocks=size(src,2) $checked_indexing_kernel($dest, $src)

function rand_kernel(dest::AbstractArray{T}) where {T}
i = (blockIdx().x-1) * blockDim().x + threadIdx().x
dest[i] = rand(T)
return
end
group["rand"] = @async_benchmarkable @cuda threads=size(src,1) blocks=size(src,2) $rand_kernel($dest)
1 change: 1 addition & 0 deletions src/CUDA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ include("device/intrinsics.jl")
include("device/llvm.jl")
include("device/runtime.jl")
include("device/texture.jl")
include("device/random.jl")

# array essentials
include("pool.jl")
Expand Down
20 changes: 8 additions & 12 deletions src/compiler/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,13 @@ end

## host-side kernels

mutable struct HostKernel{F,TT} <: AbstractKernel{F,TT}
struct HostKernel{F,TT} <: AbstractKernel{F,TT}
ctx::CuContext
mod::CuModule
fun::CuFunction

random_state::Union{Nothing,Missing,CuVector{UInt32}}

function HostKernel{F,TT}(ctx::CuContext, mod::CuModule, fun::CuFunction, random_state) where {F,TT}
kernel = new{F,TT}(ctx, mod, fun, random_state)
function HostKernel{F,TT}(ctx::CuContext, mod::CuModule, fun::CuFunction) where {F,TT}
kernel = new{F,TT}(ctx, mod, fun)
end
end

Expand Down Expand Up @@ -358,19 +356,17 @@ function cufunction_link(@nospecialize(job::CompilerJob), compiled)
filter!(!isequal("exception_flag"), compiled.external_gvars)
end

random_state = nothing
if "global_random_state" in compiled.external_gvars
# initialize random seeds, if used
if "global_random_seed" in compiled.external_gvars
random_state = missing
filter!(!isequal("global_random_state"), compiled.external_gvars)
initialize_random_seeds!(mod)
filter!(!isequal("global_random_seed"), compiled.external_gvars)
end

return HostKernel{job.source.f,job.source.tt}(ctx, mod, fun, random_state)
return HostKernel{job.source.f,job.source.tt}(ctx, mod, fun)
end

function (kernel::HostKernel)(args...; threads::CuDim=1, blocks::CuDim=1, kwargs...)
if kernel.random_state !== nothing
init_random_state!(kernel, prod(threads) * prod(blocks))
end
call(kernel, map(cudaconvert, args)...; threads, blocks, kwargs...)
end

Expand Down
1 change: 0 additions & 1 deletion src/device/intrinsics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ include("intrinsics/memory_dynamic.jl")
include("intrinsics/atomics.jl")
include("intrinsics/misc.jl")
include("intrinsics/wmma.jl")
include("intrinsics/random.jl")

# functionality from libdevice
#
Expand Down
71 changes: 0 additions & 71 deletions src/device/intrinsics/random.jl

This file was deleted.

Loading