You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As IREE controls both the compiler and runtime using static or dynamic shared memory doesn't make a big difference. Switching to dynamic shared memory all the time will allow us to allocate more shared memory to a given group and have a larger search space for code generation.
What needs to be done:
Change the logic that creates several global static shared memory in codegen and allocate a single dynamically sized global. Split the global between the different allocations. (either using subview op or by generating directly llvm pointer arithmetic). Current logic is here
Add a new attribute to the kernel to indicate the shared memory size
Add the shared memory size to the flat buffer definition.
Pass the dynamic shared memory size to the dispatch call in HAL (should support both cuda stream and cuda graph)
This shouldn't break ROCm backend, we should change it for CUDA only. If we think it may also help ROCm we could change it there as well.
That approach should be fine for now - if we need to compute a shared memory size at runtime based on device parameters and such we'll need to use the specialization constants approach instead (effectively runtime templating of executables), but that's bigger changes and easy to swap in place of this when we get there.
That approach should be fine for now - if we need to compute a shared memory size at runtime based on device parameters and such we'll need to use the specialization constants approach instead (effectively runtime templating of executables), but that's bigger changes and easy to swap in place of this when we get there.
You mean have it explicitly in the hal dialect? That makes sense, I'm hoping we won't have to do that as in general the shared memory size should be only tied to the tile size that we should always know at compile time.
Correct! When the executables are created we'll be able to pass in a table of key=value pairs that get substituted for values in the executables and those values can be derived from any VM code we want. This would result in a fixed parameter table available to all dispatches in CPU/CUDA (where we can't easily mutate compiled code) or in the case of a JIT (SPIR-V/WGSL/MSL/etc) will specialize the code in the driver compiler.
The issue with shared memory in general is that we can't know the available amount at compile-time (https://vulkan.gpuinfo.org/displaydevicelimit.php?name=maxComputeSharedMemorySize&platform=all, Metal is 16-32KB, etc) and we also need to balance the local workgroup size that also changes. Today we're implicitly assuming these limits and that prevents us from generating portable binaries - this may matter less in the CUDA case because of the closed ecosystem and the architecture<->shared memory size association that usually makes it fine to assume, but something we'll need for other backends (CPU for cache sizes, Vulkan/Metal/etc for shared memory sizes, etc). The mid-term goal for codegen should be to get to the point where the workgroup size is expressed as a computation derived from device parameters (similar to the workgroup count) - once we do that it'll be easier to wire all this up so that if not available at compilation time we can emit the code to derive it all. Anything else we want to compute could be expressed in the same way (workgroup count limits, subgroup sizes, etc).
I think going the pragmatic route here you mention is great as an early version of the specialization constants could have a special case for local workgroup size xyz and it'd be something that could wire right up in place of the flatbuffer fields!
Change the logic that creates several global static shared memory in codegen and allocate a single dynamically sized global. Split the global between the different allocations. (either using subview op or by generating directly llvm pointer arithmetic). Current logic is here
Activity
benvanik commentedon Feb 14, 2022
That approach should be fine for now - if we need to compute a shared memory size at runtime based on device parameters and such we'll need to use the specialization constants approach instead (effectively runtime templating of executables), but that's bigger changes and easy to swap in place of this when we get there.
ThomasRaoux commentedon Feb 14, 2022
You mean have it explicitly in the hal dialect? That makes sense, I'm hoping we won't have to do that as in general the shared memory size should be only tied to the tile size that we should always know at compile time.
benvanik commentedon Feb 14, 2022
Correct! When the executables are created we'll be able to pass in a table of key=value pairs that get substituted for values in the executables and those values can be derived from any VM code we want. This would result in a fixed parameter table available to all dispatches in CPU/CUDA (where we can't easily mutate compiled code) or in the case of a JIT (SPIR-V/WGSL/MSL/etc) will specialize the code in the driver compiler.
The issue with shared memory in general is that we can't know the available amount at compile-time (https://vulkan.gpuinfo.org/displaydevicelimit.php?name=maxComputeSharedMemorySize&platform=all, Metal is 16-32KB, etc) and we also need to balance the local workgroup size that also changes. Today we're implicitly assuming these limits and that prevents us from generating portable binaries - this may matter less in the CUDA case because of the closed ecosystem and the architecture<->shared memory size association that usually makes it fine to assume, but something we'll need for other backends (CPU for cache sizes, Vulkan/Metal/etc for shared memory sizes, etc). The mid-term goal for codegen should be to get to the point where the workgroup size is expressed as a computation derived from device parameters (similar to the workgroup count) - once we do that it'll be easier to wire all this up so that if not available at compilation time we can emit the code to derive it all. Anything else we want to compute could be expressed in the same way (workgroup count limits, subgroup sizes, etc).
I think going the pragmatic route here you mention is great as an early version of the specialization constants could have a special case for local workgroup size xyz and it'd be something that could wire right up in place of the flatbuffer fields!
ThomasRaoux commentedon Feb 14, 2022
ah good point, I didn't see it that way. Sounds like having real dynamic shared memory makes sense. I'll keep that in mind.
nirvedhmeshram commentedon Feb 16, 2022
I am currently working on this part
nirvedhmeshram commentedon Feb 24, 2022
I have made progress on this feature #8405
nirvedhmeshram commentedon Feb 26, 2022
This is now implemented #8405
[Codegen][ROCDL] Drop nominal support for dynamic shared mem
[Codegen][ROCDL] Drop nominal support for dynamic shared mem
[Codegen][ROCDL] Drop nominal support for dynamic shared mem (#20805)
[Codegen][ROCDL] Drop nominal support for dynamic shared mem (#20805)