diff --git a/AutoDock-Vina-GPU-2.1/OpenCL/src/kernels/code_head.cl b/AutoDock-Vina-GPU-2.1/OpenCL/src/kernels/code_head.cl index 8dcf02d..2edce67 100644 --- a/AutoDock-Vina-GPU-2.1/OpenCL/src/kernels/code_head.cl +++ b/AutoDock-Vina-GPU-2.1/OpenCL/src/kernels/code_head.cl @@ -1,4 +1,248 @@ -#include "kernel2.h" +// ----------------------------------------------------------------------------- +// PATCH: kernel2.h inlined manually (was: #include "kernel2.h") +// NVIDIA's OpenCL driver (596.36 and family) has a bug where #include directives +// in kernel source cause clBuildProgram to fail with CL_OUT_OF_HOST_MEMORY (-6) +// and zero log size. Inlining the include content is the documented workaround. +// Reference: NVIDIA Developer Forums thread on driver 595.97 #include bug. +// ----------------------------------------------------------------------------- + +// Macros below are shared in both device and host +#define TOLERANCE 1e-16 +// kernel1 macros +#define MAX_NUM_OF_EVERY_M_DATA_ELEMENT 512 +#define MAX_M_DATA_MI 16 +#define MAX_M_DATA_MJ 16 +#define MAX_M_DATA_MK 16 +#define MAX_NUM_OF_TOTAL_M_DATA MAX_M_DATA_MI*MAX_M_DATA_MJ*MAX_M_DATA_MK*MAX_NUM_OF_EVERY_M_DATA_ELEMENT + +//kernel2 macros +#define MAX_NUM_OF_LIG_TORSION 48 +#define MAX_NUM_OF_FLEX_TORSION 1 +#define MAX_NUM_OF_RIGID 48 +#define MAX_NUM_OF_ATOMS 130 +#define SIZE_OF_MOLEC_STRUC ((3+4+MAX_NUM_OF_LIG_TORSION+MAX_NUM_OF_FLEX_TORSION+ 1)*sizeof(float) ) +#define SIZE_OF_CHANGE_STRUC ((3+3+MAX_NUM_OF_LIG_TORSION+MAX_NUM_OF_FLEX_TORSION + 1)*sizeof(float)) +#define MAX_HESSIAN_MATRIX_SIZE ((6 + MAX_NUM_OF_LIG_TORSION + MAX_NUM_OF_FLEX_TORSION)*(6 + MAX_NUM_OF_LIG_TORSION + MAX_NUM_OF_FLEX_TORSION + 1) / 2) +#define MAX_NUM_OF_LIG_PAIRS 4096 +#define MAX_NUM_OF_BFGS_STEPS 64 +#define MAX_NUM_OF_RANDOM_MAP 20000 // not too large (stack overflow!) +#define GRIDS_SIZE 17 +#define MAX_NUM_OF_PROTEIN_ATOMS 50000 + +#ifdef LARGE_BOX + // docking box size <= 70x70x70 + #define MAX_NUM_OF_GRID_MI 300 + #define MAX_NUM_OF_GRID_MJ 300 + #define MAX_NUM_OF_GRID_MK 300 + #define MAX_NUM_OF_ATOM_RELATION_COUNT 38000 +#endif + +#ifdef SMALL_BOX + // docking box size <= 30x30x30 + #define MAX_NUM_OF_GRID_MI 128 + #define MAX_NUM_OF_GRID_MJ 128 + #define MAX_NUM_OF_GRID_MK 128 + #define MAX_NUM_OF_ATOM_RELATION_COUNT 1024 +#endif +//#define GRID_MI 65//55 +//#define GRID_MJ 71//55 +//#define GRID_MK 61//81 +#define MAX_P_DATA_M_DATA_SIZE 256 +//#define MAX_NUM_OF_GRID_ATOMS 130 +#define FAST_SIZE 2051 +#define SMOOTH_SIZE 2051 +#define MAX_CONTAINER_SIZE_EVERY_WI 5 +//#define EL_TYPE_H_CL 0 +#define EL_TYPE_H 0 + +#define EL_TYPE_SIZE 11 +#define AD_TYPE_SIZE 20 +#define XS_TYPE_SIZE 17 +#define SY_TYPE_SIZE 18 + + +typedef struct { + float data[GRIDS_SIZE]; +} affinities_cl; + +typedef struct { + int types[4];//el ad xs sy + float coords[3]; +} atom_cl; + +typedef struct { + atom_cl atoms[MAX_NUM_OF_PROTEIN_ATOMS]; +} pa_cl; + +typedef struct { + float coords[MAX_NUM_OF_ATOMS][3]; +} m_coords_cl; + +typedef struct { + float coords[MAX_NUM_OF_ATOMS][3]; +} ligand_atom_coords_cl; + +typedef struct { + float coords[MAX_NUM_OF_ATOMS][3]; +} m_minus_forces; + +typedef struct { // namely molec_struc + float e; + float position [3]; + float orientation [4]; + float lig_torsion [MAX_NUM_OF_LIG_TORSION]; + float flex_torsion [MAX_NUM_OF_FLEX_TORSION]; + //float coords [MAX_NUM_OF_ATOMS][3]; + //float lig_torsion_size; +} output_type_cl; + +typedef struct { // namely change_struc + //float lig_torsion_size; + float position [3]; + float orientation [3]; + float lig_torsion [MAX_NUM_OF_LIG_TORSION]; + float flex_torsion [MAX_NUM_OF_FLEX_TORSION]; +} change_cl; + + +typedef struct { // depth-first order + int num_children; + bool children_map [MAX_NUM_OF_RIGID][MAX_NUM_OF_RIGID]; // chidren_map[i][j] = true if node i's child is node j + int parent [MAX_NUM_OF_RIGID]; // every node has only 1 parent node + + int atom_range [MAX_NUM_OF_RIGID][2]; + float origin [MAX_NUM_OF_RIGID][3]; + float orientation_m [MAX_NUM_OF_RIGID][9]; // This matrix is fixed to 3*3 + float orientation_q [MAX_NUM_OF_RIGID][4]; + + float axis [MAX_NUM_OF_RIGID][3]; // 1st column is root node, all 0s + float relative_axis [MAX_NUM_OF_RIGID][3]; // 1st column is root node, all 0s + float relative_origin [MAX_NUM_OF_RIGID][3]; // 1st column is root node, all 0s + + +} rigid_cl; + +typedef struct { + int num_pairs; + int type_pair_index [MAX_NUM_OF_LIG_PAIRS]; + int a [MAX_NUM_OF_LIG_PAIRS]; + int b [MAX_NUM_OF_LIG_PAIRS]; +} lig_pairs_cl; + +typedef struct { + int begin; + int end; + lig_pairs_cl pairs; + rigid_cl rigid; +} ligand_cl; + +typedef struct { + int int_map [MAX_NUM_OF_RANDOM_MAP]; + float pi_map [MAX_NUM_OF_RANDOM_MAP]; + float sphere_map [MAX_NUM_OF_RANDOM_MAP][3]; +} random_maps; + +typedef struct { + int m_num_movable_atoms; + atom_cl atoms[MAX_NUM_OF_ATOMS]; + m_coords_cl m_coords; + m_minus_forces minus_forces; + ligand_cl ligand; +} m_cl; + +typedef struct { + int m_i; + int m_j; + int m_k; + float m_init[3]; + float m_range[3]; + float m_factor[3]; + float m_dim_fl_minus_1[3]; + float m_factor_inv[3]; + float m_data [(MAX_NUM_OF_GRID_MI) * (MAX_NUM_OF_GRID_MJ) * (MAX_NUM_OF_GRID_MK) * 8]; +} grid_cl; + +typedef struct { + int atu; + float slope; + grid_cl grids[GRIDS_SIZE]; +} grids_cl; + +typedef struct { + float factor; + float fast[FAST_SIZE]; + float smooth[SMOOTH_SIZE][2]; +} p_m_data_cl; + +typedef struct { + int n; + float m_cutoff_sqr; + float factor; + p_m_data_cl m_data[MAX_P_DATA_M_DATA_SIZE]; +} pre_cl; + +typedef struct { + int dims[3]; + float init[3]; + float range[3]; +} gb_cl; + +typedef struct { + int relation[MAX_NUM_OF_ATOM_RELATION_COUNT][MAX_NUM_OF_ATOM_RELATION_COUNT]; + int relation_size[MAX_NUM_OF_ATOM_RELATION_COUNT]; +} ar_cl; + +typedef struct { + int needed_size; + //int torsion_size; + //int search_depth; + //int max_bfgs_steps; + int total_wi; + int thread; + int ar_mi; + int ar_mj; + int ar_mk; + int grids_front; + + + + + float epsilon_fl; + float cutoff_sqr; + float max_fl; + float mutation_amplitude; + float hunt_cap[3]; + float authentic_v[3]; +} mis_cl; + + + + + +typedef struct { + int max_steps; + float average_required_improvement; + int over; + int ig_grids_m_data_step; + int p_data_m_data_step; + int atu; + int m_num_movable_atoms; + float slope; + float epsilon_fl; + float epsilon_fl2; + float epsilon_fl3; + float epsilon_fl4; + float epsilon_fl5; +}variables_bfgs; + +typedef struct { + output_type_cl container[MAX_CONTAINER_SIZE_EVERY_WI]; + int current_size; +}out_container; + +// ----------------------------------------------------------------------------- +// End of inlined kernel2.h +// ----------------------------------------------------------------------------- // Macros below are only in device diff --git a/AutoDock-Vina-GPU-2.1/OpenCL/src/wrapcl.cpp b/AutoDock-Vina-GPU-2.1/OpenCL/src/wrapcl.cpp index 611f212..4062f79 100644 --- a/AutoDock-Vina-GPU-2.1/OpenCL/src/wrapcl.cpp +++ b/AutoDock-Vina-GPU-2.1/OpenCL/src/wrapcl.cpp @@ -374,14 +374,39 @@ void SetupBuildProgramWithSource(cl_program program_cl, cl_program program_head, //Build program err = clBuildProgram(program_cl, 1, devices, options, NULL, NULL); if (CL_SUCCESS != err) { - printf("\nError: Failed to build program executable!"); + printf("\nError: Failed to build program executable! (clBuildProgram err=%d)\n", err); + fflush(stdout); char* buffer; - size_t logsize; + size_t logsize = 0; //Building log - err = clGetProgramBuildInfo(program_cl, *devices, CL_PROGRAM_BUILD_LOG, 0, NULL, &logsize); checkErr(err); - buffer = (char*)malloc(logsize * sizeof(char)); - err = clGetProgramBuildInfo(program_cl, *devices, CL_PROGRAM_BUILD_LOG, logsize, buffer, NULL); checkErr(err); - printf("\nlog:%s", buffer); + cl_int log_err = clGetProgramBuildInfo(program_cl, *devices, CL_PROGRAM_BUILD_LOG, 0, NULL, &logsize); + if (log_err != CL_SUCCESS) { + printf("clGetProgramBuildInfo(size) failed with err=%d\n", log_err); + fflush(stdout); + exit(-1); + } + buffer = (char*)malloc((logsize + 1) * sizeof(char)); + log_err = clGetProgramBuildInfo(program_cl, *devices, CL_PROGRAM_BUILD_LOG, logsize, buffer, NULL); + if (log_err != CL_SUCCESS) { + printf("clGetProgramBuildInfo(data) failed with err=%d\n", log_err); + fflush(stdout); + free(buffer); + exit(-1); + } + buffer[logsize] = '\0'; // guarantee null termination + // Print full log to stdout + printf("\n=== OpenCL Build Log (logsize=%zu bytes) ===\n", logsize); + printf("%s\n", buffer); + printf("=== End of OpenCL Build Log ===\n"); + fflush(stdout); + // Also write to file in case stdout buffering loses content during exit + FILE* logfile = fopen("opencl_build_log.txt", "w"); + if (logfile) { + fwrite(buffer, 1, logsize, logfile); + fclose(logfile); + printf("Build log also written to opencl_build_log.txt\n"); + fflush(stdout); + } free(buffer); exit(-1); } diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f243faa --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,161 @@ +# CMakeLists.txt for building Vina-GPU 2.1 on Windows with VS2022 + Boost 1.83 + CUDA 13.2 OpenCL +# Custom build script (not from upstream — upstream ships only a Linux Makefile) +# Author: written for Dhruvik N. Chauhan's kidney_lab project, Day 9 GPU investigation +# Target: AutoDock-Vina-GPU-2.1 binary on Blackwell sm_120 (RTX 5050) + +cmake_minimum_required(VERSION 3.20) + +project(VinaGPU LANGUAGES CXX) + +# C++ standard +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# Default Release build +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) +endif() + +# --------------------------------------------------------------------------- +# Boost location hint — installer prebuilt at C:/local/boost_1_83_0 +# CMake 4.x removed FindBoost.cmake; we must use BoostConfig.cmake (config mode) +# --------------------------------------------------------------------------- +set(BOOST_ROOT "C:/local/boost_1_83_0" CACHE PATH "Boost root directory") +set(Boost_ROOT "C:/local/boost_1_83_0" CACHE PATH "Boost root (CMake 4.x case)") +set(Boost_DIR "C:/local/boost_1_83_0/lib64-msvc-14.3/cmake/Boost-1.83.0" CACHE PATH "BoostConfig.cmake location") +list(APPEND CMAKE_PREFIX_PATH "C:/local/boost_1_83_0/lib64-msvc-14.3/cmake") + +set(Boost_USE_STATIC_LIBS OFF) # use the DLL versions +set(Boost_USE_MULTITHREADED ON) +set(Boost_USE_STATIC_RUNTIME OFF) + +# Set CMake policies for Boost handling on CMake 4.x +if(POLICY CMP0144) + cmake_policy(SET CMP0144 NEW) # honor _ROOT variables +endif() +if(POLICY CMP0167) + cmake_policy(SET CMP0167 NEW) # use BoostConfig.cmake (config mode) only +endif() + +# Force config mode (CONFIG keyword); avoids legacy FindBoost lookup +# Include serialization — pulled in transitively by boost/thread internals +find_package(Boost 1.77 REQUIRED CONFIG COMPONENTS program_options system filesystem thread serialization) +message(STATUS "Boost include dirs: ${Boost_INCLUDE_DIRS}") +message(STATUS "Boost libraries: ${Boost_LIBRARIES}") +message(STATUS "Boost version: ${Boost_VERSION}") + +# --------------------------------------------------------------------------- +# OpenCL — comes from CUDA 13.2 installation on Windows +# --------------------------------------------------------------------------- +set(CUDA_ROOT "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.2" CACHE PATH "CUDA root for OpenCL") +set(OpenCL_INCLUDE_DIR "${CUDA_ROOT}/include" CACHE PATH "OpenCL include directory") +set(OpenCL_LIBRARY "${CUDA_ROOT}/lib/x64/OpenCL.lib" CACHE FILEPATH "OpenCL library") + +if(NOT EXISTS "${OpenCL_LIBRARY}") + message(FATAL_ERROR "OpenCL.lib not found at ${OpenCL_LIBRARY}") +endif() +if(NOT EXISTS "${OpenCL_INCLUDE_DIR}/CL/cl.h") + message(FATAL_ERROR "cl.h not found at ${OpenCL_INCLUDE_DIR}/CL/cl.h") +endif() + +message(STATUS "OpenCL include: ${OpenCL_INCLUDE_DIR}") +message(STATUS "OpenCL library: ${OpenCL_LIBRARY}") + +# --------------------------------------------------------------------------- +# Vina-GPU 2.1 source files +# --------------------------------------------------------------------------- +set(VINA_ROOT "${CMAKE_SOURCE_DIR}/AutoDock-Vina-GPU-2.1") + +# Glob all .cpp files in lib/ (75 files) +file(GLOB VINA_LIB_SRC "${VINA_ROOT}/lib/*.cpp") +list(LENGTH VINA_LIB_SRC VINA_LIB_COUNT) +message(STATUS "Found ${VINA_LIB_COUNT} source files in lib/") + +# wrapcl.cpp and main.cpp (per the upstream Makefile) +set(WRAPCL_SRC "${VINA_ROOT}/OpenCL/src/wrapcl.cpp") +set(MAIN_SRC "${VINA_ROOT}/main/main.cpp") + +if(NOT EXISTS "${WRAPCL_SRC}") + message(FATAL_ERROR "wrapcl.cpp not found at ${WRAPCL_SRC}") +endif() +if(NOT EXISTS "${MAIN_SRC}") + message(FATAL_ERROR "main.cpp not found at ${MAIN_SRC}") +endif() + +# --------------------------------------------------------------------------- +# Executable target +# --------------------------------------------------------------------------- +add_executable(AutoDock-Vina-GPU-2-1 + ${MAIN_SRC} + ${WRAPCL_SRC} + ${VINA_LIB_SRC} +) + +target_include_directories(AutoDock-Vina-GPU-2-1 PRIVATE + "${VINA_ROOT}/lib" + "${VINA_ROOT}/OpenCL/inc" + "${Boost_INCLUDE_DIRS}" + "${OpenCL_INCLUDE_DIR}" +) + +# Preprocessor definitions (matching upstream Makefile + README Windows recommendations) +target_compile_definitions(AutoDock-Vina-GPU-2-1 PRIVATE + NVIDIA_PLATFORM # tells Vina-GPU we're on NVIDIA OpenCL + OPENCL_2_0 # OpenCL 3.0 (README recommends over 2.0) + WINDOWS # Windows-specific code paths + SMALL_BOX # default docking box size (can switch to LARGE_BOX later) + BOOST_TIMER_ENABLE_DEPRECATED # Boost 1.77+ requires this for the deprecated timer API + BUILD_KERNEL_FROM_SOURCE # compile .cl kernels at runtime from source (vs prebuilt .bin) + NDEBUG # release-mode asserts off + _SCL_SECURE_NO_WARNINGS # quiet MSVC's iterator warnings + _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS # Boost uses some deprecated C++17 features + _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING # Vina-GPU main.cpp uses + BOOST_ALLOW_DEPRECATED_HEADERS # tolerate older boost headers + BOOST_ALL_DYN_LINK # force Boost auto-link to use DLLs (matches Boost_USE_STATIC_LIBS OFF) + CL_TARGET_OPENCL_VERSION=300 # explicitly target OpenCL 3.0 (silences cl_version.h info msg) + # NOTE: _CRT_SECURE_NO_WARNINGS is defined inside Vina-GPU's commonMacros.h, so we don't redefine +) + +target_link_libraries(AutoDock-Vina-GPU-2-1 PRIVATE + Boost::program_options + Boost::system + Boost::filesystem + Boost::thread + Boost::serialization + "${OpenCL_LIBRARY}" +) + +# --------------------------------------------------------------------------- +# Windows / MSVC specific flags +# --------------------------------------------------------------------------- +if(MSVC) + # /Zc:preprocessor — standards-conforming preprocessor (required by CUDA 13.x CCCL headers) + # /bigobj — allow large object files (Vina-GPU has templates that generate huge .obj) + # /MP — parallel compilation + # /EHsc — standard C++ exception handling + target_compile_options(AutoDock-Vina-GPU-2-1 PRIVATE + /Zc:preprocessor + /bigobj + /MP + /EHsc + /wd4267 # silence size_t->int conversion warnings (Vina-GPU has many) + /wd4244 # silence float->double conversion warnings + /wd4996 # silence deprecated function warnings + ) +endif() + +# Set output directory to project root for easier testing +set_target_properties(AutoDock-Vina-GPU-2-1 PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build/bin" + RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_SOURCE_DIR}/build/bin" +) + +message(STATUS "") +message(STATUS "============================================================") +message(STATUS "Vina-GPU 2.1 build configuration complete") +message(STATUS " Boost : ${Boost_VERSION} (${BOOST_ROOT})") +message(STATUS " OpenCL : ${OpenCL_LIBRARY}") +message(STATUS " Source : ${VINA_LIB_COUNT} files in lib/ + wrapcl.cpp + main.cpp") +message(STATUS " Output : build/bin/AutoDock-Vina-GPU-2-1.exe") +message(STATUS "============================================================")