Merge branch 'maint'
[hoomd-blue.git] / libhoomd / computes_gpu / TablePotentialGPU.cc
blob157651424cacd9e4fd80dcf40b7765dae1f6561f
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: joaander
52 #ifdef WIN32
53 #pragma warning( push )
54 #pragma warning( disable : 4103 4244 )
55 #endif
57 #include <boost/python.hpp>
58 using namespace boost::python;
59 #include <boost/bind.hpp>
60 using namespace boost;
62 #include "TablePotentialGPU.h"
63 #include <stdexcept>
65 /*! \file TablePotentialGPU.cc
66 \brief Defines the TablePotentialGPU class
69 using namespace std;
71 /*! \param sysdef System to compute forces on
72 \param nlist Neighborlist to use for computing the forces
73 \param table_width Width the tables will be in memory
74 \param log_suffix Name given to this instance of the table potential
76 TablePotentialGPU::TablePotentialGPU(boost::shared_ptr<SystemDefinition> sysdef,
77 boost::shared_ptr<NeighborList> nlist,
78 unsigned int table_width,
79 const std::string& log_suffix)
80 : TablePotential(sysdef, nlist, table_width, log_suffix)
82 // can't run on the GPU if there aren't any GPUs in the execution configuration
83 if (!exec_conf->isCUDAEnabled())
85 m_exec_conf->msg->error() << "Creating a TableForceComputeGPUwith no GPU in the execution configuration" << endl;
86 throw std::runtime_error("Error initializing TableForceComputeGPU");
89 m_tuner.reset(new Autotuner(32, 1024, 32, 5, 100000, "pair_table", this->m_exec_conf));
92 /*! \post The table based forces are computed for the given timestep. The neighborlist's
93 compute method is called to ensure that it is up to date.
95 \param timestep specifies the current time step of the simulation
97 Calls gpu_compute_table_forces to do the leg work
99 void TablePotentialGPU::computeForces(unsigned int timestep)
101 // start by updating the neighborlist
102 m_nlist->compute(timestep);
104 // start the profile
105 if (m_prof) m_prof->push(exec_conf, "Table pair");
107 // The GPU implementation CANNOT handle a half neighborlist, error out now
108 bool third_law = m_nlist->getStorageMode() == NeighborList::half;
109 if (third_law)
111 m_exec_conf->msg->error() << "TablePotentialGPU cannot handle a half neighborlist" << endl;
112 throw runtime_error("Error computing forces in TablePotentialGPU");
115 // access the neighbor list
116 ArrayHandle<unsigned int> d_n_neigh(this->m_nlist->getNNeighArray(), access_location::device, access_mode::read);
117 ArrayHandle<unsigned int> d_nlist(this->m_nlist->getNListArray(), access_location::device, access_mode::read);
118 Index2D nli = this->m_nlist->getNListIndexer();
120 // access the particle data
121 ArrayHandle<Scalar4> d_pos(m_pdata->getPositions(), access_location::device, access_mode::read);
122 BoxDim box = m_pdata->getBox();
124 // access the table data
125 ArrayHandle<Scalar2> d_tables(m_tables, access_location::device, access_mode::read);
126 ArrayHandle<Scalar4> d_params(m_params, access_location::device, access_mode::read);
128 ArrayHandle<Scalar4> d_force(m_force,access_location::device,access_mode::overwrite);
129 ArrayHandle<Scalar> d_virial(m_virial,access_location::device,access_mode::overwrite);
131 // run the kernel on all GPUs in parallel
132 m_tuner->begin();
133 gpu_compute_table_forces(d_force.data,
134 d_virial.data,
135 m_virial.getPitch(),
136 m_pdata->getN(),
137 m_pdata->getNGhosts(),
138 d_pos.data,
139 box,
140 d_n_neigh.data,
141 d_nlist.data,
142 nli,
143 d_tables.data,
144 d_params.data,
145 m_ntypes,
146 m_table_width,
147 m_tuner->getParam(),
148 m_exec_conf->getComputeCapability());
150 if (exec_conf->isCUDAErrorCheckingEnabled())
151 CHECK_CUDA_ERROR();
152 m_tuner->end();
154 if (m_prof) m_prof->pop(exec_conf);
157 void export_TablePotentialGPU()
159 class_<TablePotentialGPU, boost::shared_ptr<TablePotentialGPU>, bases<TablePotential>, boost::noncopyable >
160 ("TablePotentialGPU",
161 init< boost::shared_ptr<SystemDefinition>,
162 boost::shared_ptr<NeighborList>,
163 unsigned int,
164 const std::string& >())
168 #ifdef WIN32
169 #pragma warning( pop )
170 #endif