"vscode:/vscode.git/clone" did not exist on "8f532e31b2fca9b2cd8978e6b31bba6bf764fc84"
Commit 8f2f6e39 authored by Peter Eastman's avatar Peter Eastman
Browse files

Lots of mystical CMake incantations to make Cuda platform compile both static...

Lots of mystical CMake incantations to make Cuda platform compile both static and dynamic libraries correctly
parent 93354c21
......@@ -82,27 +82,6 @@ ENDFOREACH(subdir)
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/src)
SET(FINDCUDA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/cuda-cmake)
#
# Include CUDA related files.
#
INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/cuda-cmake/FindCuda.cmake)
INCLUDE_DIRECTORIES(${CUDA_INCLUDE})
LINK_DIRECTORIES(${CUDA_TARGET_LINK})
FOREACH(subdir ${OPENMM_SOURCE_SUBDIRS})
FILE(GLOB src_files ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*.cu ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/src/*/*.cu)
FOREACH(file ${src_files})
FILE(RELATIVE_PATH file ${CMAKE_CURRENT_SOURCE_DIR} ${file})
# MESSAGE(${file})
SET(SOURCE_FILES ${SOURCE_FILES} ${file}) #append
ENDFOREACH(file)
CUDA_INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/include)
ENDFOREACH(subdir)
CUDA_INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/src)
CUDA_ADD_LIBRARY(${SHARED_TARGET} SHARED ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_ABS_INCLUDE_FILES})
#CUDA_ADD_LIBRARY(${STATIC_TARGET} STATIC ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_ABS_INCLUDE_FILES})
TARGET_LINK_LIBRARIES(${SHARED_TARGET} debug ${OPENMM_LIBRARY_NAME}_d optimized ${OPENMM_LIBRARY_NAME})
#TARGET_LINK_LIBRARIES(${STATIC_TARGET} debug ${OPENMM_LIBRARY_NAME}_static_d optimized ${OPENMM_LIBRARY_NAME}_static)
SUBDIRS (sharedTarget staticTarget)
......@@ -53,7 +53,7 @@ MACRO(CUDA_INCLUDE_NVCC_DEPENDENCIES dependency_file)
IF(${CMAKE_MAKE_PROGRAM} MATCHES "make")
IF(NOT EXISTS ${dependency_file})
CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/cuda-cmake/empty.depend.in
${FINDCUDA_DIR}/empty.depend.in
${dependency_file} IMMEDIATE)
ENDIF(NOT EXISTS ${dependency_file})
# Always include this file to force CMake to run again next
......@@ -92,7 +92,7 @@ MACRO(CUDA_INCLUDE_NVCC_DEPENDENCIES dependency_file)
SET(CUDA_NVCC_DEPEND ${dependency_file})
# Force CMake to run again next build
CONFIGURE_FILE(
${CMAKE_CURRENT_SOURCE_DIR}/cuda-cmake/empty.depend.in
${FINDCUDA_DIR}/empty.depend.in
${dependency_file} IMMEDIATE)
ENDIF(CUDA_NVCC_DEPEND_REGENERATE)
......
......@@ -94,7 +94,7 @@
# FindCuda.cmake
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
INCLUDE(${CMAKE_CURRENT_SOURCE_DIR}/cuda-cmake/CudaDependency.cmake)
INCLUDE(${FINDCUDA_DIR}/CudaDependency.cmake)
###############################################################################
###############################################################################
......@@ -339,7 +339,7 @@ MACRO(CUDA_add_custom_commands cuda_target)
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/src/cuda)
SET(source_file ${CMAKE_CURRENT_SOURCE_DIR}/${file})
SET(source_file ${CMAKE_CURRENT_SOURCE_DIR}/../${file})
# MESSAGE("${CUDA_NVCC} ${source_file} ${CUDA_NVCC_FLAGS} ${nvcc_flags} -cuda -o ${generated_file} ${CUDA_NVCC_INCLUDE_ARGS}")
......@@ -369,7 +369,7 @@ MACRO(CUDA_add_custom_commands cuda_target)
COMMAND ${CMAKE_COMMAND}
ARGS
-D input_file="${NVCC_generated_cubin_file}"
-P "${CMAKE_CURRENT_SOURCE_DIR}/cuda-cmake/parse_cubin.cmake"
-P "${FINDCUDA_DIR}/parse_cubin.cmake"
# MAIN_DEPENDENCY ${source_file}
......@@ -409,7 +409,7 @@ MACRO(CUDA_add_custom_commands cuda_target)
ARGS
-D input_file="${NVCC_generated_dependency_file}"
-D output_file="${cmake_dependency_file}"
-P "${CMAKE_CURRENT_SOURCE_DIR}/cuda-cmake/make2cmake.cmake"
-P "${FINDCUDA_DIR}/make2cmake.cmake"
MAIN_DEPENDENCY ${NVCC_generated_dependency_file}
COMMENT "Converting NVCC dependency to CMake (${cmake_dependency_file})"
)
......
#
# Include CUDA related files.
#
INCLUDE(${FINDCUDA_DIR}/FindCuda.cmake)
INCLUDE_DIRECTORIES(${CUDA_INCLUDE})
LINK_DIRECTORIES(${CUDA_TARGET_LINK})
FOREACH(subdir ${OPENMM_SOURCE_SUBDIRS})
FILE(GLOB src_files ${CMAKE_SOURCE_DIR}/platforms/cuda/${subdir}/src/*.cu ${CMAKE_SOURCE_DIR}/platforms/cuda/src/*/*.cu)
FOREACH(file ${src_files})
FILE(RELATIVE_PATH file ${CMAKE_SOURCE_DIR}/platforms/cuda ${file})
SET(SOURCE_FILES ${SOURCE_FILES} ${file}) #append
ENDFOREACH(file)
CUDA_INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/platforms/cuda/../${subdir}/include)
ENDFOREACH(subdir)
CUDA_INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/platforms/cuda/../src)
CUDA_ADD_LIBRARY(${SHARED_TARGET} SHARED ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_ABS_INCLUDE_FILES})
TARGET_LINK_LIBRARIES(${SHARED_TARGET} debug ${OPENMM_LIBRARY_NAME}_d optimized ${OPENMM_LIBRARY_NAME})
#
# Include CUDA related files.
#
INCLUDE(${FINDCUDA_DIR}/FindCuda.cmake)
INCLUDE_DIRECTORIES(${CUDA_INCLUDE})
LINK_DIRECTORIES(${CUDA_TARGET_LINK})
FOREACH(subdir ${OPENMM_SOURCE_SUBDIRS})
FILE(GLOB src_files ${CMAKE_SOURCE_DIR}/platforms/cuda/${subdir}/src/*.cu ${CMAKE_SOURCE_DIR}/platforms/cuda/src/*/*.cu)
FOREACH(file ${src_files})
FILE(RELATIVE_PATH file ${CMAKE_SOURCE_DIR}/platforms/cuda ${file})
SET(SOURCE_FILES ${SOURCE_FILES} ${file}) #append
ENDFOREACH(file)
CUDA_INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/platforms/cuda/../${subdir}/include)
ENDFOREACH(subdir)
CUDA_INCLUDE_DIRECTORIES(BEFORE ${CMAKE_SOURCE_DIR}/platforms/cuda/../src)
CUDA_ADD_LIBRARY(${STATIC_TARGET} STATIC ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_ABS_INCLUDE_FILES})
TARGET_LINK_LIBRARIES(${STATIC_TARGET} debug ${OPENMM_LIBRARY_NAME}_static_d optimized ${OPENMM_LIBRARY_NAME}_static)
......@@ -4,6 +4,9 @@
ENABLE_TESTING()
INCLUDE(${CMAKE_SOURCE_DIR}/platforms/cuda/cuda-cmake/FindCuda.cmake)
INCLUDE_DIRECTORIES(${CUDA_INCLUDE})
# Automatically create tests using files named "Test*.cpp"
FILE(GLOB TEST_PROGS "*Test*.cpp")
FOREACH(TEST_PROG ${TEST_PROGS})
......@@ -11,14 +14,14 @@ FOREACH(TEST_PROG ${TEST_PROGS})
# Link with shared library
ADD_EXECUTABLE(${TEST_ROOT} ${TEST_PROG})
CUDA_ADD_EXECUTABLE(${TEST_ROOT} ${TEST_PROG})
TARGET_LINK_LIBRARIES(${TEST_ROOT} ${SHARED_TARGET})
ADD_TEST(${TEST_ROOT} ${EXECUTABLE_OUTPUT_PATH}/${TEST_ROOT})
# Link with static library
# SET(TEST_STATIC ${TEST_ROOT}Static)
# ADD_EXECUTABLE(${TEST_STATIC} ${TEST_PROG})
# CUDA_ADD_EXECUTABLE(${TEST_STATIC} ${TEST_PROG})
# SET_TARGET_PROPERTIES(${TEST_STATIC}
# PROPERTIES
# COMPILE_FLAGS "-DOPENMM_USE_STATIC_LIBRARIES"
......
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
/**
* This tests the Cuda implementation of AndersenThermostat.
*/
#include "../../../tests/AssertionUtilities.h"
#include "AndersenThermostat.h"
#include "OpenMMContext.h"
#include "CudaPlatform.h"
#include "NonbondedForce.h"
#include "System.h"
#include "VerletIntegrator.h"
#include "../src/SimTKUtilities/SimTKOpenMMRealType.h"
#include "../src/sfmt/SFMT.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
using namespace std;
void testTemperature() {
const int numParticles = 8;
const double temp = 100.0;
const double collisionFreq = 10.0;
CudaPlatform platform;
System system(numParticles, 0);
VerletIntegrator integrator(0.01);
NonbondedForce* forceField = new NonbondedForce(numParticles, 0);
for (int i = 0; i < numParticles; ++i) {
system.setParticleMass(i, 2.0);
forceField->setParticleParameters(i, (i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
}
system.addForce(forceField);
AndersenThermostat* thermstat = new AndersenThermostat(temp, collisionFreq);
system.addForce(thermstat);
OpenMMContext context(system, integrator, platform);
vector<Vec3> positions(numParticles);
for (int i = 0; i < numParticles; ++i)
positions[i] = Vec3((i%2 == 0 ? 2 : -2), (i%4 < 2 ? 2 : -2), (i < 4 ? 2 : -2));
context.setPositions(positions);
// Let it equilibrate.
integrator.step(10000);
// Now run it for a while and see if the temperature is correct.
double ke = 0.0;
for (int i = 0; i < 1000; ++i) {
State state = context.getState(State::Energy);
ke += state.getKineticEnergy();
integrator.step(1);
}
ke /= 1000;
double expected = 0.5*numParticles*3*BOLTZ*temp;
ASSERT_EQUAL_TOL(expected, ke, 3*expected/std::sqrt(1000.0));
}
int main() {
try {
testTemperature();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment