Skip to content

Support using shared memory to store registers for faster evaluation - #515

Open
LukeP0WERS wants to merge 1 commit into
mkeeter:mainfrom
LukeP0WERS:shared_registers
Open

LukeP0WERS wants to merge 1 commit into
mkeeter:mainfrom
LukeP0WERS:shared_registers

Conversation

@LukeP0WERS

Copy link
Copy Markdown
Contributor

Shared memory is a common optimization used to store moderate amounts of data for shaders that is faster to write and load than spilling to local memory. It is significantly faster (3-4 cycles) than loading from the L1 and L2 caches (10-20 and 100-200 cycles respectively), not quite the speed of static registers (1 cycle) but its close. In fidgets case, switching to these improved performance massively, however only 16KiB is guaranteed to be supported by all devices (and for devices that support more it starts to introduce tradeoffs to performance due to lowering occupancy). This means only some of the shader variants can support shared memory registers:

REG_COUNT Float (4 B) Interval (8 B) Gradient (16 B)
8 ✓ ✓ ✓
16 ✓ ✓ ✓
32 ✓ ✓ ✗
64 ✓ ✗ ✗
128 ✗ ✗ ✗
192 ✗ ✗ ✗
255 ✗ ✗ ✗

I tested every model and every model that fit within the window benefited from using it. Each of these measurements came from the median of 3 runs:

Model Mode REG_COUNT Shared Passes Private Shared Change
quarter 2D 8 3/3 2.56 ms 2.57 ms +0.4%
hi 2D 16 3/3 2.60 ms 2.58 ms −0.8%
perlin 2D 16 3/3 3.72 ms 3.12 ms −16.1%
prospero 2D 128 0/3 18.40 ms 18.44 ms +0.2%
gyroid-sphere 3D 8 5/5 5.30 ms 4.19 ms −20.9%
tanglecube 3D 8 5/5 3.05 ms 2.69 ms −11.8%
cabin 3D 16 5/5 4.26 ms 3.26 ms −23.5%
sponge 3D 16 5/5 15.53 ms 9.41 ms −39.4%
bear 3D 32 4/5 63.33 ms 33.68 ms −46.8%
terrain 3D 32 4/5 56.28 ms 26.44 ms −53.0%
colonnade 3D 64 1/5 16.34 ms 15.64 ms −4.3%

I was also curious whether I could squeeze out any additional perf by automatically increasing the shared memory limit to whatever the users device supported. Doing so actually worsened performance for some passes. Prospero took 127.6% longer with shared float eval, but that might have been a worse case scenario. Some of the 3D passes saw 5-10% further improvement, so that feature will come with tradeoffs that need to be documented, and I can make a follow up PR to add that later on. For now this is an improvement across the board, at least on the RTX 4070 Laptop I tested this with.

@LukeP0WERS

Copy link
Copy Markdown
Contributor Author

This addresses the idea I talked about way back in #243, so I can close that separately once this goes through.

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.

1 participant