Skip to content

Commit 9d89e38

Browse files
committed
[mlir][dxsa] Add dcl_tgsm_structured instruction
Example: dxsa.dcl_tgsm_structured <type = thread_group_shared_memory, components = 0, index = [0]>, 16, 64 Signed-off-by: Vladimir Shiryaev <tagolog@users.noreply.github.com>
1 parent ccd58cf commit 9d89e38

6 files changed

Lines changed: 97 additions & 0 deletions

File tree

mlir/include/mlir/Dialect/DXSA/IR/DXSAOps.td

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,4 +894,32 @@ def DXSA_DclTgsmRaw : DXSA_Op<"dcl_tgsm_raw"> {
894894
let hasVerifier = 1;
895895
}
896896

897+
def DXSA_DclTgsmStructured : DXSA_Op<"dcl_tgsm_structured"> {
898+
let summary = "declares a reference to a Thread Group Shared Memory region";
899+
let description = [{
900+
The `dxsa.dcl_tgsm_structured` operation declares a reference to a Thread Group Shared Memory region.
901+
The memory is viewed as an array of structures.
902+
903+
The `$operand` is the `g#` register being declared.
904+
The `$struct_byte_stride` is a uint in bytes and must be a multiple of 4.
905+
The `$struct_count` is the number of structures.
906+
The total size `$struct_byte_stride * $struct_count` must not exceed
907+
32 KB.
908+
909+
Example:
910+
911+
```mlir
912+
dxsa.dcl_tgsm_structured <type = thread_group_shared_memory, components = 0, index = [0]>, 16, 64
913+
```
914+
}];
915+
let arguments = (ins DXSA_InlineOperandAttr:$operand,
916+
ConfinedAttr<I32Attr,
917+
[IntPositive, IntMaxValue<32768>]>:$struct_byte_stride,
918+
ConfinedAttr<I32Attr,
919+
[IntPositive, IntMaxValue<8192>]>:$struct_count);
920+
let assemblyFormat =
921+
"$operand `,` $struct_byte_stride `,` $struct_count attr-dict";
922+
let hasVerifier = 1;
923+
}
924+
897925
#endif // DXSA_OPS

mlir/lib/Dialect/DXSA/IR/DXSA.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ LogicalResult DclTgsmRaw::verify() {
7070
return success();
7171
}
7272

73+
LogicalResult DclTgsmStructured::verify() {
74+
auto stride = getStructByteStride();
75+
auto count = getStructCount();
76+
if (stride % 4 != 0)
77+
return emitOpError("struct byte stride must be a multiple of 4, got ")
78+
<< stride;
79+
auto totalSize = static_cast<uint64_t>(stride) * count;
80+
if (totalSize > 32768)
81+
return emitOpError("total size struct_byte_stride * struct_count must "
82+
"be <= 32768, got ") << totalSize;
83+
return success();
84+
}
85+
7386
//===----------------------------------------------------------------------===//
7487
// TableGen'd attribute method definitions
7588
//===----------------------------------------------------------------------===//

mlir/lib/Target/DXSA/BinaryParser.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,14 @@ class DXBuilder {
684684
builder.getI32IntegerAttr(byteCount));
685685
}
686686

687+
Instruction buildDclTgsmStructured(dxsa::InlineOperandAttr operand,
688+
uint32_t structByteStride,
689+
uint32_t structCount, Location loc) {
690+
return dxsa::DclTgsmStructured::create(
691+
builder, loc, operand, builder.getI32IntegerAttr(structByteStride),
692+
builder.getI32IntegerAttr(structCount));
693+
}
694+
687695
private:
688696
MLIRContext *context;
689697
ModuleOp module;
@@ -1298,6 +1306,17 @@ class Parser {
12981306
return builder.buildDclTgsmRaw(*operand, *byteCount, loc);
12991307
}
13001308

1309+
FailureOr<Instruction> parseDclTgsmStructured(Location loc) {
1310+
auto operand = parseInlineOperand();
1311+
FAILURE_IF_FAILED(operand);
1312+
auto structByteStride = parseToken();
1313+
FAILURE_IF_FAILED(structByteStride);
1314+
auto structCount = parseToken();
1315+
FAILURE_IF_FAILED(structCount);
1316+
return builder.buildDclTgsmStructured(*operand, *structByteStride,
1317+
*structCount, loc);
1318+
}
1319+
13011320
OptionalParseResult parseDclInstruction(uint32_t opcodeToken, Location loc,
13021321
Instruction &out) {
13031322
FailureOr<Instruction> result;
@@ -1371,6 +1390,9 @@ class Parser {
13711390
case D3D11_SB_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_RAW:
13721391
result = parseDclTgsmRaw(loc);
13731392
break;
1393+
case D3D11_SB_OPCODE_DCL_THREAD_GROUP_SHARED_MEMORY_STRUCTURED:
1394+
result = parseDclTgsmStructured(loc);
1395+
break;
13741396
default:
13751397
return std::nullopt;
13761398
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: mlir-translate --import-dxsa-bin %S/inputs/dcl_tgsm_structured.bin | FileCheck %s
2+
3+
// CHECK: module {
4+
// CHECK-NEXT: dxsa.dcl_tgsm_structured <type = thread_group_shared_memory, components = 0, index = [0]>, 16, 64
5+
// CHECK-NEXT: }
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// RUN: mlir-opt %s -split-input-file -verify-diagnostics
2+
3+
// expected-error@+1 {{'dxsa.dcl_tgsm_structured' op struct byte stride must be a multiple of 4, got 6}}
4+
dxsa.dcl_tgsm_structured <type = thread_group_shared_memory, components = 0, index = [0]>, 6, 64
5+
6+
// -----
7+
8+
// expected-error@+1 {{attribute 'struct_byte_stride' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive whose maximum value is 32768}}
9+
dxsa.dcl_tgsm_structured <type = thread_group_shared_memory, components = 0, index = [0]>, 0, 64
10+
11+
// -----
12+
13+
// expected-error@+1 {{attribute 'struct_byte_stride' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive whose maximum value is 32768}}
14+
dxsa.dcl_tgsm_structured <type = thread_group_shared_memory, components = 0, index = [0]>, 32772, 1
15+
16+
// -----
17+
18+
// expected-error@+1 {{attribute 'struct_count' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive whose maximum value is 8192}}
19+
dxsa.dcl_tgsm_structured <type = thread_group_shared_memory, components = 0, index = [0]>, 16, 0
20+
21+
// -----
22+
23+
// expected-error@+1 {{attribute 'struct_count' failed to satisfy constraint: 32-bit signless integer attribute whose value is positive whose maximum value is 8192}}
24+
dxsa.dcl_tgsm_structured <type = thread_group_shared_memory, components = 0, index = [0]>, 4, 8193
25+
26+
// -----
27+
28+
// expected-error@+1 {{'dxsa.dcl_tgsm_structured' op total size struct_byte_stride * struct_count must be <= 32768, got 32768 * 2}}
29+
dxsa.dcl_tgsm_structured <type = thread_group_shared_memory, components = 0, index = [0]>, 32768, 2
20 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)