Skip to content
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

Implement runtime dispatch of SIMD code #96

Merged
merged 9 commits into from
Feb 5, 2024
Merged

Implement runtime dispatch of SIMD code #96

merged 9 commits into from
Feb 5, 2024

Conversation

althonos
Copy link

@althonos althonos commented Jan 27, 2024

Hi @nicodr97 !

Sorry for the small delay in getting this implemented, I finally got to sit down and work on some extra code besides what I need for my PhD 😄

I added the cpu_features from Google as a git submodule, and updated the CMake files to compile it as a subdirectory. cpu_features is available under the Apache 2.0 license so there is no licensing issue here. When a new Manager is creeate, it checks the local CPU feature flags to check what backend is supported, using a mixture of compilation flags and runtime flags:

  • on x86, it checks for SSE2 and AVX2
  • on x86-64, SSE2 is always available, it checks for AVX2
  • on arm, it checks for NEON
  • on aarch64, NEON is always supported.

It's still possible to disable AVX2, NEON, or SSE2 at compile time; but now a single binary can be compiled and distributed for each platforms. I also added an [INFO]-level message to report when an optimized implementation of the statistics is being used, to make it easier to debug.

@althonos althonos changed the title Impl dispatch Implement runtime dispatch of SIMD code Jan 27, 2024
Copy link
Collaborator

@nicodr97 nicodr97 left a comment

Choose a reason for hiding this comment

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

Very nice!

Given that the platform value depends on the specific compilation parameter passed by the user, is it necessary to check it all around? That is, doesn't platform == ComputePlatform::SSE2 means that HAVE_SSE2 is defined?

Thank you for your contribution!

@althonos
Copy link
Author

althonos commented Feb 3, 2024

Given that the platform value depends on the specific compilation parameter passed by the user, is the necessary to check it all around? That is, doesn't platform == ComputePlatform::SSE2 means that HAVE_SSE2 is defined?

Yes, platform == ComputePlatform::SSE2 means HAVE_SSE2 is defined; however you cannot remove the include guards because the SSE2 statistics (e.g. SSE2Similarity) may not be defined if HAVE_SSE2 is not defined. If you remove the include guards, you'll get compile errors because some classes are not defined.

You could include stub files to still compile a mostly empty SSE2Similarity in have HAVE_SSE2 is not defined, but that's definitely more work than just add a few include guards at the right locations for basically the same result.

@nicodr97 nicodr97 merged commit ec2d58c into inab:2.0_RC Feb 5, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants