Skip to content

Commit 62f88d4

Browse files
authored
Merge pull request #152 from JuliaGPU/jps/gpu-workshop
GPU workshop changes!
2 parents 6d29402 + 0d88105 commit 62f88d4

9 files changed

+74
-19
lines changed

Manifest.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820"
8989

9090
[[GPUArrays]]
9191
deps = ["AbstractFFTs", "Adapt", "LinearAlgebra", "Printf", "Random", "Serialization", "Statistics"]
92-
git-tree-sha1 = "df5b8569904c5c10e84c640984cfff054b18c086"
92+
git-tree-sha1 = "ececbf05f8904c92814bdbd0aafd5540b0bf2e9a"
9393
uuid = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7"
94-
version = "6.4.1"
94+
version = "7.0.1"
9595

9696
[[GPUCompiler]]
9797
deps = ["DataStructures", "ExprTools", "InteractiveUtils", "LLVM", "Libdl", "Logging", "TimerOutputs", "UUIDs"]
@@ -101,9 +101,9 @@ version = "0.12.5"
101101

102102
[[HIP_jll]]
103103
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "ROCmCompilerSupport_jll", "ROCmDeviceLibs_jll", "ROCmOpenCLRuntime_jll", "hsa_rocr_jll"]
104-
git-tree-sha1 = "0a7a9fb9cde9cd2225d9b6dc32c744785514e9b8"
104+
git-tree-sha1 = "5097d8f7b6842156ab0928371b3d03fefd8decab"
105105
uuid = "2696aab5-0948-5276-aa9a-2a86a37016b8"
106-
version = "4.0.0+0"
106+
version = "4.0.0+1"
107107

108108
[[InteractiveUtils]]
109109
deps = ["Markdown"]

Project.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "AMDGPU"
22
uuid = "21141c5a-9bdb-4563-92ae-f87d6854732e"
33
authors = ["Julian P Samaroo <jpsamaroo@jpsamaroo.me>"]
4-
version = "0.2.10"
4+
version = "0.2.11"
55

66
[deps]
77
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
@@ -28,7 +28,7 @@ AbstractFFTs = "0.5, 1.0"
2828
Adapt = "3.0"
2929
BinaryProvider = "0.5"
3030
CEnum = "0.2, 0.3, 0.4"
31-
GPUArrays = "6"
31+
GPUArrays = "6, 7"
3232
GPUCompiler = "0.12"
3333
HIP_jll = "4"
3434
LLVM = "4"

deps/build.jl

+3
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,11 @@ function main()
213213
if use_artifacts
214214
config[:device_libs_path] = ROCmDeviceLibs_jll.bitcode_path
215215
config[:device_libs_configured] = true
216+
config[:device_libs_downloaded] = false
216217
else
217218
include("download_device_libs.jl")
219+
config[:device_libs_configured] = true
220+
config[:device_libs_downloaded] = true
218221
end
219222

220223
### Find external HIP-based libraries

deps/loaddeps.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ if !hip_configured
3535
const librocrand = nothing
3636
const libmiopen = nothing
3737
end
38-
if !device_libs_configured
38+
if device_libs_configured && device_libs_downloaded
3939
# Fallback to download
4040
device_libs_deps = joinpath(@__DIR__, "deps.jl")
4141
isfile(device_libs_deps) && include(device_libs_deps)
4242
const device_libs_path = joinpath(@__DIR__, "usr", "lib")
43+
elseif !device_libs_configured
44+
const device_libs_path = ""
4345
end
4446

4547
const configured = hsa_configured

src/AMDGPU.jl

+10-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export get_agents, profile, get_first_isa_string, launch!
2121
export get_default_agent, get_default_queue
2222

2323
export ROCArray, ROCVector, ROCMatrix, ROCVecOrMat
24-
export roc, roczeros, rocones, rocfill
24+
export roc
2525

2626
### HSA Runtime ###
2727

@@ -77,21 +77,25 @@ include("broadcast.jl")
7777
include("mapreduce.jl")
7878
#include("gpuarray_interface.jl")
7979

80-
allowscalar(x::Bool) = nothing
80+
allowscalar(x::Bool) = GPUArrays.allowscalar(x)
8181

8282
### Initialization and Shutdown ###
8383

8484
const HSA_REFCOUNT = Threads.Atomic{UInt}(0)
8585
function hsaref!()
86+
#=
8687
if Threads.atomic_add!(HSA_REFCOUNT, UInt(1)) > typemax(UInt)-10
8788
Core.println("HSA_REFCOUNT OVERFLOW!")
8889
exit(1)
8990
end
91+
=#
9092
end
9193
function hsaunref!()
94+
#=
9295
if Threads.atomic_sub!(HSA_REFCOUNT, UInt(1)) == 1
9396
HSA.shut_down()
9497
end
98+
=#
9599
end
96100

97101
# Load binary dependencies
@@ -126,6 +130,9 @@ check_library("MIOpen", libmiopen)
126130
# we need to load it after rocRAND.jl
127131
include(joinpath(@__DIR__, "random.jl"))
128132

133+
# Utilities
134+
include("utils.jl")
135+
129136
function __init__()
130137
if hsa_configured
131138
# Make sure we load the library found by the last `] build`
@@ -137,6 +144,7 @@ function __init__()
137144
status = HSA.init()
138145
if status == HSA.STATUS_SUCCESS
139146
hsaref!()
147+
HSA_REFCOUNT[] = 1
140148
# Register shutdown hook
141149
atexit() do
142150
hsaunref!()

src/array.jl

+7
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,10 @@ roc(xs) = adapt(Float32Adaptor(), xs)
362362

363363
Base.unsafe_convert(::Type{Ptr{T}}, x::ROCArray{T}) where T =
364364
Base.unsafe_convert(Ptr{T}, x.buf)
365+
366+
# some nice utilities
367+
368+
ones(dims...) = ones(Float32, dims...)
369+
ones(T::Type, dims...) = fill!(ROCArray{T}(undef, dims...), one(T))
370+
zeros(dims...) = zeros(Float32, dims...)
371+
zeros(T::Type, dims...) = fill!(ROCArray{T}(undef, dims...), zero(T))

src/random.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,11 @@ randn(T::Type, dim1::Integer, dims::Integer...; kwargs...) =
7676

7777
# untyped out-of-place
7878
rand(dim1::Integer, dims::Integer...) =
79-
Random.rand(rocrand_rng(), Dims((dim1, dims...)))
79+
#Random.rand(rocrand_rng(), Dims((dim1, dims...)))
80+
Random.rand!(ROCArray{Float32}(undef, dim1, dims...))
8081
randn(dim1::Integer, dims::Integer...; kwargs...) =
81-
Random.randn(rocrand_rng(), Dims((dim1, dims...)); kwargs...)
82+
#Random.randn(rocrand_rng(), Dims((dim1, dims...)); kwargs...)
83+
Random.randn!(ROCArray{Float32}(undef, dim1, dims...))
8284

8385
# rand_logn, rand_poisson
8486
const rand_logn = librocrand !== nothing ? rocRAND.rand_logn : (x...;kwargs...) -> error("Not supported without rocRAND.")

src/signal.jl

+12-8
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,26 @@ the minimum latency for the software waiter; lower values can decrease latency
2727
at the cost of increased polling load. `timeout`, if not `nothing`, sets the
2828
timeout for the signal, after which the call will error.
2929
"""
30-
function Base.wait(signal::HSASignal; soft=true, minlat=0.001, timeout=nothing)
30+
function Base.wait(signal::HSASignal; soft=true, minlat=0.000001, timeout=nothing)
3131
if soft
3232
start_time = time_ns()
3333
while true
3434
value = HSA.signal_load_scacquire(signal.signal[])
3535
if value < 1
3636
return
3737
end
38-
if timeout !== nothing
39-
now_time = time_ns()
40-
diff_time = (now_time - start_time) / 10^9
41-
if diff_time > timeout
42-
error("Timeout while waiting on signal")
43-
end
38+
now_time = time_ns()
39+
diff_time = (now_time - start_time) / 10^9
40+
if timeout !== nothing && diff_time > timeout
41+
error("Timeout while waiting on signal")
42+
end
43+
if minlat < 0.001 && diff_time < 10^3
44+
# Use Libc.systemsleep for higher precision in the microsecond range
45+
Libc.systemsleep(minlat)
46+
yield()
47+
else
48+
sleep(minlat)
4449
end
45-
sleep(minlat)
4650
end
4751
else
4852
# Wait on the dispatch completion signal until the kernel is finished

src/utils.jl

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function versioninfo(io::IO=stdout)
2+
println("HSA Runtime ($(hsa_configured ? "ready" : "MISSING"))")
3+
if hsa_configured
4+
println("- Version: $(libhsaruntime_version)")
5+
println("- Initialized: $(repr(HSA_REFCOUNT[] > 0))")
6+
end
7+
println("HIP Runtime ($(hip_configured ? "ready" : "MISSING"))")
8+
if hip_configured
9+
# TODO: println("- Version: $(libhip_version)")
10+
end
11+
println("ROCm-Device-Libs ($(device_libs_configured ? "ready" : "MISSING"))")
12+
if device_libs_configured
13+
# TODO: println("- Version: $(device_libs_version)")
14+
println("- Downloaded: $(repr(device_libs_downloaded))")
15+
end
16+
println("rocBLAS ($(librocblas !== nothing ? "ready" : "MISSING"))")
17+
println("rocFFT ($(librocfft !== nothing ? "ready" : "MISSING"))")
18+
println("rocRAND ($(librocrand !== nothing ? "ready" : "MISSING"))")
19+
println("rocSPARSE ($(librocsparse !== nothing ? "ready" : "MISSING"))")
20+
println("rocALUTION ($(librocalution !== nothing ? "ready" : "MISSING"))")
21+
println("MIOpen ($(libmiopen !== nothing ? "ready" : "MISSING"))")
22+
23+
if hsa_configured && HSA_REFCOUNT[] > 0
24+
println("HSA Agents ($(length(agents()))):")
25+
for agent in agents()
26+
println("- ", repr(agent))
27+
end
28+
end
29+
end

0 commit comments

Comments
 (0)