extend "Struct-of-array-of-packed-structs" to oneAPI device #122670

Open
Xavier Hallade wants to merge 2 commits from xavierh/blender:xavier/PackedState into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

This follows #122015

Gain for Intel GPUs is lower (1-4% on my A770) but welcome.

It appears after DPC++ upgrade (already planned for 4.2 with #122242)

This follows https://projects.blender.org/blender/blender/pulls/122015 Gain for Intel GPUs is lower (1-4% on my A770) but welcome. It appears after DPC++ upgrade (already planned for 4.2 with https://projects.blender.org/blender/blender/pulls/122242)
Xavier Hallade added 4 commits 2024-06-03 17:51:52 +02:00
make format
Some checks failed
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
c548500d76
Address PR feedback
Some checks failed
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
91e28e69bf
PACKED_STATE -> __INTEGRATOR_GPU_PACKED_STATE__
Remove unnecessary operator=
Add static_assert and comment about float3 padding assumption
Xavier Hallade changed title from WIP: extend "Struct-of-array-of-packed-structs" to oneAPI device to extend "Struct-of-array-of-packed-structs" to oneAPI device 2024-06-03 17:56:50 +02:00
Author
Member

@blender-bot build +gpu

@blender-bot build +gpu
Brecht Van Lommel requested changes 2024-06-03 18:34:00 +02:00
@ -28,2 +28,2 @@
#define KERNEL_STRUCT_MEMBER(parent_struct, type, name, feature) \
state_size += (kernel_features & (feature)) ? sizeof(type) : 0;
#ifdef __INTEGRATOR_GPU_PACKED_STATE__

See my comment in #122015, this needs to be a runtime check on the host side.

See my comment in #122015, this needs to be a runtime check on the host side.

I had a quick pass at making this a runtime check, but the changeset started getting quite big. A couple of approaches I started on:

  1. Define two versions of IntegratorStateGPU, one for the packed layout (IntegratorStateGPU_packed) and one for the traditional layout (IntegratorStateGPU_separate), then have separate host-side setup functions (possibly templated) to deal with both layouts.
  2. Avoid directly referring to IntegratorStateGPU in all host-side code, and instead perform any setup based on pointer offsets / struct sizes etc that can be calculated at run time.
I had a quick pass at making this a runtime check, but the changeset started getting quite big. A couple of approaches I started on: 1) Define two versions of `IntegratorStateGPU`, one for the packed layout (`IntegratorStateGPU_packed`) and one for the traditional layout (`IntegratorStateGPU_separate`), then have separate host-side setup functions (possibly templated) to deal with both layouts. 2) Avoid directly referring to `IntegratorStateGPU` in all host-side code, and instead perform any setup based on pointer offsets / struct sizes etc that can be calculated at run time.

I'm not sure I understand the second option, would this involve running some GPU kernel to compute those pointers offsets?

If so, the first option sounds better to me.

If somehow we can figure out a way to make this perform well on CUDA, we could avoid this problem entirely. Because it's not entirely clear that it should be slow. But I don't currently have much time to look into this.

I'm not sure I understand the second option, would this involve running some GPU kernel to compute those pointers offsets? If so, the first option sounds better to me. If somehow we can figure out a way to make this perform well on CUDA, we could avoid this problem entirely. Because it's not entirely clear that it should be slow. But I don't currently have much time to look into this.

I mean that we could derive offsets/sizes numerically instead of relying on symbols (e.g. memcpy(current_offset, ...); ... ; current_offset += 1; instead of memcpy(&integrator_state_gpu_.parent_struct[array_index].name, ...), but when I tried it was quite fiddly trying to get that to track the layout that the shader compiler makes.

I mean that we could derive offsets/sizes numerically instead of relying on symbols (e.g. `memcpy(current_offset, ...); ... ; current_offset += 1;` instead of `memcpy(&integrator_state_gpu_.parent_struct[array_index].name, ...`), but when I tried it was quite fiddly trying to get that to track the layout that the shader compiler makes.
Author
Member

the tricks with offsets is needed only for Apple as other platforms do have un-padded float3, maybe that simplifies things? I've rebased the changes on top of master, not started to implement a solution yet.

the tricks with offsets is needed only for Apple as other platforms do have un-padded float3, maybe that simplifies things? I've rebased the changes on top of master, not started to implement a solution yet.

I think something like this wouldn't be too bad

#define KERNEL_STRUCT_MEMBER ...

if (device->info.has_packed_integrator_state) {
#define KERNEL_STRUCT_MEMBER_PACKED ...
#include "kernel/integrator/state_template.h"
#include "kernel/integrator/shadow_state_template.h"
#undef KERNEL_STRUCT_MEMBER_PACKED
}
else
#define KERNEL_STRUCT_MEMBER_PACKED ...
#include "kernel/integrator/state_template.h"
#include "kernel/integrator/shadow_state_template.h"
#undef KERNEL_STRUCT_MEMBER_PACKED
}

#undef KERNEL_STRUCT_MEMBER
I think something like this wouldn't be too bad ``` #define KERNEL_STRUCT_MEMBER ... if (device->info.has_packed_integrator_state) { #define KERNEL_STRUCT_MEMBER_PACKED ... #include "kernel/integrator/state_template.h" #include "kernel/integrator/shadow_state_template.h" #undef KERNEL_STRUCT_MEMBER_PACKED } else #define KERNEL_STRUCT_MEMBER_PACKED ... #include "kernel/integrator/state_template.h" #include "kernel/integrator/shadow_state_template.h" #undef KERNEL_STRUCT_MEMBER_PACKED } #undef KERNEL_STRUCT_MEMBER ```

the tricks with offsets is needed only for Apple as other platforms do have un-padded float3, maybe that simplifies things? I've rebased the changes on top of master, not started to implement a solution yet.

For the CPU side layout we just need to CPU and GPU to be consistent about float3 / packed_float3. The Metal trick of stuffing dP and dD into .w coordinates shouldn't spill over into the CPU setup code, I think.

The main issue I ran across is a different thing... that IntegratorStateGPU has different fields in each case, so the CPU needs to be aware of this somehow. Either by having two versions of the struct (e.g. in Brecht's snippet, the "if" block would refer to say IntegratorStateGPU_packed and the "else" block to IntegratorStateGPU_separate), or by avoiding all use of concrete IntegratorStateGPU types in CPU code and determining field offsets / struct sizes / etc programmatically (which is a bit fiddly and probably harder to maintain).

> the tricks with offsets is needed only for Apple as other platforms do have un-padded float3, maybe that simplifies things? I've rebased the changes on top of master, not started to implement a solution yet. For the CPU side layout we just need to CPU and GPU to be consistent about float3 / packed_float3. The Metal trick of stuffing dP and dD into .w coordinates shouldn't spill over into the CPU setup code, I think. The main issue I ran across is a different thing... that `IntegratorStateGPU` has different fields in each case, so the CPU needs to be aware of this somehow. Either by having two versions of the struct (e.g. in Brecht's snippet, the "if" block would refer to say `IntegratorStateGPU_packed` and the "else" block to `IntegratorStateGPU_separate`), or by avoiding all use of concrete `IntegratorStateGPU ` types in CPU code and determining field offsets / struct sizes / etc programmatically (which is a bit fiddly and probably harder to maintain).

We could also store both pointers in the same struct, not sure if that would impact performance.

We could also store both pointers in the same struct, not sure if that would impact performance.

CC-ing @pmoursnv and @salipour in case they want to test or have ideas for CUDA and HIP.

CC-ing @pmoursnv and @salipour in case they want to test or have ideas for CUDA and HIP.
Xavier Hallade force-pushed xavier/PackedState from 89e261739a to bf931d3d1c 2024-06-04 17:11:04 +02:00 Compare
Xavier Hallade added 1 commit 2024-06-04 21:54:44 +02:00
Cycles: extend packed GPU integrator state to CUDA and HIP devices
Some checks failed
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
fcf5f4d421
Some checks failed
buildbot/vexp-code-patch-lint Build done.
buildbot/vexp-code-patch-windows-amd64 Build done.
buildbot/vexp-code-patch-darwin-x86_64 Build done.
buildbot/vexp-code-patch-darwin-arm64 Build done.
buildbot/vexp-code-patch-linux-x86_64 Build done.
buildbot/vexp-code-patch-coordinator Build done.
This pull request has changes conflicting with the target branch.
  • intern/cycles/kernel/types.h

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u xavier/PackedState:xavierh-xavier/PackedState
git checkout xavierh-xavier/PackedState
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
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
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#122670
No description provided.