Skip to main content

CAMPIE 🥧

Python APIs to simulate various CAMs (Content Addressable Memory) on GPUs at scale.

Overview

CAMPIE is a utility library that builds on top of NumPy and CuPy for fast and efficient simulation of CAM hardwares on CUDA GPUs.
It implements custom CUDA kernels for ACAM (Analog CAM) and TCAM (Ternary Cam) simulation and adjacent utility functionality accessible under a simple Python API.

Installation

CAMPIE uses CuPy under the hood, which requires you to install a different package based on your CUDA version if you are using pip.

The CUDA version that you are installing CAMPIE for is specified as an extra like below:

pip install campie[cu11x]

for Poetry, this would be:

poetry add -E cu11x campie

The available CUDA version extras are as follows: cu110, cu111, cu11x, cu12x. You should only ever install one CUDA extra or you will cause conflicts.

For more context, see the CuPy installation instructions and the pyproject.toml.

Example

import campie
import numpy as np

x = np.nan  # nan = don't care

# cam_rows x columns
cam = np.array([
  [0, 0, 1, 0],
  [1, 1, x, 0],
  [0, 0, 0, 0],
  [x, x, 0, 0],
  [0, 0, 1, 1],
])

# input_rows x columns
inputs = np.array([
  [0, 0, 0, 0],
  [0, 1, 0, 0],
  [1, 1, 1, 0],
]).astype(np.float64)

# this runs on the GPU, `matches` is still in GPU memory
matches = campie.tcam_match(inputs, cam)
print(matches)

# -> input_rows x cam_rows
array([
  [0, 0, 1, 1, 0],  # input 1 matches cam rows 3 and 4
  [0, 0, 0, 1, 0],  # input 2 matches cam row 4
  [0, 1, 0, 0, 0],  # input 3 matches cam row 2
])

For detailed information on all available APIs, visit the documentation. Alternatively, see the example notebook for a practical introduction.

Contributing

In order for us to accept your pull request, you will need to sign-off your commit. This page contains more information about it. In short, please add the following line at the end of your commit message:

Signed-off-by: First Second <email>

Dependency Management

Python dependencies are managed via Poetry:

poetry install -E cu11x

Poetry is also used to publish the library to PyPI:

poetry build
poetry publish

Formatting & Linting

CAMPIE uses ruff to format and lint Python source code.

To format all Python files:

ruff --fix .

Reference Generation

scripts/gen_reference.py is used to extract doc comments from the source code and generates docs/reference.md.

To regenerate the reference:

# installed into the virtual environment by poetry
gen-reference

# or alternatively
python scripts/gen_reference.py

License

CAMPIE is licensed under the Apache 2.0 license.

Metadata

Release files for campie 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for campie 0.5.0
File Size Uploaded Provenance Actions
campie-0.5.0.tar.gz 17.5 kB Without provenance Details for campie-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for campie 0.5.0
File Interpreter ABI Platform Actions
campie-0.5.0-py3-none-any.whl Python 3 none any Details for campie-0.5.0-py3-none-any.whl

Total release size: 40.4 kB

Release files / campie-0.5.0.tar.gz

Download URL campie-0.5.0.tar.gz
Size 17.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f202888436c274450890c8cf8e078f9572d7e03a9c45089d8c019328d8033cd0
BLAKE2b-256 checksum
How to use checksums
5e4cc6e75c20999228ff33324041b2527981d296449e28f52f069e0daf9b72e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Darwin/23.4.0

Release files / campie-0.5.0-py3-none-any.whl

Download URL campie-0.5.0-py3-none-any.whl
Size 22.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9580d0443fe6fffd1472bd9745ff1449b3a4b3e2ce5db1d4cc67045f004db652
BLAKE2b-256 checksum
How to use checksums
738933264d0bf98e67cf42203ee3328feb7fd58e358b3884e4a362bc205b2ce1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.12.3 Darwin/23.4.0

Security for campie 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page