From 3009ffe8f791809c01923e9249c2437107a93d2f Mon Sep 17 00:00:00 2001 From: Abdallah Ammar Date: Tue, 26 Nov 2024 14:36:42 +0100 Subject: [PATCH] dRPA-CUDA: saving --- src/cuda/Makefile | 44 ++++++++++---------------------- src/cuda/src/cu_quack_module.f90 | 26 +++++++++++++++++++ src/cuda/src/ph_drpa.c | 2 -- src/make_ninja.py | 7 ++--- 4 files changed, 43 insertions(+), 36 deletions(-) create mode 100644 src/cuda/src/cu_quack_module.f90 diff --git a/src/cuda/Makefile b/src/cuda/Makefile index d76e96d..04ab17a 100644 --- a/src/cuda/Makefile +++ b/src/cuda/Makefile @@ -1,63 +1,45 @@ NVCC = nvcc -NFLAGS = -O2 --compiler-options '-fPIC' -NDFLAGS = --shared +NVFLAGS = -O2 --compiler-options '-O2 -Wall' CC = gcc -CFLAGS = -fPIC -O2 -Wall -g +CFLAGS = -O2 -Wall -g FC = gfortran FFLAGS = -O2 -Wall -g SRC_DIR = src INC_DIR = include - -BIN_DIR = bin BLD_DIR = build -$(shell mkdir -p $(BIN_DIR)) $(shell mkdir -p $(BLD_DIR)) CU_SRC = $(wildcard $(SRC_DIR)/*.cu) CU_OBJ = $(CU_SRC:$(SRC_DIR)/%.cu=$(BLD_DIR)/%.o) -C_SRC = $(SRC_DIR)/ph_drpa.c -C_OBJ = $(BLD_DIR)/ph_drpa.o +C_SRC = $(wildcard $(SRC_DIR)/*.c) +C_OBJ = $(CU_SRC:$(SRC_DIR)/%.c=$(BLD_DIR)/%.o) F_SRC = $(SRC_DIR)/cu_quack_module.f90 -F_OBJ = $(BLD_DIR)/cu_quack_module.f90 - -MAIN_SRC = $(SRC_DIR)/cu_quack.f90 -MAIN_OBJ = $(BLD_DIR)/cu_quack.o - -OUTPUT_LIB = $(BLD_DIR)/libcuquack.so - -CUDA_LIBS = -lcudart -lcublas +F_OBJ = $(BLD_DIR)/cu_quack_module.o +OUTPUT_LIB = $(BLD_DIR)/cuda.a all: $(OUTPUT_LIB) -$(OUTPUT_LIB): $(CU_OBJ) $(C_OBJ) - $(NVCC) $(NFLAGS) $(NLDFLAGS) $^ -o $@ $(CUDA_LIBS) -I$(INC_DIR) +$(OUTPUT_LIB): $(CU_OBJ) $(C_OBJ) $(F_OBJ) + ar rcs $(OUTPUT_LIB) $(CU_OBJ) $(C_OBJ) $(F_OBJ) -$(BLD_DIR)/%.o: $(SRC_DIR)/%.cu - $(NVCC) $(NFLAGS) -c $< -o $@ -I$(INC_DIR) +$(CU_OBJ): $(CU_SRC) + $(NVCC) $(NVFLAGS) -c -o $@ $< -I$(INC_DIR) $(C_OBJ): $(C_SRC) - @for src in $(C_SRC); do \ - obj=$(BLD_DIR)/$$(basename $${src} .c).o; \ - echo "$(CC) $(CFLAGS) -c $$src -o $$obj -I$(INC_DIR)"; \ - $(CC) $(CFLAGS) -c $$src -o $$obj -I$(INC_DIR); \ - done + $(CC) $(CFLAGS) -c -o $@ $< -I$(INC_DIR) $(F_OBJ): $(F_SRC) - $(FC) $(FFLAGS) -c $< -o $@ -J$(BLD_DIR) - -$(MAIN_OBJ): $(MAIN_SRC) - $(FC) $(FFLAGS) -c $< -o $@ -J$(BLD_DIR) - + $(FC) $(FFLAGS) -c -o $@ $< -J$(BLD_DIR) .PHONY: clean clean: - rm -f $(BLD_DIR)/*.o $(BLD_DIR)/*.so $(BLD_DIR)/*.mod $(BIN_DIR)/* + rm -f $(BLD_DIR)/* diff --git a/src/cuda/src/cu_quack_module.f90 b/src/cuda/src/cu_quack_module.f90 new file mode 100644 index 0000000..5b5ea1a --- /dev/null +++ b/src/cuda/src/cu_quack_module.f90 @@ -0,0 +1,26 @@ +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/ph_drpa.c b/src/cuda/src/ph_drpa.c index 888abaa..aa8d357 100644 --- a/src/cuda/src/ph_drpa.c +++ b/src/cuda/src/ph_drpa.c @@ -9,8 +9,6 @@ int ph_drpa(int nO, int nBas, double *h_eps, double *h_ERI) { - - double *d_eps; double *d_ERI; diff --git a/src/make_ninja.py b/src/make_ninja.py index 09d3a72..ff67c3c 100755 --- a/src/make_ninja.py +++ b/src/make_ninja.py @@ -81,7 +81,7 @@ elif sys.platform.lower() == "linux" or os.path.exists('/proc/version'): else: if check_compiler_exists('ifort'): compiler = """ -FC = ifort -qmkl=parallel -qopenmp +FC = ifort -mkl=parallel -qopenmp AR = ar crs FFLAGS = -I$IDIR -module $IDIR -traceback -g -Ofast -xHost CC = icc @@ -182,9 +182,10 @@ build_main = "\n".join([ rule_git_clone, ]) -exe_dirs = [ "QuAcK"] +exe_dirs = ["QuAcK"] lib_dirs = list(filter(lambda x: os.path.isdir(x) and \ - x not in exe_dirs, os.listdir("."))) + x not in ["cuda"] and \ + x not in exe_dirs, os.listdir("."))) def create_ninja_in_libdir(directory): def write_rule(f, source_file, replace):