README.md 3.53 KB
Newer Older
1
2
3
# Composable Kernel

## Methodology
Chao Liu's avatar
Chao Liu committed
4
Composable Kernel (CK) library aims to provide a programming model for writing performance critical kernels for machine learning workloads across multiple architectures including GPUs, CPUs, etc, through general purpose kernel languages, like HIP C++.
5

Chao Liu's avatar
Chao Liu committed
6
CK utilizes two concepts to achieve performance portability and code maintainability:
7
8
9
* A tile-based programming model
* Algorithm complexity reduction for complex ML operators, using innovative technique we call "Tensor Coordinate Transformation".

Sam Wu's avatar
Sam Wu committed
10
![ALT](/docs/data/ck_component.png "CK Components")
11
12
13

## Code Structure
Current CK library are structured into 4 layers:
Chao Liu's avatar
Chao Liu committed
14
* "Templated Tile Operators" layer
15
16
17
18
* "Templated Kernel and Invoker" layer
* "Instantiated Kernel and Invoker" layer
* "Client API" layer

Sam Wu's avatar
Sam Wu committed
19
20
21
22
23
24
25
26
27
28
29
![ALT](/docs/data/ck_layer.png "CK Layers")

## Documentation

Run the steps below to build documentation locally.

```
cd docs
pip3 install -r .sphinx/requirements.txt
python3 -m sphinx -T -E -b html -d _build/doctrees -D language=en . _build/html
```
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

## Contributors
The list of developers and contributors is here: [Contributors](/CONTRIBUTORS.md)

## Citation
If you use CK, please use following citations:
* CK paper will be freely available on arXiv soon: [Realizing Tensor Operators Using Coordinate Transformations and Tile Based Programming](???)
* [CITATION.cff](/CITATION.cff)

## License
CK is released under the MIT license. [License File](/LICENSE)


# Build CK

## Build docker image
```bash
DOCKER_BUILDKIT=1 docker build -t ck:latest -f Dockerfile .
```

## Launch docker
51
52
53
54
55
56
57
```bash
docker run                                     \
-it                                            \
--privileged                                   \
--group-add sudo                               \
-w /root/workspace                             \
-v ${PATH_TO_LOCAL_WORKSPACE}:/root/workspace  \
58
ck:latest                                      \
59
60
/bin/bash
```
Chao Liu's avatar
Chao Liu committed
61

62
## Build CK
63
64
65
```bash
mkdir build && cd build

66
67
68
69
70
71
# Need to specify target ID, example below is for gfx908 and gfx90a
cmake                                                                                             \
-D CMAKE_PREFIX_PATH=/opt/rocm                                                                    \
-D CMAKE_CXX_COMPILER=/opt/rocm/bin/hipcc                                                         \
-D CMAKE_CXX_FLAGS="-O3"                                                                          \
-D CMAKE_BUILD_TYPE=Release                                                                       \
72
-D GPU_TARGETS="gfx908;gfx90a"                                                                    \
73
74
75
..
```

76
### Build examples and tests
77
```bash
78
 make -j examples tests
79
80
81
 make test
```

82
83
84
Instructions for running each individual examples are under [example](/example)


85
86
87
88
## Build ckProfiler
```bash
 make -j ckProfiler
```
89
Instructions for running ckProfiler are under [profiler](/profiler)
JD's avatar
JD committed
90

91
92
93
94
95
96
## Install CK
```bash
make install
```

## Using CK as pre-built kernel library
97
Instructions for using CK as a pre-built kernel library are under [client_example](/client_example)
JD's avatar
JD committed
98
99
100
101
102

## Caveat
### Kernel Timing and Verification
CK's own kernel timer will warn up kernel once, and then run it multiple times
to get average kernel time. For some kernels that use atomic add, this will cause
Chao Liu's avatar
Chao Liu committed
103
output buffer to be accumulated multiple times, causing verification failure.
JD's avatar
JD committed
104
105
106
To work around it, do not use CK's own timer and do verification at the same time.
CK's own timer and verification in each example and ckProfiler can be enabled or
disabled from command line.