-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
783211f
commit 14a5eeb
Showing
17 changed files
with
2,086 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
a.out | ||
*.o | ||
test.bin | ||
convergence.bin | ||
*.hpp.gch | ||
convergence.dat | ||
.markdown-preview.html | ||
*.sp5 | ||
*.lst | ||
*.s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[submodule "Catch2"] | ||
path = Catch2 | ||
url = https://github.com/catchorg/Catch2.git | ||
branch = v2.x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# © (or copyright) 2019-2021. Triad National Security, LLC. All rights | ||
# reserved. This program was produced under U.S. Government contract | ||
# 89233218CNA000001 for Los Alamos National Laboratory (LANL), which is | ||
# operated by Triad National Security, LLC for the U.S. Department of | ||
# Energy/National Nuclear Security Administration. All rights in the | ||
# program are reserved by Triad National Security, LLC, and the | ||
# U.S. Department of Energy/National Nuclear Security | ||
# Administration. The Government is granted for itself and others acting | ||
# on its behalf a nonexclusive, paid-up, irrevocable worldwide license | ||
# in this material to reproduce, prepare derivative works, distribute | ||
# copies to the public, perform publicly and display publicly, and to | ||
# permit others to do so. | ||
|
||
USE_HDF5=no | ||
|
||
CC=g++ | ||
INC= spiner_types.hpp \ | ||
databox.hpp \ | ||
interpolation.hpp | ||
GCH=$(INC:.hpp=.hpp.gch) | ||
|
||
H5CC=h5c++ | ||
H5_DIR=/usr/local/hdf5-parallel | ||
H5_INCLUDE=-I${H5_DIR}/include | ||
H5_LIB=-L${H5_DIR}/lib | ||
H5_LINK=-lhdf5_hl -lhdf5 -Wl,-rpath=${H5_DIR}/lib/ | ||
|
||
CATCH_INCLUDE=-ICatch2/single_include/catch2 | ||
PORTS_INCLUDE=-Iports-of-call | ||
BASE_FLAGS=-std=c++14 -Wall -fdiagnostics-color=always -g | ||
|
||
ifeq ($(USE_HDF5),yes) | ||
CC=${H5CC} | ||
INCLUDE_FLAGS=${CATCH_INCLUDE} ${PORTS_INCLUDE} ${H5_INCLUDE} | ||
LIB_FLAGS=${H5_LIB} | ||
LINK_FLAGS=${H5_LINK} | ||
CFLAGS=${BASE_FLAGS} ${INCLUDE_FLAGS} -DSPINER_USE_HDF | ||
else | ||
INCLUDE_FLAGS=${CATCH_INCLUDE} ${PORTS_INCLUDE} | ||
LIB_FLAGS= | ||
LINK_FLAGS= | ||
CFLAGS=${BASE_FLAGS} ${INCLUDE_FLAGS} | ||
endif | ||
|
||
LFLAGS=${LIB_FLAGS} ${LINK_FLAGS} | ||
|
||
default: test | ||
|
||
all: test convergence | ||
|
||
test: test.bin | ||
./test.bin | ||
|
||
convergence: convergence.bin | ||
./convergence.bin | ||
python plot_convergence.py | ||
|
||
%.bin: %.o | ||
$(CC) ${CFLAGS} ${LFLAGS} -g -o $@ $^ | ||
|
||
%.o: %.cpp ${INC} | ||
$(CC) ${CFLAGS} -c -o $@ $< | ||
|
||
.PHONY: default all test convergence clean info | ||
|
||
clean: | ||
$(RM) test.bin convergence.bin | ||
$(RM) test.o convergence.o databox.o | ||
$(RM) ${GCH} | ||
$(RM) convergence.dat | ||
$(RM) databox.sp5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# © (or copyright) 2019-2021. Triad National Security, LLC. All rights | ||
# reserved. This program was produced under U.S. Government contract | ||
# 89233218CNA000001 for Los Alamos National Laboratory (LANL), which is | ||
# operated by Triad National Security, LLC for the U.S. Department of | ||
# Energy/National Nuclear Security Administration. All rights in the | ||
# program are reserved by Triad National Security, LLC, and the | ||
# U.S. Department of Energy/National Nuclear Security | ||
# Administration. The Government is granted for itself and others acting | ||
# on its behalf a nonexclusive, paid-up, irrevocable worldwide license | ||
# in this material to reproduce, prepare derivative works, distribute | ||
# copies to the public, perform publicly and display publicly, and to | ||
# permit others to do so. | ||
|
||
KOKKOS_PATH = ${HOME}/kokkos | ||
#SRC = test.cpp | ||
SRC = convergence.cpp | ||
vpath %.cpp $(sort $(dir $(SRC))) | ||
|
||
KOKKOS_CXX_STANDARD=c++14 | ||
|
||
default: build | ||
echo "Start Build" | ||
|
||
#H5_DIR=/usr/local/hdf5-parallel | ||
#H5_INCLUDE=-I${H5_DIR}/include | ||
#H5_LIB=-L${H5_DIR}/lib | ||
#H5_LINK=-lhdf5_hl -lhdf5 -Wl,-rpath=${H5_DIR}/lib/ | ||
|
||
ifneq (,$(findstring Cuda,$(KOKKOS_DEVICES))) | ||
CXX = ${KOKKOS_PATH}/bin/nvcc_wrapper | ||
CXXFLAGS = -O3 --expt-relaxed-constexpr | ||
CXXFLAGS += -DPORTABILITY_STRATEGY_KOKKOS #-DSPINER_USE_HDF | ||
LINK = ${CXX} | ||
#LDFLAGS = | ||
#EXE = simple_test_cuda | ||
KOKKOS_DEVICES = "Cuda" | ||
KOKKOS_ARCH = "Volta70" | ||
KOKKOS_CUDA_OPTIONS += "enable_lambda;rdc" | ||
#CXXFLAGS = -O3 --expt-relaxed-constexpr #-x cuda --cuda-gpu-arch=sm_37 --stdlib=libstdc++ -lineinfo | ||
LINK = ${CXX} | ||
LDFLAGS = | ||
EXE = simple_test_cuda | ||
else | ||
CXX = g++ | ||
CXXFLAGS = -O3 -g -DPORTABILITY_STRATEGY_KOKKOS #-DSPINER_USE_HDF | ||
LINK = ${CXX} | ||
LDFLAGS = #-lhdf5_hl -lhdf5 -Wl,-rpath=${H5_DIR}/lib/ | ||
#EXE = simple_test | ||
EXE = convergence_test | ||
KOKKOS_DEVICES = "OpenMP" | ||
KOKKOS_ARCH = "" | ||
#KOKKOS_DEBUG=yes | ||
endif | ||
|
||
EXTRA_INC += -ICatch2/single_include/catch2 -Iports-of-call | ||
#EXTRA_INC += ${H5_INCLUDE} | ||
DEPFLAGS = -M | ||
|
||
OBJ = $(notdir $(SRC:.cpp=.o)) | ||
#LIB = -L${H5_DIR}/lib | ||
|
||
include $(KOKKOS_PATH)/Makefile.kokkos | ||
|
||
build: $(EXE) | ||
|
||
test: $(EXE) | ||
./$(EXE) | ||
|
||
$(EXE): $(OBJ) $(KOKKOS_LINK_DEPENDS) | ||
$(LINK) $(KOKKOS_LDFLAGS) $(LDFLAGS) $(EXTRA_PATH) $(OBJ) $(KOKKOS_LIBS) $(LIB) -o $(EXE) | ||
|
||
clean: kokkos-clean | ||
rm -f *.o *.cuda *.host *.rocm | ||
|
||
# Compilation rules | ||
|
||
%.o:%.cpp $(KOKKOS_CPP_DEPENDS) | ||
$(CXX) $(KOKKOS_CPPFLAGS) $(KOKKOS_CXXFLAGS) $(CXXFLAGS) $(EXTRA_INC) -c $< -o $(notdir $@) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
Spiner | ||
=== | ||
|
||
Performance portable utilities for representing and interpolating | ||
tabulated data. Named for [Brent | ||
Spiner](https://en.wikipedia.org/wiki/Brent_Spiner). | ||
|
||
## Installation | ||
|
||
`Spiner` is self-contained. Simply clone it as | ||
```bash | ||
git clone [email protected]:jonahm/spiner.git | ||
``` | ||
If you want to use unit tests, clone with submodules to include `Catch2`. | ||
```bash | ||
git clone --recurse-submodules [email protected]:jonahm/spiner.git | ||
``` | ||
To build the relevant object file, call | ||
```bash | ||
make databox | ||
``` | ||
To run unit tests, | ||
```bash | ||
make test | ||
``` | ||
and to do convergence testing, | ||
```bash | ||
make convergence | ||
``` | ||
At the moment, `Spiner` cannot be installed into a system directory. | ||
|
||
**Note that you may have to edit the `Makefile` to set paths to, e.g., `hdf5`.** | ||
|
||
## Dependencies | ||
|
||
`Spiner` has no dependencies for the `databox` tool. Simply include it in your project. It is header-only and requires only a few files: | ||
|
||
- `databox.hpp` | ||
- `interpolation.hpp` | ||
- `spiner_types.hpp` | ||
- `sp5.hpp` | ||
|
||
The testing tooling requires a few different pieces: | ||
|
||
- Unit testing requires [Catch2](https://github.com/catchorg/Catch2), | ||
which is header only. This is included via a git submodule. | ||
- Convergence testing requires the scientific python stack, including: | ||
- python3 | ||
- numpy | ||
- matplotlib | ||
|
||
## HDF5 | ||
|
||
`Spiner` supports reading and writing DataBox objects into a custom HDF5 format called `SP5`. | ||
To enable this, compile with the appropriate `HDF5` linking and the flag `-DSPINER_USE_HDF5`. | ||
|
||
## Features | ||
|
||
- Spiner supports interpolation in arbitrary dimensions, and it's fast in 3d and fewer. | ||
- Spiner supports interpolation onto "subtables" | ||
|
||
## Interpolation | ||
|
||
Interpolation is linear. Here's an example of interpolation in 3D (2D | ||
slice shown). Convergence is second-order, as expected. | ||
|
||
 | ||
|
||
## Copyright | ||
|
||
© (or copyright) 2019-2021. Triad National Security, LLC. All rights | ||
reserved. This program was produced under U.S. Government contract | ||
89233218CNA000001 for Los Alamos National Laboratory (LANL), which is | ||
operated by Triad National Security, LLC for the U.S. Department of | ||
Energy/National Nuclear Security Administration. All rights in the | ||
program are reserved by Triad National Security, LLC, and the | ||
U.S. Department of Energy/National Nuclear Security | ||
Administration. The Government is granted for itself and others acting | ||
on its behalf a nonexclusive, paid-up, irrevocable worldwide license | ||
in this material to reproduce, prepare derivative works, distribute | ||
copies to the public, perform publicly and display publicly, and to | ||
permit others to do so. | ||
|
||
This program is open source under the BSD-3 License. Redistribution | ||
and use in source and binary forms, with or without modification, are | ||
permitted provided that the following conditions are met: | ||
1. Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
2. 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. | ||
3. Neither the name of the copyright holder 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 THE COPYRIGHT | ||
HOLDER OR CONTRIBUTORS 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 TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// © (or copyright) 2019-2021. Triad National Security, LLC. All rights | ||
// reserved. This program was produced under U.S. Government contract | ||
// 89233218CNA000001 for Los Alamos National Laboratory (LANL), which is | ||
// operated by Triad National Security, LLC for the U.S. Department of | ||
// Energy/National Nuclear Security Administration. All rights in the | ||
// program are reserved by Triad National Security, LLC, and the | ||
// U.S. Department of Energy/National Nuclear Security | ||
// Administration. The Government is granted for itself and others acting | ||
// on its behalf a nonexclusive, paid-up, irrevocable worldwide license | ||
// in this material to reproduce, prepare derivative works, distribute | ||
// copies to the public, perform publicly and display publicly, and to | ||
// permit others to do so. | ||
|
||
#include <string> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <cmath> | ||
|
||
#include "portability.hpp" | ||
#include "spiner_types.hpp" | ||
#include "databox.hpp" | ||
#include "interpolation.hpp" | ||
|
||
using Spiner::DataBox; | ||
using Spiner::RegularGrid1D; | ||
|
||
const std::string outname = "convergence.dat"; | ||
|
||
constexpr Real KX = 2; | ||
constexpr Real KY = 3; | ||
constexpr Real KZ = 4; | ||
|
||
constexpr Real xmin = 0; | ||
constexpr Real xmax = 1; | ||
|
||
constexpr int NGRIDS = 4; | ||
Real errors[NGRIDS]; | ||
constexpr Real NCOARSE[NGRIDS] = {8,32,128,512}; | ||
constexpr int NFINE = 1024; | ||
|
||
inline Real testFunction(Real z, Real y, Real x) { | ||
return sin(2*M_PI*KX*x)*sin(2*M_PI*KY*y)*sin(2*M_PI*KZ*z); | ||
} | ||
|
||
int main() { | ||
RegularGrid1D gfine(xmin,xmax,NFINE); | ||
|
||
std::cout << "Convergence test for Spiner" << std::endl; | ||
std::cout << std::scientific; | ||
std::cout.precision(15); | ||
|
||
#ifdef PORTABILITY_STRATEGY_KOKKOS | ||
Kokkos::initialize(); | ||
#endif | ||
{ | ||
for (int i = 0; i < NGRIDS; i++) { | ||
int n = NCOARSE[i]; | ||
Real* data = (Real*)PORTABLE_MALLOC(sizeof(Real)*n*n*n); | ||
std::cout << "\tCoarse resolution = " << n << std::endl; | ||
DataBox db(data,n,n,n); | ||
for(int d = 0; d < db.rank(); d++) { | ||
db.setRange(d,xmin,xmax,n); | ||
} | ||
std::cout << "\t\tFilling DataBox" << std::endl; | ||
portableFor("filling databox", | ||
0,n,0,n,0,n, | ||
PORTABLE_LAMBDA(const int iz, | ||
const int iy, | ||
const int ix) { | ||
Real z = db.range(2).x(iz); | ||
Real y = db.range(1).x(iy); | ||
Real x = db.range(0).x(ix); | ||
db(iz,iy,ix) = testFunction(z,y,x); | ||
}); | ||
std::cout << "\t\tInterpolating..." << std::endl; | ||
errors[i] = 0; | ||
portableReduce("interpolating", | ||
0,NFINE,0,NFINE,0,NFINE, | ||
PORTABLE_LAMBDA(const int iz, | ||
const int iy, | ||
const int ix, | ||
Real& reduced) { | ||
Real z = gfine.x(iz); | ||
Real y = gfine.x(iy); | ||
Real x = gfine.x(ix); | ||
Real f_interp = db.interpToReal(z,y,x); | ||
Real f_true = testFunction(z,y,x); | ||
Real difference = f_interp - f_true; | ||
reduced += difference*difference; | ||
}, | ||
errors[i]); | ||
errors[i] = sqrt(fabs(errors[i])) / (NFINE*NFINE*NFINE); | ||
std::cout << "\t\t...error = " << errors[i] << std::endl; | ||
PORTABLE_FREE(data); | ||
} | ||
} | ||
#ifdef PORTABILITY_STRATEGY_KOKKOS | ||
Kokkos::finalize(); | ||
#endif | ||
|
||
std::cout << "Saving convergence results to: " << outname << std::endl; | ||
std::ofstream outfile; | ||
outfile.open(outname); | ||
outfile.precision(15); | ||
outfile << std::scientific; | ||
outfile << "# [0]:resolution, [1]:error" << std::endl; | ||
for (int i = 0; i < NGRIDS; i++) { | ||
outfile << NCOARSE[i] << "\t" << errors[i] << std::endl; | ||
} | ||
outfile.close(); | ||
std::cout << "Done!" << std::endl; | ||
|
||
return 0; | ||
} | ||
|
Oops, something went wrong.