Metadata-Version: 2.1
Name: femtocrux
Version: 0.6.2
Summary: Femtosense Compiler
Home-page: https://github.com/femtosense/femtocrux
Author: Femtosense
Author-email: info@femtosense.ai
Project-URL: Source, https://github.com/femtosense/femtocrux
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Cython
Requires-Dist: docker
Requires-Dist: fmot ==1.*,>=1.9.2
Requires-Dist: grpcio >=1.64.1
Requires-Dist: grpcio-tools >=1.64.1
Requires-Dist: numpy <2.0.0,>=1.18.0
Requires-Dist: protobuf
Requires-Dist: passlib
Requires-Dist: requests <2.29.0
Requires-Dist: urllib3 <2.0.0,>=1.26.0

![Build Status](https://codebuild.us-west-2.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiRGpDOFpEOXF1M0prSy9OOVNkZ3F2NkRKM0NNMG8xbmpZU0hZdUp1ejhHOEswdDRhOEZOakMrdWZyaHp1WGVtQ1lVTStzRUpXaFlYeFZPSEJFd21NdjF3PSIsIml2UGFyYW1ldGVyU3BlYyI6InJZYzhuZ3d3a1FUUzBzM0kiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=master)

# femtocrux

Compiler API for the Femotsense Sparse Processing Unit (SPU).

This package drives compilation of machine learning models to SPU binaries, as well as simulation of those binaries on SPU hardware.

The package itself is a thin Python wrapper communicating to the actual compiler / simulator via gRPC.

Supported ML model representations:
 - Femtosense Quantized IR (FQIR)

## Installation

You will need to have python `3.10` and Docker installed.
Install Docker by following [these instructions](https://docs.docker.com/get-docker/).

femtocrux is available on PyPI via

```
pip install femtocrux
```

## Basic Usage

### `ManagedCompilerClient`
`ManagedCompilerClient` is the recommended way to use femtocrux within a context manager.

```python
from femtocrux import ManagedCompilerClient, FQIRModel

# fqir_graph = ... # Assuming we have an FQIR graph using fmot
# inputs = ...     # Assuming we have numpy array inputs to the model

fqir_model = FQIRModel(fqir_graph, batch_dim=0, sequence_dim=1)
with ManagedCompilerClient() as client:
    
    # simulate execution, view power, energy, and latency metrics
    simulator = client.simulate(fqir_model)
    outputs, metrics = simulator.simulate(inputs)

    # compile the model to a bitfile
    bitstream = client.compile(fqir_model)
    with open('my_bitfile.zip', 'wb') as f: 
        f.write(bitstream)
```

The bitfile can be used to generate program files to run on the SPU, using [femtodriverpub](https://github.com/femtosense/femtodriverpub.git)

### `CompilerClient`
`CompilerClient` is another interface to the compiler. This will be deprecated in future releases, so we recommend using `ManagedCompilerClient`.

```python
from femtocrux import CompilerClient, FQIRModel

# fqir_graph = ... # Assuming we have an FQIR graph using fmot
# inputs = ...     # Assuming we have numpy array inputs to the model

fqir_model = FQIRModel(fqir_graph, batch_dim=0, sequence_dim=1)
client = CompilerClient()
    
# simulate execution, view power, energy, and latency metrics
simulator = client.simulate(fqir_model)
outputs, metrics = simulator.simulate(inputs)

# compile the model to a bitfile
bitstream = client.compile(fqir_model)
with open('my_bitfile.zip', 'wb') as f: 
    f.write(bitstream)

# close the client (important to avoid background docker containers that continue running)
client.close()
```
