Skip to content

Commit

Permalink
pgstrom_setup_gpu_fatbin() also checks pre-built fatbin, if any
Browse files Browse the repository at this point in the history
  • Loading branch information
kaigai committed Mar 1, 2024
1 parent 967567b commit a151fd3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
8 changes: 5 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# PG-Strom Makefile
#
include ../Makefile.common
PGXS := $(shell $(PG_CONFIG) --pgxs)

#
# Source of PG-Strom host code
Expand Down Expand Up @@ -66,11 +65,14 @@ MODULEDIR = pg_strom
DATA = $(STROM_SQL) ../LICENSE Makefile.cuda \
$(CUDA_SRCS) $(CUDA_HEADERS) $(STROM_HEADERS)
OBJS = $(STROM_OBJS)
ifeq ($(WITH_FATBIN),1)
DATA_built = $(CUDA_FATBIN)
endif
EXTRA_CLEAN = $(CUDA_OBJS) $(GENERATED-HEADERS) \
$(shell ls -d pgstrom-gpucode-V*-*.fatbin 2>/dev/null)
EXTENSION = pg_strom

PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)

#
Expand All @@ -95,9 +97,9 @@ githash.c:
# GPU Device Code
#
%.o: %.cu $(CUDA_HEADERS)
$(NVCC) $(NVCC_FLAGS) --device-c -o $@ $<
$(NVCC) $(NVCC_CFLAGS) --device-c -o $@ $<

$(CUDA_FATBIN): $(CUDA_OBJS)
$(NVCC) $(NVCC_FLAGS) --device-link --fatbin -o $@ $(CUDA_OBJS)
$(NVCC) $(NVCC_LDFLAGS) --device-link --fatbin -o $@ $(CUDA_OBJS)

fatbin: $(CUDA_FATBIN)
26 changes: 18 additions & 8 deletions src/Makefile.cuda
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,26 @@ NVCC_VERSION := $(shell $(NVCC) --version | grep ^Cuda | \
# (64k / 128 = up to 512 threads per SM)
MAXREGCOUNT := 128

__NUM_GPUS := $(shell ls -d /proc/driver/nvidia/gpus/*/information | wc -l)
ifeq ($(__NUM_GPUS),0)
__NVCC_TARGET := --gpu-architecture=compute_60 \
--gpu-code=sm_60,sm_61,sm_70,sm_75,sm_80,sm_86,sm_89,sm_90 \
--threads 8
else
__NVCC_TARGET := --gpu-architecture=native
endif

# flags to build GPU libraries
__NVCC_FLAGS += -I $(shell $(PG_CONFIG) --includedir-server) \
--maxrregcount=$(MAXREGCOUNT) \
--source-in-ptx -lineinfo \
-DHAVE_FLOAT2 \
-Xnvlink --suppress-stack-size-warning \
--gpu-architecture=native \
--threads 4
__NVCC_CFLAGS += -I $(shell $(PG_CONFIG) --includedir-server) \
--maxrregcount=$(MAXREGCOUNT) \
--source-in-ptx -lineinfo \
-DHAVE_FLOAT2 \
$(__NVCC_TARGET)
__NVCC_LDFLAGS += -Xnvlink --suppress-stack-size-warning \
$(__NVCC_TARGET)
# nvcc flags
NVCC_FLAGS = $(__NVCC_FLAGS) $(NVCC_FLAGS_CUSTOM)
NVCC_CFLAGS = $(__NVCC_CFLAGS) $(NVCC_FLAGS_CUSTOM) $(NVCC_CFLAGS_CUSTOM)
NVCC_LDFLAGS = $(__NVCC_LDFLAGS) $(NVCC_FLAGS_CUSTOM) $(NVCC_LDFLAGS_CUSTOM)

# PG-Strom GPU Code
__CUDA_CORE_FILES = xpu_common cuda_gpuscan cuda_gpujoin cuda_gpupreagg \
Expand Down
27 changes: 19 additions & 8 deletions src/gpu_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,8 @@ __validate_gpu_fatbin_file(const char *fatbin_dir, const char *fatbin_file)
* __rebuild_gpu_fatbin_file
*/
static void
__rebuild_gpu_fatbin_file(const char *fatbin_file)
__rebuild_gpu_fatbin_file(const char *fatbin_dir,
const char *fatbin_file)
{
StringInfoData cmd;
char workdir[200];
Expand Down Expand Up @@ -665,8 +666,8 @@ __rebuild_gpu_fatbin_file(const char *fatbin_file)
appendStringInfo(&cmd,
"mkdir -p '%s'; "
"install -m 0644 %s/%s '%s'",
PGSTROM_FATBIN_DIR,
workdir, fatbin_file, PGSTROM_FATBIN_DIR);
fatbin_dir,
workdir, fatbin_file, fatbin_dir);
strcpy(namebuf, CUDA_CORE_FILES);
for (tok = strtok_r(namebuf, " ", &pos);
tok != NULL;
Expand All @@ -692,13 +693,23 @@ static void
pgstrom_setup_gpu_fatbin(void)
{
const char *fatbin_file = __setup_gpu_fatbin_filename();
const char *fatbin_dir = PGSHAREDIR "/pg_strom";
char *path;

if (!__validate_gpu_fatbin_file(PGSTROM_FATBIN_DIR, fatbin_file))
__rebuild_gpu_fatbin_file(fatbin_file);

path = alloca(strlen(fatbin_file) + 200);
sprintf(path, "%s/%s", PGSTROM_FATBIN_DIR, fatbin_file);
if (!__validate_gpu_fatbin_file(fatbin_dir,
fatbin_file))
{
fatbin_dir = PGSTROM_FATBIN_DIR;
if (!__validate_gpu_fatbin_file(fatbin_dir,
fatbin_file))
{
__rebuild_gpu_fatbin_file(fatbin_dir,
fatbin_file);
}
}
path = alloca(strlen(fatbin_dir) +
strlen(fatbin_file) + 100);
sprintf(path, "%s/%s", fatbin_dir, fatbin_file);
pgstrom_fatbin_image_filename = strdup(path);
if (!pgstrom_fatbin_image_filename)
elog(ERROR, "out of memory");
Expand Down

0 comments on commit a151fd3

Please sign in to comment.