11
11
#include < CL/sycl/image.hpp>
12
12
#include < detail/context_impl.hpp>
13
13
14
+ #include < algorithm>
15
+ #include < vector>
16
+
14
17
__SYCL_INLINE_NAMESPACE (cl) {
15
18
namespace sycl {
16
19
namespace detail {
17
20
21
+ template <info::device Param>
22
+ static bool checkImageValueRange (const std::vector<device> &Devices,
23
+ const size_t Value) {
24
+ return Value >= 1 && std::all_of (Devices.cbegin (), Devices.cend (),
25
+ [Value](const device &Dev) {
26
+ return Value <= Dev.get_info <Param>();
27
+ });
28
+ }
29
+
30
+ template <typename T, typename ... Args> static bool checkAnyImpl (T) {
31
+ return false ;
32
+ }
33
+
34
+ template <typename ValT, typename VarT, typename ... Args>
35
+ static bool checkAnyImpl (ValT Value, VarT Variant, Args... Arguments) {
36
+ return (Value == Variant) ? true : checkAnyImpl (Value, Arguments...);
37
+ }
38
+
39
+ template <typename T, typename ... Args>
40
+ static bool checkAny (const T Value, Args... Arguments) {
41
+ return checkAnyImpl (Value, Arguments...);
42
+ }
43
+
18
44
uint8_t getImageNumberChannels (image_channel_order Order) {
19
45
switch (Order) {
20
46
case image_channel_order::a:
@@ -308,16 +334,16 @@ bool image_impl<Dimensions>::checkImageDesc(const RT::PiMemImageDesc &Desc,
308
334
void *UserPtr) {
309
335
if (checkAny (Desc.image_type , PI_MEM_TYPE_IMAGE1D, PI_MEM_TYPE_IMAGE1D_ARRAY,
310
336
PI_MEM_TYPE_IMAGE2D_ARRAY, PI_MEM_TYPE_IMAGE2D) &&
311
- !checkImageValueRange<info::device::image2d_max_width>(Context,
312
- Desc.image_width ))
337
+ !checkImageValueRange<info::device::image2d_max_width>(
338
+ getDevices (Context), Desc.image_width ))
313
339
throw invalid_parameter_error (
314
340
" For a 1D/2D image/image array, the width must be a Value >= 1 and "
315
341
" <= CL_DEVICE_IMAGE2D_MAX_WIDTH." ,
316
342
PI_INVALID_VALUE);
317
343
318
344
if (checkAny (Desc.image_type , PI_MEM_TYPE_IMAGE3D) &&
319
- !checkImageValueRange<info::device::image3d_max_width>(Context,
320
- Desc.image_width ))
345
+ !checkImageValueRange<info::device::image3d_max_width>(
346
+ getDevices (Context), Desc.image_width ))
321
347
throw invalid_parameter_error (
322
348
" For a 3D image, the width must be a Value >= 1 and <= "
323
349
" CL_DEVICE_IMAGE3D_MAX_WIDTH" ,
@@ -326,23 +352,23 @@ bool image_impl<Dimensions>::checkImageDesc(const RT::PiMemImageDesc &Desc,
326
352
if (checkAny (Desc.image_type , PI_MEM_TYPE_IMAGE2D,
327
353
PI_MEM_TYPE_IMAGE2D_ARRAY) &&
328
354
!checkImageValueRange<info::device::image2d_max_height>(
329
- Context, Desc.image_height ))
355
+ getDevices ( Context) , Desc.image_height ))
330
356
throw invalid_parameter_error (" For a 2D image or image array, the height "
331
357
" must be a Value >= 1 and <= "
332
358
" CL_DEVICE_IMAGE2D_MAX_HEIGHT" ,
333
359
PI_INVALID_VALUE);
334
360
335
361
if (checkAny (Desc.image_type , PI_MEM_TYPE_IMAGE3D) &&
336
362
!checkImageValueRange<info::device::image3d_max_height>(
337
- Context, Desc.image_height ))
363
+ getDevices ( Context) , Desc.image_height ))
338
364
throw invalid_parameter_error (
339
365
" For a 3D image, the heightmust be a Value >= 1 and <= "
340
366
" CL_DEVICE_IMAGE3D_MAX_HEIGHT" ,
341
367
PI_INVALID_VALUE);
342
368
343
369
if (checkAny (Desc.image_type , PI_MEM_TYPE_IMAGE3D) &&
344
- !checkImageValueRange<info::device::image3d_max_depth>(Context,
345
- Desc.image_depth ))
370
+ !checkImageValueRange<info::device::image3d_max_depth>(
371
+ getDevices (Context), Desc.image_depth ))
346
372
throw invalid_parameter_error (
347
373
" For a 3D image, the depth must be a Value >= 1 and <= "
348
374
" CL_DEVICE_IMAGE3D_MAX_DEPTH" ,
@@ -351,7 +377,7 @@ bool image_impl<Dimensions>::checkImageDesc(const RT::PiMemImageDesc &Desc,
351
377
if (checkAny (Desc.image_type , PI_MEM_TYPE_IMAGE1D_ARRAY,
352
378
PI_MEM_TYPE_IMAGE2D_ARRAY) &&
353
379
!checkImageValueRange<info::device::image_max_array_size>(
354
- Context, Desc.image_array_size ))
380
+ getDevices ( Context) , Desc.image_array_size ))
355
381
throw invalid_parameter_error (
356
382
" For a 1D and 2D image array, the array_size must be a "
357
383
" Value >= 1 and <= CL_DEVICE_IMAGE_MAX_ARRAY_SIZE." ,
0 commit comments