cutlass/README.md

257 lines
11 KiB
Markdown
Raw Normal View History

2018-05-17 02:44:56 +08:00
![ALT](/media/images/gemm-hierarchy-with-epilogue-no-labels.png "Complete CUDA GEMM decomposition")
2017-12-06 09:15:33 +08:00
2018-10-27 05:38:46 +08:00
# CUTLASS 1.2
2017-12-05 00:07:48 +08:00
_CUTLASS 1.2 - October 2018_
2018-10-27 05:38:46 +08:00
CUTLASS is a collection of CUDA C++ template abstractions for implementing
2018-05-17 02:44:56 +08:00
high-performance matrix-multiplication (GEMM) at all levels and scales within CUDA.
It incorporates strategies for hierarchical decomposition and data movement similar
to those used to implement cuBLAS. CUTLASS decomposes these "moving parts" into
2017-12-06 09:55:03 +08:00
reusable, modular software components abstracted by C++ template classes. These
2018-05-17 02:44:56 +08:00
thread-wide, warp-wide, block-wide, and device-wide primitives can be specialized
and tuned via custom tiling sizes, data types, and other algorithmic policy. The
resulting flexibility simplifies their use as building blocks within custom kernels
2017-12-06 09:55:54 +08:00
and applications.
2017-12-06 09:50:15 +08:00
To support a wide variety of applications, CUTLASS provides extensive support for
2018-05-17 02:44:56 +08:00
mixed-precision computations, providing specialized data-movement and
multiply-accumulate abstractions for 8-bit integer, half-precision floating
point (FP16), single-precision floating point (FP32), and double-precision floating
2017-12-06 10:32:06 +08:00
point (FP64) types. Furthermore, CUTLASS demonstrates CUDA's WMMA API for targeting
2018-05-17 02:44:56 +08:00
the programmable, high-throughput _Tensor Cores_ provided by NVIDIA's Volta architecture
2017-12-06 10:32:06 +08:00
and beyond.
2017-12-05 00:07:48 +08:00
2018-10-27 05:38:46 +08:00
CUTLASS 1.2 is described in the [CUTLASS Documentation](CUTLASS.md) and the accompanying
2018-09-19 07:58:03 +08:00
[Doxygen documentation](https://nvidia.github.io/cutlass).
We describe the structure of an efficient GEMM in our talk at the
[GPU Technology Conference 2018](http://on-demand.gputechconf.com/gtc/2018/presentation/s8854-cutlass-software-primitives-for-dense-linear-algebra-at-all-levels-and-scales-within-cuda.pdf).
2018-10-27 05:38:46 +08:00
# What's New in CUTLASS 1.2
_October 2018_
* [Parallelized Reductions](CUTLASS.md#parallel-reductions-across-gemm-k)
* Batched strided WMMA GEMM
2018-09-19 07:58:03 +08:00
# What's New in CUTLASS 1.1
2018-10-27 05:38:46 +08:00
_September 2018_
2018-09-19 07:58:03 +08:00
* [CUTLASS Documentation](CUTLASS.md)
* [Examples](examples/)
* Basic GEMM, tensor views, CUTLASS utilities, batched GEMM, WMMA GEMM
* Turing Features
2018-09-20 11:42:51 +08:00
* [WMMA GEMM targeting TensorCores](tools/test/unit/gemm/wmma_integer_gemm.cu) - INT8, INT4, 1-bit
2018-09-19 07:58:03 +08:00
* [Batched Strided GEMM](tools/test/unit/gemm/batched_strided_sgemm_128x128x8.cu)
* [Threadblock rasterization strategies](tools/test/unit/gemm/sgemm_threadblock_swizzle_nt.cu)
* Improved performance for adverse problem sizes and data layouts
2018-09-29 03:59:20 +08:00
* Extended CUTLASS Core components
2018-09-19 07:58:03 +08:00
* Tensor views support arbitrary matrix and tensor layouts
* Zip iterators for structuring multiple data streams
* Enhanced CUTLASS utilities
* [Reference implementations](tools/util/reference) for tensor operations in [host](tools/util/reference/host) and [device](tools/util/reference/device) code
* Added `HostMatrix<>` for simplified matrix creation
2017-12-06 11:53:11 +08:00
# Performance
2018-05-17 02:44:56 +08:00
<p align="center"><img src=/media/images/cutlass-performance-plot.png></p>
2018-05-17 02:44:56 +08:00
CUTLASS primitives are very efficient. When used to construct device-wide GEMM kernels,
they exhibit performance comparable to cuBLAS for scalar GEMM
computations. The above figure shows CUTLASS performance relative to cuBLAS
for large matrix dimensions (M=10240, N=K=4096) running on an NVIDIA Titan V GPU
2018-09-19 07:58:03 +08:00
when compiled with CUDA 10.0.
2017-12-06 11:25:42 +08:00
2018-05-17 02:44:56 +08:00
# Compatibility
2017-12-05 00:07:48 +08:00
2018-09-21 02:04:03 +08:00
CUTLASS performs best when compiled with the [CUDA 10.0 Toolkit](ttps://developer.nvidia.com/cuda-toolkit).
It is compatible with CUDA 9.0, 9.1, and 9.2, but these versions of the CUDA Toolkit do not support new Turing WMMA features.
We have tested the following environments.
2017-12-05 00:07:48 +08:00
2018-05-17 02:44:56 +08:00
|**Operating System** | **Compiler** |
|-----------------|----------|
| Windows 10 | Microsoft Visual Studio 2015|
| | Microsoft Visual Studio 2017|
| Ubuntu 14.04 | GCC 4.8.2 |
| Ubuntu 16.04 | GCC 5.4.0 |
2018-09-21 02:04:03 +08:00
| Ubuntu 18.04 | GCC 7.3.0 |
2017-12-05 00:07:48 +08:00
2018-05-17 02:44:56 +08:00
CUTLASS runs successfully on the following NVIDIA GPUs, and it is expected to be efficient on
any Maxwell-, Pascal-, or Volta-architecture NVIDIA GPU.
2017-12-05 00:07:48 +08:00
2018-05-17 02:44:56 +08:00
|**GPU**|
|---|
|NVIDIA GeForce 1080|
|NVIDIA TitanXP|
|NVIDIA Tesla P100|
|NVIDIA Tesla V100|
|NVIDIA TitanV|
2018-09-19 07:58:03 +08:00
|NVIDIA GeForce RTX 2080 TI, 2080, 2070|
2017-12-05 00:07:48 +08:00
2018-05-17 02:44:56 +08:00
# Building CUTLASS
2017-12-05 00:07:48 +08:00
2018-05-17 02:44:56 +08:00
CUTLASS is a header-only template library and does not need to be built to be used by other
projects. However, we distribute extensive unit tests and utility programs to demonstrate
CUTLASS. These instructions are for building those test programs.
2017-12-05 00:07:48 +08:00
2018-05-17 02:44:56 +08:00
CUTLASS's unit tests depend on Google Test which exists as a git submodule. You can fetch
submodules as follows.
```
$ git submodule update --init --recursive
```
2017-12-05 00:07:48 +08:00
2018-05-17 02:44:56 +08:00
CUTLASS can be build with CMake starting version 3.10. By default CUTLASS will build kernels
2018-09-19 07:58:03 +08:00
for CUDA architecture versions 5.0, 6.0, 6.1, 7.0 and 7.5. To reduce compile time you can specify
2018-05-17 02:44:56 +08:00
the architectures to build CUTLASS for by changing the CMake configuration setting
`CUTLASS_NVCC_ARCHS`.
2017-12-05 00:07:48 +08:00
2018-05-17 02:44:56 +08:00
Create a build directory within the CUTLASS project, then run CMake once.
2017-12-05 00:07:48 +08:00
2018-05-17 02:44:56 +08:00
```
$ mkdir build && cd build
$ cmake ..
```
2017-12-05 00:07:48 +08:00
2018-05-17 02:44:56 +08:00
Compile the CUTLASS project by running Make. Include the -j argument to compile sources in
parallel and speed up the build process.
2017-12-05 00:07:48 +08:00
2018-05-17 02:44:56 +08:00
```
$ make -j12
...
$
```
2017-12-05 00:07:48 +08:00
2018-05-17 02:44:56 +08:00
Verify CUTLASS has been built correctly by running the unit tests from the build/ directory.
```
$ ./tools/test/unit/cutlass_unit_test
...
...
...
[----------] Global test environment tear-down
2018-09-19 07:58:03 +08:00
[==========] 946 tests from 57 test cases ran. (10812 ms total)
[ PASSED ] 946 tests.
2018-05-17 02:44:56 +08:00
```
All tests should pass, though the exact number of tests may vary over time.
# Project Structure
CUTLASS is arranged as a header-only library with several example test programs
that demonstrate instantiating a GEMM task within a CUDA kernel. The Doxygen documentation
provides a complete list of files, classes, and template concepts defined in the CUTLASS
project. A brief summary is described below.
2017-12-05 00:07:48 +08:00
2018-05-17 02:44:56 +08:00
The CUTLASS library is defined in the cutlass/ directory and consists of CUDA C++ template
classes and other definitions for implementing efficient GPU GEMM kernels. A set of core
classes and templates define basic primitives that are then applied to compute GEMM via
templates in the cutlass/gemm directory.
2017-12-05 00:07:48 +08:00
2017-12-06 23:00:59 +08:00
```
2018-05-17 02:44:56 +08:00
cutlass/
2018-09-19 07:58:03 +08:00
gemm/
util/
<core API components>
2017-12-06 23:00:59 +08:00
```
2018-05-17 02:44:56 +08:00
Several tools and test programs are also distributed with the CUTLASS library. They are
contained in the following directories.
```
2018-09-19 07:58:03 +08:00
examples/
00_basic_gemm/
01_tensor_view/
02_cutlass_utilities/
03_batched_gemm/
04_tile_iterator/
05_wmma_gemm/
2018-05-17 02:44:56 +08:00
tools/
2018-09-19 07:58:03 +08:00
test/
unit/
core/
gemm/
perf/
util/
reference/
device/
host/
<utilities>
2018-05-17 02:44:56 +08:00
```
The `test/unit/` directory consist of unit tests implemented with Google Test that demonstrate
basic usage of Core API components and complete tests of the CUTLASS GEMM computations.
2018-09-19 07:58:03 +08:00
The `tools/util` directory contains CUTLASS utilities including reference implementations of GEMM and
several element-wise tensor operations.
2018-05-17 02:44:56 +08:00
# Performance Profiling
The `test/perf/` directory contains a command-line utility for launching each of the GEMM kernels.
Its usage is shown below.
Program usage:
```
cutlass_perf_test [options]
--help
--append=<true|false*> If true, appends output to existing CSV file. If false, overwrites.
--alpha=<alpha> Value for alpha to be used in GEMM experiments
--beta=<beta> Value for beta to be used in GEMM experiments
2018-05-17 03:47:07 +08:00
--dist=<distribution> Describes the random distribution of each of the input matrix operands.
--execution_mode=<mode> Specifies execution mode: profile, verify, single
2018-05-17 02:44:56 +08:00
--output=<filename.csv> Writes summary of profiling to specified .csv file
--iterations=<timing iterations> maximum number of iterations to execute when profiling
--m=<height>[:max height[:step]] Height of GEMM problem (number of rows of C). May specify a range with optional step size.
--n=<width>[:max width[:step]] Width of GEMM problem (number of columns of C). May specify a range with optional step size.
--k=<depth>[:max depth[:step]] Size of inner dimension of A and B. May specify a range with optional step size.
2018-05-18 06:10:55 +08:00
--kernels=<{s|d|h|i|wmma_}gemm_{nn,nt,tn,tt}> Select GEMM datatype and layout to use for tests
2018-05-17 02:44:56 +08:00
--peak=<bool> If true, only reports peak performance per kernel after profiling specified problem space.
2018-05-17 03:47:07 +08:00
--save_workspace={*never,incorrect,always} Specifies when to save the GEMM inputs and results to the filesystem.
2018-05-17 02:44:56 +08:00
--seed=<seed> Random seed used by the random number generator in initializing input matrices.
2018-05-17 03:47:07 +08:00
--tags=<column:tag,...> Inserts leading columns in output table and uniform values for each column.
2018-05-17 02:44:56 +08:00
Example usage:
# Runs one problem size for all kernels
$ ./tools/test/perf/cutlass_perf_test --m=10240 --n=1024 --k=1024
# Varies GEMM K dimension for SGEMM and IGEMM with column-major multiplicands
$ ./tools/test/perf/cutlass_perf_test --m=10240 --n=4096 --k=1024:8192:128 --kernels=sgemm_nn,igemm_nn
```
# About
CUTLASS is released by NVIDIA Corporation as Open Source software under the
3-clause "New" BSD license.
# Copyright
Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved.
2018-05-17 03:50:10 +08:00
```
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
* Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
to endorse or promote products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```