Skip to content

Commit 9f1b8c6

Browse files
authored
[SYCLomatic] Add migration support for 4 APIs ( __fmaf_ieee_r[d/n/u/z] to sycl::ext::intel::math::fmaf_r[d/n/u/z]) (#2808)
Signed-off-by: Jiang, Zhiwei <zhiwei.jiang@intel.com>
1 parent 1cff868 commit 9f1b8c6

File tree

10 files changed

+171
-12
lines changed

10 files changed

+171
-12
lines changed

clang/lib/DPCT/Diagnostics/Diagnostics.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,8 @@ DEF_WARNING(UNSUPPORTED_EXTMEM_WIN_HANDLE, 1136, HIGH_LEVEL, "SYCL Bindless Imag
300300
DEF_COMMENT(UNSUPPORTED_EXTMEM_WIN_HANDLE, 1136, HIGH_LEVEL, "SYCL Bindless Images extension only supports importing external resource using NT handle on Windows. If assert({0}.get_win32_handle()) fails, you may need to adjust the code to use ({0}.get_win32_handle()).")
301301
DEF_WARNING(ASYNC_COPY_DEVICE_WARN, 1137, LOW_LEVEL, "ASM instruction \"%0\" is asynchronous copy, currently it is migrated to synchronous copy operation. You may need to adjust the code to tune the performance.")
302302
DEF_COMMENT(ASYNC_COPY_DEVICE_WARN, 1137, LOW_LEVEL, "ASM instruction \"{0}\" is asynchronous copy, currently it is migrated to synchronous copy operation. You may need to adjust the code to tune the performance.")
303+
DEF_WARNING(FTZ_BEHAVIOR, 1138, MEDIUM_LEVEL, "The API %0 ignores the flush-to-zero compiler option when handling denormalized data, while it impacts the migrated SYCL API. Please verify the correctness of the migrated code.")
304+
DEF_COMMENT(FTZ_BEHAVIOR, 1138, MEDIUM_LEVEL, "The API {0} ignores the flush-to-zero compiler option when handling denormalized data, while it impacts the migrated SYCL API. Please verify the correctness of the migrated code.")
303305

304306
// clang-format on
305307

clang/lib/DPCT/RulesLang/APINamesMath.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ ENTRY_REWRITE("__fmaf_rd")
116116
ENTRY_REWRITE("__fmaf_rn")
117117
ENTRY_REWRITE("__fmaf_ru")
118118
ENTRY_REWRITE("__fmaf_rz")
119+
ENTRY_REWRITE("__fmaf_ieee_rd")
120+
ENTRY_REWRITE("__fmaf_ieee_rn")
121+
ENTRY_REWRITE("__fmaf_ieee_ru")
122+
ENTRY_REWRITE("__fmaf_ieee_rz")
119123
ENTRY_RENAMED_SINGLE("__frcp_rd", MapNames::getClNamespace(false, true) + "native::recip")
120124
ENTRY_RENAMED_SINGLE("__frcp_rn", MapNames::getClNamespace(false, true) + "native::recip")
121125
ENTRY_RENAMED_SINGLE("__frcp_ru", MapNames::getClNamespace(false, true) + "native::recip")

clang/lib/DPCT/RulesLang/Math/RewriterSinglePrecisionIntrinsics.cpp

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,98 @@ RewriterMap dpct::createSinglePrecisionIntrinsicsRewriterMap() {
170170
CAST_IF_NOT_SAME(makeLiteral("float"), ARG(1)),
171171
CAST_IF_NOT_SAME(makeLiteral("float"), ARG(2)))),
172172
Diagnostics::ROUNDING_MODE_UNSUPPORTED)))
173+
// __fmaf_ieee_rd
174+
MATH_API_REWRITERS_V2(
175+
"__fmaf_ieee_rd",
176+
MATH_API_REWRITER_PAIR(
177+
math::Tag::math_libdevice,
178+
WARNING_FACTORY_ENTRY(
179+
"__fmaf_ieee_rd",
180+
CALL_FACTORY_ENTRY("__fmaf_ieee_rd",
181+
CALL(MapNames::getClNamespace() +
182+
"ext::intel::math::fmaf_rd",
183+
ARG(0), ARG(1), ARG(2))),
184+
Diagnostics::FTZ_BEHAVIOR, ARG("__fmaf_ieee_rd"))),
185+
MATH_API_REWRITER_PAIR(
186+
math::Tag::emulation,
187+
WARNING_FACTORY_ENTRY(
188+
"__fmaf_ieee_rd",
189+
CALL_FACTORY_ENTRY(
190+
"__fmaf_ieee_rd",
191+
CALL(MapNames::getClNamespace(false, true) + "fma",
192+
CAST_IF_NOT_SAME(makeLiteral("float"), ARG(0)),
193+
CAST_IF_NOT_SAME(makeLiteral("float"), ARG(1)),
194+
CAST_IF_NOT_SAME(makeLiteral("float"), ARG(2)))),
195+
Diagnostics::ROUNDING_MODE_UNSUPPORTED)))
196+
// __fmaf_ieee_rn
197+
MATH_API_REWRITERS_V2(
198+
"__fmaf_ieee_rn",
199+
MATH_API_REWRITER_PAIR(
200+
math::Tag::math_libdevice,
201+
WARNING_FACTORY_ENTRY(
202+
"__fmaf_ieee_rn",
203+
CALL_FACTORY_ENTRY("__fmaf_ieee_rn",
204+
CALL(MapNames::getClNamespace() +
205+
"ext::intel::math::fmaf_rn",
206+
ARG(0), ARG(1), ARG(2))),
207+
Diagnostics::FTZ_BEHAVIOR, ARG("__fmaf_ieee_rn"))),
208+
MATH_API_REWRITER_PAIR(
209+
math::Tag::emulation,
210+
WARNING_FACTORY_ENTRY(
211+
"__fmaf_ieee_rn",
212+
CALL_FACTORY_ENTRY(
213+
"__fmaf_ieee_rn",
214+
CALL(MapNames::getClNamespace(false, true) + "fma",
215+
CAST_IF_NOT_SAME(makeLiteral("float"), ARG(0)),
216+
CAST_IF_NOT_SAME(makeLiteral("float"), ARG(1)),
217+
CAST_IF_NOT_SAME(makeLiteral("float"), ARG(2)))),
218+
Diagnostics::ROUNDING_MODE_UNSUPPORTED)))
219+
// __fmaf_ieee_ru
220+
MATH_API_REWRITERS_V2(
221+
"__fmaf_ieee_ru",
222+
MATH_API_REWRITER_PAIR(
223+
math::Tag::math_libdevice,
224+
WARNING_FACTORY_ENTRY(
225+
"__fmaf_ieee_ru",
226+
CALL_FACTORY_ENTRY("__fmaf_ieee_ru",
227+
CALL(MapNames::getClNamespace() +
228+
"ext::intel::math::fmaf_ru",
229+
ARG(0), ARG(1), ARG(2))),
230+
Diagnostics::FTZ_BEHAVIOR, ARG("__fmaf_ieee_ru"))),
231+
MATH_API_REWRITER_PAIR(
232+
math::Tag::emulation,
233+
WARNING_FACTORY_ENTRY(
234+
"__fmaf_ieee_ru",
235+
CALL_FACTORY_ENTRY(
236+
"__fmaf_ieee_ru",
237+
CALL(MapNames::getClNamespace(false, true) + "fma",
238+
CAST_IF_NOT_SAME(makeLiteral("float"), ARG(0)),
239+
CAST_IF_NOT_SAME(makeLiteral("float"), ARG(1)),
240+
CAST_IF_NOT_SAME(makeLiteral("float"), ARG(2)))),
241+
Diagnostics::ROUNDING_MODE_UNSUPPORTED)))
242+
// __fmaf_ieee_rz
243+
MATH_API_REWRITERS_V2(
244+
"__fmaf_ieee_rz",
245+
MATH_API_REWRITER_PAIR(
246+
math::Tag::math_libdevice,
247+
WARNING_FACTORY_ENTRY(
248+
"__fmaf_ieee_rz",
249+
CALL_FACTORY_ENTRY("__fmaf_ieee_rz",
250+
CALL(MapNames::getClNamespace() +
251+
"ext::intel::math::fmaf_rz",
252+
ARG(0), ARG(1), ARG(2))),
253+
Diagnostics::FTZ_BEHAVIOR, ARG("__fmaf_ieee_rz"))),
254+
MATH_API_REWRITER_PAIR(
255+
math::Tag::emulation,
256+
WARNING_FACTORY_ENTRY(
257+
"__fmaf_ieee_rz",
258+
CALL_FACTORY_ENTRY(
259+
"__fmaf_ieee_rz",
260+
CALL(MapNames::getClNamespace(false, true) + "fma",
261+
CAST_IF_NOT_SAME(makeLiteral("float"), ARG(0)),
262+
CAST_IF_NOT_SAME(makeLiteral("float"), ARG(1)),
263+
CAST_IF_NOT_SAME(makeLiteral("float"), ARG(2)))),
264+
Diagnostics::ROUNDING_MODE_UNSUPPORTED)))
173265
// __fmul_rd
174266
MATH_API_REWRITER_DEVICE(
175267
"__fmul_rd",

clang/lib/DPCT/SrcAPI/APINames.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,10 +1097,10 @@ ENTRY(__fdiv_rn, __fdiv_rn, true, NO_FLAG, P4, "Successful: DPCT1013")
10971097
ENTRY(__fdiv_ru, __fdiv_ru, true, NO_FLAG, P0, "Successful: DPCT1013")
10981098
ENTRY(__fdiv_rz, __fdiv_rz, true, NO_FLAG, P4, "Successful: DPCT1013")
10991099
ENTRY(__fdividef, __fdividef, true, NO_FLAG, P0, "Successful")
1100-
ENTRY(__fmaf_ieee_rd, __fmaf_ieee_rd, false, NO_FLAG, P4, "comment")
1101-
ENTRY(__fmaf_ieee_rn, __fmaf_ieee_rn, false, NO_FLAG, P4, "comment")
1102-
ENTRY(__fmaf_ieee_ru, __fmaf_ieee_ru, false, NO_FLAG, P4, "comment")
1103-
ENTRY(__fmaf_ieee_rz, __fmaf_ieee_rz, false, NO_FLAG, P4, "comment")
1100+
ENTRY(__fmaf_ieee_rd, __fmaf_ieee_rd, true, NO_FLAG, P4, "Successful: DPCT1013")
1101+
ENTRY(__fmaf_ieee_rn, __fmaf_ieee_rn, true, NO_FLAG, P4, "Successful: DPCT1013")
1102+
ENTRY(__fmaf_ieee_ru, __fmaf_ieee_ru, true, NO_FLAG, P4, "Successful: DPCT1013")
1103+
ENTRY(__fmaf_ieee_rz, __fmaf_ieee_rz, true, NO_FLAG, P4, "Successful: DPCT1013")
11041104
ENTRY(__fmaf_rd, __fmaf_rd, true, NO_FLAG, P4, "Successful: DPCT1013")
11051105
ENTRY(__fmaf_rn, __fmaf_rn, true, NO_FLAG, P0, "Successful: DPCT1013")
11061106
ENTRY(__fmaf_ru, __fmaf_ru, true, NO_FLAG, P4, "Successful: DPCT1013")

clang/test/dpct/help_option_check/lin/help_all.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ All DPCT options
128128
--rule-file=<file> - Specify the rule file for migration. Also, reference the predefined rules in the "extensions" directory in the root folder of the tool.
129129
--stop-on-parse-err - Stop migration and generation of reports if parsing errors happened. Default: off.
130130
--suppress-warnings=<value> - A comma separated list of migration warnings to suppress. Valid warning IDs range
131-
from 1000 to 1137. Hyphen separated ranges are also allowed. For example:
131+
from 1000 to 1138. Hyphen separated ranges are also allowed. For example:
132132
--suppress-warnings=1000-1010,1011.
133133
--suppress-warnings-all - Suppress all migration warnings. Default: off.
134134
--sycl-file-extension=<value> - Specify the extension of migrated source file(s).

clang/test/dpct/help_option_check/lin/help_option_check.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// RUN: cd %T/help_option_check
55

66
// RUN: dpct --help > output.txt
7-
// RUN: diff --strip-trailing-cr %S/help_all.txt %T/help_option_check/output.txt >> %T/diff.txt
7+
// RUN: diff --strip-trailing-cr %S/help_all.txt %T/help_option_check/output.txt
88
// RUN: dpct --help=basic > output.txt
9-
// RUN: diff --strip-trailing-cr %S/help_basic.txt %T/help_option_check/output.txt >> %T/diff.txt
9+
// RUN: diff --strip-trailing-cr %S/help_basic.txt %T/help_option_check/output.txt
1010
// RUN: dpct --help=advanced > output.txt
11-
// RUN: diff --strip-trailing-cr %S/help_advanced.txt %T/help_option_check/output.txt >> %T/diff.txt
11+
// RUN: diff --strip-trailing-cr %S/help_advanced.txt %T/help_option_check/output.txt

clang/test/dpct/help_option_check/win/help_all.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ All DPCT options
127127
--rule-file=<file> - Specify the rule file for migration. Also, reference the predefined rules in the "extensions" directory in the root folder of the tool.
128128
--stop-on-parse-err - Stop migration and generation of reports if parsing errors happened. Default: off.
129129
--suppress-warnings=<value> - A comma separated list of migration warnings to suppress. Valid warning IDs range
130-
from 1000 to 1137. Hyphen separated ranges are also allowed. For example:
130+
from 1000 to 1138. Hyphen separated ranges are also allowed. For example:
131131
--suppress-warnings=1000-1010,1011.
132132
--suppress-warnings-all - Suppress all migration warnings. Default: off.
133133
--sycl-file-extension=<value> - Specify the extension of migrated source file(s).

clang/test/dpct/help_option_check/win/help_option_check.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// RUN: cd %T/help_option_check
55

66
// RUN: dpct --help > output.txt
7-
// RUN: diff --strip-trailing-cr %S/help_all.txt %T/help_option_check/output.txt >> %T/diff.txt
7+
// RUN: diff --strip-trailing-cr %S/help_all.txt %T/help_option_check/output.txt
88
// RUN: dpct --help=basic > output.txt
9-
// RUN: diff --strip-trailing-cr %S/help_basic.txt %T/help_option_check/output.txt >> %T/diff.txt
9+
// RUN: diff --strip-trailing-cr %S/help_basic.txt %T/help_option_check/output.txt
1010
// RUN: dpct --help=advanced > output.txt
11-
// RUN: diff --strip-trailing-cr %S/help_advanced.txt %T/help_option_check/output.txt >> %T/diff.txt
11+
// RUN: diff --strip-trailing-cr %S/help_advanced.txt %T/help_option_check/output.txt

clang/test/dpct/math/cuda-math-extension.cu

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,25 @@ __global__ void kernelFuncFloat(float *deviceArrayFloat) {
181181
f2 = __fmaf_ru(f0, f1, f2);
182182
// CHECK: f2 = sycl::ext::intel::math::fmaf_rz(f0, f1, f2);
183183
f2 = __fmaf_rz(f0, f1, f2);
184+
// CHECK: DPCT1138:{{[0-9]+}}: The API __fmaf_ieee_rd ignores the flush-to-zero compiler option when handling denormalized data, while it impacts the migrated SYCL API. Please verify the correctness of the migrated code.
185+
// CHECK-NEXT: */
186+
// CHECK-NEXT: f2 = sycl::ext::intel::math::fmaf_rd(f0, f1, f2);
187+
f2 = __fmaf_ieee_rd(f0, f1, f2);
188+
// CHECK: /*
189+
// CHECK-NEXT: DPCT1138:{{[0-9]+}}: The API __fmaf_ieee_rn ignores the flush-to-zero compiler option when handling denormalized data, while it impacts the migrated SYCL API. Please verify the correctness of the migrated code.
190+
// CHECK-NEXT: */
191+
// CHECK-NEXT: f2 = sycl::ext::intel::math::fmaf_rn(f0, f1, f2);
192+
f2 = __fmaf_ieee_rn(f0, f1, f2);
193+
// CHECK: /*
194+
// CHECK-NEXT: DPCT1138:{{[0-9]+}}: The API __fmaf_ieee_ru ignores the flush-to-zero compiler option when handling denormalized data, while it impacts the migrated SYCL API. Please verify the correctness of the migrated code.
195+
// CHECK-NEXT: */
196+
// CHECK-NEXT: f2 = sycl::ext::intel::math::fmaf_ru(f0, f1, f2);
197+
f2 = __fmaf_ieee_ru(f0, f1, f2);
198+
// CHECK: /*
199+
// CHECK-NEXT: DPCT1138:{{[0-9]+}}: The API __fmaf_ieee_rz ignores the flush-to-zero compiler option when handling denormalized data, while it impacts the migrated SYCL API. Please verify the correctness of the migrated code.
200+
// CHECK-NEXT: */
201+
// CHECK-NEXT: f2 = sycl::ext::intel::math::fmaf_rz(f0, f1, f2);
202+
f2 = __fmaf_ieee_rz(f0, f1, f2);
184203
// CHECK: f2 = sycl::ext::intel::math::fmul_rd(f0, f1);
185204
f2 = __fmul_rd(f0, f1);
186205
// CHECK: f2 = sycl::ext::intel::math::fmul_rn(f0, f1);

clang/test/dpct/math/cuda-math-intrinsics.cu

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,27 @@ __global__ void kernelFuncFloat(float *deviceArrayFloat) {
13391339
// CHECK-NEXT: f2 = sycl::fma(f0, f1, f2);
13401340
f2 = __fmaf_rz(f0, f1, f2);
13411341

1342+
// CHECK: /*
1343+
// CHECK-NEXT: DPCT1013:{{[0-9]+}}: The rounding mode could not be specified and the generated code may have different accuracy than the original code. Verify the correctness. SYCL math built-in function rounding mode is aligned with OpenCL C 1.2 standard.
1344+
// CHECK-NEXT: */
1345+
// CHECK-NEXT: f2 = sycl::fma(f0, f1, f2);
1346+
f2 = __fmaf_ieee_rd(f0, f1, f2);
1347+
// CHECK: /*
1348+
// CHECK-NEXT: DPCT1013:{{[0-9]+}}: The rounding mode could not be specified and the generated code may have different accuracy than the original code. Verify the correctness. SYCL math built-in function rounding mode is aligned with OpenCL C 1.2 standard.
1349+
// CHECK-NEXT: */
1350+
// CHECK-NEXT: f2 = sycl::fma(f0, f1, f2);
1351+
f2 = __fmaf_ieee_rn(f0, f1, f2);
1352+
// CHECK: /*
1353+
// CHECK-NEXT: DPCT1013:{{[0-9]+}}: The rounding mode could not be specified and the generated code may have different accuracy than the original code. Verify the correctness. SYCL math built-in function rounding mode is aligned with OpenCL C 1.2 standard.
1354+
// CHECK-NEXT: */
1355+
// CHECK-NEXT: f2 = sycl::fma(f0, f1, f2);
1356+
f2 = __fmaf_ieee_ru(f0, f1, f2);
1357+
// CHECK: /*
1358+
// CHECK-NEXT: DPCT1013:{{[0-9]+}}: The rounding mode could not be specified and the generated code may have different accuracy than the original code. Verify the correctness. SYCL math built-in function rounding mode is aligned with OpenCL C 1.2 standard.
1359+
// CHECK-NEXT: */
1360+
// CHECK-NEXT: f2 = sycl::fma(f0, f1, f2);
1361+
f2 = __fmaf_ieee_rz(f0, f1, f2);
1362+
13421363
// CHECK: /*
13431364
// CHECK-NEXT: DPCT1013:{{[0-9]+}}: The rounding mode could not be specified and the generated code may have different accuracy than the original code. Verify the correctness. SYCL math built-in function rounding mode is aligned with OpenCL C 1.2 standard.
13441365
// CHECK-NEXT: */
@@ -1360,6 +1381,27 @@ __global__ void kernelFuncFloat(float *deviceArrayFloat) {
13601381
// CHECK-NEXT: f2 = sycl::fma((float)i, (float)i, (float)i);
13611382
f2 = __fmaf_rz(i, i, i);
13621383

1384+
// CHECK: /*
1385+
// CHECK-NEXT: DPCT1013:{{[0-9]+}}: The rounding mode could not be specified and the generated code may have different accuracy than the original code. Verify the correctness. SYCL math built-in function rounding mode is aligned with OpenCL C 1.2 standard.
1386+
// CHECK-NEXT: */
1387+
// CHECK-NEXT: f2 = sycl::fma((float)i, (float)i, (float)i);
1388+
f2 = __fmaf_ieee_rd(i, i, i);
1389+
// CHECK: /*
1390+
// CHECK-NEXT: DPCT1013:{{[0-9]+}}: The rounding mode could not be specified and the generated code may have different accuracy than the original code. Verify the correctness. SYCL math built-in function rounding mode is aligned with OpenCL C 1.2 standard.
1391+
// CHECK-NEXT: */
1392+
// CHECK-NEXT: f2 = sycl::fma((float)i, (float)i, (float)i);
1393+
f2 = __fmaf_ieee_rn(i, i, i);
1394+
// CHECK: /*
1395+
// CHECK-NEXT: DPCT1013:{{[0-9]+}}: The rounding mode could not be specified and the generated code may have different accuracy than the original code. Verify the correctness. SYCL math built-in function rounding mode is aligned with OpenCL C 1.2 standard.
1396+
// CHECK-NEXT: */
1397+
// CHECK-NEXT: f2 = sycl::fma((float)i, (float)i, (float)i);
1398+
f2 = __fmaf_ieee_ru(i, i, i);
1399+
// CHECK: /*
1400+
// CHECK-NEXT: DPCT1013:{{[0-9]+}}: The rounding mode could not be specified and the generated code may have different accuracy than the original code. Verify the correctness. SYCL math built-in function rounding mode is aligned with OpenCL C 1.2 standard.
1401+
// CHECK-NEXT: */
1402+
// CHECK-NEXT: f2 = sycl::fma((float)i, (float)i, (float)i);
1403+
f2 = __fmaf_ieee_rz(i, i, i);
1404+
13631405
// CHECK: /*
13641406
// CHECK-NEXT: DPCT1013:{{[0-9]+}}: The rounding mode could not be specified and the generated code may have different accuracy than the original code. Verify the correctness. SYCL math built-in function rounding mode is aligned with OpenCL C 1.2 standard.
13651407
// CHECK-NEXT: */

0 commit comments

Comments
 (0)