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
9 changes: 9 additions & 0 deletions tensilelite/Tensile/Common.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,12 @@ def getArchitectureName(gfxName):
# 1 indicates no assertion (since all sizes are multiples of 1)
"AssertFree1ElementMultiple" : [1,2,4,8,16],

# Assertions that require arithmetic intensity to be specified value.
# Arithmetic intensity measures the ratio of computation to memory bandwidth required for a problem.
# These predicates can be used to adjust solution selection compute-bound or memory-bound problems.
"AssertAIGreaterThanEqual": -1,
"AssertAILessThanEqual": -1,

Comment thread
adityalj marked this conversation as resolved.
Resolved
# Stagger the start summation position of the tiles.
# Elements from the summation dimension are loaded at offsets rather than all starting at 0.
# StaggerU is the max 'clicks' of StaggerUStride bytes where each wg starts ; see StaggerUMapping
Expand Down Expand Up @@ -1130,6 +1136,9 @@ def getArchitectureName(gfxName):
{"AssertSummationElementMultiple": [ 1 ] },
{"AssertFree0ElementMultiple": [ 1 ] },
{"AssertFree1ElementMultiple": [ 1 ] },

{"AssertAIGreaterThanEqual": [-1]},
{"AssertAILessThanEqual": [-1]},

{"StaggerU": [ 32 ] }, # recommend [0,32]
{"StaggerUStride": [ 256 ] }, # recommend 256 for V10,V20
Expand Down
6 changes: 6 additions & 0 deletions tensilelite/Tensile/Contractions.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,12 @@ class ProblemPredicate(Properties.Predicate):
@classmethod
def FromOriginalKeyPair(cls, pair):
(key, value) = pair
# Arithmetic intensity assertions
if key == "AssertAIGreaterThanEqual":
return cls("AIGreaterThanEqual", value=value) if value > 0 else None
if key == "AssertAILessThanEqual":
return cls("AILessThanEqual", value=value) if value > 0 else None

if key.endswith('Multiple'):
if value == 1:
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,11 @@ namespace Tensile
return m_eligibleForPK;
}

double arithmeticIntensity() const
{
return m_arithmeticIntensity;
}

virtual std::vector<ConstantDescriptor> const constants() const
{
std::vector<ConstantDescriptor> c = {{"alpha", m_alphaType}, {"beta", m_betaType}};
Expand Down Expand Up @@ -1103,7 +1108,7 @@ namespace Tensile

KernelLanguage m_kernelLanguage = KernelLanguage::Any;
PerformanceMetric m_performanceMetric = PerformanceMetric::DeviceEfficiency;

double m_arithmeticIntensity;
DataType m_alphaType = DataType::None; // if not assigned, will follow d-type
DataType m_betaType = DataType::None; // for bwd-compatible
DataType m_scaleAType = DataType::None; // if not assigned, will follow alpha-type
Expand Down Expand Up @@ -1145,6 +1150,7 @@ namespace Tensile

void normalize();
void normalizeSparse();
void calcArithmeticIntensity();

void consistencyCheck() const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,83 @@ namespace Tensile
}
};

struct AIGreaterThanEqual
: public Predicate_CRTP<AIGreaterThanEqual, ContractionProblemGemm>
{
enum
{
HasIndex = false,
HasValue = true
};

double value;

AIGreaterThanEqual() = default;
AIGreaterThanEqual(double value)
: value(value)
{
}

static std::string Type()
{
return "AIGreaterThanEqual";
}

virtual bool operator()(ContractionProblemGemm const& problem) const override
{
return problem.arithmeticIntensity() >= value;
}

virtual bool debugEval(ContractionProblemGemm const& problem,
std::ostream& stream) const override
{
bool rv = (*this)(problem);

stream << *this << ": (" << problem.arithmeticIntensity() << " >= " << value
<< ") == " << rv;

return rv;
}
};

struct AILessThanEqual : public Predicate_CRTP<AILessThanEqual, ContractionProblemGemm>
{
enum
{
HasIndex = false,
HasValue = true
};

double value;

AILessThanEqual() = default;
AILessThanEqual(double value)
: value(value)
{
}

static std::string Type()
{
return "AILessThanEqual";
}

virtual bool operator()(ContractionProblemGemm const& problem) const override
{
return problem.arithmeticIntensity() <= value;
}

virtual bool debugEval(ContractionProblemGemm const& problem,
std::ostream& stream) const override
{
bool rv = (*this)(problem);

stream << *this << ": (" << problem.arithmeticIntensity() << " <= " << value
<< ") == " << rv;

return rv;
}
};

struct AlphaValue : public Predicate_CRTP<AlphaValue, ContractionProblemGemm>
{
enum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ namespace Tensile
Base::template Pair<Predicates::Contraction::StrideDEqual>(),
Base::template Pair<Predicates::Contraction::LDCEqualsLDD>(),
Base::template Pair<Predicates::Contraction::CEqualsD>(),
Base::template Pair<Predicates::Contraction::AIGreaterThanEqual>(),
Base::template Pair<Predicates::Contraction::AILessThanEqual>(),
Base::template Pair<Predicates::Contraction::AlphaValue>(),
Base::template Pair<Predicates::Contraction::BetaValue>(),
Base::template Pair<Predicates::Contraction::BetaZero>(),
Expand Down Expand Up @@ -245,6 +247,18 @@ namespace Tensile
{
};

template <typename IO>
struct MappingTraits<Predicates::Contraction::AIGreaterThanEqual, IO>
: public AutoMappingTraits<Predicates::Contraction::AIGreaterThanEqual, IO>
{
};

template <typename IO>
struct MappingTraits<Predicates::Contraction::AILessThanEqual, IO>
: public AutoMappingTraits<Predicates::Contraction::AILessThanEqual, IO>
{
};

template <typename IO>
struct MappingTraits<Predicates::Contraction::AlphaValue, IO>
: public AutoMappingTraits<Predicates::Contraction::AlphaValue, IO>
Expand Down
37 changes: 37 additions & 0 deletions tensilelite/Tensile/Source/lib/source/ContractionProblem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ namespace Tensile
m_beta); // Set enum using beta to potentially allow for faster solutions
consistencyCheck();
normalize();
calcArithmeticIntensity();
}

size_t ContractionProblemGemm::toAPos(size_t idx) const
Expand Down Expand Up @@ -1065,6 +1066,42 @@ namespace Tensile
TENSILE_ASSERT_EXC(dUse == 1);
}

void ContractionProblemGemm::calcArithmeticIntensity()
{
size_t problemSize = 1;
for(size_t i = 0; i < m_problemSizes.size(); ++i)
{
problemSize *= m_problemSizes[i];
}
double gflop = 2 * problemSize * 1e-9;

size_t aSize = 1;
for(size_t i = 0; i < m_a.dimensions(); ++i)
{
aSize *= m_a.sizes()[i];
}
size_t bSize = 1;
for(size_t i = 0; i < m_b.dimensions(); ++i)
{
bSize *= m_b.sizes()[i];
}
size_t cSize = 1;
for(size_t i = 0; i < m_c.dimensions(); ++i)
{
cSize *= m_c.sizes()[i];
}
if(m_beta != 0) // If problem includes beta, update gflops and gbytes
{
gflop += 2 * cSize * 1e-9; // Include (+ beta * C) in gflops
cSize *= 2; // Include read C and write D in gbytes
}
double gbyte
= (aSize * m_a.elementBytes() + bSize * m_b.elementBytes() + cSize * m_c.elementBytes())
* 1e-9;

m_arithmeticIntensity = gflop / gbyte;
}

size_t ContractionProblemGemm::freeSizeA(size_t idx) const
{
return m_freeSizesA.at(idx);
Expand Down