shmem-ops-torch-bind

Wraps SHMEM operators as PyTorch CustomClass bindings and validates them with multi-PE tests.

Updated Sep 15, 2026
One-click install
npx skills add https://github.com/WangWindow/CANN-BatchMatMulMaxsum --skill shmem-ops-torch-bind-wangwindow
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: shmem-ops-torch-bind
Source: https://github.com/WangWindow/CANN-BatchMatMulMaxsum/tree/main/.agents/skills/shmem-ops-torch-bind
Command: npx skills add https://github.com/WangWindow/CANN-BatchMatMulMaxsum --skill shmem-ops-torch-bind-wangwindow

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch, torch_npu, and includes references (resource) components.

What problem does it solve? Integrating a verified SHMEM operator into PyTorch requires writing C++ CustomClassHolder bindings, CMake build configuration, and multi-PE test scripts by hand, which is error-prone around dtype dispatch, ABI flags, and shared-memory session management. ## Core Features & Use Cases - C++ Binding Generation: Produces torch_bind_<op_name>.cpp with a CustomClassHolder subclass, TORCH_CHECK validation, dtype dispatch, and REGISTER_SHMEM_OPS_CLASS registration, plus the shared Manager class when missing. - CMake Integration: Adds the operator to the shared custom-ops/torch_binding/ build producing shmem_custom_ops_torch.so, or to the in-tree examples/torch_binding/ producing aclshmem_torch.so, with correct _GLIBCXX_USE_CXX11_ABI detection. - Multi-PE Test Generation: Creates torch_test_<op_name>.py with fixed-seed data generation, golden output comparison, and multiprocessing-based 2-PE and 8-PE verification on Ascend NPU. - Use Case: After a SHMEM AllGather-style operator passes correctness evaluation, use this Skill to generate its Torch binding, compile the shared extension, and run an 8-PE PyTorch test to confirm end-to-end correctness. ## Quick Start Generate the PyTorch CustomClass binding and multi-PE test script for my verified SHMEM operator, then compile the shared Torch extension and run the 8-PE validation.

Frequently Asked Questions about shmem-ops-torch-bind

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I bind a SHMEM operator to PyTorch as a CustomClass?

Create a C++ class inheriting torch::jit::CustomClassHolder with a compute() method containing TORCH_CHECK validation and dtype dispatch, then register it with REGISTER_SHMEM_OPS_CLASS. The class becomes callable in Python via torch.classes.ShmemOps.<OpName>.

How to test a multi-PE SHMEM operator in PyTorch on Ascend NPU?

Generate a torch_test_<op_name>.py script using multiprocessing.Process to spawn one worker per PE, each calling torch_npu.npu.set_device(pe), initializing the Manager with a unique ip_port, running compute, and comparing against a fixed-seed golden output.

Why does loading the Torch extension fail with undefined symbol errors?

Undefined symbol errors like torchInternalAssertFail occur when the extension's _GLIBCXX_USE_CXX11_ABI flag mismatches the installed torch build. Detect the correct value with torch._C._GLIBCXX_USE_CXX11_ABI and set the compile option accordingly.

What is the difference between aclshmem_torch.so and shmem_custom_ops_torch.so?

aclshmem_torch.so is the product of the in-tree examples/torch_binding build, while shmem_custom_ops_torch.so is the shared extension for custom-ops projects. Custom operators must use the shared custom-ops/torch_binding layer and never produce a second aclshmem_torch.so.

Why does the SHMEM Torch test produce all-zero outputs or init failures?

This happens when torch_test scripts share a fixed IPPORT or SHMEM_UID_SESSION_ID with concurrently running C++ tests. Assign a unique port and session ID per test round and check for lingering torch_test processes before running C++ scripts.