Skip to content

Commit 29ef0dd

Browse files
committed
OutOfGPUMemoryError definition
1 parent d2deb1a commit 29ef0dd

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed

lib/level-zero/oneL0.jl

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ else
1515
using oneAPI_Level_Zero_Loader_jll
1616
end
1717

18-
include("common.jl")
1918
include("utils.jl")
2019
include("pointer.jl")
2120

2221
# core API
22+
include("common.jl")
2323
include("libze.jl")
2424

2525
# level zero's structure types are often assumed to be zero-initialized (`= {}` in C).
@@ -88,6 +88,39 @@ end
8888
include("error.jl")
8989
include("driver.jl")
9090
include("device.jl")
91+
92+
# Define OutOfGPUMemoryError after device.jl to ensure ZeDevice is available
93+
export OutOfGPUMemoryError
94+
95+
"""
96+
OutOfGPUMemoryError(sz::Integer=0, dev::ZeDevice)
97+
98+
An operation allocated too much GPU memory.
99+
"""
100+
struct OutOfGPUMemoryError <: Exception
101+
sz::Int
102+
dev::Union{ZeDevice, Nothing}
103+
104+
function OutOfGPUMemoryError(sz::Integer=0, dev::Union{ZeDevice, Nothing}=nothing)
105+
new(sz, dev)
106+
end
107+
end
108+
109+
function Base.showerror(io::IO, err::OutOfGPUMemoryError)
110+
print(io, "Out of GPU memory")
111+
if err.sz > 0
112+
print(io, " trying to allocate $(Base.format_bytes(err.sz))")
113+
end
114+
if err.dev !== nothing
115+
print(" on device $(properties(err.dev).name)")
116+
if length(memory_properties(err.dev)) == 1
117+
# XXX: how to handle multiple memories?
118+
print(" with $(Base.format_bytes(only(memory_properties(err.dev)).totalSize))")
119+
end
120+
end
121+
return io
122+
end
123+
91124
include("context.jl")
92125
include("cmdqueue.jl")
93126
include("cmdlist.jl")
@@ -131,7 +164,7 @@ function __init__()
131164
zeInit(0)
132165
functional[] = true
133166
catch err
134-
@warn "Failed to initialize oneAPI"
167+
@error "Failed to initialize oneAPI" exception=(err,catch_backtrace())
135168
functional[] = false
136169
return
137170
end

src/pool.jl

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,3 @@
1-
export OutOfGPUMemoryError
2-
3-
"""
4-
OutOfGPUMemoryError()
5-
6-
An operation allocated too much GPU memory.
7-
"""
8-
struct OutOfGPUMemoryError <: Exception
9-
sz::Int
10-
dev::ZeDevice
11-
12-
function OutOfGPUMemoryError(sz::Integer=0, dev::ZeDevice=device())
13-
new(sz, dev)
14-
end
15-
end
16-
17-
function Base.showerror(io::IO, err::OutOfGPUMemoryError)
18-
print(io, "Out of GPU memory")
19-
if err.sz > 0
20-
print(io, " trying to allocate $(Base.format_bytes(err.sz))")
21-
end
22-
print(" on device $(properties(err.dev).name)")
23-
if length(memory_properties(err.dev)) == 1
24-
# XXX: how to handle multiple memories?
25-
print(" with $(Base.format_bytes(only(memory_properties(err.dev)).totalSize))")
26-
end
27-
return io
28-
end
29-
301
function allocate(::Type{oneL0.DeviceBuffer}, ctx, dev, bytes::Int, alignment::Int)
312
bytes == 0 && return oneL0.DeviceBuffer(ZE_NULL, bytes, ctx, dev)
323

0 commit comments

Comments
 (0)