Skip to content

Commit

Permalink
grid: Add GPU backend
Browse files Browse the repository at this point in the history
  • Loading branch information
oschuett committed Nov 16, 2020
1 parent e18b1c5 commit 8bb4190
Show file tree
Hide file tree
Showing 17 changed files with 1,326 additions and 19 deletions.
1 change: 1 addition & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ version of CP2K (ssmp or psmp), the FFTW3 threading library libfftw3_threads
- Use `-D__CUDA_PROFILING` to turn on Nvidia Tools Extensions.
It requires to link `-lnvToolsExt`.
- Link to a blas/scalapack library that accelerates large DGEMMs (e.g. libsci_acc)
- Use the `-D__GRID_CUDA` to compile the GPU and HYBRID backends for the grid library.

### 2k. libxc (optional, wider choice of xc functionals)

Expand Down
4 changes: 4 additions & 0 deletions src/cp2k_info.F
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ FUNCTION cp2k_flags() RESULT(flags)
flags = TRIM(flags)//" check_diag"
#endif

#if defined __GRID_CUDA
flags = TRIM(flags)//" grid_cuda"
#endif

END FUNCTION cp2k_flags

! **************************************************************************************************
Expand Down
16 changes: 12 additions & 4 deletions src/grid/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ all: grid_collocate_miniapp.x grid_collocate_unittest.x
clean:
rm -fv grid_*.o */grid_*.o grid_*.x

CFLAGS := -fopenmp -g -O3 -std=c99 -march=native -Wall -Wextra -Wpedantic
CFLAGS := -fopenmp -g -O3 -std=c99 -march=native -Wall -Wextra -Wpedantic -I${CUDA_PATH}/include -D__GRID_CUDA
NVFLAGS := -g -O3 -arch sm_50 -Wno-deprecated-gpu-targets -Xcompiler "-fopenmp -Wall -Wextra" -D__GRID_CUDA

LIBS := -lm -lblas -lcudart -lcuda -L${CUDA_PATH}/lib64

ALL_HEADERS := $(shell find . -name "*.h")

Expand All @@ -18,15 +21,20 @@ ALL_OBJECTS := grid_collocate_replay.o \
ref/grid_ref_task_list.o \
ref/grid_ref_collocate.o \
ref/grid_ref_integrate.o \
ref/grid_ref_prepare_pab.o
ref/grid_ref_prepare_pab.o \
gpu/grid_gpu_task_list.o \
gpu/grid_gpu_collocate.o

%.o: %.c $(ALL_HEADERS)
cd $(dir $<); $(CC) -c $(CFLAGS) $(notdir $<)

%.o: %.cu $(ALL_HEADERS)
cd $(dir $<); nvcc -c $(NVFLAGS) $(notdir $<)

grid_collocate_miniapp.x: grid_collocate_miniapp.o $(ALL_OBJECTS)
$(CC) $(CFLAGS) -o $@ $^ -lm -lblas
nvcc $(NVFLAGS) -o $@ $^ $(LIBS)

grid_collocate_unittest.x: grid_collocate_unittest.o $(ALL_OBJECTS)
$(CC) $(CFLAGS) -o $@ $^ -lm -lblas
nvcc $(NVFLAGS) -o $@ $^ $(LIBS)

#EOF
1 change: 1 addition & 0 deletions src/grid/PACKAGE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"./common",
"./ref",
"./cpu",
"./gpu",
],
"public": ["grid_api.F"],
}
4 changes: 4 additions & 0 deletions src/grid/common/grid_basis_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ typedef struct {
double *zet;
} grid_basis_set;

#ifndef __cplusplus

/*******************************************************************************
* \brief Allocates a basis set which can be passed to grid_create_task_list.
*
Expand Down Expand Up @@ -63,4 +65,6 @@ void grid_free_basis_set(grid_basis_set *basis_set);

#endif

#endif

// EOF
1 change: 1 addition & 0 deletions src/grid/common/grid_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@
#define GRID_BACKEND_AUTO 10
#define GRID_BACKEND_REF 11
#define GRID_BACKEND_CPU 12
#define GRID_BACKEND_GPU 13

// EOF
8 changes: 7 additions & 1 deletion src/grid/common/grid_prepare_pab.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,13 @@ GRID_DEVICE static void prepare_pab_Di2(const int ider, const orbital a,
}

/*******************************************************************************
* \brief TODO
* \brief Transforms a given element of the density matrix according to func.
* \param func Transformation function to apply, one of GRID_FUNC_*.
* \param {a,b} Orbital angular momenta.
* \param zet_{a,b} Gaussian exponents.
* \param pab_val Input matrix element of pab.
* \param n Leading dimensions of output matrix cab.
* \param cab Output matrix.
* \author Ole Schuett
******************************************************************************/
GRID_DEVICE static void prepare_pab(const int func, const orbital a,
Expand Down
5 changes: 5 additions & 0 deletions src/grid/gpu/PACKAGE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"description": "Optimized GPU backend",
"requires": ["../common",],
"archive": "libcp2kgridgpu",
}

0 comments on commit 8bb4190

Please sign in to comment.