mirror of
https://github.com/pfloos/quack
synced 2025-01-03 01:56:09 +01:00
linked CUDA module with QuAcK properley
This commit is contained in:
parent
a10e4c8c23
commit
41dd532d0e
@ -1,11 +1,11 @@
|
|||||||
NVCC = nvcc
|
NVCC = nvcc
|
||||||
NVFLAGS = -O2 --compiler-options '-O2 -Wall'
|
NVFLAGS = -O2 --compiler-options '-O2 -Wall -fPIC'
|
||||||
|
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -O2 -Wall -g
|
CFLAGS = -O2 -Wall -g -fPIC
|
||||||
|
|
||||||
FC = gfortran
|
FC = gfortran
|
||||||
FFLAGS = -O2 -Wall -g
|
FFLAGS = -O2 -Wall -g -fPIC
|
||||||
|
|
||||||
SRC_DIR = src
|
SRC_DIR = src
|
||||||
INC_DIR = include
|
INC_DIR = include
|
||||||
@ -16,28 +16,27 @@ CU_SRC = $(wildcard $(SRC_DIR)/*.cu)
|
|||||||
CU_OBJ = $(CU_SRC:$(SRC_DIR)/%.cu=$(BLD_DIR)/%.o)
|
CU_OBJ = $(CU_SRC:$(SRC_DIR)/%.cu=$(BLD_DIR)/%.o)
|
||||||
|
|
||||||
C_SRC = $(wildcard $(SRC_DIR)/*.c)
|
C_SRC = $(wildcard $(SRC_DIR)/*.c)
|
||||||
C_OBJ = $(CU_SRC:$(SRC_DIR)/%.c=$(BLD_DIR)/%.o)
|
C_OBJ = $(C_SRC:$(SRC_DIR)/%.c=$(BLD_DIR)/%.o)
|
||||||
|
|
||||||
F_SRC = $(SRC_DIR)/cu_quack_module.f90
|
F_SRC = #$(SRC_DIR)/cu_quack_module.f90
|
||||||
F_OBJ = $(BLD_DIR)/cu_quack_module.o
|
F_OBJ = #$(BLD_DIR)/cu_quack_module.o
|
||||||
|
|
||||||
OUTPUT_LIB = $(BLD_DIR)/cuda.a
|
OUTPUT_LIB = $(BLD_DIR)/libcuquack.so
|
||||||
|
|
||||||
all: $(OUTPUT_LIB)
|
all: $(OUTPUT_LIB)
|
||||||
|
|
||||||
$(OUTPUT_LIB): $(CU_OBJ) $(C_OBJ) $(F_OBJ)
|
$(OUTPUT_LIB): $(CU_OBJ) $(C_OBJ) $(F_OBJ)
|
||||||
ar rcs $(OUTPUT_LIB) $(CU_OBJ) $(C_OBJ) $(F_OBJ)
|
$(CC) -shared -o $(OUTPUT_LIB) $(CU_OBJ) $(C_OBJ) $(F_OBJ)
|
||||||
|
|
||||||
$(CU_OBJ): $(CU_SRC)
|
$(BLD_DIR)/%.o: $(SRC_DIR)/%.cu
|
||||||
$(NVCC) $(NVFLAGS) -c -o $@ $< -I$(INC_DIR)
|
$(NVCC) $(NVFLAGS) -c -o $@ $< -I$(INC_DIR)
|
||||||
|
|
||||||
$(C_OBJ): $(C_SRC)
|
$(BLD_DIR)/%.o: $(SRC_DIR)/%.c
|
||||||
$(CC) $(CFLAGS) -c -o $@ $< -I$(INC_DIR)
|
$(CC) $(CFLAGS) -c -o $@ $< -I$(INC_DIR)
|
||||||
|
|
||||||
$(F_OBJ): $(F_SRC)
|
$(F_OBJ): $(F_SRC)
|
||||||
$(FC) $(FFLAGS) -c -o $@ $< -J$(BLD_DIR)
|
$(FC) $(FFLAGS) -c -o $@ $< -J$(BLD_DIR)
|
||||||
|
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -f $(BLD_DIR)/*
|
rm -f $(BLD_DIR)/*
|
||||||
|
@ -1,26 +0,0 @@
|
|||||||
module cu_quack_module
|
|
||||||
|
|
||||||
use, intrinsic :: iso_c_binding
|
|
||||||
|
|
||||||
implicit none
|
|
||||||
|
|
||||||
interface
|
|
||||||
|
|
||||||
! ---
|
|
||||||
|
|
||||||
subroutine ph_drpa(nO, nBas, eps, ERI) bind(C, name = "cutc_int")
|
|
||||||
|
|
||||||
import c_int, c_double
|
|
||||||
integer(c_int), intent(in), value :: nO, nBas
|
|
||||||
real(c_double), intent(in) :: eps(nBas)
|
|
||||||
real(c_double), intent(in) :: ERI(nBas,nBas,nBas,nBas)
|
|
||||||
|
|
||||||
end subroutine ph_drpa
|
|
||||||
|
|
||||||
! ---
|
|
||||||
|
|
||||||
end interface
|
|
||||||
|
|
||||||
end module cu_quack_module
|
|
||||||
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
|||||||
#include <cuda.h>
|
#include <cuda.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <cublas_v2.h>
|
#include <cublas_v2.h>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern "C" void check_Cuda_Errors(cudaError_t err, const char* msg, const char* file, int line) {
|
extern "C" void check_Cuda_Errors(cudaError_t err, const char* msg, const char* file, int line) {
|
||||||
@ -13,7 +15,7 @@ extern "C" void check_Cuda_Errors(cudaError_t err, const char* msg, const char*
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char* cublasGetErrorString(cublasStatus_t status) {
|
const char* cublas_Get_Error_String(cublasStatus_t status) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case CUBLAS_STATUS_SUCCESS:
|
case CUBLAS_STATUS_SUCCESS:
|
||||||
return "CUBLAS_STATUS_SUCCESS";
|
return "CUBLAS_STATUS_SUCCESS";
|
||||||
@ -41,9 +43,9 @@ const char* cublasGetErrorString(cublasStatus_t status) {
|
|||||||
|
|
||||||
extern "C" void check_Cublas_Errors(cublasStatus_t status, const char* msg, const char* file, int line) {
|
extern "C" void check_Cublas_Errors(cublasStatus_t status, const char* msg, const char* file, int line) {
|
||||||
|
|
||||||
const char* err = cublasGetErrorString(status);
|
const char* err = cublas_Get_Error_String(status);
|
||||||
|
|
||||||
if (err != "CUBLAS_STATUS_SUCCESS") {
|
if (strcmp(err, "CUBLAS_STATUS_SUCCESS") != 0) {
|
||||||
printf("CUBLAS Error in %s at line %d\n", file, line);
|
printf("CUBLAS Error in %s at line %d\n", file, line);
|
||||||
printf("%s - %s\n", msg, err);
|
printf("%s - %s\n", msg, err);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -120,7 +120,6 @@ IDIR=$QUACK_ROOT/include
|
|||||||
LDIR=$QUACK_ROOT/lib
|
LDIR=$QUACK_ROOT/lib
|
||||||
BDIR=$QUACK_ROOT/bin
|
BDIR=$QUACK_ROOT/bin
|
||||||
SDIR=$QUACK_ROOT/src
|
SDIR=$QUACK_ROOT/src
|
||||||
CUDA_DIR=$QUACK_ROOT/src/cuda/build
|
|
||||||
|
|
||||||
LIBXC_VERSION=5.0.0
|
LIBXC_VERSION=5.0.0
|
||||||
|
|
||||||
@ -187,6 +186,12 @@ exe_dirs = ["QuAcK"]
|
|||||||
lib_dirs = list(filter(lambda x: os.path.isdir(x) and \
|
lib_dirs = list(filter(lambda x: os.path.isdir(x) and \
|
||||||
x not in ["cuda"] and \
|
x not in ["cuda"] and \
|
||||||
x not in exe_dirs, os.listdir(".")))
|
x not in exe_dirs, os.listdir(".")))
|
||||||
|
if USE_GPU:
|
||||||
|
i = lib_dirs.index("mod")
|
||||||
|
lib_dirs[0], lib_dirs[i] = lib_dirs[i], lib_dirs[0]
|
||||||
|
else:
|
||||||
|
lib_dirs.remove("mod")
|
||||||
|
print(lib_dirs)
|
||||||
|
|
||||||
def create_ninja_in_libdir(directory):
|
def create_ninja_in_libdir(directory):
|
||||||
def write_rule(f, source_file, replace):
|
def write_rule(f, source_file, replace):
|
||||||
@ -249,10 +254,7 @@ rule build_lib
|
|||||||
sources = [ "$SDIR/{0}/{1}".format(exe_dir,x) for x in os.listdir(exe_dir) ]
|
sources = [ "$SDIR/{0}/{1}".format(exe_dir,x) for x in os.listdir(exe_dir) ]
|
||||||
sources = filter(lambda x: x.endswith(".f") or x.endswith(".f90"), sources)
|
sources = filter(lambda x: x.endswith(".f") or x.endswith(".f90"), sources)
|
||||||
sources = " ".join(sources)
|
sources = " ".join(sources)
|
||||||
if USE_GPU:
|
f.write("build $BDIR/{0}: build_exe {1} {2}\n".format(exe_dir,libs,sources))
|
||||||
f.write("build $BDIR/{0}: build_exe $CUDA_DIR/cuda.a {1} {2}\n".format(exe_dir,libs,sources))
|
|
||||||
else:
|
|
||||||
f.write("build $BDIR/{0}: build_exe {1} {2}\n".format(exe_dir,libs,sources))
|
|
||||||
f.write(" dir = {0} \n".format(exe_dir) )
|
f.write(" dir = {0} \n".format(exe_dir) )
|
||||||
|
|
||||||
for libname in lib_dirs:
|
for libname in lib_dirs:
|
||||||
|
Loading…
Reference in New Issue
Block a user