Skip to content

Commit

Permalink
Port over most previous GPU related changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshugoel2797 committed Dec 4, 2023
1 parent 09f6d27 commit 9654826
Show file tree
Hide file tree
Showing 41 changed files with 3,182 additions and 3,933 deletions.
41 changes: 41 additions & 0 deletions cpp/gcc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ else
endif
endif

# HG30112023
CUDA_PATH ?= /usr/local/cuda
CUDA_MATHLIBS_PATH ?= /usr/local/cuda
NVCC = $(CUDA_PATH)/bin/nvcc
NVCXX = $(CUDA_PATH)/bin/nvc++

SRW_SRC_DEF= -D_GNU_SOURCE -D__USE_XOPEN2K8 -DFFTW_ENABLE_FLOAT -D_GM_WITHOUT_BASE -DSRWLIB_STATIC -DNO_TIMER -DANSI_DECLARATORS -DTRILIBRARY $(OSFLAG)
SRW_INCLUDES= -I$(SRW_SRC_GEN_DIR) -I$(SRW_SRC_LIB_DIR) -I$(SH_SRC_PARSE_DIR) -I$(SH_SRC_GEN_MATH_DIR) $(SRW_SRC_DEF)
SRW_CFLAGS= -O3 -fPIC
Expand All @@ -35,6 +41,17 @@ LDFLAGS=-L$(LIB_DIR) -lm
ifeq ($(MODE), omp)
SRW_CFLAGS+= -D_WITH_OMP -fopenmp -Wno-write-strings
LDFLAGS+= -lfftw
else #HG30112023
ifeq ($(MODE), cuda)
CUDA_INCLUDES = -I$(CUDA_PATH)/include -I$(CUDA_MATHLIBS_PATH)/include
CUDA_LIBS = -L$(CUDA_PATH)/lib64 -L$(CUDA_MATHLIBS_PATH)/lib64

SRW_SRC_DEF += -D_OFFLOAD_GPU -DUSE_CUDA -D_FFTW3
SRW_INCLUDES += $(CUDA_INCLUDES)
SRW_CFLAGS += -std=c++17
LDFLAGS += $(CUDA_LIBS) -lcudart_static -lcudadevrt -lcufft -lrt
NVCFLAGS = -O3 -arch=sm_80 -dlto -rdc=true
CUDA_OBJ=gmfft_gpu.o srradstr_gpu.o sroptelm_gpu.o sroptdrf_gpu.o sroptgtr_gpu.o srradmnp_gpu.o
else
ifeq ($(MODE), 0)
SRW_CFLAGS+= -D_FFTW3
Expand All @@ -43,6 +60,7 @@ else
$(error Unknown SRW compilation option)
endif
endif
endif

PYFLAGS=-I$(shell python -c "from __future__ import print_function; from sysconfig import get_paths as gp; print(gp()['include'])")
PYFLAGS+=-L$(shell python -c "from __future__ import print_function; from sysconfig import get_paths as gp; import os; print(os.path.join(gp()['stdlib'], '../libs'))")
Expand Down Expand Up @@ -71,6 +89,10 @@ OBJ += timerec.o track.o srerror.o

# src/lib
OBJ += srwlib.o
# HG30112023
ifeq ($(MODE), cuda)
OBJ += auxgpu.o
endif

PRG= libsrw.a

Expand All @@ -89,6 +111,24 @@ PRG= libsrw.a
%.o: $(SRW_SRC_GENESIS_DIR)/%.c
$(CC) $(CFLAGS) -c $<

# HG30112023
ifeq ($(MODE), cuda)
lib: $(CUDA_OBJ) $(OBJ)
$(NVCC) $(NVCFLAGS) -Xcompiler="$(SRW_CFLAGS)" -dlink -o srwl_link.o *.o $(LDFLAGS)
ar -cvq $(PRG) *.o
#cp $(PRG) $(LIB_DIR)/
rm -f *.o

%.o: $(SRW_SRC_LIB_DIR)/%.cu
$(NVCC) -dc $(NVCFLAGS) $(SRW_INCLUDES) $(SRW_SRC_DEF) -Xcompiler="$(CFLAGS)" -c $<

%.o: $(SH_SRC_GEN_MATH_DIR)/%.cu
$(NVCC) -dc $(NVCFLAGS) $(SRW_INCLUDES) $(SRW_SRC_DEF) -Xcompiler="$(CFLAGS)" -c $<

%.o: $(SRW_SRC_GEN_DIR)/%.cu
$(NVCC) -dc $(NVCFLAGS) $(SRW_INCLUDES) $(SRW_SRC_DEF) -Xcompiler="$(CFLAGS)" -c $<

else
lib: $(OBJ)
ar -cvq $(PRG) *.o
#cp $(PRG) $(LIB_DIR)/
Expand All @@ -102,6 +142,7 @@ lib: $(OBJ)

%.o: $(SRW_SRC_GEN_DIR)/%.cu
$(NVCC) -x=c++ -Xcompiler="$(CFLAGS)" -c $<
endif

pylib:
$(CXX) -shared $(CFLAGS) $(PYFLAGS) -o srwlpy.so $(SRW_SRC_DIR)/clients/python/srwlpy.cpp libsrw.a $(LDFLAGS)
Expand Down
6 changes: 5 additions & 1 deletion cpp/py/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@

if 'MODE' in os.environ:
sMode = str(os.environ['MODE'])
if sMode == 'omp':
if sMode == 'cuda': # HG30112023
ext_kwargs.update({'libraries': ['srw', 'm', 'cudart_static', 'cudadevrt', 'cufft', 'fftw3f', 'fftw3', 'rt'], 'extra_compile_args': ['-O3', '-mavx2', '-fno-math-errno']})
ext_kwargs['library_dirs'].append('{0}/lib64'.format(os.environ['CUDA_PATH']))
ext_kwargs['library_dirs'].append('{0}/lib64'.format(os.environ['CUDA_MATHLIBS_PATH']))
elif sMode == 'omp':
#ext_kwargs.update({'extra_link_args': ['-fopenmp'],
ext_kwargs.update({'libraries': ['srw', 'm', 'fftw'], #OC07022019
'extra_link_args': ['-fopenmp'],
Expand Down
Loading

0 comments on commit 9654826

Please sign in to comment.