xref: /libCEED/README.md (revision 045b9c47918b4f2e6fc35c132ba58510691ff6fb)
1# libCEED: the CEED API Library
2
3[![Build Status](https://travis-ci.org/CEED/libCEED.svg?branch=master)](https://travis-ci.org/CEED/libCEED)
4[![Code Coverage](https://codecov.io/gh/CEED/libCEED/branch/master/graphs/badge.svg)](https://codecov.io/gh/CEED/libCEED/)
5[![License](https://img.shields.io/badge/License-BSD%202--Clause-orange.svg)](https://opensource.org/licenses/BSD-2-Clause)
6[![Doxygen](https://codedocs.xyz/CEED/libCEED.svg)](https://codedocs.xyz/CEED/libCEED/)
7
8## Code for Efficient Extensible Discretization
9
10This repository contains an initial low-level API library for the efficient
11high-order discretization methods developed by the ECP co-design [Center for
12Efficient Exascale Discretizations (CEED)](http://ceed.exascaleproject.org).
13While our focus is on high-order finite elements, the approach is mostly
14algebraic and thus applicable to other discretizations in factored form, as
15explained in the API documentation portion of the [Doxygen documentation](https://codedocs.xyz/CEED/libCEED/md_doc_libCEEDapi.html).
16
17One of the challenges with high-order methods is that a global sparse matrix is
18no longer a good representation of a high-order linear operator, both with
19respect to the FLOPs needed for its evaluation, as well as the memory transfer
20needed for a matvec.  Thus, high-order methods require a new "format" that still
21represents a linear (or more generally non-linear) operator, but not through a
22sparse matrix.
23
24The goal of libCEED is to propose such a format, as well as supporting
25implementations and data structures, that enable efficient operator evaluation
26on a variety of computational device types (CPUs, GPUs, etc.). This new operator
27description is based on algebraically [factored form](https://codedocs.xyz/CEED/libCEED/md_doc_libCEEDapi.html),
28which is easy to incorporate in a wide variety of applications, without significant
29refactoring of their own discretization infrastructure.
30
31The repository is part of the [CEED software suite][ceed-soft], a collection of
32software benchmarks, miniapps, libraries and APIs for efficient exascale
33discretizations based on high-order finite element and spectral element methods.
34See http://github.com/ceed for more information and source code availability.
35
36The CEED research is supported by the [Exascale Computing Project][ecp]
37(17-SC-20-SC), a collaborative effort of two U.S. Department of Energy
38organizations (Office of Science and the National Nuclear Security
39Administration) responsible for the planning and preparation of a [capable
40exascale ecosystem](https://exascaleproject.org/what-is-exascale), including
41software, applications, hardware, advanced system engineering and early testbed
42platforms, in support of the nation’s exascale computing imperative.
43
44For more details on the CEED API see http://ceed.exascaleproject.org/ceed-code/.
45
46## Building
47
48The CEED library, `libceed`, is a C99 library with no external dependencies.  It
49can be built using
50
51    make
52
53or, with optimization flags
54
55    make OPT='-O3 -march=skylake-avx512 -ffp-contract=fast'
56
57These optimization flags are used by all languages (C, C++, Fortran) and this
58makefile variable can also be set for testing and examples (below).
59
60The library attempts to automatically detect support for the AVX
61instruction set using gcc-style compiler options for the host.
62Support may need to be manually specified via
63
64    make AVX=1
65
66or
67
68    make AVX=0
69
70if your compiler does not support gcc-style options, if you are cross
71compiling, etc.
72
73## Testing
74
75The test suite produces [TAP](https://testanything.org) output and is run by:
76
77    make test
78
79or, using the `prove` tool distributed with Perl (recommended)
80
81    make prove
82
83## Backends
84
85There are multiple supported backends, which can be selected at runtime in the examples:
86
87<<<<<<< HEAD
88|  CEED resource           | Backend                                           |
89| :----------------------- | :------------------------------------------------ |
90| `/cpu/self/ref/serial`   | Serial reference implementation                   |
91| `/cpu/self/ref/blocked`  | Blocked refrence implementation                   |
92| `/cpu/self/tmpl`         | Backend template, delegates to `/cpu/self/ref/blocked` |
93| `/cpu/self/ref/memcheck` | Memcheck backend, undefined value checks          |
94| `/cpu/self/avx/serial`   | Serial AVX implementation                         |
95| `/cpu/self/avx/blocked`  | Blocked AVX implementation                        |
96| `/cpu/self/xsmm/serial`  | Serial LIBXSMM implementation                     |
97| `/cpu/self/xsmm/blocked` | Blocked LIBXSMM implementation                    |
98| `/cpu/occa`              | Serial OCCA kernels                               |
99| `/gpu/occa`              | CUDA OCCA kernels                                 |
100| `/omp/occa`              | OpenMP OCCA kernels                               |
101| `/ocl/occa`              | OpenCL OCCA kernels                               |
102| `/gpu/cuda/ref`          | Reference pure CUDA kernels                       |
103| `/gpu/cuda/reg`          | Pure CUDA kernels using one thread per element    |
104| `/gpu/magma`             | CUDA MAGMA kernels                                |
105=======
106|  CEED resource                | Backend                                                |
107| :---------------------------- | :----------------------------------------------------- |
108| `/cpu/self/ref/serial`        | Serial reference implementation                        |
109| `/cpu/self/ref/blocked`       | Blocked refrence implementation                        |
110| `/cpu/self/ref/blocked/full`  | Blocked refrence implementation with full Evectors     |
111| `/cpu/self/tmpl`              | Backend template, delegates to `/cpu/self/ref/blocked` |
112| `/cpu/self/avx/serial`        | Serial AVX implementation                              |
113| `/cpu/self/avx/blocked`       | Blocked AVX implementation                             |
114| `/cpu/self/xsmm/serial`       | Serial LIBXSMM implementation                          |
115| `/cpu/self/xsmm/blocked`      | Blocked LIBXSMM implementation                         |
116| `/cpu/occa`                   | Serial OCCA kernels                                    |
117| `/gpu/occa`                   | CUDA OCCA kernels                                      |
118| `/omp/occa`                   | OpenMP OCCA kernels                                    |
119| `/ocl/occa`                   | OpenCL OCCA kernels                                    |
120| `/gpu/cuda/ref`               | Reference pure CUDA kernels                            |
121| `/gpu/cuda/reg`               | Pure CUDA kernels using one thread per element         |
122| `/gpu/magma`                  | CUDA MAGMA kernels                                     |
123>>>>>>> Include full evec blocked backend
124
125
126The `/cpu/self/*/serial` backends process one element at a time and are intended for meshes
127with a smaller number of high order elements. The `/cpu/self/*/blocked` backends process
128blocked batches of eight interlaced elements and are intended for meshes with higher numbers
129of elements.
130
131The `/cpu/self/ref/*` backends are written in pure C and provide basic functionality.
132
133The `/cpu/self/avx/*` backends rely upon AVX instructions to provide vectorized CPU performance.
134
135The `/cpu/self/xsmm/*` backends rely upon the [LIBXSMM](http://github.com/hfp/libxsmm) package
136to provide vectorized CPU performance. The LIBXSMM backend does not use BLAS or MKL; however,
137if LIBXSMM was linked to MKL, this can be specified with the compilation flag `MKL=1`.
138
139The `/cpu/self/ref/memcheck` backend relies upon the [Valgrind](http://valgrind.org/) Memcheck tool
140to help verify that user QFunctions have no undefined values. To use, run your code with
141Valgrind and the Memcheck backend, e.g. `valgrind ./build/ex1 -ceed /cpu/self/ref/memcheck`.
142
143The `/*/occa` backends rely upon the [OCCA](http://github.com/libocca/occa) package to provide
144cross platform performance.
145
146The `/gpu/cuda/*` backends provide GPU performance strictly using CUDA.
147
148The `/gpu/magma` backend relies upon the [MAGMA](https://bitbucket.org/icl/magma) package.
149
150## Examples
151
152libCEED comes with several examples of its usage, ranging from standalone C
153codes in the `/examples/ceed` directory to examples based on external packages,
154such as MFEM, PETSc, and Nek5000. Nek5000 v18.0 or greater is required.
155
156To build the examples, set the `MFEM_DIR`, `PETSC_DIR` and `NEK5K_DIR` variables
157and run:
158
159```console
160# libCEED examples on CPU and GPU
161cd examples/ceed
162make
163./ex1 -ceed /cpu/self
164./ex1 -ceed /gpu/occa
165cd ../..
166
167# MFEM+libCEED examples on CPU and GPU
168cd examples/mfem
169make
170./bp1 -ceed /cpu/self -no-vis
171./bp1 -ceed /gpu/occa -no-vis
172cd ../..
173
174# PETSc+libCEED examples on CPU and GPU
175cd examples/petsc
176make
177./bp1 -ceed /cpu/self
178./bp1 -ceed /gpu/occa
179cd ../..
180
181cd navier-stokes
182make
183./navierstokes -ceed /cpu/self
184./navierstokes -ceed /gpu/occa
185cd ../..
186
187# Nek+libCEED examples on CPU and GPU
188cd examples/nek5000
189./make-nek-examples.sh
190./run-nek-example.sh -ceed /cpu/self -b 3
191./run-nek-example.sh -ceed /gpu/occa -b 3
192cd ../..
193```
194
195The above code assumes a GPU-capable machine with the OCCA backend
196enabled. Depending on the available backends, other Ceed resource specifiers can
197be provided with the `-ceed` option.
198
199## Benchmarks
200
201A sequence of benchmarks for all enabled backends can be run using
202
203```console
204make benchmarks
205```
206
207The results from the benchmarks are stored inside the `benchmarks/` directory
208and they can be viewed using the commands (requires python with matplotlib):
209
210```console
211cd benchmarks
212python postprocess-plot.py petsc-bp1-*-output.txt
213python postprocess-plot.py petsc-bp3-*-output.txt
214```
215
216Using the `benchmarks` target runs a comprehensive set of benchmarks which may
217take some time to run. Subsets of the benchmarks can be run using targets such
218as `make bench-petsc-bp1`, or `make bench-petsc-bp3`.
219
220For more details about the benchmarks, see
221[`benchmarks/README.md`](benchmarks/README.md)
222
223
224## Install
225
226To install libCEED, run
227
228    make install prefix=/usr/local
229
230or (e.g., if creating packages),
231
232    make install prefix=/usr DESTDIR=/packaging/path
233
234Note that along with the library, libCEED installs kernel sources, e.g. OCCA
235kernels are installed in `$prefix/lib/okl`. This allows the OCCA backend to
236build specialized kernels at run-time. In a normal setting, the kernel sources
237will be found automatically (relative to the library file `libceed.so`).
238However, if that fails (e.g. if `libceed.so` is moved), one can copy (cache) the
239kernel sources inside the user OCCA directory, `~/.occa` using
240
241    $(OCCA_DIR)/bin/occa cache ceed $(CEED_DIR)/lib/okl/*.okl
242
243This will allow OCCA to find the sources regardless of the location of the CEED
244library. One may occasionally need to clear the OCCA cache, which can be accomplished
245by removing the `~/.occa` directory or by calling `$(OCCA_DIR)/bin/occa clear -a`.
246
247### pkg-config
248
249In addition to library and header, libCEED provides a [pkg-config][pkg-config1]
250file that can be used to easily compile and link. [For example][pkg-config2], if
251`$prefix` is a standard location or you set the environment variable
252`PKG_CONFIG_PATH`,
253
254    cc `pkg-config --cflags --libs ceed` -o myapp myapp.c
255
256will build `myapp` with libCEED.  This can be used with the source or
257installed directories.  Most build systems have support for pkg-config.
258
259## Contact
260
261You can reach the libCEED team by emailing [ceed-users@llnl.gov](mailto:ceed-users@llnl.gov)
262or by leaving a comment in the [issue tracker](https://github.com/CEED/libCEED/issues).
263
264## Copyright
265
266The following copyright applies to each file in the CEED software suite, unless
267otherwise stated in the file:
268
269> Copyright (c) 2017, Lawrence Livermore National Security, LLC. Produced at the
270> Lawrence Livermore National Laboratory. LLNL-CODE-734707. All Rights reserved.
271
272See files LICENSE and NOTICE for details.
273
274[ceed-soft]:   http://ceed.exascaleproject.org/software/
275[ecp]:         https://exascaleproject.org/exascale-computing-project
276[pkg-config1]: https://en.wikipedia.org/wiki/Pkg-config
277[pkg-config2]: https://people.freedesktop.org/~dbn/pkg-config-guide.html#faq
278