Merge branch 'maint'
[hoomd-blue.git] / libhoomd / computes_gpu / HarmonicDihedralForceComputeGPU.cc
blob44337dd5e1ca322d3adb3c647d108f3828dafac5
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 HarmonicDihedralForceComputeGPU.cc
53 \brief Defines HarmonicDihedralForceComputeGPU
56 #ifdef WIN32
57 #pragma warning( push )
58 #pragma warning( disable : 4244 )
59 #endif
61 #include "HarmonicDihedralForceComputeGPU.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 bond forces on
73 HarmonicDihedralForceComputeGPU::HarmonicDihedralForceComputeGPU(boost::shared_ptr<SystemDefinition> sysdef)
74 : HarmonicDihedralForceCompute(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 DihedralForceComputeGPU with no GPU in the execution configuration" << endl;
80 throw std::runtime_error("Error initializing DihedralForceComputeGPU");
83 // allocate and zero device memory
84 GPUArray<Scalar4> params(m_dihedral_data->getNTypes(),exec_conf);
85 m_params.swap(params);
87 m_tuner.reset(new Autotuner(32, 1024, 32, 5, 100000, "harmonic_dihedral", this->m_exec_conf));
90 HarmonicDihedralForceComputeGPU::~HarmonicDihedralForceComputeGPU()
94 /*! \param type Type of the dihedral to set parameters for
95 \param K Stiffness parameter for the force computation
96 \param sign the sign of the cosine term
97 \param multiplicity the multiplicity of the cosine term
99 Sets parameters for the potential of a particular dihedral type and updates the
100 parameters on the GPU.
102 void HarmonicDihedralForceComputeGPU::setParams(unsigned int type, Scalar K, int sign, unsigned int multiplicity)
104 HarmonicDihedralForceCompute::setParams(type, K, sign, multiplicity);
106 ArrayHandle<Scalar4> h_params(m_params, access_location::host, access_mode::readwrite);
107 // update the local copy of the memory
108 h_params.data[type] = make_scalar4(Scalar(K), Scalar(sign), Scalar(multiplicity), Scalar(0.0));
111 /*! Internal method for computing the forces on the GPU.
112 \post The force data on the GPU is written with the calculated forces
114 \param timestep Current time step of the simulation
116 Calls gpu_compute_harmonic_dihedral_forces to do the dirty work.
118 void HarmonicDihedralForceComputeGPU::computeForces(unsigned int timestep)
120 // start the profile
121 if (m_prof) m_prof->push(exec_conf, "Harmonic Dihedral");
123 ArrayHandle<DihedralData::members_t> d_gpu_dihedral_list(m_dihedral_data->getGPUTable(), access_location::device,access_mode::read);
124 ArrayHandle<unsigned int> d_n_dihedrals(m_dihedral_data->getNGroupsArray(), access_location::device, access_mode::read);
125 ArrayHandle<unsigned int> d_dihedrals_ABCD(m_dihedral_data->getGPUPosTable(), access_location::device, access_mode::read);
127 // the dihedral table is up to date: we are good to go. Call the kernel
128 ArrayHandle<Scalar4> d_pos(m_pdata->getPositions(), access_location::device, access_mode::read);
129 BoxDim box = m_pdata->getGlobalBox();
131 ArrayHandle<Scalar4> d_force(m_force,access_location::device,access_mode::overwrite);
132 ArrayHandle<Scalar> d_virial(m_virial,access_location::device,access_mode::overwrite);
133 ArrayHandle<Scalar4> d_params(m_params, access_location::device, access_mode::read);
135 // run the kernel in parallel on all GPUs
136 this->m_tuner->begin();
137 gpu_compute_harmonic_dihedral_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_dihedral_list.data,
144 d_dihedrals_ABCD.data,
145 m_dihedral_data->getGPUTableIndexer().getW(),
146 d_n_dihedrals.data,
147 d_params.data,
148 m_dihedral_data->getNTypes(),
149 this->m_tuner->getParam(),
150 m_exec_conf->getComputeCapability());
151 if (exec_conf->isCUDAErrorCheckingEnabled())
152 CHECK_CUDA_ERROR();
153 this->m_tuner->end();
155 if (m_prof) m_prof->pop(exec_conf);
158 void export_HarmonicDihedralForceComputeGPU()
160 class_<HarmonicDihedralForceComputeGPU, boost::shared_ptr<HarmonicDihedralForceComputeGPU>, bases<HarmonicDihedralForceCompute>, boost::noncopyable >
161 ("HarmonicDihedralForceComputeGPU", init< boost::shared_ptr<SystemDefinition> >())