You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "tlopex (via GitHub)" <gi...@apache.org> on 2026/06/19 04:49:38 UTC
[PR] [TIRx] Phase out flat device-intrinsic op aliases [tvm]
tlopex opened a new pull request, #19838:
URL: https://github.com/apache/tvm/pull/19838
PR #19677 registered every CUDA / Trainium device intrinsic under two Op names: a flat `tirx.<ns>_<name>` alias plus the canonical `tirx.<ns>.<name>`. The flat aliases were a migration shim; passes and codegen that match an intrinsic had to check both spellings (the dual-name IsOp pattern). The Python builders and TVMScript parser already canonicalize, so every real Call already carries the canonical op and the flat aliases were dead weight.
This pr removes the flat device-intrinsic aliases, keeping only the canonical namespaced ops:
- RegisterDeviceIntrinsic (backend/cuda) and RegisterNKIIntrinsic (backend/trn) register only the canonical name.
- Drop the flat-only macro registrations for device intrinsics; the canonical op with all attrs is registered from the alias table. The WMMA tvm_*_sync / mma_store / mma_fill builtins and the profiling timer_*_cuda builtins keep their flat names (no namespace / canonical form, category "builtin").
- Remove the redundant flat tirx.ptx_fetch_register registration.
- C++ consumers that resolved a flat op by name string now use the canonical name; the ptx_elect_sync / cuda_func_call dual-name matchers collapse to the canonical check.
- Python: the InjectPTXAsyncCopy round-trip Op.get and the matching test assertion use the canonical name. call_intrin keeps its flat->canonical rewrite for back-compat, so user-facing wrappers are unchanged.
- test_op_namespace_cleanup asserts device_intrin op names are canonical so a flat alias cannot silently reappear.
Generated CUDA is byte-identical: helper names are literals and codegen dispatches by op name, with the registry resolving the canonical name to the same helper.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [TIRx] Phase out flat device-intrinsic op aliases [tvm]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #19838:
URL: https://github.com/apache/tvm/pull/19838#discussion_r3440318611
##########
src/backend/cuda/op/target_builtin.cc:
##########
@@ -333,76 +115,27 @@ TIRX_DEFINE_BUILTIN_FUNC(timer_end_cuda)
TIRX_DEFINE_BUILTIN_FUNC(timer_finalize_cuda)
.set_attr<TCallEffectKind>("TCallEffectKind", static_cast<int64_t>(CallEffectKind::kOpaque));
-TIRX_DEFINE_BUILTIN_FUNC(nvshmem_my_pe)
- .set_attr<TCallEffectKind>("TCallEffectKind", static_cast<int64_t>(CallEffectKind::kOpaque));
-
-TIRX_DEFINE_BUILTIN_FUNC(nvshmem_n_pes)
- .set_attr<TCallEffectKind>("TCallEffectKind", static_cast<int64_t>(CallEffectKind::kOpaque));
-
-TIRX_DEFINE_BUILTIN_FUNC(nvshmem_getmem_nbi)
- .set_attr<TCallEffectKind>("TCallEffectKind", static_cast<int64_t>(CallEffectKind::kOpaque));
-
-TIRX_DEFINE_BUILTIN_FUNC(nvshmem_putmem_nbi)
- .set_attr<TCallEffectKind>("TCallEffectKind", static_cast<int64_t>(CallEffectKind::kOpaque));
-
-TIRX_DEFINE_BUILTIN_FUNC(nvshmem_getmem_nbi_warp)
- .set_attr<TCallEffectKind>("TCallEffectKind", static_cast<int64_t>(CallEffectKind::kOpaque));
-
-TIRX_DEFINE_BUILTIN_FUNC(nvshmem_putmem_nbi_warp)
- .set_attr<TCallEffectKind>("TCallEffectKind", static_cast<int64_t>(CallEffectKind::kOpaque));
-
-TIRX_DEFINE_BUILTIN_FUNC(nvshmem_getmem_nbi_block)
- .set_attr<TCallEffectKind>("TCallEffectKind", static_cast<int64_t>(CallEffectKind::kOpaque));
-
-TIRX_DEFINE_BUILTIN_FUNC(nvshmem_putmem_nbi_block)
- .set_attr<TCallEffectKind>("TCallEffectKind", static_cast<int64_t>(CallEffectKind::kOpaque));
-
-TIRX_DEFINE_BUILTIN_FUNC(nvshmem_signal_op)
- .set_attr<TCallEffectKind>("TCallEffectKind", static_cast<int64_t>(CallEffectKind::kOpaque));
-
-TIRX_DEFINE_BUILTIN_FUNC(nvshmem_wait_until)
- .set_attr<TCallEffectKind>("TCallEffectKind", static_cast<int64_t>(CallEffectKind::kOpaque));
-
-TIRX_DEFINE_BUILTIN_FUNC(nvshmem_quiet)
- .set_attr<TCallEffectKind>("TCallEffectKind", static_cast<int64_t>(CallEffectKind::kOpaque));
-
-TIRX_DEFINE_BUILTIN_FUNC(nvshmem_putmem_signal_nbi)
- .set_attr<TCallEffectKind>("TCallEffectKind", static_cast<int64_t>(CallEffectKind::kOpaque));
-
-TIRX_DEFINE_BUILTIN_FUNC(nvshmem_putmem_signal_nbi_warp)
- .set_attr<TCallEffectKind>("TCallEffectKind", static_cast<int64_t>(CallEffectKind::kOpaque));
-
-TIRX_DEFINE_BUILTIN_FUNC(nvshmem_putmem_signal_nbi_block)
- .set_attr<TCallEffectKind>("TCallEffectKind", static_cast<int64_t>(CallEffectKind::kOpaque));
-
-TIRX_DEFINE_BUILTIN_FUNC(nvshmem_fence)
- .set_attr<TCallEffectKind>("TCallEffectKind", static_cast<int64_t>(CallEffectKind::kOpaque));
-
-TIRX_DEFINE_BUILTIN_FUNC(nvshmem_barrier_all)
- .set_attr<TCallEffectKind>("TCallEffectKind", static_cast<int64_t>(CallEffectKind::kOpaque));
-
RegisterDeviceIntrinsicAliases();
// clang-format on
}
namespace {
struct DeviceIntrinsicRegistration {
- const char* flat_name;
+ const char* name;
Review Comment:

Phasing out the flat macro registrations has caused a regression where the `TScriptDtypePrintLocation` attribute is lost for several key PTX intrinsics (such as `ptx.mma`, `ptx.mma_sp`, `ptx.ldmatrix`, `ptx.cp_async`, etc.). These intrinsics previously had this attribute set to `ScriptDtypePrintLocation::kFirst` to ensure correct TVMScript printing and parsing.\n\nTo fix this, we should add a `dtype_print_location` field to `DeviceIntrinsicRegistration` (defaulted to `0` or `ScriptDtypePrintLocation::kNone` to avoid breaking existing registrations):\n\n```cpp\nstruct DeviceIntrinsicRegistration {\n const char* name;\n const char* namespace_name;\n CallEffectKind effect_kind;\n int dtype_print_location = 0; // Default to 0 (no print location attribute)\n};\n```
##########
src/backend/cuda/op/target_builtin.cc:
##########
@@ -419,12 +152,11 @@ void RegisterDeviceIntrinsic(const DeviceIntrinsicRegistration& reg) {
.set_attr<TScriptPrinterName>("TScriptPrinterName", printer_name, /*plevel=*/15);
};
- register_one(flat_op_name);
register_one(canonical_op_name);
Review Comment:

To support restoring the lost `TScriptDtypePrintLocation` attribute for PTX intrinsics, we should update the `register_one` lambda inside `RegisterDeviceIntrinsic` to set the attribute when `reg.dtype_print_location` is non-zero:\n\n```cpp\n auto register_one = [&](const std::string& op_name) {\n auto entry = OpRegEntry::RegisterOrGet(op_name)\n .set_name()\n .set_num_inputs(-1)\n .set_attr<TCallEffectKind>("TCallEffectKind", static_cast<int64_t>(reg.effect_kind))\n .set_attr<TIRxOpCategory>("TIRxOpCategory", ffi::String("device_intrin"), /*plevel=*/15)\n .set_attr<TDeviceIntrinsicNamespace>("TDeviceIntrinsicNamespace", namespace_attr, /*plevel=*/15)\n .set_attr<TScriptPrinterName>("TScriptPrinterName", printer_name, /*plevel=*/15);\n if (reg.dtype_print_location != 0) {\n entry.set_attr<TScriptDtypePrintLocation>(\n "TScriptDtypePrintLocation", static_cast<int64_t>(reg.dtype_print_location), /*plevel=*/15);\n }\n
};\n```
##########
src/tirx/transform/tile_primitive_dispatch.cc:
##########
@@ -125,7 +125,7 @@ class ElectSyncFinder : public StmtExprVisitor {
void VisitExpr_(const CallNode* op) final {
auto is_canonical_elect_sync = [&]() {
- static const Op& ptx_elect_sync_op = Op::Get("tirx.ptx_elect_sync");
+ static const Op& ptx_elect_sync_op = Op::Get("tirx.ptx.elect_sync");
Review Comment:

The dual-name matching logic for `ptx_elect_sync` can be simplified now that the flat alias has been removed. Since `ptx_elect_sync_op` is resolved directly to the canonical `tirx.ptx.elect_sync` operator, the subsequent string comparison check is redundant and can be removed, similar to the cleanup done in `IsPtxElectSyncCall` in `src/tirx/analysis/filter_canonical.cc`.\n\nConsider simplifying the lambda to:\n```cpp\n auto is_canonical_elect_sync = [&]() {\n static const Op& ptx_elect_sync_op = Op::Get("tirx.ptx.elect_sync");\n return op->op.same_as(ptx_elect_sync_op);\n };\n```
##########
src/backend/cuda/op/target_builtin.cc:
##########
@@ -419,12 +152,11 @@ void RegisterDeviceIntrinsic(const DeviceIntrinsicRegistration& reg) {
.set_attr<TScriptPrinterName>("TScriptPrinterName", printer_name, /*plevel=*/15);
};
- register_one(flat_op_name);
register_one(canonical_op_name);
}
#define TIRX_DEVICE_INTRIN_ALIAS(OpName, Namespace, EffectKind) \
- {#OpName, #Namespace, CallEffectKind::EffectKind}
+ { #OpName, #Namespace, CallEffectKind::EffectKind }
Review Comment:

To allow registering intrinsics with a specific `TScriptDtypePrintLocation` (such as `ptx.mma`, `ptx.ldmatrix`, etc.), we can define a companion macro `TIRX_DEVICE_INTRIN_ALIAS_WITH_DTYPE`:\n\n```cpp\n#define TIRX_DEVICE_INTRIN_ALIAS_WITH_DTYPE(OpName, Namespace, EffectKind, DtypeLoc) { #OpName, #Namespace, CallEffectKind::EffectKind, static_cast<int>(ScriptDtypePrintLocation::DtypeLoc) }\n```\n\nThis can then be used in `kDeviceIntrinsics` for the affected intrinsics to restore their TVMScript printing behavior.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [TIRx] Phase out flat device-intrinsic op aliases [tvm]
Posted by "spectrometerHBH (via GitHub)" <gi...@apache.org>.
spectrometerHBH merged PR #19838:
URL: https://github.com/apache/tvm/pull/19838
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org