Skip to content

akielaries/openGPMP

Repository files navigation

Version PyPi Codacy Badge license codecov clones openGPMP

Overview

openGPMP is an open-source, multi-threaded, mathematics package written in C++, C, Fortran and Assembly with no runtime dependencies. The primary focus in Number Theory and Cryptographic algorithms, Linear Algebra, Calculus, Statistics, and Machine Learning concepts, and more. openGPMP aims to serve as a warehouse and one-stop shop for mathematical operations. Additional acceleration methods are featured for optional use and installation via OpenCL and CUDA. By default, SIMD intrinsics will be used for the supported platforms.

Look in the samples folder for examples on how to use some of openGPMP's functionalities and the in-depth documentation.

Installation

openGPMP C++ & Python is tested on the following:

OS Architecture Status
OSX Monterey 12.6.3 x86 darwin
RasPi OS ARMv6/v7 cppRPi
bullseye 11.6 ARMv6 arm6CPP
ubuntu 22.10 ARMv7 arm7CPP
ubuntu 22.10 ARMv8 arm8CPP
ubuntu 22.10 RISCV64 riscCPP
ubuntu 22.10 S390X s390xCPP
ubuntu 22.10 PPC64LE ppc64leCPP
ubuntu 22.10 Intel GPU INTELGPU
ubuntu 18.04 Nvidia GPU (CUDA) NVIDIACUDA
ubuntu 18.04 Nvidia GPU (OpenCL) NVIDIAOPENCL

Note Testing on Apple specific hardware (M1, M2) is in progress.

C++ (source)

Requirements

  • Linux/OSX
  • CMake v3.18+ (build from source for latest version)
  • C++20
  • gcc, g++, gfortran v12+ (clang, clang++, and flang are being tested)

Build

Clone the repository or download the codebase from a release:

# clone repo
$ git clone git@github.com:akielaries/openGPMP.git
$ cd openGPMP

Create a build directory and configure with CMake:

$ mkdir build && cd build
$ cmake -S ../
  • Additional CMake options include:
    • -DBUILD_TESTS=ON
    • -DCMAKE_C_COMPILER=/path/to/C/compiler
    • -DCMAKE_CXX_COMPILER=/path/to/CPP/compiler
    • -DCMAKE_FC_COMPILER=/path/to/Fortran/compiler

Note ATM OSX requires GCC for compilation

Install the compiled static library and headers:

$ make
$ sudo make install

Note Keep the build directory for easy uninstallation.

Python (pygpmp)

To install the Python interface, use the pip package manager and run the following, pip install pygpmp. Additional hardware support is available with SWIG as a dependency for the pip installation.

From source

Building the Python pip wheel from source is easy as well. Run the following:

# install dependencies
$ pip install -r requirements.txt
# create CMake files in py_build dir
$ cmake -B py_build -DBUILD_PYGPMP=ON
# install
$ pip install .

Julia (gpmp.jl)

Note In progress The Julia interface is built with the help of wrapit.

To test the installation build some of the example drivers in the projects samples directory.

# compile yourself
$ cd samples/cpp
$ g++ mtx.cpp -lopenGPMP -o mtx
$ g++ primes.cpp -lopenGPMP -o primes

To uninstall files related to openGPMP, simply run the following:

# enter the build dir from installation
$ cd build
$ sudo make uninstall

tinygpmp

tinygpmp targets low-voltage, resource-constrained devices and is currently aiming to support AVR series MCUs, STM32 chips, and other embedded devices.

Modules

During early stages, modules will be developed in breadth while focusing on depth in later stages of the PRE-V1.0.0 phase. The modules below are all in progress.

  1. Core (utilities & common interfaces)
  2. Arithmetic
  3. Calculus
  4. Discrete Mathematics
  5. Linear Algebra
  6. Machine/Deep Learning
  7. Number Theory
  8. Complex
  9. Statistics
  10. Optimization

For more details view the project documentation.

Examples

View the simple examples on how to use some of the modules in different languages here.

# clone the repo and enter
$ git clone git@github.com:akielaries/openGPMP.git 
$ cd openGPMP/scripts

# to run all examples 
$ ./all.sh

# to remove the generated binaries
$ cd ../ && make clean-mods

# run unit tests and other checking methods
$ make run-tests

# clean up generated test files
$ make clean-tests

Example C++ driver file for running Caesar Cipher & Mono-Alphabetic Substitution Keyword cipher:

#include <iostream>
#include <string>
// include the number theory module header
#include <openGPMP/nt.hpp>

int main() {
    // declare CIPHER class obj
    gpmp::Cipher cc;

    /* CAESAR CIPHER */
    std::string text0 = "Plaintext";
    int shift_key_0 = 5;
    std::string hashtext_0 = cc.caesar(text0, shift_key_0);
    std::cout << "Hashtext0 = " << hashtext_0 << std::endl;

    /* TESTING MONOALPHABETIC SUBSTITUION KEYWORD CIPHER */
    std::string shift_key_2 = "Computer";
    std::string text2 = "Password";
    // encode the plaintext
    std::string encoded_text = cc.keyword_encode(shift_key_2);
    // call the cipher function
    std::string hashtext_2 = cc.keyword(text2 , encoded_text);

    std::cout << "Hashtext2 = " << hashtext_2 << std::endl;

    return 0;
}

A Python example showing the same functionalities.

>>> from pygpmp import nt
>>> c = nt.Cipher()
>>> text0 = c.caesar('Plaintext', 5)
>>> print(ciphertext_0)
Uqfnsyjcy
>>> 
>>> text1 = c.caesar('ATTACKATONCE', 4)
>>> print(text1)
EXXEGOEXSRGI
>>> 
>>> text = "Password"
>>> shift = "Computer"
>>> encoded_text = c.keyword_encode(shift);
>>> hashtext = c.keyword(text, encoded_text);
>>> print(hashtext)
JCNNWILP