From 41dd532d0ea9c13669c0560bb8b3fcf666e6af16 Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Tue, 26 Nov 2024 16:33:06 +0100 Subject: [PATCH] linked CUDA module with QuAcK properley --- src/cuda/Makefile | 21 ++++++++++----------- src/cuda/src/cu_quack_module.f90 | 26 -------------------------- src/cuda/src/utils.cu | 8 +++++--- src/make_ninja.py | 12 +++++++----- 4 files changed, 22 insertions(+), 45 deletions(-) delete mode 100644 src/cuda/src/cu_quack_module.f90 diff --git a/src/cuda/Makefile b/src/cuda/Makefile index 04ab17a..61ac1d2 100644 --- a/src/cuda/Makefile +++ b/src/cuda/Makefile @@ -1,11 +1,11 @@ NVCC = nvcc -NVFLAGS = -O2 --compiler-options '-O2 -Wall' +NVFLAGS = -O2 --compiler-options '-O2 -Wall -fPIC' CC = gcc -CFLAGS = -O2 -Wall -g +CFLAGS = -O2 -Wall -g -fPIC FC = gfortran -FFLAGS = -O2 -Wall -g +FFLAGS = -O2 -Wall -g -fPIC SRC_DIR = src INC_DIR = include @@ -16,28 +16,27 @@ CU_SRC = $(wildcard $(SRC_DIR)/*.cu) CU_OBJ = $(CU_SRC:$(SRC_DIR)/%.cu=$(BLD_DIR)/%.o) 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_OBJ = $(BLD_DIR)/cu_quack_module.o +F_SRC = #$(SRC_DIR)/cu_quack_module.f90 +F_OBJ = #$(BLD_DIR)/cu_quack_module.o -OUTPUT_LIB = $(BLD_DIR)/cuda.a +OUTPUT_LIB = $(BLD_DIR)/libcuquack.so all: $(OUTPUT_LIB) $(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) -$(C_OBJ): $(C_SRC) +$(BLD_DIR)/%.o: $(SRC_DIR)/%.c $(CC) $(CFLAGS) -c -o $@ $< -I$(INC_DIR) $(F_OBJ): $(F_SRC) $(FC) $(FFLAGS) -c -o $@ $< -J$(BLD_DIR) - .PHONY: clean clean: rm -f $(BLD_DIR)/* diff --git a/src/cuda/src/cu_quack_module.f90 b/src/cuda/src/cu_quack_module.f90 deleted file mode 100644 index 5b5ea1a..0000000 --- a/src/cuda/src/cu_quack_module.f90 +++ /dev/null @@ -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 - - diff --git a/src/cuda/src/utils.cu b/src/cuda/src/utils.cu index b20c52d..ff5d83d 100644 --- a/src/cuda/src/utils.cu +++ b/src/cuda/src/utils.cu @@ -2,6 +2,8 @@ #include #include #include +#include + 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) { case 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) { - 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("%s - %s\n", msg, err); exit(0); diff --git a/src/make_ninja.py b/src/make_ninja.py index 49ac43b..c78bc7d 100755 --- a/src/make_ninja.py +++ b/src/make_ninja.py @@ -120,7 +120,6 @@ IDIR=$QUACK_ROOT/include LDIR=$QUACK_ROOT/lib BDIR=$QUACK_ROOT/bin SDIR=$QUACK_ROOT/src -CUDA_DIR=$QUACK_ROOT/src/cuda/build LIBXC_VERSION=5.0.0 @@ -187,6 +186,12 @@ exe_dirs = ["QuAcK"] lib_dirs = list(filter(lambda x: os.path.isdir(x) and \ x not in ["cuda"] and \ 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 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 = filter(lambda x: x.endswith(".f") or x.endswith(".f90"), sources) sources = " ".join(sources) - if USE_GPU: - 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("build $BDIR/{0}: build_exe {1} {2}\n".format(exe_dir,libs,sources)) f.write(" dir = {0} \n".format(exe_dir) ) for libname in lib_dirs: