Repository navigation
Closed
Labels
codegenShared code generation infrastructure and dialectscodegen/spirvSPIR-V code generation compiler backendhal/vulkanRuntime Vulkan GPU HAL backend
Description
Current kernel generation introduces lot of control overhead. There are two reasons for this
- The generated kernel is accounting for when the number of workgroups is not enough to execute the entire iteration space
- All operations are tiled to partition to workgroups, and then partitioned to workitems.
The result is the current kernel has the following structure (using CUDA parlance)
for (bz = lb_z + blockIdx.z * blockDim.z ; bz < ub_z; bz+= gridDim.z * blockDim.z)
for (by = lb_y + blockIdx.y * blockDim.y ; by < ub_y; by+= gridDim.y * blockDim.y)
for (bx = lb_x + blockIdx.x * blockDim.x ; bx < ub_x; bx+= gridDim.x * blockDim.x) {
...
for (tz = bz + threadIdx.z ; bz < ub_z; tz+= blockDim.z)
for (ty = by + threadIdx.y ; ty < ub_y; ty+= blockDim.y)
for (tx = lb_x + threadIdx.x ; tx < ub_x; tx+= blockDim.x) {
....
}
}
Ideally for most operations, you dont require tiling. Tiling is only needed when you want to utilize workgroup local memory for staging intermediate computations (or for efficient data access for the tile being computed). For now these would be for matmul, conv, pooling. For elementwise operations, you can
- linearize the iteration space
- Use a single
ifstatement to make threads "outside" of the iteration space inactive.
niters = (ub_z - lb_z) * (ub_y - lb_y) * (ub_x - lb_x)
if (threadIdx.x + blockIdx.x * blockDim.x < niters) {
.....
}
Further improvements could be done for reducing control overhead even for matmul, conv, etc. that do require tiling.
bz = lb_z + blockIdx.z * blockDim.z;
by = lb_y + blockIdx.y * blockDim.y;
bx = lb_x + blockIdx.x * blockDim.x;
tz = bz + threadIdx.z
ty = by + threadIdx.y
tx = bx + threadIdx.x
if (tz < ub_z && ty < ub_y && tx < ub_x) {
}
This will require making sure that the number of blocks launched is enough to execute the entire iteration space.
Metadata
Metadata
Assignees
Labels
codegenShared code generation infrastructure and dialectscodegen/spirvSPIR-V code generation compiler backendhal/vulkanRuntime Vulkan GPU HAL backend
Activity
MaheshRavishankar commentedon Jun 8, 2020
@antiagainst @hanhanW for visibility.
I am looking at not making tiling required for all operations now.
Reduce control overhead in generated code.
Reduce control overhead in generated code.
Reduce control overhead in generated code.
Remove control overhead in loop -> workgroup distribution.
MaheshRavishankar commentedon Jun 29, 2020
Commit 6073d91 resubmits PR #2134. Some outstanding issues using the reduced control flow for distributing loops within a workgourp seems to have a correctness issue in convolution/pooling and it only shows up in Resnet. Thinking it might be because of loop bound computation when lowering a tiled convolution op
FYI : @nicolasvasilache
Remove control overhead in loop -> workgroup distribution.
Remove control overhead in loop -> workgroup distribution.
Remove control overhead in loop -> workgroup distribution.
Remove control overhead in loop -> workgroup distribution.
Remove control overhead in loop -> workgroup distribution.
MaheshRavishankar commentedon Oct 8, 2020
This is blocked by some correctness issue that manifests on Resnet models. @hanhanW was able to create a smaller repro