rocr: Use view3dAs2dArray flag, for thick/3D swizzle modes.

Added HSA_IMAGE_ENABLE_3D_SWIZZLE_DEBUG environment flag to
enable/disable this. Default value is false (view3dAs2dArray = 1)
Enabling this flag will enable support for swizzles that do 3D
interleaving. Note that all features of 3D images are supported
with 2D swizzles,it's just that the access patterns are different
and therefore cache hit-rates may be better or worse, depending
on how it's used. Volumetric algorithms do better with 3D and apps
that tend to access a single slice at a time do better with 2D.

Change-Id: Id8574a6710fe4333a1ee331e5ce9195a81434198
This commit is contained in:
Shweta Khatri
2025-01-22 11:39:07 -05:00
parent 8a38f121ea
commit 6361466baa
3 changed files with 42 additions and 3 deletions
@@ -48,6 +48,7 @@
#include <algorithm>
#include <climits>
#include "core/inc/runtime.h"
#include "inc/hsa_ext_amd.h"
#include "core/inc/hsa_internal.h"
#include "core/util/utils.h"
@@ -681,9 +682,39 @@ uint32_t ImageManagerGfx12::GetAddrlibSurfaceInfoNv(
break;
case HSA_EXT_IMAGE_GEOMETRY_3D:
in.resourceType = ADDR_RSRC_TEX_3D;
break;
{
in.resourceType = ADDR_RSRC_TEX_3D;
/*
* 3D swizzle modes on GFX12 enforces alignment
* of the number of slices to the block depth.
* If numSlices = 3 then the 3 slices are
* interleaved for 3D locality among the 8 slices
* that make up each block. This causes the memory
* footprint to jump from an ideal size of ~12 GB
* to ~32 GB.
* 'enable3DSwizzleMode' flag tests for env variable
* HSA_IMAGE_ENABLE_3D_SWIZZLE_DEBUG to enable or disable
* 3D swizzle:
* true: Keep view3dAs2dArray = 0 for real 3D interleaving.
* false: Use view3dAs2dArray = 1 to avoid the alignment
* expansion.
* 2D swizzle modes can lower size overhead but may yield
* suboptimal cache behavior for fully 3D volumetric
* operations.
*/
bool enable3DSwizzleMode = core::Runtime::runtime_singleton_->flag().enable_3d_swizzle();
if (enable3DSwizzleMode)
{
in.flags.view3dAs2dArray = 0;
}
else
{
in.flags.view3dAs2dArray = 1;
}
break;
}
}
in.flags.texture = 1;
if (tileMode == Image::TileMode::LINEAR)
@@ -779,6 +810,7 @@ uint32_t ImageManagerGfx12::GetAddrlibSurfaceInfoNv(
minSize = surfaceSize;
bestSwizzle = (Addr3SwizzleMode) i;
} else if ((surfaceSize * ratioHigh) <= (minSize * ratioLow)) {
minSize = surfaceSize;
bestSwizzle = (Addr3SwizzleMode) i;
}
}