Skip to content

Commit

Permalink
README files updated
Browse files Browse the repository at this point in the history
  • Loading branch information
gkestor authored and pthomadakis committed Jun 12, 2024
1 parent 285b64b commit 8621922
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 237 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ We will try our best to timely incorporate user requests.
We encourage you to use GitHub’s tracking system to report any issues or for code contributions as mentioned above.
For any other queries, please feel free to contact us via email:
* **Gokcen Kestor** (email: *[email protected]*), [Pacific Northwest National Laboratory (PNNL), United States.](https://www.pnnl.gov/)
* **Rizwan Ashraf** (email: *[email protected]*), [Pacific Northwest National Laboratory, United States.](https://www.pnnl.gov/)
* **Zhen Peng** (email: *[email protected]*), [Pacific Northwest National Laboratory, United States.](https://www.pnnl.gov/)
* **Polykarpos Thomadakis** (email: *[email protected]*), [Pacific Northwest National Laboratory, United States.](https://www.pnnl.gov/)
* **Ryan Friese** (email: *[email protected]*), [Pacific Northwest National Laboratory, United States.](https://www.pnnl.gov/)

## Cite Our Project
Expand Down
3 changes: 3 additions & 0 deletions frontends/numpy-scipy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build/*
cometpy.egg-info/*
cometpy/cfg.py
51 changes: 29 additions & 22 deletions frontends/numpy-scipy/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# cometpy

Comet Domain Specific Compiler for NumPy and Scipy frontends.
COMET Domain Specific Compiler for NumPy and Scipy frontends.

Latest Version : v0.2

Expand All @@ -15,7 +15,7 @@ Requirements:

Tested OS support - Linux and macOS

# "COMET" / Domain specific COMpiler for Extreme Targets
# ⚡️ "COMET" / Domain specific COMpiler for Extreme Targets

The COMET compiler consists of a Domain Specific Language (DSL) for sparse and dense tensor algebra computations, a progressive lowering process to map high-level operations to low-level architectural resources, a series of optimizations performed in the lowering process, and various IR dialects to represent key concepts, operations, and types at each level of the multi-level IR. At each level of the IR stack, COMET performs different optimizations and code transformations. Domain-specific, hardware- agnostic optimizations that rely on high-level semantic information are applied at high-level IRs. These include reformulation of high-level operations in a form that is amenable for execution on heterogeneous devices (e.g., rewriting Tensor contraction operations as Transpose-Transpose-GEMM-Transpose) and automatic parallelization of high-level primitives (e.g., tiling for thread- and task-level parallelism).

Expand All @@ -26,38 +26,45 @@ More information about the COMET compiler can be found at:

# Installation and Testing:

1. Installing COMET's python package:
* Install [COMET backend](../../README.md)
1) **COMET's python package instalation:**
* Install [COMET Domain Specific Compiler](../../README.md) instructions

* Set environmental variables for paths to COMET and LLVM:

```
COMETPY_COMET_PATH=/path/to/comet/build/
COMETPY_LLVM_PATH=/path/to/llvm/build/
export COMETPY_COMET_PATH=$COMET_SRC/build/
export COMETPY_LLVM_PATH=$COMET_SRC/llvm/build
```
* In directory `frontends/numpy-scipy` run:
* In directory `frontends/numpy-scipy` run the following comment. It will also install the package dependencies if not already installed.
```
python3 -m pip install .
```
* This will also install the package dependencies if not already installed
2. Run the integration tests to make sure the installation was successfull
2) **Testing:** Run the integration tests to make sure the installation was successfull
```
cd integration_tests
python3 numpy_integration.py
python3 numpy_integration.py -v
```
3. Using COMET compiler as a backend to lower and execute test methods:
- Import the Comet Python package in your python script using - "import cometpy as comet"
- To compile a test method using COMET, add the decorator "@comet.compile(flags=...)"
before the method.
- The "numpy" keyword in a target method needs to be replace with "comet"
e.g. "comet.einsum" , "comet.multiply"
# How to use cometpy in a program:
- For the actual "einsum" computation, follow the convention - "comet.einsum()"
Using COMET compiler as a backend to lower and execute test methods:
* Import the Comet Python package in your python script using - "import cometpy as comet"
* To compile a test method using COMET, add the decorator "@comet.compile(flags=...)" before the method.
* The "numpy" keyword in a target method needs to be replace with "comet"
e.g. "comet.einsum" , "comet.multiply"
* For the actual "einsum" computation, follow the convention - "comet.einsum()"
4. Currently the code included in a comet kernel (i.e. functions annotated with @comet.compile) should take as input only ndarrays and only operate on them with the following supported operations:
- +, -, *, @ which work as intended for ndarrays
- A.transpose() or comet.einsum('ij->ji', A) for transpose operations
- comet.einsum() for tensor contraction operations
# Important Notes:
Currently the code included in a comet kernel
(i.e. functions annotated with @comet.compile) should take as input only ndarrays and only operate
on them with the following supported operations:
* +, -, *, @ which work as intended for ndarrays
* A.transpose() or comet.einsum('ij->ji', A) for transpose operations
* comet.einsum() for tensor contraction operations
5. Control flow operations are not supported and should be handled outside of the kernel call
Control flow operations are not supported and should be handled outside of the kernel call.
124 changes: 18 additions & 106 deletions frontends/rust/comet-rs/README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
# Comet-rs
This crate is a Rust-based eDSL front end for the COMET compiler.

Requirements:
1. [COMET Domain Specific Compiler](../../README.md) installed on your computer
2. rust - Rust Programming Language


## ⚡️ "COMET" / Domain specific COMpiler for Extreme Targets

The COMET compiler consists of a Domain Specific Language (DSL) for sparse and dense tensor algebra computations, a progressive lowering process to map high-level operations to low-level architectural resources, a series of optimizations performed in the lowering process, and various IR dialects to represent key concepts, operations, and types at each level of the multi-level IR. At each level of the IR stack, COMET performs different optimizations and code transformations. Domain-specific, hardware- agnostic optimizations that rely on high-level semantic information are applied at high-level IRs. These include reformulation of high-level operations in a form that is amenable for execution on heterogeneous devices (e.g., rewriting Tensor contraction operations as Transpose-Transpose-GEMM-Transpose) and automatic parallelization of high-level primitives (e.g., tiling for thread- and task-level parallelism).

Through the use of procedural macros, this crate exposes to the user a Rust based eDSL which will be lowered to various dialects and then compiled into a shared library at compile time of the user application. At runtime the shared library is dynamically linked to, exposing the compiled COMET functions, allowing the user to execute them as the would any other function.

## External Dependencies
- [COMET](https://github.com/pnnl/COMET)

Please follow the build instructions in the COMET repository to install the COMET compiler. (Also included in the COMET installation section below)

## Cargo.toml
```toml
```toml
[dependencies]
comet-rs = "0.1.0"
```

## Required Environment Variables
If you have followed the COMET build instructions exactly, you will only need to set the following envrionment variable:
```text
COMET_DIR=/path/to/COMET/root/dir
export COMET_DIR=/path/to/COMET/root/dir
```

If you have changed the build locations from what was listed in the COMET build instructions you will instead need to set the following environment variables:
```text
COMET_BIN_DIR=/path/to/COMET/bin/dir
COMET_LIB_DIR=/path/to/COMET/lib/dir
MLIR_BIN_DIR=/path/to/MLIR/bin/dir
MLIR_LIB_DIR=/path/to/MLIR/lib/dir
export COMET_BIN_DIR=/path/to/COMET/bin/dir
export COMET_LIB_DIR=/path/to/COMET/lib/dir
export MLIR_BIN_DIR=/path/to/MLIR/bin/dir
export MLIR_LIB_DIR=/path/to/MLIR/lib/dir
```
*Note that as part of the COMET build process we will also build a specific version of MLIR (managed as a git submodule),
COMET will only work with this specific commit, so please do not point to a different MLIR version you might have build outside the COMET build process.*
Expand Down Expand Up @@ -58,38 +59,15 @@ If you have changed the build locations from what was listed in the COMET build
}
```
## Operations

We have implemented the following tensor operations (most of which are not valid rust syntax, but are valid COMET eDSL syntax)
We support various tensor operations (most of which are not valid rust syntax, but are valid COMET eDSL syntax) such matrix-matrix multiplication `A * B`.
please refer to the [COMET documentation](https://pnnl-comet.readthedocs.io/en/latest/operations.html) for more in-depth descriptions of each operation.
- Multiplication: `A * B`
- Elementwise Multiplication: `A .* B`
- Semiring Operations: `@(op1, op2)`
- Min: ` A @(min) B`
- Plus: `A @(+) B`
- Mul: `A @(*) B`
- Any-Pair: `A @(any,pair) B`
- Plus-Mul: `A @(+,*)B `
- Plus-Pair: `A @(+,pair) B`
- Plus-First: `A @(+,first) B`
- Plus-Second: `A @(+,Second) B`
- Min-Plus: `A @(min,+) B`
- Min-First: `A @(min,first) B`
- Min-Second: `A @(min,second) B`
- Transpose: `B = A.transpose()`

## Optimizations

## Compiler Optimizations
We also support the ability to specify various optimizations to be performed by the COMET compiler.
please refer to the [COMET documentation](https://pnnl-comet.readthedocs.io/en/latest/optimizations.html) for more in-depth descriptions of each optimization.
- [Permutation TTGT](https://pnnl-comet.readthedocs.io/en/latest/passes/PermTTGT.html): `BestPermTtgt`
- [Tensor Algebra to Index Tree](https://pnnl-comet.readthedocs.io/en/latest/passes/TAtoIT.html): `TaToIt`
- [Tensor Contraction to TTGT](https://pnnl-comet.readthedocs.io/en/latest/passes/TC.html): `TcToTtgt`
- [Loops](https://pnnl-comet.readthedocs.io/en/latest/passes/loops.html): `ToLoops`
- [Matmult Kernel](https://pnnl-comet.readthedocs.io/en/latest/passes/mkernel.html): `MatMulKernel`
- [Matmult Tiling](https://pnnl-comet.readthedocs.io/en/latest/passes/tiling.html): `MatMulTiling`
- [Dense Transpose](https://pnnl-comet.readthedocs.io/en/latest/passes/transpose.html): `DenseTranspose`
- [Workspace](https://pnnl-comet.readthedocs.io/en/latest/passes/workspace.html): `CompWorkspace`

The above optimizations can be passed to the compiler as part of a custom syntax proivded as an argument to the `comet_fn` macro.
Please refer to the [COMET documentation](https://pnnl-comet.readthedocs.io/en/latest/optimizations.html) for more in-depth descriptions of each optimization.

The compiler optimizations can be passed to the compiler as part of a custom syntax proivded as an argument to the `comet_fn` macro.

### Example
```rust
Expand All @@ -103,7 +81,7 @@ If you have changed the build locations from what was listed in the COMET build
## COMET Output
During evaluation of the `comet_fn` macro, the COMET compiler will generate a shared library containing the compiled COMET function.
The shared library will be located in the same directory as the user application in a directory labelled `comet_libs`.
This crate handles linking this shared library into your application automatically, but it depends on the library remaining in the `comet_libs` directory
This crate handles linking this shared library into your application automatically, but it depends on the library remaining in the `comet_libs` directory.

## Crate Features
By default if a COMET function fails to compile, it will also cause the overall Rust application to fail.
Expand All @@ -113,69 +91,3 @@ If you have changed the build locations from what was listed in the COMET build
```
cargo test --no-fail-fast --features comet_errors_as_warnings
```
## COMET Installation Instructions

These commands can be used to setup COMET project:
This crate will not work without a successful COMET installation.
1) **Install Dependencies** To install COMET and LLVM/MLIR, the following dependencies need to be installed:
* [CMake (3.13.4 or later)](https://cmake.org/download),
* [Ninja (1.5 or later)](https://ninja-build.org/),
* C++ compiler toolchain as [mentioned here](https://llvm.org/docs/GettingStarted.html#requirements) and
* [Python3 (3.6 or later)](https://www.python.org/downloads/).

2) **Check out LLVM and COMET repos.** COMET contains LLVM as a git
submodule. The LLVM repo here includes staged changes to MLIR which
may be necessary to support COMET. It also represents the version of
LLVM that has been tested. MLIR is still changing relatively rapidly,
so feel free to use the current version of LLVM, but APIs may have
changed.

```
$ git clone https://github.com/pnnl/COMET.git
$ cd COMET
$ git submodule init
$ git submodule update
```

*Note:* The repository is set up so that `git submodule update` performs a
shallow clone, meaning it downloads just enough of the LLVM repository to check
out the currently specified commit. Optionally, if you wish to work with the full history of
the LLVM repository, you can manually "unshallow" the submodule.

3) **Build and test LLVM/MLIR:**

```
$ mkdir llvm/build
$ cd llvm/build
$ cmake -G Ninja ../llvm \
-DLLVM_ENABLE_PROJECTS="mlir" \
-DLLVM_TARGETS_TO_BUILD="X86" \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_BUILD_TYPE=DEBUG
$ ninja
$ ninja check-mlir
```

4) **Build and test COMET:**

```
$ cd ../../
$ mkdir build
$ cd build
$ cmake -G Ninja .. \
-DMLIR_DIR=$PWD/../llvm/build/lib/cmake/mlir \
-DLLVM_DIR=$PWD/../llvm/build/lib/cmake/llvm \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_BUILD_TYPE=DEBUG
$ ninja
$ ninja check-comet-integration # Run the integration tests.
```

The `-DCMAKE_BUILD_TYPE=DEBUG` flag enables debug information, which makes the
whole tree compile slower, but allows you to step through code into the LLVM
and MLIR frameworks.

To get something that runs fast, use `-DCMAKE_BUILD_TYPE=Release` or
`-DCMAKE_BUILD_TYPE=RelWithDebInfo` if you want to go fast and optionally if
you want debug info to go with it. `Release` mode makes a very large difference
in performance.
Loading

0 comments on commit 8621922

Please sign in to comment.