Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically choose all available Cuda compute targets > 50 #270

Merged
merged 4 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@
# Choose OpenCL device
# Valid values: CPU, GPU, CUDA, OCLGPU

OVERLAP = ON

ifeq ($(DEVICE), $(filter $(DEVICE),GPU CUDA))
TEST_CUDA := $(shell ./test_cuda.sh nvcc "$(GPU_INCLUDE_PATH)" "$(GPU_LIBRARY_PATH)")
TARGETS_SUPPORTED := $(shell ./test_cuda.sh nvcc "$(GPU_INCLUDE_PATH)" "$(GPU_LIBRARY_PATH)" "$(TARGETS)")
# if user specifies DEVICE=CUDA it will be used (wether the test succeeds or not)
# if user specifies DEVICE=GPU the test result determines wether CUDA will be used or not
ifeq ($(DEVICE)$(TEST_CUDA),GPUyes)
override DEVICE:=CUDA
ifeq ($(TARGETS_SUPPORTED),)
$(error Cuda verification failed)
endif
override TARGETS:=$(TARGETS_SUPPORTED)
export
override DEVICE:=CUDA
endif
ifeq ($(DEVICE),CUDA)
override DEVICE:=GPU
Expand Down
4 changes: 2 additions & 2 deletions Makefile.Cuda
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ else
NWI=-DN16WI
TARGET:=$(TARGET)_16wi
else ifeq ($(DEVICE), GPU)
NWI=-DN64WI
TARGET:=$(TARGET)_64wi
NWI=-DN128WI
TARGET:=$(TARGET)_128wi
endif
endif

Expand Down
4 changes: 2 additions & 2 deletions Makefile.OpenCL
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ else
NWI=-DN16WI
TARGET:=$(TARGET)_16wi
else ifeq ($(DEVICE), GPU)
NWI=-DN64WI
TARGET:=$(TARGET)_64wi
NWI=-DN128WI
TARGET:=$(TARGET)_128wi
endif
endif

Expand Down
18 changes: 6 additions & 12 deletions host/src/getparameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,8 @@ int parse_dpf(
if(mypars->ligandfile) free(mypars->ligandfile);
if(strincmp(argstr,"empty",5) != 0){
if(check_path && !has_absolute_path(argstr)){
len = strlen(argstr);
mypars->ligandfile = (char*)malloc((dpf_path.size()+len+1)*sizeof(char));
mypars->ligandfile[dpf_path.size()] = '\0'; // make sure first part to copy is terminated
strncat(strncpy(mypars->ligandfile, dpf_path.c_str(), dpf_path.size()), argstr, len);
mypars->ligandfile = (char*)malloc((dpf_path.size()+strlen(argstr)+1)*sizeof(char));
strcat(strcpy(mypars->ligandfile, dpf_path.c_str()), argstr);
} else mypars->ligandfile = strdup(argstr);
}
}
Expand All @@ -211,10 +209,8 @@ int parse_dpf(
sscanf(line.c_str(),"%*s %255s",argstr);
if(mypars->flexresfile) free(mypars->flexresfile);
if(check_path && !has_absolute_path(argstr)){
len = strlen(argstr);
mypars->flexresfile = (char*)malloc((dpf_path.size()+len+1)*sizeof(char));
mypars->flexresfile[dpf_path.size()] = '\0'; // make sure first part to copy is terminated
strncat(strncpy(mypars->flexresfile, dpf_path.c_str(), dpf_path.size()), argstr, len);
mypars->flexresfile = (char*)malloc((dpf_path.size()+strlen(argstr)+1)*sizeof(char));
strcat(strcpy(mypars->flexresfile, dpf_path.c_str()), argstr);
} else mypars->flexresfile = strdup(argstr);
}
break;
Expand All @@ -224,10 +220,8 @@ int parse_dpf(
// Add the .fld file
if(mypars->fldfile) free(mypars->fldfile);
if(check_path && !has_absolute_path(argstr)){
len = strlen(argstr);
mypars->fldfile = (char*)malloc((dpf_path.size()+len+1)*sizeof(char));
mypars->fldfile[dpf_path.size()] = '\0'; // make sure first part to copy is terminated
strncat(strncpy(mypars->fldfile, dpf_path.c_str(), dpf_path.size()), argstr, len);
mypars->fldfile = (char*)malloc((dpf_path.size()+strlen(argstr)+1)*sizeof(char));
strcat(strcpy(mypars->fldfile, dpf_path.c_str()), argstr);
} else mypars->fldfile = strdup(argstr); // this allows using the dpf to set up all parameters but the ligand
// Filling mygrid according to the specified fld file
if (get_gridinfo(mypars->fldfile, mygrid) != 0)
Expand Down
25 changes: 22 additions & 3 deletions test_cuda.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,31 @@

current_dir=`pwd`
script_dir=`dirname $0`
CUDA_VERSION=`nvcc --version | grep release | awk '{ print $(NF-1) }' | sed "s/,//g"`
if [[ $CUDA_VERSION != "" ]]; then
printf "Using Cuda %s\n" $CUDA_VERSION >&2
else
printf "Error: nvcc command is not working.\n" >&2
exit 1
fi
if [[ "$4" != "" ]]; then
for T in $4; do
TARGET_SUPPORTED=`nvcc --list-gpu-arch | grep $T`
atillack marked this conversation as resolved.
Show resolved Hide resolved
if [[ $TARGET_SUPPORTED == "" ]]; then
printf "Error: Specified compute target <$T> not supported by installed Cuda version.\n" >&2
exit 1
fi
done
TARGETS="$4"
else
TARGETS=`nvcc --list-gpu-arch | awk -F'_' '{if(\$2>50) print \$2}' | tr "\n" " "`
fi
printf "Compiling for targets: %s\n" "$TARGETS" >&2
cd "$script_dir"
if [[ ! -f "test_cuda" ]]; then
$1 -I$2 -L$3 -lcuda -lcudart -o test_cuda test_cuda.cpp &> /dev/null
test -e test_cuda && echo yes || echo no
test -e test_cuda && echo $TARGETS
else
test -e test_cuda && echo yes || echo no
test -e test_cuda && echo $TARGETS
fi
cd "$current_dir"