Cycles: Cleanup, simplify and expand math/vectorization build flags #128342

Manually merged
Lukas Stockner merged 7 commits from LukasStockner/blender:kernel-cpu-flags-cmake-cleanup into main 2024-09-30 15:59:53 +02:00
Member

The existing code to set vectorization and optimization build flags was a bit of a mess.
This PR cleans it up and makes some improvements:

  • There were bits of AVX code left, even though we only compile SSE4.2 and AVX2 kernels nowadays
  • Vectorization and optimization flags were mixed together for no reason
    • This caused some downsides - e.g., enabling NATIVE_ONLY would skip all the optimization flags
  • The names were confusing/misleading - for example, CYCLES_KERNEL_FLAGS was also used for host code
    • Optimizations are now directly appended to CMAKE_CXX_FLAGS instead of building CYCLES_KERNEL_FLAGS and then appending that at the end
    • Vectorization is renamed from CYCLES_x_KERNEL_FLAGS to CYCLES_x_FLAGS
  • The math optimization flags were duplicated between Windows+Clang and GCC or Linux+Clang
    • Since the only difference is a prefix, CMake lists can clean this up nicely
  • SSE4.2 was only enabled for host code on GCC/Clang, but we require it on all x86 platforms, so now it's assumed on all compilers that support it
  • There are some additional math optimizations that I think we can enable safely
    • Specifically:
      • -ffp-contract=fast (enables FMA generation)
      • -freciprocal-math (enables x/y -> x*(1/y))
      • -fassociative-math (enables e.g. a*b + c*b -> (a+c)*b)
    • These are used on Windows and HIP anyways, so our code can't expect exact IEEE semantics in any case
    • The only difference between the new set and -ffast-math is that we don't use -ffinite-math-only since this causes issues with the BVH (see ce1f2e271d) and breaks e.g. isnan
    • This causes a ~1.5% speedup in my very quick test, but might be higher for some more math-intensive cases
The existing code to set vectorization and optimization build flags was a bit of a mess. This PR cleans it up and makes some improvements: - There were bits of AVX code left, even though we only compile SSE4.2 and AVX2 kernels nowadays - Vectorization and optimization flags were mixed together for no reason - This caused some downsides - e.g., enabling `NATIVE_ONLY` would skip all the optimization flags - The names were confusing/misleading - for example, `CYCLES_KERNEL_FLAGS` was also used for host code - Optimizations are now directly appended to `CMAKE_CXX_FLAGS` instead of building `CYCLES_KERNEL_FLAGS` and then appending that at the end - Vectorization is renamed from `CYCLES_x_KERNEL_FLAGS` to `CYCLES_x_FLAGS` - The math optimization flags were duplicated between Windows+Clang and GCC or Linux+Clang - Since the only difference is a prefix, CMake lists can clean this up nicely - SSE4.2 was only enabled for host code on GCC/Clang, but we require it on all x86 platforms, so now it's assumed on all compilers that support it - There are some additional math optimizations that I think we can enable safely - Specifically: - `-ffp-contract=fast` (enables FMA generation) - `-freciprocal-math` (enables `x/y -> x*(1/y)`) - `-fassociative-math` (enables e.g. `a*b + c*b -> (a+c)*b`) - These are used on Windows and HIP anyways, so our code can't expect exact IEEE semantics in any case - The only difference between the new set and `-ffast-math` is that we don't use `-ffinite-math-only` since this causes issues with the BVH (see ce1f2e271d84f0bb7798c04cb9ca8459f12cee50) and breaks e.g. `isnan` - This causes a ~1.5% speedup in my very quick test, but might be higher for some more math-intensive cases
Lukas Stockner added 7 commits 2024-09-30 00:20:38 +02:00
Add some more math optimizations
All checks were successful
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
f1f32649b2
Lukas Stockner added this to the Render & Cycles project 2024-09-30 00:20:42 +02:00
Author
Member

@blender-bot build

@blender-bot build
Lukas Stockner requested review from Sergey Sharybin 2024-09-30 00:21:01 +02:00
Lukas Stockner requested review from Weizhen Huang 2024-09-30 00:21:01 +02:00

Overall it seems nice, when you look at the individual commits.

I think we need to land this PR as a non-squished change, for the ease of reading the changes in Git log. But for this it would be nice to have a more proper commit messages (doesn't need to be anything super fancy, but follow the commit title guideline, and briefly explain what the commit is about -- can copy the corresponding lines from the PR description).

Overall it seems nice, when you look at the individual commits. I think we need to land this PR as a non-squished change, for the ease of reading the changes in Git log. But for this it would be nice to have a more proper commit messages (doesn't need to be anything super fancy, but follow the commit title guideline, and briefly explain what the commit is about -- can copy the corresponding lines from the PR description).
Lukas Stockner manually merged commit f96f3c33af into main 2024-09-30 15:59:53 +02:00
Lukas Stockner deleted branch kernel-cpu-flags-cmake-cleanup 2024-09-30 16:00:02 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#128342
No description provided.