Skip to main content

Fast PyTorch tensor access for slangpy

Project description

slangpy-torch

Minimal PyTorch native extension providing fast (~28ns) tensor metadata access from native code without Python API overhead (~350ns).

Prerequisites

  • Python 3.9+
  • PyTorch 2.0+ installed
  • C++ compiler

Windows

Install Visual Studio 2019 or 2022 with the "Desktop development with C++" workload.

Linux

# Ubuntu/Debian
sudo apt-get install build-essential

Install

This extension must be installed with --no-build-isolation to ensure ABI compatibility with your installed PyTorch version:

pip install slangpy-torch --no-build-isolation

Verify Installation

import slangpy_torch
print(slangpy_torch.get_api_ptr())  # Should print a non-zero integer

Troubleshooting

  • "torch not found": Ensure PyTorch is installed first (pip install torch)
  • Windows linker errors: Run from a "Developer Command Prompt for VS" or ensure MSVC is in PATH

Usage from native code (slangpy_ext)

#include "tensor_bridge_api.h"

// At init time:
auto bridge = nb::module_::import_("slangpy_torch");
auto api = reinterpret_cast<const TensorBridgeAPI*>(
    nb::cast<uintptr_t>(bridge.attr("get_api_ptr")())
);

// In hot path (~28ns):
TensorBridgeInfo info;
api->extract(handle.ptr(), &info);
// Use info.data_ptr, info.shape, info.strides, etc.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slangpy_torch-0.4.0.tar.gz (9.1 kB view details)

Uploaded Source

File details

Details for the file slangpy_torch-0.4.0.tar.gz.

File metadata

  • Download URL: slangpy_torch-0.4.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for slangpy_torch-0.4.0.tar.gz
Algorithm Hash digest
SHA256 5432c2e10aa0d4d452ab1f8a685d5861787158f79629fe2a7ee4776083a5b802
MD5 dcfe40864581c5b368da46dbfaf51ac2
BLAKE2b-256 9e15a3e9d09651eaaf0dd5e5752fa79bfd5fd473a6d7ba8bc601e0f1c2449a39

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page