Skip to content

Commit d15d440

Browse files
authored
[SYCL] Deprecate sycl::abs(genfloat) (#11188)
Deprecate the `sycl::abs` function for floating point types since it's non-standard. --------- Signed-off-by: Michael Aziz <[email protected]>
1 parent 2a7246d commit d15d440

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

sycl/source/builtins_generator.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,11 @@ class DefCommon:
498498
implementation used when possible.
499499
template_scalar_args - A bool specifying if the builtin should combine the
500500
scalar arguments into common template types.
501+
deprecation_message - A message that will appear in a declaration warning.
501502
"""
502503
def __init__(self, return_type, arg_types, invoke_name, invoke_prefix,
503504
custom_invoke, size_alias, marray_use_loop,
504-
template_scalar_args):
505+
template_scalar_args, deprecation_message=""):
505506
self.return_type = return_type
506507
self.arg_types = arg_types
507508
self.invoke_name = invoke_name
@@ -510,6 +511,7 @@ def __init__(self, return_type, arg_types, invoke_name, invoke_prefix,
510511
self.size_alias = size_alias
511512
self.marray_use_loop = marray_use_loop
512513
self.template_scalar_args = template_scalar_args
514+
self.deprecation_message = deprecation_message
513515

514516
def require_size_alias(self, alternative_name, marray_type):
515517
"""
@@ -641,10 +643,11 @@ class Def(DefCommon):
641643
def __init__(self, return_type, arg_types, invoke_name=None,
642644
invoke_prefix="", custom_invoke=None, fast_math_invoke_name=None,
643645
fast_math_custom_invoke=None, convert_args=[], size_alias=None,
644-
marray_use_loop=False, template_scalar_args=False):
646+
marray_use_loop=False, template_scalar_args=False,
647+
deprecation_message=None):
645648
super().__init__(return_type, arg_types, invoke_name, invoke_prefix,
646649
custom_invoke, size_alias, marray_use_loop,
647-
template_scalar_args)
650+
template_scalar_args, deprecation_message)
648651
self.fast_math_invoke_name = fast_math_invoke_name
649652
self.fast_math_custom_invoke = fast_math_custom_invoke
650653
# List of tuples with mappings for arguments to cast to argument types.
@@ -965,7 +968,9 @@ def custom_nan_invoke(return_type, arg_types, arg_names):
965968
Def("mdoublen", ["double", "double", "mdoublen"]),
966969
Def("mhalfn", ["half", "half", "mhalfn"])],
967970
"sign": [Def("genfloat", ["genfloat"], template_scalar_args=True)],
968-
"abs": [Def("genfloat", ["genfloat"], invoke_prefix="f", template_scalar_args=True), # TODO: Non-standard. Deprecate.
971+
"abs": [Def("genfloat", ["genfloat"],
972+
deprecation_message="abs for floating point types is non-standard and has been deprecated. Please use fabs instead.",
973+
invoke_prefix="f", template_scalar_args=True),
969974
Def("sigeninteger", ["sigeninteger"], custom_invoke=custom_signed_abs_scalar_invoke, template_scalar_args=True),
970975
Def("vigeninteger", ["vigeninteger"], custom_invoke=custom_signed_abs_vec_invoke),
971976
Def("migeninteger", ["migeninteger"], marray_use_loop=True),
@@ -1277,7 +1282,8 @@ def get_template_args(arg_types):
12771282

12781283
def get_deprecation(builtin, return_type, arg_types):
12791284
"""Gets the deprecation statement for a given builtin."""
1280-
# TODO: Check builtin for deprecation message and prioritize that.
1285+
if builtin.deprecation_message:
1286+
return f'__SYCL_DEPRECATED("{builtin.deprecation_message}")\n'
12811287
for t in [return_type] + arg_types:
12821288
if hasattr(t, 'deprecation_message') and t.deprecation_message:
12831289
return f'__SYCL_DEPRECATED("{t.deprecation_message}")\n'

sycl/test/warnings/sycl_2020_deprecations.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ int main() {
134134
sycl::byte B;
135135
(void)B;
136136

137+
// expected-warning@+1{{'abs<float>' is deprecated: abs for floating point types is non-standard and has been deprecated. Please use fabs instead.}}
138+
sycl::abs(0.0f);
139+
137140
// expected-warning@+1{{'image_support' is deprecated: deprecated in SYCL 2020, use device::has(aspect::ext_intel_legacy_image) to query for SYCL 1.2.1 image support}}
138141
using IS = sycl::info::device::image_support;
139142
// expected-warning@+1{{'max_constant_buffer_size' is deprecated: deprecated in SYCL 2020}}

0 commit comments

Comments
 (0)