-
Notifications
You must be signed in to change notification settings - Fork 372
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
SIMD Friendly Math and Noise refinements to work inside SIMD loops #1108
SIMD Friendly Math and Noise refinements to work inside SIMD loops #1108
Conversation
…tions friendly to use inside SIMD loops. Introduce IntHashBasedNoise to serve as base for HashNoise & CellNoise. Reimplemented PeriodicHashNoise and PeriodicCellNose to use an adapter to wrap their input values and reuse existing HashNoise & CellNoise implementations. Introduce code generation policies for Perlin based based functions and Noise objects in order to resuse the same perlin noise functions with or without SIMD intrinsics. Using a "scalar"(non-intrinsic) version of the algorithm is required when calling from inside a SIMD loop. Defined Scalar versions of any Noise objects that used SIMD intrinsics internally. Provide optimized inthash, sfm_simplexnoise, sfm_gabornoise implementations suitable for use inside SIMD loops. Introduce wide.h with Block<T, int Width> to store data as structure of arrays internally, more Wide and Masked wrappers to Block<T> be added in future. Added osl::conjunction and osl::enable_if_type for compatibility with older C++ versions that do not have their equivalents defined in std:: Added OSL_NON_INTEL_CLANG = [0 | 1] to identify when compiler is a truely clang, as OSX still has __clang__ defined when using Intel compiler. Added OSL_NODISCARD Added OSL_OMP_PRAGMA(unquoted_text) that will only be emitted when -DOSL_OPENMP_SIMD and -DNDEBUG (disabled in debug builds) Added OSL_FORCEINLINE_BLOCK on supported compilers will recursively inline the following statement Split common portions of gabornoise.cpp into gabornoise.h that can be shared with sfm_gabornoise.h (the SIMD friendly version of gabornoise).
… of & [-Werror=parentheses] in sfmath.h
I have not forgotten about this, @AlexMWells , it's just a lot to digest. The gist of this work LGTM, but I want to do some benchmarking on my end before merging, and also double check that nothing breaks in OptiX mode, which the CI tests do not check. I feel like I need to read through it deeply one more time, too. After I merge, I'll take a pass at porting a lot of the SIMD-friendly versions of things in OIIO, back to OIIO, and perhaps eventually removing them from here if we are willing to live with the assumption that consumers of the SIMD OSL might be expected to have a higher version floor of OIIO than those who don't need those features. |
A lot of this breaks the build when USE_OPTIX=1 |
…e successful nvcc builds
// NOTE: parameters must NOT be references, to avoid inlining caller's creation of | ||
// these values down inside the conditional assignments which can create to complex | ||
// of a code flow for Clang's vectorizer to handle | ||
static_assert(!std::is_reference<decltype(b)>::value, "parameters to select cannot be references"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside: I think these static_assert calls are probably a holdover from when this function was a template. But now fully specialized to float, they don't serve a purpose. Some time later, we should just remove them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I left the static assert in there as strong teeth vs. just a comment, should someone come along later and change the parameters to references the static assert would fire. In fact I might have done that myself and not wanted to repeat the same mistake. It took a while to track it down, as inlining an entire AST tree inside a select because it is a reference is not obvious
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a big fan of defensive programming. :-)
Yes, the fixes build cleanly with I will merge. |
Note: as I explained before, I intend to migrate a good portion of the "sfm" functions back into OIIO fmath.h and OpenEXR's headers, and then undo some of these changes to use those versions rather than replicating that code here. It will require that people wanting full performance of the SIMD batch shading will need sufficiently new OIIO+OpenEXR, but I'm ok with that restriction. |
Also passes our renderer's testsuite. |
Yes, that is a solid plan. |
Introduce sfm (SIMD Friendly Math) namespace with versions of math functions friendly to use inside SIMD loops.
Introduce IntHashBasedNoise to serve as base for HashNoise & CellNoise.
Reimplemented PeriodicHashNoise and PeriodicCellNose to use an adapter to wrap their input values and reuse existing HashNoise & CellNoise implementations.
Introduce code generation policies for Perlin based based functions and Noise objects in order to resuse the same perlin noise functions with or without SIMD intrinsics. Using a "scalar"(non-intrinsic) version of the algorithm is required when calling from inside a SIMD loop.
Defined Scalar versions of any Noise objects that used SIMD intrinsics internally.
Provide optimized inthash, sfm_simplexnoise, sfm_gabornoise implementations suitable for use inside SIMD loops.
Introduce wide.h with Block<T, int Width> to store data as structure of arrays internally, more Wide and Masked wrappers to Block be added in future.
Added osl::conjunction and osl::enable_if_type for compatibility with older C++ versions that do not have their equivalents defined in std::
Added OSL_NON_INTEL_CLANG = [0 | 1] to identify when compiler is a truely clang, as OSX still has clang defined when using Intel compiler.
Added OSL_NODISCARD
Added OSL_OMP_PRAGMA(unquoted_text) that will only be emitted when -DOSL_OPENMP_SIMD and -DNDEBUG (disabled in debug builds)
Added OSL_FORCEINLINE_BLOCK on supported compilers will recursively inline the following statement
Split common portions of gabornoise.cpp into gabornoise.h that can be shared with sfm_gabornoise.h (the SIMD friendly version of gabornoise).