Skip to content

Commit 89e2280

Browse files
authored
[SYCL][Bindless] Deprecate standalone mipmap alloc and free (#11149)
This MR aligns the implementation with the proposal by deprecating the standalone mipmap alloc and free functions. It also slightly modifies the wording in the proposal to state that the correct image type is allocated using `alloc_image_mem` and the `image_type`. There is also a minor typo fix in both the impl and proposal.
1 parent 925c004 commit 89e2280

File tree

5 files changed

+126
-49
lines changed

5 files changed

+126
-49
lines changed

sycl/doc/extensions/experimental/sycl_ext_oneapi_bindless_images.asciidoc

+4-3
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ void free_image_mem(image_mem_handle memHandle,
322322

323323
The first method of allocating device memory for images is through
324324
`alloc_image_mem`. This takes a `sycl::device`, `sycl::context`,
325-
and `image_descriptor` to allocate device memory, appropriately sized
326-
based on the `image_descriptor`. Alternatively, we can also pass a
325+
and `image_descriptor` to allocate device memory, with the appropriate image
326+
type and size based on the `image_descriptor`. Alternatively, we can also pass a
327327
`sycl::queue` instead of both `sycl::device` and `sycl::context`.
328328

329329
Memory allocated in this way requires the user to free that memory after all
@@ -673,7 +673,7 @@ sample, with the minimum value being 0.
673673
`max_mipmap_level_clamp` defines the maximum mipmap level from which we can
674674
sample. This cannot value cannot be higher than the number of allocated levels.
675675

676-
`max_anisotropy` dictates the anisotropic ratio used when samplling the mipmap
676+
`max_anisotropy` dictates the anisotropic ratio used when sampling the mipmap
677677
with anisotropic filtering.
678678

679679
=== Explicit copies
@@ -1975,4 +1975,5 @@ These features still need to be handled:
19751975
- Remove support for packed normalized image formats
19761976
(`unorm_short_555`, `unorm_short_565`, `unorm_int_101010`)
19771977
|4.4|2023-09-12| - Added overload with `sycl::queue` to standalone functions
1978+
|4.5|2023-09-14| - Update wording for allocating images + fix typo
19781979
|======================

sycl/include/sycl/ext/oneapi/bindless_images.hpp

+50-18
Original file line numberDiff line numberDiff line change
@@ -61,67 +61,99 @@ alloc_image_mem(const image_descriptor &desc, const sycl::device &syclDevice,
6161
__SYCL_EXPORT image_mem_handle alloc_image_mem(const image_descriptor &desc,
6262
const sycl::queue &syclQueue);
6363

64+
/**
65+
* @brief [Deprecated] Free image memory
66+
*
67+
* @param handle Memory handle to allocated memory on the device
68+
* @param syclDevice The device in which we create our memory handle
69+
* @param syclContext The context in which we created our memory handle
70+
*/
71+
__SYCL_EXPORT_DEPRECATED("Distinct image frees are deprecated. "
72+
"Instead use overload that accepts image_type.")
73+
void free_image_mem(image_mem_handle handle, const sycl::device &syclDevice,
74+
const sycl::context &syclContext);
75+
76+
/**
77+
* @brief [Deprecated] Free image memory
78+
*
79+
* @param handle Memory handle to allocated memory on the device
80+
* @param syclQueue The queue in which we create our memory handle
81+
*/
82+
__SYCL_EXPORT_DEPRECATED("Distinct image frees are deprecated. "
83+
"Instead use overload that accepts image_type.")
84+
void free_image_mem(image_mem_handle handle, const sycl::device &syclQueue);
85+
6486
/**
6587
* @brief Free image memory
6688
*
6789
* @param handle Memory handle to allocated memory on the device
90+
* @param imageType Type of image memory to be freed
6891
* @param syclDevice The device in which we create our memory handle
6992
* @param syclContext The context in which we created our memory handle
7093
*/
71-
__SYCL_EXPORT void free_image_mem(image_mem_handle handle,
94+
__SYCL_EXPORT void free_image_mem(image_mem_handle handle, image_type imageType,
7295
const sycl::device &syclDevice,
7396
const sycl::context &syclContext);
7497

7598
/**
7699
* @brief Free image memory
77100
*
78101
* @param handle Memory handle to allocated memory on the device
102+
* @param imageType Type of image memory to be freed
79103
* @param syclQueue The queue in which we create our memory handle
80104
*/
81-
__SYCL_EXPORT void free_image_mem(image_mem_handle handle,
82-
const sycl::device &syclQueue);
105+
__SYCL_EXPORT void free_image_mem(image_mem_handle handle, image_type imageType,
106+
const sycl::queue &syclQueue);
83107

84108
/**
85-
* @brief Allocate mipmap memory based on image_descriptor
109+
* @brief [Deprecated] Allocate mipmap memory based on image_descriptor
86110
*
87111
* @param desc The image descriptor
88112
* @param syclDevice The device in which we create our memory handle
89113
* @param syclContext The context in which we create our memory handle
90114
* @return Memory handle to allocated memory on the device
91115
*/
92-
__SYCL_EXPORT image_mem_handle
93-
alloc_mipmap_mem(const image_descriptor &desc, const sycl::device &syclDevice,
94-
const sycl::context &syclContext);
116+
__SYCL_EXPORT_DEPRECATED("Distinct mipmap allocs are deprecated. "
117+
"Instead use alloc_image_mem().")
118+
image_mem_handle alloc_mipmap_mem(const image_descriptor &desc,
119+
const sycl::device &syclDevice,
120+
const sycl::context &syclContext);
95121

96122
/**
97-
* @brief Allocate mipmap memory based on image_descriptor
123+
* @brief [Deprecated] Allocate mipmap memory based on image_descriptor
98124
*
99125
* @param desc The image descriptor
100126
* @param syclQueue The queue in which we create our memory handle
101127
* @return Memory handle to allocated memory on the device
102128
*/
103-
__SYCL_EXPORT image_mem_handle alloc_mipmap_mem(const image_descriptor &desc,
104-
const sycl::device &syclQueue);
129+
__SYCL_EXPORT_DEPRECATED("Distinct mipmap allocs are deprecated. "
130+
"Instead use alloc_image_mem().")
131+
image_mem_handle alloc_mipmap_mem(const image_descriptor &desc,
132+
const sycl::device &syclQueue);
105133

106134
/**
107-
* @brief Free mipmap memory
135+
* @brief [Deprecated] Free mipmap memory
108136
*
109137
* @param handle The mipmap memory handle
110138
* @param syclDevice The device in which we created our memory handle
111139
* @param syclContext The context in which we created our memory handle
112140
*/
113-
__SYCL_EXPORT void free_mipmap_mem(image_mem_handle handle,
114-
const sycl::device &syclDevice,
115-
const sycl::context &syclContext);
141+
__SYCL_EXPORT_DEPRECATED(
142+
"Distinct mipmap frees are deprecated. "
143+
"Instead use free_image_mem() that accepts image_type.")
144+
void free_mipmap_mem(image_mem_handle handle, const sycl::device &syclDevice,
145+
const sycl::context &syclContext);
116146

117147
/**
118-
* @brief Free mipmap memory
148+
* @brief [Deprecated] Free mipmap memory
119149
*
120150
* @param handle The mipmap memory handle
121151
* @param syclQueue The queue in which we created our memory handle
122152
*/
123-
__SYCL_EXPORT void free_mipmap_mem(image_mem_handle handle,
124-
const sycl::queue &syclQueue);
153+
__SYCL_EXPORT_DEPRECATED(
154+
"Distinct mipmap frees are deprecated. "
155+
"Instead use free_image_mem() that accepts image_type.")
156+
void free_mipmap_mem(image_mem_handle handle, const sycl::queue &syclQueue);
125157

126158
/**
127159
* @brief Retrieve the memory handle to an individual mipmap image
@@ -205,7 +237,7 @@ __SYCL_EXPORT image_mem_handle map_external_memory_array(
205237
* @return Memory handle to externally allocated memory on the device
206238
*/
207239
__SYCL_EXPORT image_mem_handle map_external_memory_array(
208-
interop_mem_handle memHandle, const image_descriptor &descm,
240+
interop_mem_handle memHandle, const image_descriptor &desc,
209241
const sycl::queue &syclQueue);
210242

211243
/**

sycl/source/detail/bindless_images.cpp

+68-28
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,12 @@ detail::image_mem_impl::image_mem_impl(const image_descriptor &desc,
4949
const device &syclDevice,
5050
const context &syclContext)
5151
: descriptor(desc), syclDevice(syclDevice), syclContext(syclContext) {
52-
if (desc.type == image_type::mipmap) {
53-
handle = alloc_mipmap_mem(desc, syclDevice, syclContext);
54-
} else {
55-
handle = alloc_image_mem(desc, syclDevice, syclContext);
56-
}
52+
handle = alloc_image_mem(desc, syclDevice, syclContext);
5753
}
5854

5955
detail::image_mem_impl::~image_mem_impl() {
60-
if (handle.raw_handle != nullptr) {
61-
if (descriptor.type == image_type::mipmap) {
62-
free_mipmap_mem(handle, syclDevice, syclContext);
63-
} else {
64-
free_image_mem(handle, syclDevice, syclContext);
65-
}
66-
}
56+
free_image_mem(this->get_handle(), this->get_descriptor().type,
57+
this->get_device(), this->get_context());
6758
}
6859

6960
__SYCL_EXPORT
@@ -163,10 +154,21 @@ alloc_image_mem(const image_descriptor &desc, const sycl::device &syclDevice,
163154
pi_device Device = DevImpl->getHandleRef();
164155
const sycl::detail::PluginPtr &Plugin = CtxImpl->getPlugin();
165156

166-
// Non-mipmap images must have only 1 level
167-
if (desc.num_levels != 1)
157+
if (desc.type == image_type::mipmap) {
158+
// Mipmaps must have more than one level
159+
if (desc.num_levels <= 1)
160+
throw sycl::exception(sycl::make_error_code(sycl::errc::invalid),
161+
"Mipmap number of levels must be 2 or more");
162+
} else if (desc.type == image_type::standard) {
163+
// Non-mipmap images must have only 1 level
164+
if (desc.num_levels != 1)
165+
throw sycl::exception(sycl::make_error_code(sycl::errc::invalid),
166+
"Image number of levels must be 1");
167+
} else {
168+
// Not an image to allocate
168169
throw sycl::exception(sycl::make_error_code(sycl::errc::invalid),
169-
"Image number of levels must be 1");
170+
"Invalid image type to allocate");
171+
}
170172

171173
pi_image_desc piDesc;
172174
pi_image_format piFormat;
@@ -187,9 +189,11 @@ __SYCL_EXPORT image_mem_handle alloc_image_mem(const image_descriptor &desc,
187189
return alloc_image_mem(desc, syclQueue.get_device(), syclQueue.get_context());
188190
}
189191

190-
__SYCL_EXPORT image_mem_handle
191-
alloc_mipmap_mem(const image_descriptor &desc, const sycl::device &syclDevice,
192-
const sycl::context &syclContext) {
192+
__SYCL_EXPORT_DEPRECATED("Distinct mipmap allocs are deprecated. "
193+
"Instead use alloc_image_mem().")
194+
image_mem_handle alloc_mipmap_mem(const image_descriptor &desc,
195+
const sycl::device &syclDevice,
196+
const sycl::context &syclContext) {
193197
std::shared_ptr<sycl::detail::context_impl> CtxImpl =
194198
sycl::detail::getSyclObjImpl(syclContext);
195199
pi_context C = CtxImpl->getHandleRef();
@@ -216,8 +220,10 @@ alloc_mipmap_mem(const image_descriptor &desc, const sycl::device &syclDevice,
216220
return retHandle;
217221
}
218222

219-
__SYCL_EXPORT image_mem_handle alloc_mipmap_mem(const image_descriptor &desc,
220-
const sycl::queue &syclQueue) {
223+
__SYCL_EXPORT_DEPRECATED("Distinct mipmap allocs are deprecated. "
224+
"Instead use alloc_image_mem().")
225+
image_mem_handle alloc_mipmap_mem(const image_descriptor &desc,
226+
const sycl::queue &syclQueue) {
221227
return alloc_mipmap_mem(desc, syclQueue.get_device(),
222228
syclQueue.get_context());
223229
}
@@ -251,6 +257,7 @@ get_mip_level_mem_handle(const image_mem_handle mipMem, unsigned int level,
251257
}
252258

253259
__SYCL_EXPORT void free_image_mem(image_mem_handle memHandle,
260+
image_type imageType,
254261
const sycl::device &syclDevice,
255262
const sycl::context &syclContext) {
256263
std::shared_ptr<sycl::detail::context_impl> CtxImpl =
@@ -261,19 +268,49 @@ __SYCL_EXPORT void free_image_mem(image_mem_handle memHandle,
261268
pi_device Device = DevImpl->getHandleRef();
262269
const sycl::detail::PluginPtr &Plugin = CtxImpl->getPlugin();
263270

264-
Plugin->call<sycl::errc::memory_allocation,
265-
sycl::detail::PiApiKind::piextMemImageFree>(
266-
C, Device, memHandle.raw_handle);
271+
if (memHandle.raw_handle != nullptr) {
272+
if (imageType == image_type::mipmap) {
273+
Plugin->call<sycl::errc::memory_allocation,
274+
sycl::detail::PiApiKind::piextMemMipmapFree>(
275+
C, Device, memHandle.raw_handle);
276+
} else if (imageType == image_type::standard) {
277+
Plugin->call<sycl::errc::memory_allocation,
278+
sycl::detail::PiApiKind::piextMemImageFree>(
279+
C, Device, memHandle.raw_handle);
280+
} else {
281+
throw sycl::exception(sycl::make_error_code(sycl::errc::invalid),
282+
"Invalid image type to free");
283+
}
284+
}
267285
}
268286

269287
__SYCL_EXPORT void free_image_mem(image_mem_handle memHandle,
288+
image_type imageType,
270289
const sycl::queue &syclQueue) {
290+
free_image_mem(memHandle, imageType, syclQueue.get_device(),
291+
syclQueue.get_context());
292+
}
293+
294+
__SYCL_EXPORT_DEPRECATED("Distinct image frees are deprecated. "
295+
"Instead use overload that accepts image_type.")
296+
void free_image_mem(image_mem_handle memHandle, const sycl::device &syclDevice,
297+
const sycl::context &syclContext) {
298+
return free_image_mem(memHandle, image_type::standard, syclDevice,
299+
syclContext);
300+
}
301+
302+
__SYCL_EXPORT_DEPRECATED("Distinct image frees are deprecated. "
303+
"Instead use overload that accepts image_type.")
304+
void free_image_mem(image_mem_handle memHandle, const sycl::queue &syclQueue) {
271305
free_image_mem(memHandle, syclQueue.get_device(), syclQueue.get_context());
272306
}
273307

274-
__SYCL_EXPORT void free_mipmap_mem(image_mem_handle memoryHandle,
275-
const sycl::device &syclDevice,
276-
const sycl::context &syclContext) {
308+
__SYCL_EXPORT_DEPRECATED(
309+
"Distinct mipmap frees are deprecated. "
310+
"Instead use free_image_mem() that accepts image_type.")
311+
void free_mipmap_mem(image_mem_handle memoryHandle,
312+
const sycl::device &syclDevice,
313+
const sycl::context &syclContext) {
277314
std::shared_ptr<sycl::detail::context_impl> CtxImpl =
278315
sycl::detail::getSyclObjImpl(syclContext);
279316
pi_context C = CtxImpl->getHandleRef();
@@ -287,8 +324,11 @@ __SYCL_EXPORT void free_mipmap_mem(image_mem_handle memoryHandle,
287324
C, Device, memoryHandle.raw_handle);
288325
}
289326

290-
__SYCL_EXPORT void free_mipmap_mem(image_mem_handle memoryHandle,
291-
const sycl::queue &syclQueue) {
327+
__SYCL_EXPORT_DEPRECATED(
328+
"Distinct mipmap frees are deprecated. "
329+
"Instead use free_image_mem() that accepts image_type.")
330+
void free_mipmap_mem(image_mem_handle memoryHandle,
331+
const sycl::queue &syclQueue) {
292332
free_mipmap_mem(memoryHandle, syclQueue.get_device(),
293333
syclQueue.get_context());
294334
}

sycl/test/abi/sycl_symbols_linux.dump

+2
Original file line numberDiff line numberDiff line change
@@ -3671,6 +3671,8 @@ _ZN4sycl3_V13ext6oneapi12experimental12create_imageERNS3_9image_memERKNS3_16imag
36713671
_ZN4sycl3_V13ext6oneapi12experimental12create_imageERNS3_9image_memERKNS3_16image_descriptorERKNS0_6deviceERKNS0_7contextE
36723672
_ZN4sycl3_V13ext6oneapi12experimental12create_imageERNS3_9image_memERKNS3_22bindless_image_samplerERKNS3_16image_descriptorERKNS0_5queueE
36733673
_ZN4sycl3_V13ext6oneapi12experimental12create_imageERNS3_9image_memERKNS3_22bindless_image_samplerERKNS3_16image_descriptorERKNS0_6deviceERKNS0_7contextE
3674+
_ZN4sycl3_V13ext6oneapi12experimental14free_image_memENS3_16image_mem_handleENS3_10image_typeERKNS0_5queueE
3675+
_ZN4sycl3_V13ext6oneapi12experimental14free_image_memENS3_16image_mem_handleENS3_10image_typeERKNS0_6deviceERKNS0_7contextE
36743676
_ZN4sycl3_V13ext6oneapi12experimental14free_image_memENS3_16image_mem_handleERKNS0_5queueE
36753677
_ZN4sycl3_V13ext6oneapi12experimental14free_image_memENS3_16image_mem_handleERKNS0_6deviceERKNS0_7contextE
36763678
_ZN4sycl3_V13ext6oneapi12experimental15alloc_image_memERKNS3_16image_descriptorERKNS0_5queueE

sycl/test/abi/sycl_symbols_windows.dump

+2
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,8 @@
10871087
?free@_V1@sycl@@YAXPEAXAEBVqueue@12@AEBUcode_location@detail@12@@Z
10881088
?free_image_mem@experimental@oneapi@ext@_V1@sycl@@YAXUimage_mem_handle@12345@AEBVdevice@45@AEBVcontext@45@@Z
10891089
?free_image_mem@experimental@oneapi@ext@_V1@sycl@@YAXUimage_mem_handle@12345@AEBVqueue@45@@Z
1090+
?free_image_mem@experimental@oneapi@ext@_V1@sycl@@YAXUimage_mem_handle@12345@W4image_type@12345@AEBVdevice@45@AEBVcontext@45@@Z
1091+
?free_image_mem@experimental@oneapi@ext@_V1@sycl@@YAXUimage_mem_handle@12345@W4image_type@12345@AEBVqueue@45@@Z
10901092
?free_mipmap_mem@experimental@oneapi@ext@_V1@sycl@@YAXUimage_mem_handle@12345@AEBVdevice@45@AEBVcontext@45@@Z
10911093
?free_mipmap_mem@experimental@oneapi@ext@_V1@sycl@@YAXUimage_mem_handle@12345@AEBVqueue@45@@Z
10921094
?get@context@_V1@sycl@@QEBAPEAU_cl_context@@XZ

0 commit comments

Comments
 (0)