Skip to content

Commit e40469d

Browse files
committed
Add MLIR support (#1044)
1 parent 5b4e9f0 commit e40469d

File tree

4 files changed

+203
-126
lines changed

4 files changed

+203
-126
lines changed

source/mlir-metadata.json

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23436,7 +23436,7 @@
2343623436
},
2343723437
{
2343823438
"name": "nvvm.fence.mbarrier.init",
23439-
"description": "Fence operation that applies on the prior nvvm.mbarrier.init\n \n [For more information, see PTX ISA](https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-membar)",
23439+
"description": "Fence operation that applies on the prior nvvm.mbarrier.init\n\n [For more information, see PTX ISA](https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-membar)",
2344023440
"assemblyFormat": "attr-dict"
2344123441
},
2344223442
{
@@ -23474,10 +23474,30 @@
2347423474
],
2347523475
"assemblyFormat": "$scope (`from_proxy` `=` $fromProxy^)? (`to_proxy` `=` $toProxy^)? attr-dict"
2347623476
},
23477+
{
23478+
"name": "nvvm.fence.proxy.sync_restrict",
23479+
"summary": "Uni-directional proxy fence operation with sync_restrict",
23480+
"description": "The `nvvm.fence.proxy.sync_restrict` Op used to establish\n ordering between a prior memory access performed between proxies. Currently,\n the ordering is only supported between async and generic proxies. `sync_restrict`\n restricts `acquire` memory semantics to `shared_cluster` and `release` memory\n semantics to `shared_cta` with cluster scope.\n [For more information, see PTX ISA](https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-membar)",
23481+
"attributes": [
23482+
{ "name": "order", "type": "MemOrderKindAttr{weak|relaxed|acquire|release|acq_rel|sc|mmio|volatile}" },
23483+
{ "name": "fromProxy", "type": "DefaultValuedAttr<ProxyKindAttr{alias|async|async.global|async.shared|tensormap|generic}, ProxyKind::GENERIC>" },
23484+
{ "name": "toProxy", "type": "DefaultValuedAttr<ProxyKindAttr{alias|async|async.global|async.shared|tensormap|generic}, ProxyKind::async>" }
23485+
],
23486+
"assemblyFormat": "attr-dict"
23487+
},
2347723488
{
2347823489
"name": "nvvm.fence.sc.cluster",
2347923490
"assemblyFormat": "attr-dict"
2348023491
},
23492+
{
23493+
"name": "nvvm.fence.sync_restrict",
23494+
"summary": "Uni-directional thread fence operation",
23495+
"description": "The `nvvm.fence.sync_restrict` Op restricts the class of memory\n operations for which the fence instruction provides the memory ordering guarantees.\n `sync_restrict` restricts `acquire` memory semantics to `shared_cluster` and\n `release` memory semantics to `shared_cta` with cluster scope.\n [For more information, see PTX ISA](https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#parallel-synchronization-and-communication-instructions-membar)",
23496+
"attributes": [
23497+
{ "name": "order", "type": "MemOrderKindAttr{weak|relaxed|acquire|release|acq_rel|sc|mmio|volatile}" }
23498+
],
23499+
"assemblyFormat": "attr-dict"
23500+
},
2348123501
{
2348223502
"name": "nvvm.griddepcontrol",
2348323503
"description": "If the $kind attribute is set to `wait`, it causes the \n executing thread to wait until all prerequisite grids in flight \n have completed and all the memory operations from the prerequisite grids \n are performed and made visible to the current grid.\n\n When the $kind is launch_dependents, it signals that specific dependents \n the runtime system designated to react to this instruction can be scheduled \n as soon as all other CTAs in the grid issue the same instruction or have \n completed.\n\n [For more information, see PTX ISA](https://docs.nvidia.com/cuda/parallel-thread-execution/#parallel-synchronization-and-communication-instructions-griddepcontrol)",
@@ -23705,6 +23725,24 @@
2370523725
],
2370623726
"assemblyFormat": "$addr `,` $stateOrPhase attr-dict `:` type(operands) `->` type($res)"
2370723727
},
23728+
{
23729+
"name": "nvvm.mbarrier.try_wait",
23730+
"summary": "MBarrier try wait on state or phase with an optional timelimit",
23731+
"description": "The `nvvm.mbarrier.try_wait` operation checks whether the specified\n *mbarrier object* at `addr` has completed the given phase. Note that\n unlike the `nvvm.mbarrier.test.wait` operation, the try_wait operation\n is a potentially-blocking one. If the phase is not yet complete, the\n calling thread may be suspended. A suspended thread resumes execution\n once the phase completes or when a system-defined timeout occurs.\n Optionally, the `ticks` operand can be used to provide a custom timeout\n (in nanoseconds), overriding the system-defined one. The semantics of\n this operation and its operands are otherwise similar to those of the\n `nvvm.mbarrier.test.wait` Op.\n\n [For more information, see PTX ISA](https://docs.nvidia.com/cuda/parallel-thread-execution/#parallel-synchronization-and-communication-instructions-mbarrier-test-wait-try-wait)",
23732+
"inputs": [
23733+
{ "name": "addr", "type": "AnyTypeOf<[LLVM_PointerGeneric, LLVM_PointerShared]>" },
23734+
{ "name": "stateOrPhase", "type": "AnyTypeOf<[I64, I32]>" },
23735+
{ "name": "ticks", "type": "Optional<I32>" }
23736+
],
23737+
"outputs": [
23738+
{ "name": "res", "type": "I1" }
23739+
],
23740+
"attributes": [
23741+
{ "name": "scope", "type": "DefaultValuedAttr<MemScopeKindAttr{cta|cluster|gpu|sys}, MemScopeKind::CTA>" },
23742+
{ "name": "relaxed", "type": "DefaultValuedAttr<BoolAttr, false>" }
23743+
],
23744+
"assemblyFormat": "$addr `,` $stateOrPhase (`,` $ticks^)? attr-dict `:` type(operands) `->` type($res)"
23745+
},
2370823746
{
2370923747
"name": "nvvm.mbarrier.try_wait.parity",
2371023748
"summary": "MBarrier Potentially-Blocking Try Wait with Phase Parity",
@@ -43976,6 +44014,27 @@
4397644014
"assemblyFormat": "`(` $args `)` `waits` `(` $wait_fence_likes `)` `signals` `(` $signal_fence_like `)`\n attr-dict `:` functional-type($args, $results)",
4397744015
"hasCustomAssemblyFormat": true
4397844016
},
44017+
{
44018+
"name": "stream.test.timeline_op",
44019+
"summary": "Test op implementing TimelineOpInterface.",
44020+
"description": "Test-only operation that implements TimelineOpInterface directly,\n allowing Stream dialect tests to verify timeline behavior without\n requiring execution regions or specific op semantics.\n\n This op takes zero or more resource operands with their sizes, zero or more\n await timepoints, and produces zero or more resource results with a result\n timepoint. It has no side effects and no execution region - it purely exists\n to test timepoint propagation, coverage analysis, and timeline scheduling.\n\n The `await_limit` attribute (default -1) controls how many await timepoints\n this op can accept before forcing join creation:\n - await_limit = -1: Unlimited awaits (default, no joins created)\n - await_limit = 0: No awaits allowed (all timepoints must be joined)\n - await_limit = 1: Max 1 await (mimics stream.async.execute behavior)\n - await_limit = N: Max N awaits\n\n Use this op when testing passes that operate on TimelineOpInterface methods.\n It's simpler than stream.async.execute (no execution region) but can still\n model resource-timepoint flows. For example:\n - ElideTimepointsPass coverage analysis (elide_timepoints_coverage.mlir)\n - PropagateTimepointsPass scheduling (propagate_timepoints.mlir)\n - SCF region handling with resources (elide_timepoints_scf.mlir)\n\n Examples:\n // Simple timeline op with no dependencies or resources.\n %tp0 = stream.test.timeline_op with() : () -> () => !stream.timepoint\n\n // Timeline op awaiting other timepoints.\n %tp1 = stream.test.timeline_op await(%tp0) => with() : () -> () => !stream.timepoint\n\n // Timeline op with resource operands and results.\n %r, %tp = stream.test.timeline_op\n with(%arg) : (!stream.resource<external>{%size}) -> !stream.resource<external>{%size}\n => !stream.timepoint\n\n // Timeline op with await_limit to test join creation.\n %r, %tp = stream.test.timeline_op await_limit(1) await(%tp0) =>\n with(%arg) : (!stream.resource<external>{%size}) -> !stream.resource<external>{%size}\n => !stream.timepoint",
44021+
"inputs": [
44022+
{ "name": "resource_operands", "type": "Variadic<AnyTypeOf<[ Stream_AnyStreamResource, Stream_StagingResource, ]>>" },
44023+
{ "name": "resource_operand_sizes", "type": "Variadic<Stream_Size>" },
44024+
{ "name": "result_sizes", "type": "Variadic<Stream_Size>" },
44025+
{ "name": "await_operands", "type": "Variadic<Stream_Timepoint>" }
44026+
],
44027+
"outputs": [
44028+
{ "name": "results", "type": "Variadic<AnyTypeOf<[ Stream_AnyStreamResource, Stream_StagingResource, ]>>" },
44029+
{ "name": "result_timepoint", "type": "Stream_Timepoint" }
44030+
],
44031+
"attributes": [
44032+
{ "name": "tied_operands", "type": "OptionalAttr<Util_TiedOpStorageAttr>" },
44033+
{ "name": "await_limit", "type": "OptionalAttr<I64Attr>" }
44034+
],
44035+
"assemblyFormat": "(`await_limit` `(` $await_limit^ `)`)?\n (`await` `(` $await_operands^ `)` `=` `` `>`)?\n `with` `(` $resource_operands `)` attr-dict `:`\n custom<ShapedFunctionType>(ref($resource_operands),\n type($resource_operands), $resource_operand_sizes,\n type($results), $result_sizes,\n $tied_operands)\n `=` `` `>` type($result_timepoint)",
44036+
"hasCustomAssemblyFormat": true
44037+
},
4397944038
{
4398044039
"name": "stream.timepoint.await",
4398144040
"summary": "Awaits a timepoint before returning a set of resources.",

source/mlir.js

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3127,6 +3127,33 @@ mlir.FunctionType = class extends mlir.Type {
31273127
}
31283128
};
31293129

3130+
mlir.LLVMFunctionType = class extends mlir.Type {
3131+
3132+
constructor(returnType, params, varArg = false) {
3133+
super(null);
3134+
this.returnType = returnType;
3135+
this.params = params || [];
3136+
this.varArg = varArg;
3137+
}
3138+
3139+
get inputs() {
3140+
return this.params;
3141+
}
3142+
3143+
get results() {
3144+
return this.returnType ? [this.returnType] : [];
3145+
}
3146+
3147+
toString() {
3148+
const params = this.params.map((t) => t.toString());
3149+
if (this.varArg) {
3150+
params.push('...');
3151+
}
3152+
const returnType = this.returnType ? this.returnType.toString() : 'void';
3153+
return `!llvm.func<${returnType} (${params.join(', ')})>`;
3154+
}
3155+
};
3156+
31303157
mlir.Utility = class {
31313158

31323159
static dataType(value) {
@@ -11794,17 +11821,15 @@ mlir.LLVMDialect = class extends mlir.Dialect {
1179411821
op.attributes.push({ name: 'CConv', value: parser.expect('id') });
1179511822
}
1179611823
parser.parseSymbolName('sym_name', op.attributes);
11797-
const type = {};
1179811824
const argResult = parser.parseFunctionArgumentList(true);
11799-
type.inputs = argResult.arguments.map((a) => a.type);
11800-
if (argResult.isVariadic) {
11801-
op.attributes.push({ name: 'var_arg_', value: true });
11802-
}
11803-
type.results = [];
11825+
const params = argResult.arguments.map((a) => a.type);
11826+
const results = [];
1180411827
const resultAttrs = [];
1180511828
if (parser.accept('->')) {
11806-
parser.parseFunctionResultList(type.results, resultAttrs);
11829+
parser.parseFunctionResultList(results, resultAttrs);
1180711830
}
11831+
const returnType = results.length > 0 ? results[0] : null;
11832+
const type = new mlir.LLVMFunctionType(returnType, params, argResult.isVariadic);
1180811833
op.attributes.push({ name: 'function_type', value: type });
1180911834
if (parser.accept('id', 'vscale_range')) {
1181011835
parser.expect('(');

tools/mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ schema() {
5959

6060
test() {
6161
echo "mlir test"
62-
node ./tools/mlir_script.js test $@
62+
node ./tools/mlir_script.js test "$@"
6363
}
6464

6565
while [ "$#" != 0 ]; do
@@ -68,6 +68,6 @@ while [ "$#" != 0 ]; do
6868
"clean") clean;;
6969
"sync") sync;;
7070
"schema") schema;;
71-
"test") test $@;;
71+
"test") test "$@";;
7272
esac
7373
done

0 commit comments

Comments
 (0)