Hyperdimensional Computing

Use Sparsr through a hyperdimensional computing library, from C or from Python.

This path is for people who work with hypervectors and want them to run on Sparsr without writing a kernel. You do not install the Sparsr SDK and you do not need a cross-toolchain. A hypervector is one 4,096-bit wide register, so binding two of them is one instruction, and the kernels are inside the library.

There are two pieces, and they are the same library seen from two languages:

  • The HDC library - libsparsr_hdc, a C library with the four operations HDC needs: bind, bundle, similarity and train. Everything below runs through it.
  • torchhd-sparsr - a PyTorch device. Standard Torchhd code runs on Sparsr with .to("sparsr"), and the package computes nothing itself: every operation is a call into the C library.

What it runs on

Both run on the Sparsr VM, the software model of the processor. The library's kernels are RV32I, and the VM runs RV32I. Set SPARSR_BACKEND=vm to choose it.

How you get it

  • The C library is its own download, sparsr-hdc-<version>.tar.gz, beside the Kernel SDK on the Sparsr Developer Zone. It holds the library, its header, the runtime it needs and its licences. The assembler and the intrinsics header belong to the Kernel SDK and are not in it, because a caller of this library never needs them.
  • The Python package is on PyPI: pip install torchhd-sparsr. It carries everything it needs, so you do not have to install an SDK or a compiler. Its page says which Torchhd operations it runs and which it refuses.

Pages in this chapter

  • Getting Started - recognise handwritten digits on Sparsr, then run the same file on a cloud instance.
  • The HDC library - the four operations, the algebra the library uses, what fits in a register, and what it measures on MNIST.
  • torchhd-sparsr - the PyTorch device, which Torchhd calls run on Sparsr, and which ones refuse and why.
  • Digits in C - the same classifier as one file of plain C, walked through step by step: the item memory, the encoding, the majority vote, and the two constraints to design around before writing your own.