Python APIs to simulate various CAMs on GPUs at scale
Project description
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.
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
Built Distribution
File details
Details for the file campie-0.5.0.tar.gz
.
File metadata
- Download URL: campie-0.5.0.tar.gz
- Upload date:
- Size: 17.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Darwin/23.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f202888436c274450890c8cf8e078f9572d7e03a9c45089d8c019328d8033cd0 |
|
MD5 | f429da436854cc79f58610386b516575 |
|
BLAKE2b-256 | 5e4cc6e75c20999228ff33324041b2527981d296449e28f52f069e0daf9b72e6 |
File details
Details for the file campie-0.5.0-py3-none-any.whl
.
File metadata
- Download URL: campie-0.5.0-py3-none-any.whl
- Upload date:
- Size: 22.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Darwin/23.4.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9580d0443fe6fffd1472bd9745ff1449b3a4b3e2ce5db1d4cc67045f004db652 |
|
MD5 | e6fbc210eb35ea5f8b7730116f39f4a0 |
|
BLAKE2b-256 | 738933264d0bf98e67cf42203ee3328feb7fd58e358b3884e4a362bc205b2ce1 |