BLI: faster float<->half array conversions, use in Vulkan #127838
No reviewers
Labels
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 project
No Assignees
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#127838
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "aras_p/blender:fp16_conv_batch"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
In addition to float<->half functions to convert one number (#127708), add
float_to_half_array
andhalf_to_float_array
functions:Use these functions in Vulkan buffer/texture conversion code. Time taken to convert float->half texture while viewing EXR file in image space (22M numbers to convert): 39.7ms -> 10.1ms (would be 6.9ms if building for AVX2)
I didn't test the code. So only added some small comments.
@ -117,0 +246,4 @@
src += 4;
dst += 4;
}
#endif
Would add comment that this will convert the remaining elements.
@ -1004,3 +1004,3 @@
case ConversionType::FLOAT_TO_HALF:
convert_per_component<F16, F32>(dst_memory, src_memory, buffer_size, device_format);
blender::math::float_to_half_array(static_cast<const float *>(src_memory),
Can we remove
as those should not be used anymore.
@ -117,0 +222,4 @@
{
size_t i = 0;
#if defined(USE_HARDWARE_FP16_F16C) /* 8-wide loop using AVX2 F16C */
for (; i + 7 < length; i += 8) {
Not for this patch, but perhaps we should do runtime check for intrinsics for such functions.
Yeah I thought about that, but within Blender there's no way to query CPU cap bits right now, right? (only very indirectly through e.g. "what does ffmpeg thinks our CPU caps are?" and so on). Or if there is, where is it?
Check the
intern/cycles/util/system.cpp
,system_cpu_capabilities()
,system_cpu_support_sse42()
,system_cpu_support_avx2()
. We can copy this function to Blender side.@ -117,0 +231,4 @@
}
#elif defined(USE_SSE2_FP16) /* 4-wide loop using SSE2 */
for (; i + 3 < length; i += 4) {
__m128 src4 = _mm_loadu_ps(src);
It is a bit annoying to do unaligned reads. Maybe it is benefitial to chekc
src
anddst
alignment and have a dedicated code path for this case?I checked on my PC (Ryzen 5950X) whether replacing unaligned loads with aligned ones brings any performance benefit, and as I expected... it is not faster at all; i.e. same performance.
Then I checked Agner Fog's CPU instruction latency/throughput tables, and basically these days there's no performance difference between unaligned load/store and aligned load/store (unaligned are slower in case your data crosses cacheline, but normally that does not happen). Both latency and throughput of unaligned vs aligned have been the same since Intel Ivy Bridge (2012) and AMD Bulldozer (2011).
@ -117,0 +240,4 @@
}
#elif defined(USE_HARDWARE_FP16_NEON) /* 4-wide loop using NEON */
for (; i + 3 < length; i += 4) {
float32x4_t src4 = vld1q_f32(src);
Did you experiment with using more than one register for conversion? Something like an extra loop
I didn't check details for this use-case, but for kernels like dot-product having multiple accumulators gives measurable speedup.
I can try, but the primary reason why it ends up helping accumulation/dot-product is because the loops in there are serial, and by doing 2 (or more) accumulations at once, you're allowing CPU to have more things processed in parallel. Whereas this half<->float loop does not have dependencies between the loop iterations; the CPU can already schedule/process ahead as much as it can.
Sure. I am just on a skeptical side and double-check whether CPU actually does of what you logically expect from it.
But it is not something I'd call essential to happen for this PR.
Yeah, just tried going 2x wider and 4x wider within one loop iteration. On Mac M1 (NEON path), does not bring any performance benefits at all.
Thanks for checking!
@ -107,0 +171,4 @@
double t0 = BLI_time_now_seconds();
size_t sum = 0;
blender::math::half_to_float_array(src, dst, test_size);
for (int i = 0; i < test_size; i++) {
Don't think we should be including this look into the timing.
Perosnally i'd put the end timing before the loop which sums the elements in the result. But if you have stronger feelings about it, just stick to the current code.
The rest seems fine, so marking it as green so ti can go in without extra review iterations.
@blender-bot build