Skip to main content

Aakaar

A lightweight, high-performance C++/CUDA tensor engine for Python.
Built from scratch using Python, C++, raw CUDA, cuBLAS, cuRAND, and pybind11.


Overview

Aakaar is a standalone tensor computation library designed to provide transparent, high-performance numerical computing without relying on heavyweight deep learning frameworks.

Unlike traditional libraries that abstract away the underlying implementation, Aakaar exposes a clean Python API backed by a custom C++ tensor engine capable of running on both CPU and NVIDIA GPUs.

Its goal is to serve as both a practical tensor library and an educational framework for understanding how modern AI frameworks work internally.


Features

🚀 High Performance

  • Native C++ tensor engine
  • Raw CUDA kernels for GPU execution
  • Optimized matrix multiplication using cuBLAS
  • Random number generation using cuRAND

🧠 Custom Tensor Implementation

  • N-dimensional tensors
  • Shape and stride aware
  • Supports arbitrary dimensions
  • Automatic memory management
  • CPU and GPU tensor storage

Example:

import aakaar

x = aakaar.rand((3,4))
print(x.shape)

⚡ Dual Device Support

Create tensors directly on either CPU or GPU.

cpu_tensor = aakaar.rand((4,4), device="cpu")

gpu_tensor = aakaar.rand((4,4), device="cuda")

If CUDA is unavailable, Aakaar automatically falls back to CPU mode.


📐 Zero-Copy Tensor Views

Tensor slicing never copies memory.

Instead, Aakaar creates lightweight tensor views by modifying only:

  • shape
  • strides
  • storage offset

Example:

x = aakaar.rand((5,5))

view = x[1:4, 2:5]

print(view.shape)

The returned tensor references the original memory.

No additional allocation occurs.

Supported slicing includes:

  • Integer indexing
  • Negative indexing
  • Range slicing
  • Step slicing
  • Multi-dimensional slicing

Examples:

x[2]

x[-1]

x[1:4]

x[:,2]

x[::2]

x[1:4,2:5]

🔄 NumPy Interoperability

Transfer tensors back to Python using

tensor.to_numpy()

This explicitly copies data from the tensor engine into NumPy memory.

GPU tensors remain in VRAM until this function is called.


⚙ Automatic CPU Fallback

Installation automatically detects CUDA.

If CUDA is unavailable:

  • CUDA files are skipped
  • CPU backend is compiled
  • API remains identical

No code changes are required.


🖥 GPU Memory Residency

GPU tensors remain entirely inside GPU memory.

Operations execute without repeatedly transferring data across PCIe.

Data moves back to host memory only when:

tensor.to_numpy()

is called.


Installation

Install directly from PyPI:

pip install aakaar

Requirements

Windows

Prebuilt wheels are available for

  • Python 3.10
  • Python 3.11
  • Python 3.12
  • Python 3.13
  • Python 3.14

CUDA support is included in compatible builds.


Linux / macOS

Aakaar builds from source.

Requirements:

  • C++ compiler (g++, clang++)
  • Python development headers

Optional:

  • NVIDIA CUDA Toolkit
  • nvcc compiler

Without CUDA, installation automatically produces a CPU-only build.


Quick Start

Creating Tensors

import aakaar

x = aakaar.rand((4,5), seed=42)

print(x)

CPU Tensor

cpu = aakaar.rand((4,5), device="cpu")

CUDA Tensor

gpu = aakaar.rand((4,5), device="cuda")

Tensor Properties

print(x.shape)

print(len(x))

print(x.device)

print(x.ndim)

print(x.size)

Accessing Elements

value = x[0,2]

Returns a Python float.


Tensor Slicing

sub = x[1:3,2:4]

print(sub.shape)

No memory copy occurs.


Checking Contiguity

print(sub.is_contiguous())

Convert to NumPy

numpy_array = sub.to_numpy()

Matrix Multiplication

Aakaar performs hardware-accelerated matrix multiplication through cuBLAS.

a = aakaar.rand((1024,1024), device="cuda")

b = aakaar.rand((1024,1024), device="cuda")

c = aakaar.matmul(a,b)

The computation stays entirely on the GPU.

Move results back to Python only when needed:

result = c.to_numpy()

Random Number Generation

Random tensors are generated using cuRAND on CUDA builds.

x = aakaar.rand((512,512), device="cuda")

CPU builds use the native C++ backend.


Architecture

Aakaar follows a layered architecture designed for minimal overhead.

Python API
      │
      ▼
pybind11 Bindings
      │
      ▼
Custom C++ Tensor Engine
      │
 ┌────┴─────┐
 │          │
CPU Backend CUDA Backend
 │          │
 │       cuBLAS
 │       cuRAND
 │
Memory Manager

Python serves only as the interface.

Tensor metadata, indexing, slicing, memory management, and mathematical operations are executed entirely in compiled C++ or CUDA.


Memory Model

Every tensor stores:

  • Pointer to data
  • Shape
  • Strides
  • Storage offset
  • Device information
  • Data type

Tensor views reuse the same underlying storage.

Only metadata changes during slicing.


Performance Philosophy

Aakaar minimizes unnecessary memory movement.

Typical workflow:

Python

↓

Create Tensor

↓

GPU Memory

↓

Multiple CUDA Operations

↓

Matrix Multiplication

↓

More CUDA Operations

↓

to_numpy()

↓

Host Memory

The expensive PCIe transfer occurs only when explicitly requested.


CUDA Views

Step slicing on CUDA tensors is mathematically correct.

However,

tensor.to_numpy()

may currently copy the full spanned memory region instead of only the selected elements for highly fragmented strided views.

This optimization is under active development.


API Stability

Aakaar is under active development.

Internal APIs may change between minor releases as additional functionality is introduced, including:

  • Automatic differentiation (Autograd)
  • Tensor broadcasting
  • Additional mathematical operators
  • Neural network primitives
  • Optimized CUDA kernels

Roadmap

Planned features include:

  • Automatic differentiation
  • Broadcasting
  • Tensor arithmetic operators
  • Convolution kernels
  • Reduction operations
  • Activation functions
  • Optimizers
  • Neural network layers
  • Mixed precision support
  • CUDA graph execution
  • Multi-GPU support

Why Aakaar?

Aakaar was created to demonstrate how modern tensor libraries work internally while remaining lightweight enough to study, modify, and extend.

Instead of hiding the implementation behind millions of lines of code, Aakaar focuses on providing a clean architecture where developers can understand:

  • Tensor memory layout
  • GPU execution
  • CUDA programming
  • Shape and stride mechanics
  • pybind11 integration
  • High-performance numerical computing

It is both a usable tensor engine and a learning resource for developers interested in building AI infrastructure from the ground up.


License

This project is released under the MIT License.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aakaar-0.1.7.tar.gz (15.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

aakaar-0.1.7-cp314-cp314-win_amd64.whl (165.6 kB view details)

Uploaded CPython 3.14Windows x86-64

aakaar-0.1.7-cp313-cp313-win_amd64.whl (161.5 kB view details)

Uploaded CPython 3.13Windows x86-64

aakaar-0.1.7-cp312-cp312-win_amd64.whl (161.5 kB view details)

Uploaded CPython 3.12Windows x86-64

aakaar-0.1.7-cp311-cp311-win_amd64.whl (159.9 kB view details)

Uploaded CPython 3.11Windows x86-64

aakaar-0.1.7-cp310-cp310-win_amd64.whl (158.4 kB view details)

Uploaded CPython 3.10Windows x86-64

File details

Details for the file aakaar-0.1.7.tar.gz.

File metadata

  • Download URL: aakaar-0.1.7.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for aakaar-0.1.7.tar.gz
Algorithm Hash digest
SHA256 b15210390c585137bb6d00933440df3dfb7fdf6069b3e80f11720e9ebd6a51cd
MD5 71b9ae2c682f6bb80e8889a879405897
BLAKE2b-256 2686b60b33982545e5e4b952a036838e7f15da7b97e29a380ae920cae723a7f2

See more details on using hashes here.

File details

Details for the file aakaar-0.1.7-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: aakaar-0.1.7-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 165.6 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for aakaar-0.1.7-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 91381630fc5c772558279cc02e43dea1a26f2d09cd8cc87caffa88782fe1bbdd
MD5 f984b7644508653642b5bd31bbfca906
BLAKE2b-256 7db69e41faa00ee0d6b55f05754962c433e2de870a80267c1d63d33b89b6d767

See more details on using hashes here.

File details

Details for the file aakaar-0.1.7-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: aakaar-0.1.7-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 161.5 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for aakaar-0.1.7-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4b0821ee0fc4f95b2cb4659588175e1e92d1b8b0e1e8a4460d0db657464c76f3
MD5 9c9d6b9984a00ad2e8a0d1ebc8b35573
BLAKE2b-256 232a0eea822b9922d66e7eb0311e2dd23d40354fb6c2bfb9da40d1f225ecb399

See more details on using hashes here.

File details

Details for the file aakaar-0.1.7-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: aakaar-0.1.7-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 161.5 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for aakaar-0.1.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 de4dafda9a5bf40f5ac7a68f1444868fdaa333141d62fe434e54627ae6f9fee4
MD5 ef78ffc5fb1850dea23f43d6e5812a2a
BLAKE2b-256 69c02727f0ff88432e79b799c81d09da1423b40c93da8c54b9400595ce362abe

See more details on using hashes here.

File details

Details for the file aakaar-0.1.7-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: aakaar-0.1.7-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 159.9 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for aakaar-0.1.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c1a90d6a809a2d3b263e875ad91e961ea462ccead59bacf8fbde4d58c7833826
MD5 ea6bbf1b0c4cd145d9da6dd29c1789c0
BLAKE2b-256 37392b6dbca0825e20d6f0fdfe2a0dcfe5309cc703e517d1ffc1a20b9d8bd6d2

See more details on using hashes here.

File details

Details for the file aakaar-0.1.7-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: aakaar-0.1.7-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 158.4 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for aakaar-0.1.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 32e025ecc1c18d846278d6e322e6b533d0fc349bcbe25d4c1258b5280d742ffd
MD5 0cfe291c302fd938e67365a90529e149
BLAKE2b-256 f76533c9e553ea12d07665c098a6b5a9288b2d1659d33cdb3ba635cd6d97d7e2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page