Last active
August 3, 2017 15:33
-
-
Save annanay25/1f582d6be367ec98426a6ccce4f4b319 to your computer and use it in GitHub Desktop.
Code excerpt for concept implementation of MatMul pattern recognition.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. | |
. | |
. | |
static isl_stat isMatMulOperand(__isl_take isl_basic_map *bmap, | |
void *user) { | |
int InPosPair[] = {-1, -1}; | |
auto DimInPos = user ? static_cast<int *>(user) : InPosPair; | |
auto RefMap = isl_map_equate(isl_map_from_basic_map(bmap), | |
isl_dim_in, DimInPos[0], isl_dim_out, DimInPos[0]); | |
RefMap = isl_map_intersect(RefMap, isl_map_equate(isl_map_from_basic_map(bmap), | |
isl_dim_in, DimInPos[1], isl_dim_out, DimInPos[1])); | |
RefMap = isl_map_intersect_domain(RefMap, isl_basic_map_get_space(bmap)); | |
return isl_map_is_subset(RefMap, isl_map_from_basic_map(bmap)) ? isl_stat_ok : isl_stat_error; | |
} | |
/// Check the form of the access relation. | |
/// | |
/// Check that the access relation @p AccMap has the form M[i][j], where i | |
/// is a @p FirstPos and j is a @p SecondPos. | |
/// | |
/// @param AccMap The access relation to be checked. | |
/// @param FirstPos The index of the input dimension that is mapped to | |
/// the first output dimension. | |
/// @param SecondPos The index of the input dimension that is mapped to the | |
/// second output dimension. | |
/// @return True in case @p AccMap has the expected form and false, | |
/// otherwise. | |
static bool isMatMulOperandAcc(__isl_keep isl_map *AccMap, int &FirstPos, | |
int &SecondPos) { | |
int DimInPos[] = {FirstPos, SecondPos}; | |
if (isl_map_foreach_basic_map(AccMap, isMatMulOperand, | |
static_cast<void *>(DimInPos)) != isl_stat_ok || | |
DimInPos[0] < 0 || DimInPos[1] < 0) | |
return false; | |
FirstPos = DimInPos[0]; | |
SecondPos = DimInPos[1]; | |
return true; | |
} | |
. | |
. | |
. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment