Commit 05d64aea authored by peastman's avatar peastman
Browse files

Merge pull request #567 from peastman/pnacl

Support Chrome portable native client
parents f6b20365 ec785e70
......@@ -115,7 +115,7 @@ ELSE( CMAKE_SIZEOF_VOID_P EQUAL 8 )
SET( LIB64 )
ENDIF( CMAKE_SIZEOF_VOID_P EQUAL 8 )
IF (APPLE)
IF (APPLE AND (NOT PNACL))
# Build universal binaries compatible with OS X 10.7
IF (NOT CMAKE_OSX_DEPLOYMENT_TARGET)
SET (CMAKE_OSX_DEPLOYMENT_TARGET "10.7" CACHE STRING "The minimum version of OS X to support" FORCE)
......@@ -127,13 +127,13 @@ IF (APPLE)
# Improve the linking behavior of Mac libraries
SET (CMAKE_INSTALL_NAME_DIR "@rpath")
SET(EXTRA_COMPILE_FLAGS "-msse2 -stdlib=libc++")
ELSE (APPLE)
IF (MSVC OR ANDROID)
ELSE (APPLE AND (NOT PNACL))
IF (MSVC OR ANDROID OR PNACL)
SET(EXTRA_COMPILE_FLAGS)
ELSE (MSVC OR ANDROID)
ELSE (MSVC OR ANDROID OR PNACL)
SET(EXTRA_COMPILE_FLAGS "-msse2")
ENDIF (MSVC OR ANDROID)
ENDIF (APPLE)
ENDIF (MSVC OR ANDROID OR PNACL)
ENDIF (APPLE AND (NOT PNACL))
IF(UNIX AND NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Release CACHE STRING "Debug or Release build" FORCE)
......@@ -264,11 +264,11 @@ FOREACH(subdir ${OPENMM_SOURCE_SUBDIRS})
## OpenMM was previously installed there.
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/${subdir}/include)
ENDFOREACH(subdir)
IF (ANDROID)
IF (ANDROID OR PNACL)
SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/libraries/sfmt/src/SFMT.cpp PROPERTIES COMPILE_FLAGS "-UHAVE_SSE2")
ELSE (ANDROID)
ELSE (ANDROID OR PNACL)
SET_SOURCE_FILES_PROPERTIES(${CMAKE_SOURCE_DIR}/libraries/sfmt/src/SFMT.cpp PROPERTIES COMPILE_FLAGS "-DHAVE_SSE2=1")
ENDIF(ANDROID)
ENDIF(ANDROID OR PNACL)
# If API wrappers are being generated, and add them to the build.
SET(OPENMM_BUILD_C_AND_FORTRAN_WRAPPERS ON CACHE BOOL "Build wrappers for C and Fortran")
......@@ -280,11 +280,15 @@ ENDIF(OPENMM_BUILD_C_AND_FORTRAN_WRAPPERS)
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/src)
ADD_LIBRARY(${SHARED_TARGET} SHARED ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_ABS_INCLUDE_FILES})
SET_TARGET_PROPERTIES(${SHARED_TARGET} PROPERTIES LINK_FLAGS "${EXTRA_COMPILE_FLAGS}" COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -DOPENMM_BUILDING_SHARED_LIBRARY -DLEPTON_BUILDING_SHARED_LIBRARY -DOPENMM_VALIDATE_BUILDING_SHARED_LIBRARY")
IF(WIN32)
SET(OPENMM_BUILD_SHARED_LIB ON CACHE BOOL "Whether to build shared OpenMM libraries")
IF(OPENMM_BUILD_SHARED_LIB)
ADD_LIBRARY(${SHARED_TARGET} SHARED ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_ABS_INCLUDE_FILES})
SET_TARGET_PROPERTIES(${SHARED_TARGET} PROPERTIES LINK_FLAGS "${EXTRA_COMPILE_FLAGS}" COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -DOPENMM_BUILDING_SHARED_LIBRARY -DLEPTON_BUILDING_SHARED_LIBRARY -DOPENMM_VALIDATE_BUILDING_SHARED_LIBRARY")
IF(WIN32)
ADD_DEPENDENCIES(${SHARED_TARGET} PthreadsLibraries)
ENDIF(WIN32)
ENDIF(WIN32)
ENDIF(OPENMM_BUILD_SHARED_LIB)
SET(OPENMM_BUILD_STATIC_LIB OFF CACHE BOOL "Whether to build static OpenMM libraries")
IF(OPENMM_BUILD_STATIC_LIB)
......@@ -303,17 +307,21 @@ ENDIF(OPENMM_BUILD_C_AND_FORTRAN_WRAPPERS)
# On Linux need to link to libdl
FIND_LIBRARY(DL_LIBRARY dl)
IF(DL_LIBRARY)
IF(OPENMM_BUILD_SHARED_LIB)
TARGET_LINK_LIBRARIES(${SHARED_TARGET} ${DL_LIBRARY} ${PTHREADS_LIB})
ENDIF(OPENMM_BUILD_SHARED_LIB)
IF(OPENMM_BUILD_STATIC_LIB)
TARGET_LINK_LIBRARIES(${STATIC_TARGET} ${DL_LIBRARY} ${PTHREADS_LIB})
ENDIF(OPENMM_BUILD_STATIC_LIB)
MARK_AS_ADVANCED(DL_LIBRARY)
ELSE(DL_LIBRARY)
IF(OPENMM_BUILD_SHARED_LIB)
IF (ANDROID)
TARGET_LINK_LIBRARIES(${SHARED_TARGET} ${PTHREADS_LIB} cpufeatures)
ELSE (ANDROID)
TARGET_LINK_LIBRARIES(${SHARED_TARGET} ${PTHREADS_LIB})
ENDIF (ANDROID)
ENDIF(OPENMM_BUILD_SHARED_LIB)
ENDIF(DL_LIBRARY)
ADD_SUBDIRECTORY(platforms/reference/tests)
......@@ -433,7 +441,9 @@ IF(OPENMM_BUILD_PME_PLUGIN)
ADD_SUBDIRECTORY(plugins/cpupme)
ENDIF(OPENMM_BUILD_PME_PLUGIN)
INSTALL_TARGETS(/lib RUNTIME_DIRECTORY /lib ${SHARED_TARGET})
IF(OPENMM_BUILD_SHARED_LIB)
INSTALL_TARGETS(/lib RUNTIME_DIRECTORY /lib ${SHARED_TARGET})
ENDIF(OPENMM_BUILD_SHARED_LIB)
IF(OPENMM_BUILD_STATIC_LIB)
INSTALL_TARGETS(/lib RUNTIME_DIRECTORY /lib ${STATIC_TARGET})
ENDIF(OPENMM_BUILD_STATIC_LIB)
......
......@@ -21,14 +21,8 @@ SET(CPP_EXAMPLES HelloArgon HelloSodiumChloride HelloEthane HelloWaterBox)
SET(C_EXAMPLES HelloArgonInC HelloSodiumChlorideInC)
SET(F_EXAMPLES HelloArgonInFortran HelloSodiumChlorideInFortran)
SET(BUILD_TESTING_SHARED 1)
SET(BUILD_TESTING_STATIC OFF)
IF(OPENMM_BUILD_STATIC_LIB)
SET(BUILD_TESTING_STATIC ON)
ENDIF(OPENMM_BUILD_STATIC_LIB)
FOREACH(EX_ROOT ${CPP_EXAMPLES})
IF (BUILD_TESTING_SHARED)
IF (OPENMM_BUILD_SHARED_LIB)
# Link with shared library
ADD_EXECUTABLE(${EX_ROOT} ${EX_ROOT}.cpp)
SET_TARGET_PROPERTIES(${EX_ROOT}
......@@ -37,9 +31,9 @@ FOREACH(EX_ROOT ${CPP_EXAMPLES})
LINK_FLAGS "${EXTRA_COMPILE_FLAGS}"
COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS}")
TARGET_LINK_LIBRARIES(${EX_ROOT} ${SHARED_TARGET})
ENDIF (BUILD_TESTING_SHARED)
ENDIF (OPENMM_BUILD_SHARED_LIB)
IF (BUILD_TESTING_STATIC)
IF (OPENMM_BUILD_STATIC_LIB)
# Link with static library
SET(EX_STATIC ${EX_ROOT}Static)
ADD_EXECUTABLE(${EX_STATIC} ${EX_ROOT}.cpp)
......@@ -49,7 +43,7 @@ FOREACH(EX_ROOT ${CPP_EXAMPLES})
LINK_FLAGS "${EXTRA_COMPILE_FLAGS}"
COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -DOPENMM_USE_STATIC_LIBRARIES")
TARGET_LINK_LIBRARIES(${EX_STATIC} ${STATIC_TARGET})
ENDIF (BUILD_TESTING_STATIC)
ENDIF (OPENMM_BUILD_STATIC_LIB)
INSTALL(FILES ${EX_ROOT}.cpp DESTINATION examples)
......@@ -60,7 +54,7 @@ IF(OPENMM_BUILD_C_AND_FORTRAN_WRAPPERS)
INCLUDE_DIRECTORIES(BEFORE ${PROJECT_BINARY_DIR}/wrappers)
FOREACH(EX_ROOT ${C_EXAMPLES})
IF (BUILD_TESTING_SHARED)
IF (OPENMM_BUILD_SHARED_LIB)
# Link with shared library
# We need at least one .cpp here to get CMake to include
# C++ libraries on the link line.
......@@ -72,9 +66,9 @@ IF(OPENMM_BUILD_C_AND_FORTRAN_WRAPPERS)
COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS}")
TARGET_LINK_LIBRARIES(${EX_ROOT} ${SHARED_TARGET})
ADD_DEPENDENCIES(${EX_ROOT} ApiWrappers)
ENDIF (BUILD_TESTING_SHARED)
ENDIF (OPENMM_BUILD_SHARED_LIB)
IF (BUILD_TESTING_STATIC)
IF (OPENMM_BUILD_STATIC_LIB)
# Link with static library
SET(EX_STATIC ${EX_ROOT}Static)
# We need at least one .cpp here to get CMake to include
......@@ -87,7 +81,7 @@ IF(OPENMM_BUILD_C_AND_FORTRAN_WRAPPERS)
COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -DOPENMM_USE_STATIC_LIBRARIES")
TARGET_LINK_LIBRARIES(${EX_STATIC} ${STATIC_TARGET})
ADD_DEPENDENCIES(${EX_STATIC} ApiWrappers)
ENDIF (BUILD_TESTING_STATIC)
ENDIF (OPENMM_BUILD_STATIC_LIB)
ENDFOREACH(EX_ROOT ${C_EXAMPLES})
ENDIF(OPENMM_BUILD_C_AND_FORTRAN_WRAPPERS)
......
......@@ -116,7 +116,6 @@
#endif
#endif
#include <memory.h>
#include <limits.h>
#ifdef SHA1_UTILITY_FUNCTIONS
......
......@@ -26,7 +26,7 @@
/* $Id: arithmetic_ansi.h 65 2010-01-29 12:19:16Z naoaki $ */
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#if LBFGS_FLOAT == 32 && LBFGS_IEEE_FLOAT
#define fsigndiff(x, y) (((*(uint32_t*)(x)) ^ (*(uint32_t*)(y))) & 0x80000000U)
......
......@@ -38,7 +38,9 @@
#include <windows.h>
#include <sstream>
#else
#include <dlfcn.h>
#ifndef __PNACL__
#include <dlfcn.h>
#endif
#include <dirent.h>
#include <cstdlib>
#endif
......@@ -187,13 +189,18 @@ static void initializePlugins(vector<HMODULE>& plugins) {
}
#else
static void* loadOneLibrary(const string& file) {
#ifdef __PNACL__
throw OpenMMException("Loading dynamic libraries is not supported on PNaCl");
#else
void *handle = dlopen(file.c_str(), RTLD_LAZY | RTLD_GLOBAL);
if (handle == NULL)
throw OpenMMException("Error loading library "+file+": "+dlerror());
return handle;
#endif
}
static void initializePlugins(vector<void*>& plugins) {
#ifndef __PNACL__
for (int i = 0; i < (int) plugins.size(); i++) {
void (*init)();
*(void **)(&init) = dlsym(plugins[i], "registerPlatforms");
......@@ -206,6 +213,7 @@ static void initializePlugins(vector<void*>& plugins) {
if (init != NULL)
(*init)();
}
#endif
}
#endif
......
......@@ -50,7 +50,6 @@
#ifdef __ANDROID__
#include <cpu-features.h>
#else
#include <dlfcn.h>
#include <unistd.h>
#endif
#endif
......@@ -93,7 +92,7 @@ static int getNumProcessors() {
#ifdef _WIN32
#define cpuid __cpuid
#else
#ifndef __ANDROID__
#if !defined(__ANDROID__) && !defined(__PNACL__)
static void cpuid(int cpuInfo[4], int infoType){
#ifdef __LP64__
__asm__ __volatile__ (
......
......@@ -35,7 +35,11 @@
#if defined(__ANDROID__)
#include "vectorize_neon.h"
#else
#if defined(__PNACL__)
#include "vectorize_pnacl.h"
#else
#include "vectorize_sse.h"
#endif
#endif
#endif /*OPENMM_VECTORIZE_H_*/
......@@ -40,6 +40,14 @@ typedef int int32_t;
// This file defines classes and functions to simplify vectorizing code with NEON.
/**
* Determine whether ivec4 and fvec4 are supported on this processor.
*/
static bool isVec4Supported() {
uint64_t features = android_getCpuFeatures();
return (features & ANDROID_CPU_ARM_FEATURE_NEON) != 0;
}
class ivec4;
/**
......
#ifndef OPENMM_VECTORIZE_PNACL_H_
#define OPENMM_VECTORIZE_PNACL_H_
/* -------------------------------------------------------------------------- *
* 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) 2013-2014 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. *
* -------------------------------------------------------------------------- */
#include <cmath>
#include <cstdlib>
// This file defines classes and functions to simplify vectorizing code with portable SIMD vectors.
/**
* Determine whether ivec4 and fvec4 are supported on this processor.
*/
static bool isVec4Supported() {
return true;
}
typedef float __m128 __attribute__((vector_size(16), aligned(4)));
typedef int __m128i __attribute__((vector_size(16), aligned(4)));
class ivec4;
/**
* A four element vector of floats.
*/
class fvec4 {
public:
__m128 val;
fvec4() {}
fvec4(float v) {
val = {v, v, v, v};
}
fvec4(float v1, float v2, float v3, float v4) {
val = {v1, v2, v3, v4};
}
fvec4(__m128 v) : val(v) {}
fvec4(const float* v) {
val = *((__m128*) v);
}
operator __m128() const {
return val;
}
float operator[](int i) const {
return val[i];
}
void store(float* v) const {
*((__m128*) v) = val;
}
fvec4 operator+(const fvec4& other) const {
return val+other;
}
fvec4 operator-(const fvec4& other) const {
return val-other;
}
fvec4 operator*(const fvec4& other) const {
return val*other;
}
fvec4 operator/(const fvec4& other) const {
return val/other;
}
void operator+=(const fvec4& other) {
val = val+other;
}
void operator-=(const fvec4& other) {
val = val-other;
}
void operator*=(const fvec4& other) {
val = val*other;
}
void operator/=(const fvec4& other) {
val = val/other;
}
fvec4 operator-() const {
return -val;
}
fvec4 operator&(const fvec4& other) const {
return (fvec4) (((__m128i)val)&((__m128i)other.val));
}
fvec4 operator|(const fvec4& other) const {
return (fvec4) (((__m128i)val)|((__m128i)other.val));
}
fvec4 operator==(const fvec4& other) const {
return (val==other.val);
}
fvec4 operator!=(const fvec4& other) const {
return (val!=other.val);
}
fvec4 operator>(const fvec4& other) const {
return (val>other.val);
}
fvec4 operator<(const fvec4& other) const {
return (val<other.val);
}
fvec4 operator>=(const fvec4& other) const {
return (val>=other.val);
}
fvec4 operator<=(const fvec4& other) const {
return (val<=other.val);
}
operator ivec4() const;
};
/**
* A four element vector of ints.
*/
class ivec4 {
public:
__m128i val;
ivec4() {}
ivec4(int v) {
val = {v, v, v, v};
}
ivec4(int v1, int v2, int v3, int v4) {
val = {v1, v2, v3, v4};
}
ivec4(__m128i v) : val(v) {}
ivec4(const int* v) {
val = *((__m128*) v);
}
operator __m128i() const {
return val;
}
int operator[](int i) const {
return val[i];
}
void store(int* v) const {
*((__m128*) v) = val;
}
ivec4 operator+(const ivec4& other) const {
return val+other;
}
ivec4 operator-(const ivec4& other) const {
return val-other;
}
ivec4 operator*(const ivec4& other) const {
return val*other;
}
void operator+=(const ivec4& other) {
val = val+other;
}
void operator-=(const ivec4& other) {
val = val-other;
}
void operator*=(const ivec4& other) {
val = val*other;
}
ivec4 operator-() const {
return -val;
}
ivec4 operator&(const ivec4& other) const {
return val&other.val;
}
ivec4 operator|(const ivec4& other) const {
return val|other.val;
}
ivec4 operator==(const ivec4& other) const {
return (val==other.val);
}
ivec4 operator!=(const ivec4& other) const {
return (val!=other.val);
}
ivec4 operator>(const ivec4& other) const {
return (val>other.val);
}
ivec4 operator<(const ivec4& other) const {
return (val<other.val);
}
ivec4 operator>=(const ivec4& other) const {
return (val>=other.val);
}
ivec4 operator<=(const ivec4& other) const {
return (val<=other.val);
}
operator fvec4() const;
};
// Conversion operators.
inline fvec4::operator ivec4() const {
return __builtin_convertvector(val, __m128i);
}
inline ivec4::operator fvec4() const {
return __builtin_convertvector(val, __m128);
}
// Functions that operate on fvec4s.
static inline fvec4 floor(const fvec4& v) {
return fvec4(std::floor(v[0]), std::floor(v[1]), std::floor(v[2]), std::floor(v[3]));
}
static inline fvec4 ceil(const fvec4& v) {
return fvec4(std::ceil(v[0]), std::ceil(v[1]), std::ceil(v[2]), std::ceil(v[3]));
}
static inline fvec4 round(const fvec4& v) {
return fvec4(std::round(v[0]), std::round(v[1]), std::round(v[2]), std::round(v[3]));
}
static inline fvec4 min(const fvec4& v1, const fvec4& v2) {
return fvec4(std::min(v1[0], v2[0]), std::min(v1[1], v2[1]), std::min(v1[2], v2[2]), std::min(v1[3], v2[3]));
}
static inline fvec4 max(const fvec4& v1, const fvec4& v2) {
return fvec4(std::max(v1[0], v2[0]), std::max(v1[1], v2[1]), std::max(v1[2], v2[2]), std::max(v1[3], v2[3]));
}
static inline fvec4 abs(const fvec4& v) {
return fvec4(std::abs(v[0]), std::abs(v[1]), std::abs(v[2]), std::abs(v[3]));
}
static inline fvec4 sqrt(const fvec4& v) {
return fvec4(std::sqrt(v[0]), std::sqrt(v[1]), std::sqrt(v[2]), std::sqrt(v[3]));
}
static inline float dot3(const fvec4& v1, const fvec4& v2) {
fvec4 r = v1*v2;
return r[0]+r[1]+r[2];
}
static inline float dot4(const fvec4& v1, const fvec4& v2) {
fvec4 r = v1*v2;
return r[0]+r[1]+r[2]+r[3];
}
static inline void transpose(fvec4& v1, fvec4& v2, fvec4& v3, fvec4& v4) {
__m128 a1 = __builtin_shufflevector(v1.val, v2.val, 0, 4, 2, 6);
__m128 a2 = __builtin_shufflevector(v1.val, v2.val, 1, 5, 3, 7);
__m128 a3 = __builtin_shufflevector(v3.val, v4.val, 0, 4, 2, 6);
__m128 a4 = __builtin_shufflevector(v3.val, v4.val, 1, 5, 3, 7);
v1 = __builtin_shufflevector(a1, a3, 0, 1, 4, 5);
v2 = __builtin_shufflevector(a2, a4, 0, 1, 4, 5);
v3 = __builtin_shufflevector(a1, a3, 2, 3, 6, 7);
v4 = __builtin_shufflevector(a2, a4, 2, 3, 6, 7);
}
// Functions that operate on ivec4s.
static inline ivec4 min(const ivec4& v1, const ivec4& v2) {
return ivec4(std::min(v1[0], v2[0]), std::min(v1[1], v2[1]), std::min(v1[2], v2[2]), std::min(v1[3], v2[3]));
}
static inline ivec4 max(const ivec4& v1, const ivec4& v2) {
return ivec4(std::max(v1[0], v2[0]), std::max(v1[1], v2[1]), std::max(v1[2], v2[2]), std::max(v1[3], v2[3]));
}
static inline ivec4 abs(const ivec4& v) {
return ivec4(abs(v[0]), abs(v[1]), abs(v[2]), abs(v[3]));
}
static inline bool any(const __m128i& v) {
return (v[0] || v[1] || v[2] || v[3]);
}
// Mathematical operators involving a scalar and a vector.
static inline fvec4 operator+(float v1, const fvec4& v2) {
return fvec4(v1)+v2;
}
static inline fvec4 operator-(float v1, const fvec4& v2) {
return fvec4(v1)-v2;
}
static inline fvec4 operator*(float v1, const fvec4& v2) {
return fvec4(v1)*v2;
}
static inline fvec4 operator/(float v1, const fvec4& v2) {
return fvec4(v1)/v2;
}
// Operations for blending fvec4s based on an ivec4.
static inline fvec4 blend(const fvec4& v1, const fvec4& v2, const __m128i& mask) {
return fvec4(mask[0] ? v2[0] : v1[0], mask[1] ? v2[1] : v1[1], mask[2] ? v2[2] : v1[2], mask[3] ? v2[3] : v1[3]);
}
#endif /*OPENMM_VECTORIZE_PNACL_H_*/
......@@ -33,10 +33,23 @@
* -------------------------------------------------------------------------- */
#include <smmintrin.h>
#include "hardware.h"
// This file defines classes and functions to simplify vectorizing code with SSE.
/**
* Determine whether ivec4 and fvec4 are supported on this processor.
*/
static bool isVec4Supported() {
int cpuInfo[4];
cpuid(cpuInfo, 0);
if (cpuInfo[0] >= 1) {
cpuid(cpuInfo, 1);
return ((cpuInfo[2] & ((int) 1 << 19)) != 0);
}
return false;
}
class ivec4;
/**
......@@ -146,7 +159,7 @@ public:
return _mm_sub_epi32(val, other);
}
ivec4 operator*(const ivec4& other) const {
return _mm_mul_epi32(val, other);
return _mm_mullo_epi32(val, other);
}
void operator+=(const ivec4& other) {
val = _mm_add_epi32(val, other);
......@@ -155,7 +168,7 @@ public:
val = _mm_sub_epi32(val, other);
}
void operator*=(const ivec4& other) {
val = _mm_mul_epi32(val, other);
val = _mm_mullo_epi32(val, other);
}
ivec4 operator-() const {
return _mm_sub_epi32(_mm_set1_epi32(0), val);
......
......@@ -76,7 +76,9 @@ INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/src)
FILE(GLOB CORE_HEADERS include/*.h)
INSTALL_FILES(/include/openmm/cpu FILES ${CORE_HEADERS})
SUBDIRS (sharedTarget)
IF(OPENMM_BUILD_SHARED_LIB)
SUBDIRS (sharedTarget)
ENDIF(OPENMM_BUILD_SHARED_LIB)
IF(OPENMM_BUILD_STATIC_LIB)
SUBDIRS (staticTarget)
ENDIF(OPENMM_BUILD_STATIC_LIB)
......
......@@ -98,9 +98,9 @@ private:
float periodicBoxSize[3];
float cutoffDistance, soluteDielectric, solventDielectric;
std::vector<std::pair<float, float> > particleParams;
std::vector<float> bornRadii;
std::vector<std::vector<float> > threadBornForces;
std::vector<float> obcChain;
AlignedArray<float> bornRadii;
std::vector<AlignedArray<float> > threadBornForces;
AlignedArray<float> obcChain;
std::vector<double> threadEnergy;
std::vector<float> logTable;
float logDX, logDXInv;
......
......@@ -213,7 +213,7 @@ void CpuGBSAOBCForce::threadComputeForce(ThreadPool& threads, int threadIndex) {
const float probeRadius = 0.14f;
const float surfaceAreaFactor = 28.3919551;
double energy = 0.0;
vector<float>& bornForces = threadBornForces[threadIndex];
AlignedArray<float>& bornForces = threadBornForces[threadIndex];
for (int i = 0; i < numParticles; i++)
bornForces[i] = 0.0f;
while (true) {
......
......@@ -35,6 +35,7 @@
#include "CpuSETTLE.h"
#include "ReferenceConstraints.h"
#include "openmm/internal/hardware.h"
#include "openmm/internal/vectorize.h"
#include <sstream>
#include <stdlib.h>
......@@ -94,20 +95,7 @@ bool CpuPlatform::supportsDoublePrecision() const {
}
bool CpuPlatform::isProcessorSupported() {
// Make sure the CPU supports SSE 4.1 or NEON.
#ifdef __ANDROID__
uint64_t features = android_getCpuFeatures();
return (features & ANDROID_CPU_ARM_FEATURE_NEON) != 0;
#else
int cpuInfo[4];
cpuid(cpuInfo, 0);
if (cpuInfo[0] >= 1) {
cpuid(cpuInfo, 1);
return ((cpuInfo[2] & ((int) 1 << 19)) != 0);
}
return false;
#endif
return isVec4Supported();
}
void CpuPlatform::contextCreated(ContextImpl& context, const map<string, string>& properties) const {
......
......@@ -33,7 +33,7 @@ CpuRandom::CpuRandom() : hasInitialized(false) {
}
CpuRandom::~CpuRandom() {
for (int i = 0; i < threadRandom.size(); i++)
for (int i = 0; i < (int) threadRandom.size(); i++)
delete threadRandom[i];
}
......
......@@ -2,18 +2,20 @@ FOREACH(file ${SOURCE_FILES})
IF (file MATCHES ".*Vec8.*")
IF (MSVC)
SET_SOURCE_FILES_PROPERTIES(${file} PROPERTIES COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} /arch:AVX /D__AVX__")
ELSEIF (PNACL)
SET_SOURCE_FILES_PROPERTIES(${file} PROPERTIES COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS}")
ELSE (MSVC)
SET_SOURCE_FILES_PROPERTIES(${file} PROPERTIES COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -msse4.1 -mavx")
ENDIF (MSVC)
ELSE (file MATCHES ".*Vec8.*")
IF (NOT MSVC)
IF (NOT (MSVC OR ANDROID OR PNACL))
SET_SOURCE_FILES_PROPERTIES(${file} PROPERTIES COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -msse4.1")
ENDIF (NOT MSVC)
ENDIF (NOT (MSVC OR ANDROID OR PNACL))
ENDIF (file MATCHES ".*Vec8.*")
ENDFOREACH(file)
ADD_LIBRARY(${STATIC_TARGET} STATIC ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_ABS_INCLUDE_FILES})
TARGET_LINK_LIBRARIES(${STATIC_TARGET} ${OPENMM_LIBRARY_NAME} ${PTHREADS_LIB_STATIC})
TARGET_LINK_LIBRARIES(${STATIC_TARGET} ${OPENMM_LIBRARY_NAME}_static ${PTHREADS_LIB_STATIC})
#-DPTW32_STATIC_LIB only works for the windows pthreads.
SET_TARGET_PROPERTIES(${STATIC_TARGET} PROPERTIES LINK_FLAGS "${EXTRA_COMPILE_FLAGS}" COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -DOPENMM_CPU_BUILDING_STATIC_LIBRARY -DPTW32_STATIC_LIB")
......
......@@ -17,9 +17,12 @@ FILE(GLOB TEST_PROGS "*Test*.cpp")
FOREACH(TEST_PROG ${TEST_PROGS})
GET_FILENAME_COMPONENT(TEST_ROOT ${TEST_PROG} NAME_WE)
# Link with shared library
ADD_EXECUTABLE(${TEST_ROOT} ${TEST_PROG})
IF (OPENMM_BUILD_SHARED_LIB)
TARGET_LINK_LIBRARIES(${TEST_ROOT} ${SHARED_TARGET})
ELSE (OPENMM_BUILD_SHARED_LIB)
TARGET_LINK_LIBRARIES(${TEST_ROOT} ${STATIC_TARGET})
ENDIF (OPENMM_BUILD_SHARED_LIB)
SET_TARGET_PROPERTIES(${TEST_ROOT} PROPERTIES LINK_FLAGS "${EXTRA_COMPILE_FLAGS}" COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS}")
ADD_TEST(${TEST_ROOT} ${EXECUTABLE_OUTPUT_PATH}/${TEST_ROOT} single)
......
......@@ -9,9 +9,12 @@ FILE(GLOB TEST_PROGS "*Test*.cpp")
FOREACH(TEST_PROG ${TEST_PROGS})
GET_FILENAME_COMPONENT(TEST_ROOT ${TEST_PROG} NAME_WE)
# All tests use shared libraries
ADD_EXECUTABLE(${TEST_ROOT} ${TEST_PROG})
IF (OPENMM_BUILD_SHARED_LIB)
TARGET_LINK_LIBRARIES(${TEST_ROOT} ${SHARED_TARGET})
ELSE (OPENMM_BUILD_SHARED_LIB)
TARGET_LINK_LIBRARIES(${TEST_ROOT} ${STATIC_TARGET})
ENDIF (OPENMM_BUILD_SHARED_LIB)
SET_TARGET_PROPERTIES(${TEST_ROOT} PROPERTIES LINK_FLAGS "${EXTRA_COMPILE_FLAGS}" COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS}")
ADD_TEST(${TEST_ROOT} ${EXECUTABLE_OUTPUT_PATH}/${TEST_ROOT})
......
......@@ -79,8 +79,8 @@ void testMasslessParticle() {
for (int i = 0; i < 1000; ++i) {
State state = context.getState(State::Positions | State::Velocities | State::Forces);
double time = state.getTime();
ASSERT_EQUAL_VEC(Vec3(), state.getPositions()[0], 0.0);
ASSERT_EQUAL_VEC(Vec3(), state.getVelocities()[0], 0.0);
ASSERT_EQUAL_VEC(Vec3(0, 0, 0), state.getPositions()[0], 0.0);
ASSERT_EQUAL_VEC(Vec3(0, 0, 0), state.getVelocities()[0], 0.0);
ASSERT_EQUAL_VEC(Vec3(cos(time), sin(time), 0), state.getPositions()[1], 0.01);
ASSERT_EQUAL_VEC(Vec3(-sin(time), cos(time), 0), state.getVelocities()[1], 0.01);
integrator.step(1);
......
......@@ -57,32 +57,34 @@ ENDFOREACH(subdir)
INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/src)
IF (NOT MSVC)
IF (ANDROID)
IF (ANDROID OR PNACL)
SET_SOURCE_FILES_PROPERTIES(${SOURCE_FILES} PROPERTIES COMPILE_FLAGS "")
ELSE (ANDROID)
ELSE (ANDROID OR PNACL)
SET_SOURCE_FILES_PROPERTIES(${SOURCE_FILES} PROPERTIES COMPILE_FLAGS "-msse4.1")
ENDIF (ANDROID)
ENDIF (ANDROID OR PNACL)
ENDIF (NOT MSVC)
# Include FFTW related files.
INCLUDE_DIRECTORIES(${FFTW_INCLUDES})
# Build the shared plugin library.
ADD_LIBRARY(${SHARED_TARGET} SHARED ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_INCLUDE_FILES})
IF (OPENMM_BUILD_SHARED_LIB)
ADD_LIBRARY(${SHARED_TARGET} SHARED ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_INCLUDE_FILES})
TARGET_LINK_LIBRARIES(${SHARED_TARGET} ${OPENMM_LIBRARY_NAME} ${PTHREADS_LIB} ${FFTW_LIBRARY})
IF (FFTW_THREADS_LIBRARY)
TARGET_LINK_LIBRARIES(${SHARED_TARGET} ${OPENMM_LIBRARY_NAME} ${PTHREADS_LIB} ${FFTW_LIBRARY})
IF (FFTW_THREADS_LIBRARY)
TARGET_LINK_LIBRARIES(${SHARED_TARGET} ${FFTW_THREADS_LIBRARY})
ENDIF (FFTW_THREADS_LIBRARY)
SET_TARGET_PROPERTIES(${SHARED_TARGET} PROPERTIES LINK_FLAGS "${EXTRA_COMPILE_FLAGS}" COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -DOPENMM_PME_BUILDING_SHARED_LIBRARY")
ENDIF (FFTW_THREADS_LIBRARY)
SET_TARGET_PROPERTIES(${SHARED_TARGET} PROPERTIES LINK_FLAGS "${EXTRA_COMPILE_FLAGS}" COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -DOPENMM_PME_BUILDING_SHARED_LIBRARY")
INSTALL_TARGETS(/lib/plugins RUNTIME_DIRECTORY /lib/plugins ${SHARED_TARGET})
INSTALL_TARGETS(/lib/plugins RUNTIME_DIRECTORY /lib/plugins ${SHARED_TARGET})
ENDIF (OPENMM_BUILD_SHARED_LIB)
# Build the static plugin library.
IF(OPENMM_BUILD_STATIC_LIB)
ADD_LIBRARY(${STATIC_TARGET} STATIC ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_INCLUDE_FILES})
TARGET_LINK_LIBRARIES(${STATIC_TARGET} ${OPENMM_LIBRARY_NAME} ${PTHREADS_LIB} ${FFTW_LIBRARY})
TARGET_LINK_LIBRARIES(${STATIC_TARGET} ${OPENMM_LIBRARY_NAME}_static ${PTHREADS_LIB} ${FFTW_LIBRARY})
IF (FFTW_THREADS_LIBRARY)
TARGET_LINK_LIBRARIES(${STATIC_TARGET} ${FFTW_THREADS_LIBRARY})
ENDIF (FFTW_THREADS_LIBRARY)
......
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