@@ -44,14 +44,24 @@ struct DeviceBuffer <: AbstractBuffer
44
44
device:: ZeDevice
45
45
end
46
46
47
- function device_alloc (ctx:: ZeContext , dev:: ZeDevice , bytesize:: Integer , alignment:: Integer = 1 ;
48
- flags= 0 , ordinal:: Integer = 0 )
49
- desc_ref = Ref (ze_device_mem_alloc_desc_t (; flags, ordinal))
50
-
51
- ptr_ref = Ref {Ptr{Cvoid}} ()
52
- zeMemAllocDevice (ctx, desc_ref, bytesize, alignment, dev, ptr_ref)
53
-
54
- return DeviceBuffer (reinterpret (ZePtr{Cvoid}, ptr_ref[]), bytesize, ctx, dev)
47
+ function device_alloc (ctx:: ZeContext , dev:: ZeDevice , bytesize:: Integer ,
48
+ alignment:: Integer = 1 ; flags= 0 , ordinal:: Integer = 0 )
49
+ relaxed_allocation_ref = Ref (ze_relaxed_allocation_limits_exp_desc_t (;
50
+ flags = ZE_RELAXED_ALLOCATION_LIMITS_EXP_FLAG_MAX_SIZE,
51
+ ))
52
+ GC. @preserve relaxed_allocation_ref begin
53
+ desc_ref = if bytesize > properties (dev). maxMemAllocSize
54
+ pNext = Base. unsafe_convert (Ptr{Cvoid}, relaxed_allocation_ref)
55
+ Ref (ze_device_mem_alloc_desc_t (; flags, ordinal, pNext))
56
+ else
57
+ Ref (ze_device_mem_alloc_desc_t (; flags, ordinal))
58
+ end
59
+
60
+ ptr_ref = Ref {Ptr{Cvoid}} ()
61
+ zeMemAllocDevice (ctx, desc_ref, bytesize, alignment, dev, ptr_ref)
62
+
63
+ return DeviceBuffer (reinterpret (ZePtr{Cvoid}, ptr_ref[]), bytesize, ctx, dev)
64
+ end
55
65
end
56
66
57
67
Base. pointer (buf:: DeviceBuffer ) = buf. ptr
@@ -84,7 +94,8 @@ struct HostBuffer <: AbstractBuffer
84
94
context:: ZeContext
85
95
end
86
96
87
- function host_alloc (ctx:: ZeContext , bytesize:: Integer , alignment:: Integer = 1 ; flags= 0 )
97
+ function host_alloc (ctx:: ZeContext , bytesize:: Integer , alignment:: Integer = 1 ;
98
+ flags= 0 )
88
99
desc_ref = Ref (ze_host_mem_alloc_desc_t (; flags))
89
100
90
101
ptr_ref = Ref {Ptr{Cvoid}} ()
@@ -122,17 +133,27 @@ struct SharedBuffer <: AbstractBuffer
122
133
device:: Union{Nothing,ZeDevice}
123
134
end
124
135
125
- function shared_alloc (ctx:: ZeContext , dev:: Union{Nothing,ZeDevice} , bytesize :: Integer ,
126
- alignment:: Integer = 1 ; host_flags= 0 ,
136
+ function shared_alloc (ctx:: ZeContext , dev:: Union{Nothing,ZeDevice} ,
137
+ bytesize :: Integer , alignment:: Integer = 1 ; host_flags= 0 ,
127
138
device_flags= 0 , ordinal:: Integer = 0 )
128
- device_desc_ref = Ref (ze_device_mem_alloc_desc_t (; flags= device_flags, ordinal))
129
- host_desc_ref = Ref (ze_host_mem_alloc_desc_t (; flags= host_flags))
130
-
131
- ptr_ref = Ref {Ptr{Cvoid}} ()
132
- zeMemAllocShared (ctx, device_desc_ref, host_desc_ref, bytesize, alignment,
133
- something (dev, C_NULL ), ptr_ref)
134
-
135
- return SharedBuffer (reinterpret (ZePtr{Cvoid}, ptr_ref[]), bytesize, ctx, dev)
139
+ relaxed_allocation_ref = Ref (ze_relaxed_allocation_limits_exp_desc_t (;
140
+ flags = ZE_RELAXED_ALLOCATION_LIMITS_EXP_FLAG_MAX_SIZE,
141
+ ))
142
+ GC. @preserve relaxed_allocation_ref begin
143
+ device_desc_ref = if dev != = nothing && bytesize > properties (dev). maxMemAllocSize
144
+ pNext = Base. unsafe_convert (Ptr{Cvoid}, relaxed_allocation_ref)
145
+ Ref (ze_device_mem_alloc_desc_t (; flags= device_flags, ordinal, pNext))
146
+ else
147
+ Ref (ze_device_mem_alloc_desc_t (; flags= device_flags, ordinal))
148
+ end
149
+ host_desc_ref = Ref (ze_host_mem_alloc_desc_t (; flags= host_flags))
150
+
151
+ ptr_ref = Ref {Ptr{Cvoid}} ()
152
+ zeMemAllocShared (ctx, device_desc_ref, host_desc_ref, bytesize, alignment,
153
+ something (dev, C_NULL ), ptr_ref)
154
+
155
+ return SharedBuffer (reinterpret (ZePtr{Cvoid}, ptr_ref[]), bytesize, ctx, dev)
156
+ end
136
157
end
137
158
138
159
Base. pointer (buf:: SharedBuffer ) = buf. ptr
0 commit comments