Merged
refactor(operation): Replace GatherInUB magic numbers with named constants #6590
refactor(operation): Replace GatherInUB magic numbers with named constants #6590
Merged
bynshardAdd on Sep 21
Total: 1 files changed+7-3
@@ -2011,6 +2011,9 @@ Tensor Reshape(const Tensor& operand, const std::vector<SymbolicScalar>& dstShap
2011 return dst;2011 return dst;
2012}2012}
2013 2013 
2014+constexpr int64_t GATHER_IN_UB_INDICES_LEADING_DIM = 1;
2015+constexpr int GATHER_IN_UB_SUPPORTED_AXIS = -2;
2016+ 
2014void TiledGatherInUB(Function& function, const TileShape& tileShape, const LogicalTensorPtr& param,2017void TiledGatherInUB(Function& function, const TileShape& tileShape, const LogicalTensorPtr& param,
2015 const LogicalTensorPtr& indices, const LogicalTensorPtr& blockTable,2018 const LogicalTensorPtr& indices, const LogicalTensorPtr& blockTable,
2016 const LogicalTensorPtr& result, int blockSize)2019 const LogicalTensorPtr& result, int blockSize)
@@ -2031,7 +2034,7 @@ void TiledGatherInUB(Function& function, const TileShape& tileShape, const Logic
2031 for (int64_t j = 0; j < result->GetShape()[1]; j += secondDimTileShape) {2034 for (int64_t j = 0; j < result->GetShape()[1]; j += secondDimTileShape) {
2032 auto shape1 = std::min(result->GetShape()[1] - j, secondDimTileShape);2035 auto shape1 = std::min(result->GetShape()[1] - j, secondDimTileShape);
2033 auto paramTile = param->View(function, {param->GetShape()[0], shape1}, {0, j});2036 auto paramTile = param->View(function, {param->GetShape()[0], shape1}, {0, j});
2034- auto indicesTile = indices->View(function, {1, shape0}, {0, i});2037+ auto indicesTile = indices->View(function, {GATHER_IN_UB_INDICES_LEADING_DIM, shape0}, {0, i});
2035 auto blockTableTile = blockTable->View(function, {blockTable->GetShape()[0], blockTable->GetShape()[1]},2038 auto blockTableTile = blockTable->View(function, {blockTable->GetShape()[0], blockTable->GetShape()[1]},
2036 {0, 0});2039 {0, 0});
2037 auto resultTile = result->View(function, {shape0, shape1}, {i, j});2040 auto resultTile = result->View(function, {shape0, shape1}, {i, j});
@@ -2064,9 +2067,10 @@ Tensor experimental::GatherInUB(const Tensor& params, const Tensor& indices, con
2064 2067 
2065 CheckTensorDimRange(params.GetStorage(), NUM_VALUE_2, NUM_VALUE_2, "GatherInUB params");2068 CheckTensorDimRange(params.GetStorage(), NUM_VALUE_2, NUM_VALUE_2, "GatherInUB params");
2066 CheckTensorDimRange(indices.GetStorage(), NUM_VALUE_2, NUM_VALUE_2, "GatherInUB indices");2069 CheckTensorDimRange(indices.GetStorage(), NUM_VALUE_2, NUM_VALUE_2, "GatherInUB indices");
2067- CHECK(VectorErrorCode::ERR_PARAM_INVALID, indices.GetShape()[0] == 1)2070+ CHECK(VectorErrorCode::ERR_PARAM_INVALID, indices.GetShape()[0] == GATHER_IN_UB_INDICES_LEADING_DIM)
2068 << "GatherInUB requires indices with shape [1, c]; got first dimension " << indices.GetShape()[0] << ".";2071 << "GatherInUB requires indices with shape [1, c]; got first dimension " << indices.GetShape()[0] << ".";
2069- CHECK(VectorErrorCode::ERR_PARAM_INVALID, axis == -2) << "GatherInUB only supports axis = -2; got " << axis << ".";2072+ CHECK(VectorErrorCode::ERR_PARAM_INVALID, axis == GATHER_IN_UB_SUPPORTED_AXIS)
2073+ << "GatherInUB only supports axis = " << GATHER_IN_UB_SUPPORTED_AXIS << "; got " << axis << ".";
2070 Tensor result{params.GetStorage()->Datatype(), {indices.GetShape()[1], params.GetShape()[1]}};2074 Tensor result{params.GetStorage()->Datatype(), {indices.GetShape()[1], params.GetShape()[1]}};
2071 if (!indices.GetStorage()->GetDynValidShape().empty()) {2075 if (!indices.GetStorage()->GetDynValidShape().empty()) {
2072 result.GetStorage()->UpdateDynValidShape(2076 result.GetStorage()->UpdateDynValidShape(