Standardize math functions in SYCL kernels: std::/::f → sycl::, __f → sycl::native::#3203
Draft
Standardize math functions in SYCL kernels: std::/::f → sycl::, __f → sycl::native::#3203
Conversation
…sion, keep std:: for complex types and host code Agent-Logs-Url: https://github.com/intel/torch-xpu-ops/sessions/1c6785b9-c285-4ddc-bfd2-ed4892d7387a Co-authored-by: jianyizh <79236274+jianyizh@users.noreply.github.com>
…, improve readability Agent-Logs-Url: https://github.com/intel/torch-xpu-ops/sessions/1c6785b9-c285-4ddc-bfd2-ed4892d7387a Co-authored-by: jianyizh <79236274+jianyizh@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor math functions in SYCL kernels
Standardize math functions in SYCL kernels: std::/::f → sycl::, __f → sycl::native::
Mar 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SYCL kernels were inconsistently mixing
sycl::,std::,::, andsycl::native::math functions. The rule: high-precision calls (expf,std::exp,::expf) →sycl::exp; CUDA fast intrinsics (__expf) →sycl::native::exp.Changes
src/comm/XPUMathCompat.h: Replace::expf/::tanhf/::exp/::tanhwithsycl::exp/sycl::tanh58 SYCL kernel files: Replace all
std::math functions withsycl::equivalents in device code:exp,log,log1p,log2,log10,expm1,exp2,sqrt,powsin,cos,tan,sinh,cosh,tanh,asin,acos,atan,atan2erf,erfc,lgamma,fabs,fmax,fmin,hypot,floor,ceil,round,trunc,fmodComplex type handling: Added specializations that preserve
std::for complex number math where SYCL has no equivalent (e.g.,std::log1p(complex), complexsqrt). AffectsSqrtFunctor,ExpFunctorinUnaryKernels.cpp;LogspaceFunctorinRangeFactoriesKernel.cpp;Rsqrt<c10::complex<T>>inForeachUnaryKernels.cpp.sycl::native::: No existing__expf-style intrinsic calls found — no changes required for this category.Kept as
std::(intentional):sycl_kernel_submit, e.g.,AdaptiveAveragePooling,AttentionKernelsscale factor)std::modf/std::frexp— SYCL variants requiremulti_ptr, different APIcompat_powinSharedReduceOps.h— dispatched with complex accumulator types✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.