Skip to content

Commit 0a99000

Browse files
authored
[SYCL] Ensure utility methods are not exported from image_impl (#1760)
checkImageValueRange and checkAny are transformed to pure functions with private linkage. This prevents linker to export these functions from the library. Signed-off-by: Alexander Batashev <[email protected]>
1 parent 8536ca1 commit 0a99000

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

sycl/include/CL/sycl/detail/image_impl.hpp

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -233,27 +233,6 @@ class __SYCL_EXPORT image_impl final : public SYCLMemObjT {
233233
private:
234234
vector_class<device> getDevices(const ContextImplPtr Context);
235235

236-
template <info::device Param>
237-
bool checkImageValueRange(const ContextImplPtr Context, const size_t Value) {
238-
const auto &Devices = getDevices(Context);
239-
return Value >= 1 && std::all_of(Devices.cbegin(), Devices.cend(),
240-
[Value](const device &Dev) {
241-
return Value <= Dev.get_info<Param>();
242-
});
243-
}
244-
245-
template <typename T, typename... Args> bool checkAnyImpl(T) { return false; }
246-
247-
template <typename ValT, typename VarT, typename... Args>
248-
bool checkAnyImpl(ValT Value, VarT Variant, Args... Arguments) {
249-
return (Value == Variant) ? true : checkAnyImpl(Value, Arguments...);
250-
}
251-
252-
template <typename T, typename... Args>
253-
bool checkAny(const T Value, Args... Arguments) {
254-
return checkAnyImpl(Value, Arguments...);
255-
}
256-
257236
RT::PiMemObjectType getImageType() {
258237
if (Dimensions == 1)
259238
return (MIsArrayImage ? PI_MEM_TYPE_IMAGE1D_ARRAY : PI_MEM_TYPE_IMAGE1D);

sycl/source/detail/image_impl.cpp

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,36 @@
1111
#include <CL/sycl/image.hpp>
1212
#include <detail/context_impl.hpp>
1313

14+
#include <algorithm>
15+
#include <vector>
16+
1417
__SYCL_INLINE_NAMESPACE(cl) {
1518
namespace sycl {
1619
namespace detail {
1720

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+
1844
uint8_t getImageNumberChannels(image_channel_order Order) {
1945
switch (Order) {
2046
case image_channel_order::a:
@@ -308,16 +334,16 @@ bool image_impl<Dimensions>::checkImageDesc(const RT::PiMemImageDesc &Desc,
308334
void *UserPtr) {
309335
if (checkAny(Desc.image_type, PI_MEM_TYPE_IMAGE1D, PI_MEM_TYPE_IMAGE1D_ARRAY,
310336
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))
313339
throw invalid_parameter_error(
314340
"For a 1D/2D image/image array, the width must be a Value >= 1 and "
315341
"<= CL_DEVICE_IMAGE2D_MAX_WIDTH.",
316342
PI_INVALID_VALUE);
317343

318344
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))
321347
throw invalid_parameter_error(
322348
"For a 3D image, the width must be a Value >= 1 and <= "
323349
"CL_DEVICE_IMAGE3D_MAX_WIDTH",
@@ -326,23 +352,23 @@ bool image_impl<Dimensions>::checkImageDesc(const RT::PiMemImageDesc &Desc,
326352
if (checkAny(Desc.image_type, PI_MEM_TYPE_IMAGE2D,
327353
PI_MEM_TYPE_IMAGE2D_ARRAY) &&
328354
!checkImageValueRange<info::device::image2d_max_height>(
329-
Context, Desc.image_height))
355+
getDevices(Context), Desc.image_height))
330356
throw invalid_parameter_error("For a 2D image or image array, the height "
331357
"must be a Value >= 1 and <= "
332358
"CL_DEVICE_IMAGE2D_MAX_HEIGHT",
333359
PI_INVALID_VALUE);
334360

335361
if (checkAny(Desc.image_type, PI_MEM_TYPE_IMAGE3D) &&
336362
!checkImageValueRange<info::device::image3d_max_height>(
337-
Context, Desc.image_height))
363+
getDevices(Context), Desc.image_height))
338364
throw invalid_parameter_error(
339365
"For a 3D image, the heightmust be a Value >= 1 and <= "
340366
"CL_DEVICE_IMAGE3D_MAX_HEIGHT",
341367
PI_INVALID_VALUE);
342368

343369
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))
346372
throw invalid_parameter_error(
347373
"For a 3D image, the depth must be a Value >= 1 and <= "
348374
"CL_DEVICE_IMAGE3D_MAX_DEPTH",
@@ -351,7 +377,7 @@ bool image_impl<Dimensions>::checkImageDesc(const RT::PiMemImageDesc &Desc,
351377
if (checkAny(Desc.image_type, PI_MEM_TYPE_IMAGE1D_ARRAY,
352378
PI_MEM_TYPE_IMAGE2D_ARRAY) &&
353379
!checkImageValueRange<info::device::image_max_array_size>(
354-
Context, Desc.image_array_size))
380+
getDevices(Context), Desc.image_array_size))
355381
throw invalid_parameter_error(
356382
"For a 1D and 2D image array, the array_size must be a "
357383
"Value >= 1 and <= CL_DEVICE_IMAGE_MAX_ARRAY_SIZE.",

0 commit comments

Comments
 (0)