MCPcopy Index your code
hub / github.com/autumnai/collenchyma

github.com/autumnai/collenchyma @0.0.8

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.0.8 ↗ · + Follow
425 symbols 739 edges 61 files 160 documented · 38%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Collenchyma • Join the chat at https://gitter.im/autumnai/collenchyma Build Status Coverage Status Crates.io License

Collenchyma is an extensible, pluggable, backend-agnostic framework for parallel, high-performance computations on CUDA, OpenCL and common host CPU. It is fast, easy to build and provides an extensible Rust struct to execute operations on almost any machine, even if it does not have CUDA or OpenCL capable devices.

Collenchyma's abstracts over the different computation languages (Native, OpenCL, Cuda) and let's you run highly-performant code, thanks to easy parallelization, on servers, desktops or mobiles without the need to adapt your code for the machine you deploy to. Collenchyma does not require OpenCL or Cuda on the machine and automatically falls back to the native host CPU, making your application highly flexible and fast to build.

Collenchyma was started at Autumn to support the Machine Intelligence Framework Leaf with backend-agnostic, state-of-the-art performance.

  • Parallelizing Performance

Collenchyma makes it easy to parallelize computations on your machine, putting all the available cores of your CPUs/GPUs to use. Collenchyma provides optimized operations through Plugins, that you can use right away to speed up your application.

  • Easily Extensible

Writing custom operations for GPU execution becomes easy with Collenchyma, as it already takes care of Framework peculiarities, memory management, safety and other overhead. Collenchyma provides Plugins (see examples below), that you can use to extend the Collenchyma backend with your own, business-specific operations.

  • Butter-smooth Builds

As Collenchyma does not require the installation of various frameworks and libraries, it will not add significantly to the build time of your application. Collenchyma checks at run-time if these frameworks can be used and gracefully falls back to the standard, native host CPU if they are not. No long and painful build procedures for you or your users.

For more information,

Disclaimer: Collenchyma is currently in a very early and heavy stage of development. If you are experiencing any bugs that are not due to not yet implemented features, feel free to create an issue.

Getting Started

If you're using Cargo, just add Collenchyma to your Cargo.toml:

[dependencies]
collenchyma = "0.0.8"

If you're using Cargo Edit, you can call:

$ cargo add collenchyma

Plugins

You can easily extend Collenchyma's Backend with more backend-agnostic operations, through Plugins. Plugins provide a set of related operations - BLAS would be a good example. To extend Collenchyma's Backend with operations from a Plugin, just add a the desired Plugin crate to your Cargo.toml file. Here is a list of available Collenchyma Plugins, that you can use right away for your own application, or take as a starting point, if you would like to create your own Plugin.

  • BLAS - Collenchyma plugin for backend-agnostic Basic Linear Algebra Subprogram Operations.
  • NN - Collenchyma plugin for Neural Network related algorithms.

You can easily write your own backend-agnostic, parallel operations and provide it for others, via a Plugin - we are happy to feature your Plugin here, just send us a PR.

Examples

Collenchyma comes without any operations. The following examples therefore assumes, that you have added both collenchyma and the Collenchyma Plugin collenchyma-nn to your Cargo manifest.

extern crate collenchyma as co;
extern crate collenchyma_nn as nn;
use co::prelude::*;
use nn::*;

fn write_to_memory<T: Copy>(mem: &mut MemoryType, data: &[T]) {
    if let &mut MemoryType::Native(ref mut mem) = mem {
        let mut mem_buffer = mem.as_mut_slice::<T>();
        for (index, datum) in data.iter().enumerate() {
            mem_buffer[index] = *datum;
        }
    }
}

fn main() {
    // Initialize a CUDA Backend.
    let backend = Backend::<Cuda>::default().unwrap();
    // Initialize two SharedTensors.
    let mut x = SharedTensor::<f32>::new(backend.device(), &(1, 1, 3)).unwrap();
    let mut result = SharedTensor::<f32>::new(backend.device(), &(1, 1, 3)).unwrap();
    // Fill `x` with some data.
    let payload: &[f32] = &::std::iter::repeat(1f32).take(x.capacity()).collect::<Vec<f32>>();
    let native = Backend::<Native>::default().unwrap();
    x.add_device(native.device()).unwrap(); // Add native host memory
    x.sync(native.device()).unwrap(); // Sync to native host memory
    write_to_memory(x.get_mut(native.device()).unwrap(), payload); // Write to native host memory.
    x.sync(backend.device()).unwrap(); // Sync the data to the CUDA device.
    // Run the sigmoid operation, provided by the NN Plugin, on your CUDA enabled GPU.
    backend.sigmoid(&mut x, &mut result).unwrap();
    // See the result.
    result.add_device(native.device()).unwrap(); // Add native host memory
    result.sync(native.device()).unwrap(); // Sync the result to host memory.
    println!("{:?}", result.get(native.device()).unwrap().as_native().unwrap().as_slice::<f32>());
}

Contributing

Want to contribute? Awesome! We have instructions to help you get started contributing code or documentation. And high priority issues, that we could need your help with.

We have a mostly real-time collaboration culture and happens here on Github and on the Collenchyma Gitter Channel. You can also reach out to the Maintainers {@MJ, @hobofan}.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as below, without any additional terms or conditions.

Changelog

You can find the release history in the root file CHANGELOG.md.

A changelog is a log or record of all the changes made to a project, such as a website or software project, usually including such records as bug fixes, new features, etc. - Wikipedia

We are using Clog, the Rust tool for auto-generating CHANGELOG files.

License

Licensed under either of

  • Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.

Extension points exported contracts — how you extend this code

IntoTensorDesc (Interface)
Describes a conversion into a Tensor Descriptor. This allows for convenient creation of a new SharedTensor. e.g. (2, 4) [12 …
src/tensor.rs
IOperation (Interface)
Provides the generic functionality for backend-agnostic operations. An Operation describes the execution of a [library] [3 …
src/operation.rs
IDevice (Interface)
Specifies Hardware behavior across frameworks. [3 implementers]
src/device.rs
IBinary (Interface)
Provides the generic functionality for a backend-specific implementation of a [library][libraries]. [libraries]: ../libr [3 …
src/binary.rs
IFramework (Interface)
Defines a Framework. [3 implementers]
src/framework.rs
IMemory (Interface)
Specifies Memory behavior accross frameworks. [3 implementers]
src/memory.rs
IHardware (Interface)
Specifies Hardware behavior accross frameworks. [3 implementers]
src/hardware.rs
IBackend (Interface)
Describes a Backend. Serves as a marker trait and helps for extern implementation. [3 implementers]
src/backend.rs

Core symbols most depended-on inside this repo

clone
called by 35
src/frameworks/cuda/api/driver/ffi.rs
hardwares
called by 23
src/backend.rs
new_device
called by 16
src/frameworks/cuda/mod.rs
id_c
called by 13
src/frameworks/opencl/event.rs
device
called by 9
src/backend.rs
sync
called by 7
src/tensor.rs
alloc_memory
called by 7
src/frameworks/cuda/context.rs
add_device
called by 5
src/tensor.rs

Shape

Method 266
Class 76
Function 46
Enum 25
Interface 12

Languages

Rust100%

Modules by API surface

src/frameworks/cuda/api/driver/ffi.rs74 symbols
src/tensor.rs30 symbols
src/frameworks/opencl/device.rs21 symbols
src/frameworks/cuda/device.rs21 symbols
src/frameworks/opencl/context.rs13 symbols
src/frameworks/cuda/context.rs13 symbols
benches/shared_tensor.rs12 symbols
src/memory.rs11 symbols
src/frameworks/native/hardware.rs11 symbols
tests/shared_memory_specs.rs9 symbols
src/frameworks/opencl/mod.rs9 symbols
src/frameworks/native/mod.rs9 symbols

For agents

$ claude mcp add collenchyma \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page