Skip to content

Commit 7323d2d

Browse files
committed
change waves_per_block to DenseI32ArrayAttr to allow to use struct(params) in assemblyFormat
Signed-off-by: Tim Gymnich <tim@gymni.ch>
1 parent bceb332 commit 7323d2d

12 files changed

Lines changed: 44 additions & 42 deletions

File tree

water/include/water/Dialect/Wave/IR/WaveAttrs.td

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,18 +237,12 @@ def HardwareConstraintAttr : AttrDef<WaveDialect, "HardwareConstraint"> {
237237
configuration rather than fundamental hardware constraints.
238238
}];
239239
let parameters = (ins "unsigned":$threads_per_wave,
240-
OptionalArrayRefParameter<"unsigned">:$waves_per_block,
240+
OptionalParameter<"::mlir::DenseI32ArrayAttr">:$waves_per_block,
241241
OptionalParameter<"::wave::WaveMmaKindAttr">:$mma_type,
242242
OptionalParameter<"::mlir::DictionaryAttr">:$vector_shapes,
243243
DefaultValuedParameter<"unsigned", "128">:$max_bits_per_load);
244244

245-
let assemblyFormat = [{
246-
`<` `threads_per_wave` `=` $threads_per_wave
247-
(`,` `waves_per_block` `=` `[` $waves_per_block^ `]`)?
248-
(`,` `mma_type` `=` $mma_type^)?
249-
(`,` `vector_shapes` `=` $vector_shapes^)?
250-
(`,` `max_bits_per_load` `=` $max_bits_per_load^)? `>`
251-
}];
245+
let assemblyFormat = "`<` struct(params) `>`";
252246

253247
let genVerifyDecl = 1;
254248
}

water/include/water/Dialect/Wave/IR/WaveInterfaces.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,8 @@ class IndexExprsAnalysisInit {
558558
symbolConstraints;
559559

560560
// Waves-per-block extracted from the hardware constraint or computed from
561-
// wave constraints. Always stored here, even if copied from an attribute.
562-
llvm::SmallVector<unsigned, 3> wavesPerBlock;
561+
// wave constraints.
562+
llvm::SmallVector<int32_t, 3> wavesPerBlock;
563563
};
564564

565565
// Lattice for propagating index expressions across wave dialect operations.

water/include/water/Dialect/Wave/IR/WaveUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ llvm::LogicalResult computeWavesPerBlockFromConstraints(
6262
const llvm::SmallDenseMap<wave::WaveSymbolAttr, wave::WaveConstraintAttr>
6363
&waveConstraints,
6464
wave::WaveHyperparameterAttr hyperparams,
65-
llvm::SmallVectorImpl<unsigned> &wavesPerBlock);
65+
llvm::SmallVectorImpl<int32_t> &wavesPerBlock);
6666

6767
/// Permute the shape according to the mapping.
6868
void permuteShape(llvm::ArrayRef<wave::WaveSymbolAttr> shape,

water/include/water/c/Dialects.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ mlirAttributeIsAHardwareConstraintAttr(MlirAttribute attr);
475475
/// Creates a new HardwareConstraintAttr
476476
MLIR_CAPI_EXPORTED MlirAttribute mlirHardwareConstraintAttrGet(
477477
MlirContext mlirCtx, unsigned threadsPerWave, size_t wavesPerBlockSize,
478-
unsigned *wavesPerBlock, MlirAttribute mmaType, MlirAttribute vectorShapes,
478+
int32_t *wavesPerBlock, MlirAttribute mmaType, MlirAttribute vectorShapes,
479479
unsigned maxBitsPerLoad);
480480

481481
/// Returns the typeID of a HardwareConstraintAttr.
@@ -486,7 +486,7 @@ MLIR_CAPI_EXPORTED unsigned
486486
mlirHardwareConstraintAttrGetThreadsPerWave(MlirAttribute attr);
487487
MLIR_CAPI_EXPORTED intptr_t
488488
mlirHardwareConstraintAttrGetNumWavesPerBlock(MlirAttribute attr);
489-
MLIR_CAPI_EXPORTED unsigned
489+
MLIR_CAPI_EXPORTED int32_t
490490
mlirHardwareConstraintAttrGetWavesPerBlockElem(MlirAttribute attr, intptr_t i);
491491
MLIR_CAPI_EXPORTED MlirAttribute
492492
mlirHardwareConstraintAttrGetMmaType(MlirAttribute attr);

water/lib/CAPI/Dialects.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ bool mlirAttributeIsAHardwareConstraintAttr(MlirAttribute attr) {
516516

517517
MlirAttribute
518518
mlirHardwareConstraintAttrGet(MlirContext mlirCtx, unsigned threadsPerWave,
519-
size_t wavesPerBlockSize, unsigned *wavesPerBlock,
519+
size_t wavesPerBlockSize, int32_t *wavesPerBlock,
520520
MlirAttribute mmaType, MlirAttribute vectorShapes,
521521
unsigned maxBitsPerLoad) {
522522
MLIRContext *ctx = unwrap(mlirCtx);
@@ -525,9 +525,14 @@ mlirHardwareConstraintAttrGet(MlirContext mlirCtx, unsigned threadsPerWave,
525525
auto vectorShapesAttr =
526526
llvm::cast_if_present<DictionaryAttr>(unwrap(vectorShapes));
527527

528+
DenseI32ArrayAttr wavesPerBlockAttr;
529+
if (wavesPerBlockSize > 0)
530+
wavesPerBlockAttr = DenseI32ArrayAttr::get(
531+
ctx, llvm::ArrayRef(wavesPerBlock, wavesPerBlockSize));
532+
528533
return wrap(wave::HardwareConstraintAttr::get(
529-
ctx, threadsPerWave, llvm::ArrayRef(wavesPerBlock, wavesPerBlockSize),
530-
mmaTypeAttr, vectorShapesAttr, maxBitsPerLoad));
534+
ctx, threadsPerWave, wavesPerBlockAttr, mmaTypeAttr, vectorShapesAttr,
535+
maxBitsPerLoad));
531536
}
532537

533538
MlirTypeID mlirWHardwareConstraintAttrGetTypeID() {
@@ -539,14 +544,15 @@ unsigned mlirHardwareConstraintAttrGetThreadsPerWave(MlirAttribute attr) {
539544
.getThreadsPerWave();
540545
}
541546
intptr_t mlirHardwareConstraintAttrGetNumWavesPerBlock(MlirAttribute attr) {
542-
return llvm::cast<wave::HardwareConstraintAttr>(unwrap(attr))
543-
.getWavesPerBlock()
544-
.size();
547+
DenseI32ArrayAttr wpb =
548+
llvm::cast<wave::HardwareConstraintAttr>(unwrap(attr)).getWavesPerBlock();
549+
return wpb ? wpb.size() : 0;
545550
}
546-
unsigned mlirHardwareConstraintAttrGetWavesPerBlockElem(MlirAttribute attr,
547-
intptr_t i) {
551+
int32_t mlirHardwareConstraintAttrGetWavesPerBlockElem(MlirAttribute attr,
552+
intptr_t i) {
548553
return llvm::cast<wave::HardwareConstraintAttr>(unwrap(attr))
549-
.getWavesPerBlock()[i];
554+
.getWavesPerBlock()
555+
.asArrayRef()[i];
550556
}
551557
MlirAttribute mlirHardwareConstraintAttrGetMmaType(MlirAttribute attr) {
552558
return wrap(

water/lib/Dialect/Wave/IR/WaveAttrs.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -708,12 +708,11 @@ WaveExprListAttr::verify(function_ref<InFlightDiagnostic()> emitError,
708708

709709
LogicalResult HardwareConstraintAttr::verify(
710710
function_ref<InFlightDiagnostic()> emitError, unsigned threadsPerWave,
711-
ArrayRef<unsigned> wavesPerBlock, WaveMmaKindAttr mmaType,
711+
DenseI32ArrayAttr wavesPerBlock, WaveMmaKindAttr mmaType,
712712
DictionaryAttr vectorShapes, unsigned maxBitsPerLoad) {
713713

714-
if (!(wavesPerBlock.empty() || wavesPerBlock.size() == 3))
715-
return emitError() << "waves_per_block (" << wavesPerBlock
716-
<< ") should have 3 elements";
714+
if (wavesPerBlock && wavesPerBlock.size() != 3)
715+
return emitError() << "waves_per_block should have 3 elements";
717716

718717
if (vectorShapes) {
719718
for (NamedAttribute attr : vectorShapes) {

water/lib/Dialect/Wave/IR/WaveDialect.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,10 @@ verifyConstraints(ArrayAttr constraints,
315315
// verify consistency between wave constraints and waves_per_block
316316
// * If both wave constraints and waves_per_block are present, the computed
317317
// number of waves per dimension should match the waves_per_block attribute.
318-
if (hardwareConstraint && !hardwareConstraint.getWavesPerBlock().empty() &&
318+
if (hardwareConstraint && hardwareConstraint.getWavesPerBlock() &&
319319
!waveConstraints.empty()) {
320-
llvm::ArrayRef<unsigned> wavesPerBlock =
321-
hardwareConstraint.getWavesPerBlock();
320+
llvm::ArrayRef<int32_t> wavesPerBlock =
321+
hardwareConstraint.getWavesPerBlock().asArrayRef();
322322
for (auto &&[symbol, waveConstraint] : waveConstraints) {
323323
wave::WorkgroupConstraintAttr wgConstraint = workgroupConstraints[symbol];
324324
unsigned wgDim =

water/lib/Dialect/Wave/IR/WaveInterfaces.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -889,11 +889,11 @@ wave::IndexExprsAnalysisInit::create(Location loc, Attribute constraintsAttr,
889889
// If waves_per_block is explicitly provided, copy it to storage. Note that we
890890
// have verified they match the result of dividing block tiles with wave tiles
891891
// previously.
892-
if (!initObject.hardwareConstraint.getWavesPerBlock().empty()) {
892+
if (initObject.hardwareConstraint.getWavesPerBlock()) {
893893
assert(initObject.hardwareConstraint.getWavesPerBlock().size() == 3 &&
894894
"expected waves_per_block to have 3 elements");
895-
llvm::ArrayRef<unsigned> explicitWpb =
896-
initObject.hardwareConstraint.getWavesPerBlock();
895+
llvm::ArrayRef<int32_t> explicitWpb =
896+
initObject.hardwareConstraint.getWavesPerBlock().asArrayRef();
897897
initObject.wavesPerBlock.assign(explicitWpb);
898898
return initObject;
899899
}

water/lib/Dialect/Wave/IR/WaveOps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ void MmaSingleIndexExprBuilder::populate(
870870
// dimension.
871871
static llvm::LogicalResult
872872
populateMmaIndexingExpr(wave::WaveMmaKind kind, bool isAccumulator,
873-
llvm::ArrayRef<unsigned> wavesPerWorkgroup,
873+
llvm::ArrayRef<int32_t> wavesPerWorkgroup,
874874
int64_t threadsPerWave, wave::WaveSymbolAttr mSymbol,
875875
wave::WaveSymbolAttr nSymbol,
876876
wave::WaveSymbolAttr kSymbol,

water/lib/Dialect/Wave/IR/WaveUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ LogicalResult wave::computeWavesPerBlockFromConstraints(
133133
const llvm::SmallDenseMap<wave::WaveSymbolAttr, wave::WaveConstraintAttr>
134134
&waveConstraints,
135135
wave::WaveHyperparameterAttr hyperparams,
136-
SmallVectorImpl<unsigned> &wavesPerBlock) {
136+
SmallVectorImpl<int32_t> &wavesPerBlock) {
137137
// Default to 1 wave per block for each dimension, this may be recomputed
138138
// later if the corresponding constraints are provided.
139139
wavesPerBlock.assign(/*NumElts=*/3, /*Elt=*/1);
@@ -168,7 +168,7 @@ LogicalResult wave::computeWavesPerBlockFromConstraints(
168168
int64_t numWaves = workgroupSize / waveSize;
169169
unsigned wgDim =
170170
static_cast<unsigned>(wgConstraint.getWorkgroupDim().getValue());
171-
wavesPerBlock[wgDim] = static_cast<unsigned>(numWaves);
171+
wavesPerBlock[wgDim] = static_cast<int32_t>(numWaves);
172172
}
173173

174174
return success();

0 commit comments

Comments
 (0)