Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <mxDataGen.hpp>

#include <cstddef>
#include <map>
#include <random>

#include "RunListener.hpp"
Expand Down Expand Up @@ -1191,6 +1192,10 @@ namespace TensileLite
// hand back gpuInput.valid as-is rather than re-swizzling).
bool m_mxPreswizzledA = false;
bool m_mxPreswizzledB = false;

// Scale descriptor most recently swizzled into gpuInput.valid, per
// tensor index. The MX equivalent of g_swizzleCache.
std::map<size_t, TensorDescriptor> m_mxSwizzledDescriptor;
};

template <>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2130,6 +2130,28 @@ namespace TensileLite
auto& pristineData = m_vdata[dataTensorEnum].pristine[dataDesc.dataType()];
auto& pristineScale = m_vdata[scaleTensorEnum].pristine[scaleEltType];

// prepareGPUInputs() runs once per solution, so without this
// the generator re-runs for every solution on identical input.
// Same idea as the non-MX initDescriptor check below.
//
// gfx1250 only: its scale layout comes from problem geometry, so
// the descriptors fully determine the generated bytes. GFX950
// preswizzles per solution matrix instruction and must not reuse.
bool const reuseSupported = (m_mxScaleLayout == MXScaleLayout::GFX1250);
bool const descriptorsUnchanged
= pristineData.initDescriptor.size() == 1
&& pristineScale.initDescriptor.size() == 1
&& pristineData.initDescriptor[0] == dataDesc
&& pristineScale.initDescriptor[0] == scaleDesc;

if(reuseSupported && descriptorsUnchanged)
return;

if(pristineData.initDescriptor.size() == 1)
pristineData.initDescriptor[0] = dataDesc;
if(pristineScale.initDescriptor.size() == 1)
pristineScale.initDescriptor[0] = scaleDesc;

// Element-size-aware byte stride: FP4 (0.5), FP6 (0.75), FP8 (1.0).
size_t dataBatchStrideBytes = 0;
size_t scaleBatchStrideBytes = 0;
Expand Down Expand Up @@ -2848,8 +2870,18 @@ namespace TensileLite
{
ptr = p.gpuInput.valid.get();
}
else if(auto mxIt = m_mxSwizzledDescriptor.find(i);
m_mxScaleLayout == MXScaleLayout::GFX1250
&& mxIt != m_mxSwizzledDescriptor.end() && mxIt->second == desc)
{
// Already swizzled, and initOneMXSide kept the source bytes
// unchanged, so skip the host-side permute.
ptr = p.gpuInput.valid.get();
}
else
{
m_mxSwizzledDescriptor[i] = desc;

// Fallback K-dimension swizzle for the case where
// initializeMXData did NOT pre-produce a swizzled
// scale into gpuInput.valid (e.g. m_mxScaleLayout is
Expand Down
Loading