Enable -march=native in OS X clang builds
[hoomd-blue.git] / libhoomd / computes_gpu / HarmonicAngleForceComputeGPU.cc
blob60b71346769f0e5d586767975c3b79e1b77254cd
1 /*
2 Highly Optimized Object-oriented Many-particle Dynamics -- Blue Edition
3 (HOOMD-blue) Open Source Software License Copyright 2009-2014 The Regents of
4 the University of Michigan All rights reserved.
6 HOOMD-blue may contain modifications ("Contributions") provided, and to which
7 copyright is held, by various Contributors who have granted The Regents of the
8 University of Michigan the right to modify and/or distribute such Contributions.
10 You may redistribute, use, and create derivate works of HOOMD-blue, in source
11 and binary forms, provided you abide by the following conditions:
13 * Redistributions of source code must retain the above copyright notice, this
14 list of conditions, and the following disclaimer both in the code and
15 prominently in any materials provided with the distribution.
17 * Redistributions in binary form must reproduce the above copyright notice, this
18 list of conditions, and the following disclaimer in the documentation and/or
19 other materials provided with the distribution.
21 * All publications and presentations based on HOOMD-blue, including any reports
22 or published results obtained, in whole or in part, with HOOMD-blue, will
23 acknowledge its use according to the terms posted at the time of submission on:
24 http://codeblue.umich.edu/hoomd-blue/citations.html
26 * Any electronic documents citing HOOMD-Blue will link to the HOOMD-Blue website:
27 http://codeblue.umich.edu/hoomd-blue/
29 * Apart from the above required attributions, neither the name of the copyright
30 holder nor the names of HOOMD-blue's contributors may be used to endorse or
31 promote products derived from this software without specific prior written
32 permission.
34 Disclaimer
36 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' AND
37 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
38 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR ANY
39 WARRANTIES THAT THIS SOFTWARE IS FREE OF INFRINGEMENT ARE DISCLAIMED.
41 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
42 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
43 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
45 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
46 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
47 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 // Maintainer: dnlebard
52 /*! \file HarmonicAngleForceComputeGPU.cc
53 \brief Defines HarmonicAngleForceComputeGPU
56 #ifdef WIN32
57 #pragma warning( push )
58 #pragma warning( disable : 4244 )
59 #endif
61 #include "HarmonicAngleForceComputeGPU.h"
63 #include <boost/python.hpp>
64 using namespace boost::python;
66 #include <boost/bind.hpp>
67 using namespace boost;
69 using namespace std;
71 /*! \param sysdef System to compute angle forces on
73 HarmonicAngleForceComputeGPU::HarmonicAngleForceComputeGPU(boost::shared_ptr<SystemDefinition> sysdef)
74 : HarmonicAngleForceCompute(sysdef)
76 // can't run on the GPU if there aren't any GPUs in the execution configuration
77 if (!exec_conf->isCUDAEnabled())
79 m_exec_conf->msg->error() << "Creating a AngleForceComputeGPU with no GPU in the execution configuration" << endl;
80 throw std::runtime_error("Error initializing AngleForceComputeGPU");
83 // allocate and zero device memory
84 GPUArray<Scalar2> params(m_angle_data->getNTypes(), exec_conf);
85 m_params.swap(params);
87 m_tuner.reset(new Autotuner(32, 1024, 32, 5, 100000, "harmonic_angle", this->m_exec_conf));
90 HarmonicAngleForceComputeGPU::~HarmonicAngleForceComputeGPU()
94 /*! \param type Type of the angle to set parameters for
95 \param K Stiffness parameter for the force computation
96 \param t_0 Equilibrium angle (in radians) for the force computation
98 Sets parameters for the potential of a particular angle type and updates the
99 parameters on the GPU.
101 void HarmonicAngleForceComputeGPU::setParams(unsigned int type, Scalar K, Scalar t_0)
103 HarmonicAngleForceCompute::setParams(type, K, t_0);
105 ArrayHandle<Scalar2> h_params(m_params, access_location::host, access_mode::readwrite);
106 // update the local copy of the memory
107 h_params.data[type] = make_scalar2(K, t_0);
110 /*! Internal method for computing the forces on the GPU.
111 \post The force data on the GPU is written with the calculated forces
113 \param timestep Current time step of the simulation
115 Calls gpu_compute_harmonic_angle_forces to do the dirty work.
117 void HarmonicAngleForceComputeGPU::computeForces(unsigned int timestep)
119 // start the profile
120 if (m_prof) m_prof->push(exec_conf, "Harmonic Angle");
122 // the angle table is up to date: we are good to go. Call the kernel
123 ArrayHandle<Scalar4> d_pos(m_pdata->getPositions(), access_location::device, access_mode::read);
125 BoxDim box = m_pdata->getGlobalBox();
127 ArrayHandle<Scalar4> d_force(m_force,access_location::device,access_mode::overwrite);
128 ArrayHandle<Scalar> d_virial(m_virial,access_location::device,access_mode::overwrite);
129 ArrayHandle<Scalar2> d_params(m_params, access_location::device, access_mode::read);
131 ArrayHandle<AngleData::members_t> d_gpu_anglelist(m_angle_data->getGPUTable(), access_location::device,access_mode::read);
132 ArrayHandle<unsigned int> d_gpu_angle_pos_list(m_angle_data->getGPUPosTable(), access_location::device,access_mode::read);
133 ArrayHandle<unsigned int> d_gpu_n_angles(m_angle_data->getNGroupsArray(), access_location::device, access_mode::read);
135 // run the kernel on the GPU
136 m_tuner->begin();
137 gpu_compute_harmonic_angle_forces(d_force.data,
138 d_virial.data,
139 m_virial.getPitch(),
140 m_pdata->getN(),
141 d_pos.data,
142 box,
143 d_gpu_anglelist.data,
144 d_gpu_angle_pos_list.data,
145 m_angle_data->getGPUTableIndexer().getW(),
146 d_gpu_n_angles.data,
147 d_params.data,
148 m_angle_data->getNTypes(),
149 m_tuner->getParam(),
150 m_exec_conf->getComputeCapability());
152 if (exec_conf->isCUDAErrorCheckingEnabled())
153 CHECK_CUDA_ERROR();
154 m_tuner->end();
156 if (m_prof) m_prof->pop(exec_conf);
159 void export_HarmonicAngleForceComputeGPU()
161 class_<HarmonicAngleForceComputeGPU, boost::shared_ptr<HarmonicAngleForceComputeGPU>, bases<HarmonicAngleForceCompute>, boost::noncopyable >
162 ("HarmonicAngleForceComputeGPU", init< boost::shared_ptr<SystemDefinition> >())