Skip to content

Commit 93a7525

Browse files
authored
[SYCLomaitc] Use the rewrite to impl cospif (#2715)
Signed-off-by: Chen, Sheng S <sheng.s.chen@intel.com>
1 parent 836eca6 commit 93a7525

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

clang/lib/DPCT/RulesLang/APINamesMath.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ ENTRY_REWRITE("ceilf")
6262
ENTRY_RENAMED_SINGLE("copysignf", MapNames::getClNamespace(false, true) + "copysign")
6363
ENTRY_RENAMED_SINGLE("cosf", MapNames::getClNamespace(false, true) + "cos")
6464
ENTRY_RENAMED_SINGLE("coshf", MapNames::getClNamespace(false, true) + "cosh")
65-
ENTRY_RENAMED_SINGLE("cospif", MapNames::getClNamespace(false, true) + "cospi")
65+
ENTRY_REWRITE("cospif")
6666
ENTRY_RENAMED_SINGLE("erfcf", MapNames::getClNamespace(false, true) + "erfc")
6767
ENTRY_RENAMED_SINGLE("erff", MapNames::getClNamespace(false, true) + "erf")
6868
ENTRY_RENAMED_SINGLE("exp10f", MapNames::getClNamespace(false, true) + "exp10")

clang/lib/DPCT/RulesLang/Math/CallExprRewriterMath.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ enum class Tag : size_t {
251251
ext_experimental, // device API using experimental feature
252252
host_perf, // host API for performance
253253
host_normal, // host API
254+
host_device, // host deivce API
254255
unsupported_warning,
255256
no_rewrite,
256257
tag_size
@@ -280,6 +281,8 @@ class MathRewriterFactory final : public CallExprRewriterFactoryBase {
280281
MathAPIRewriters[static_cast<size_t>(math::Tag::math_libdevice)];
281282
element_t &DeviceStdRewriter =
282283
MathAPIRewriters[static_cast<size_t>(math::Tag::device_std)];
284+
element_t &HostDeviceRewriter =
285+
MathAPIRewriters[static_cast<size_t>(math::Tag::host_device)];
283286
element_t &EmulationRewriter =
284287
MathAPIRewriters[static_cast<size_t>(math::Tag::emulation)];
285288
element_t &ExtExperimentalRewriter =
@@ -378,6 +381,9 @@ class MathRewriterFactory final : public CallExprRewriterFactoryBase {
378381
if (EmulationRewriter && EmulationRewriter.value().first(C))
379382
return EmulationRewriter.value().second.second->create(C);
380383

384+
if (HostDeviceRewriter && HostDeviceRewriter.value().first(C))
385+
return HostDeviceRewriter.value().second.second->create(C);
386+
381387
if (UnsupportedWarningRewriter &&
382388
UnsupportedWarningRewriter.value().first(C))
383389
return UnsupportedWarningRewriter.value().second.second->create(C);

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ RewriterMap dpct::createSinglePrecisionMathematicalFunctionsRewriterMap() {
295295
"sinpif",
296296
CALL(MapNames::getClNamespace() + "sinpi",
297297
CAST_IF_NOT_SAME(makeLiteral("float"), ARG(0))))))
298+
// cospif
299+
MATH_API_REWRITERS_V2(
300+
"cospif", MATH_API_REWRITER_PAIR(
301+
math::Tag::host_device,
302+
CALL_FACTORY_ENTRY(
303+
"cospif", CALL(MapNames::getClNamespace() + "cospi",
304+
CAST_IF_NOT_SAME(
305+
makeLiteral("float"), ARG(0))))))
298306
// tanhf
299307
MATH_API_REWRITERS_V2(
300308
"tanhf",

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3539,3 +3539,14 @@ __global__ void foo7(float aa) {
35393539
// CHECK: sycl::sinpi(aa);
35403540
::sinpif(aa);
35413541
}
3542+
3543+
void foo8(float aa) {
3544+
// CHECK: sycl::cospi(aa);
3545+
::cospif(aa);
3546+
}
3547+
3548+
__global__ void foo9(float aa) {
3549+
// CHECK: sycl::cospi(aa);
3550+
::cospif(aa);
3551+
}
3552+

0 commit comments

Comments
 (0)