Skip to content

Fix vectorization pragmas for icx compiler #3246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

Vika-F
Copy link
Contributor

@Vika-F Vika-F commented Jun 3, 2025

Description

  • Vectorization pragmas were defined for icx/icpx compilers. Previously they were defined only for icc.
  • Vectorization pragmas were redefined for all compilers in attempt to use OpenMP 5 #pragma omp simd for vectorization where possible:
    cpp/daal/src/services/service_defines.h
  • Compilation warnings were fixed after pragmas re-definition

Note: The use of #pargma omp simd was not implemented for MSVC because it is required to link with OpenMP to support the feature leading to additional dependency in Windows build.


PR should start as a draft, then move to ready for review state after CI is passed and all applicable checkboxes are closed.
This approach ensures that reviewers don't spend extra time asking for regular requirements.

You can remove a checkbox as not applicable only if it doesn't relate to this PR in any way.
For example, PR with docs update doesn't require checkboxes for performance while PR with any change in actual code should have checkboxes and justify how this code change is expected to affect performance (or justification should be self-evident).

Checklist to comply with before moving PR from draft:

PR completeness and readability

  • I have reviewed my changes thoroughly before submitting this pull request.
  • I have commented my code, particularly in hard-to-understand areas.
  • Git commit message contains an appropriate signed-off-by string (see CONTRIBUTING.md for details).
  • I have added a respective label(s) to PR if I have a permission for that.
  • I have resolved any merge conflicts that might occur with the base branch.

Testing

  • I have run it locally and tested the changes extensively.
  • All CI jobs are green or I have provided justification why they aren't.

Performance

  • I have measured performance for affected algorithms using scikit-learn_bench and provided at least summary table with measured data, if performance change is expected.
  • I have provided justification why performance has changed or why changes are not expected.
  • I have provided justification why quality metrics have changed or why changes are not expected.
  • I have extended benchmarking suite and provided corresponding scikit-learn_bench PR if new measurable functionality was introduced in this PR.

@@ -44,59 +44,49 @@ DAAL_EXPORT bool daal_check_is_intel_cpu();

#define DAAL_CHECK_CPU_ENVIRONMENT (daal_check_is_intel_cpu())

#if defined(__INTEL_COMPILER)
#if defined(__INTEL_COMPILER) || defined(__INTEL_LLVM_COMPILER)
#define PRAGMA_FORCE_SIMD _Pragma("ivdep")
#define PRAGMA_NOVECTOR _Pragma("novector")
#define PRAGMA_VECTOR_ALIGNED _Pragma("vector aligned")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this play along with omp simd? How about passing the alignment to the OMP pragma? It also supports #pragma omp simd aligned(pointer_name:64).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to pass any arguments to #pragma omp simd with PRAGMA_OMP_SIMD() macro.
For example:
https://github.com/uxlfoundation/oneDAL/pull/3246/files#diff-61b267e32558b19a2dba159ff0128be35c0c8eafe9b140791a7073e262af17f7R1201

Alignment options can be passed similarly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But does the compiler actually use the hint if put before omp simd?

#define DAAL_TYPENAME typename
#elif defined(_MSC_VER)
#define PRAGMA_FORCE_SIMD
#define PRAGMA_NOVECTOR
#define PRAGMA_FORCE_SIMD _Pragma("loop(ivdep)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MSVC supports omp simd if enabling experimental mode:
https://learn.microsoft.com/en-us/cpp/parallel/openmp/openmp-simd?view=msvc-170

#define PRAGMA_FORCE_SIMD _Pragma("omp simd")
#define PRAGMA_FORCE_SIMD _Pragma("omp simd")
#define PRAGMA_TO_STR(ARGS) _Pragma(#ARGS)
#define PRAGMA_OMP_SIMD(ARGS) PRAGMA_TO_STR(omp simd ARGS)
#else
#define PRAGMA_FORCE_SIMD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omp simd is supported by GCC on all platforms as far as I am aware.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/// \param[in] x Pointer to the input matrix x of size nRows * nColumns
/// \param[out] sum Pointer to the output array of size nRows, where the sum of each row of x will be stored
template <typename algorithmFPType, CpuType cpu>
void sumByRows(const size_t nRows, const size_t nColumns, const algorithmFPType * x, algorithmFPType * sum)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is out of the scope of this PR.
Here I am just trying to enable the pragmas for ICX. The refactoring was made just to reduce code duplication and not to do the same modifications in 3 files.

{
if (block[i * blockSize + i] > (algorithmFPType)0.0)
{
block[i * blockSize + i] = (algorithmFPType)1.0 / daal::internal::MathInst<algorithmFPType, cpu>::sSqrt(block[i * blockSize + i]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a PR adding a function for this from MKL: #3227

Perhaps that other one could be merged first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am Ok to have that one merged first and reuse that functionality; but I think the performance have to be measured, as that PR clearly might have performance impact on the algorithm.

@Vika-F
Copy link
Contributor Author

Vika-F commented Jun 17, 2025

/intelci: run

@Vika-F Vika-F mentioned this pull request Jun 18, 2025
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants