Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
ef627240
Commit
ef627240
authored
Jul 29, 2015
by
peastman
Browse files
Very minor optimizations
parent
c744444a
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
60 additions
and
44 deletions
+60
-44
platforms/cuda/include/CudaBondedUtilities.h
platforms/cuda/include/CudaBondedUtilities.h
+2
-2
platforms/cuda/include/CudaKernels.h
platforms/cuda/include/CudaKernels.h
+1
-1
platforms/cuda/src/CudaBondedUtilities.cpp
platforms/cuda/src/CudaBondedUtilities.cpp
+5
-2
platforms/cuda/src/CudaKernels.cpp
platforms/cuda/src/CudaKernels.cpp
+22
-17
platforms/opencl/include/OpenCLBondedUtilities.h
platforms/opencl/include/OpenCLBondedUtilities.h
+2
-2
platforms/opencl/include/OpenCLKernels.h
platforms/opencl/include/OpenCLKernels.h
+1
-1
platforms/opencl/src/OpenCLBondedUtilities.cpp
platforms/opencl/src/OpenCLBondedUtilities.cpp
+6
-3
platforms/opencl/src/OpenCLKernels.cpp
platforms/opencl/src/OpenCLKernels.cpp
+21
-16
No files found.
platforms/cuda/include/CudaBondedUtilities.h
View file @
ef627240
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2011-201
2
Stanford University and the Authors. *
* Portions copyright (c) 2011-201
5
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -130,7 +130,7 @@ private:
...
@@ -130,7 +130,7 @@ private:
std
::
vector
<
std
::
vector
<
CudaArray
*>
>
atomIndices
;
std
::
vector
<
std
::
vector
<
CudaArray
*>
>
atomIndices
;
std
::
vector
<
std
::
string
>
prefixCode
;
std
::
vector
<
std
::
string
>
prefixCode
;
std
::
vector
<
void
*>
kernelArgs
;
std
::
vector
<
void
*>
kernelArgs
;
int
numForceBuffers
,
maxBonds
;
int
numForceBuffers
,
maxBonds
,
allGroups
;
bool
hasInitializedKernels
,
hasInteractions
;
bool
hasInitializedKernels
,
hasInteractions
;
};
};
...
...
platforms/cuda/include/CudaKernels.h
View file @
ef627240
...
@@ -1294,7 +1294,7 @@ private:
...
@@ -1294,7 +1294,7 @@ private:
double
prevStepSize
,
energy
;
double
prevStepSize
,
energy
;
float
energyFloat
;
float
energyFloat
;
int
numGlobalVariables
;
int
numGlobalVariables
;
bool
hasInitializedKernels
,
deviceValuesAreCurrent
,
deviceGlobalsAreCurrent
,
modifiesParameters
,
keNeedsForce
;
bool
hasInitializedKernels
,
deviceValuesAreCurrent
,
deviceGlobalsAreCurrent
,
modifiesParameters
,
keNeedsForce
,
hasAnyConstraints
;
mutable
bool
localValuesAreCurrent
;
mutable
bool
localValuesAreCurrent
;
CudaArray
*
globalValues
;
CudaArray
*
globalValues
;
CudaArray
*
sumBuffer
;
CudaArray
*
sumBuffer
;
...
...
platforms/cuda/src/CudaBondedUtilities.cpp
View file @
ef627240
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2011-201
2
Stanford University and the Authors. *
* Portions copyright (c) 2011-201
5
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -34,7 +34,7 @@
...
@@ -34,7 +34,7 @@
using
namespace
OpenMM
;
using
namespace
OpenMM
;
using
namespace
std
;
using
namespace
std
;
CudaBondedUtilities
::
CudaBondedUtilities
(
CudaContext
&
context
)
:
context
(
context
),
numForceBuffers
(
0
),
maxBonds
(
0
),
hasInitializedKernels
(
false
)
{
CudaBondedUtilities
::
CudaBondedUtilities
(
CudaContext
&
context
)
:
context
(
context
),
numForceBuffers
(
0
),
maxBonds
(
0
),
allGroups
(
0
),
hasInitializedKernels
(
false
)
{
}
}
CudaBondedUtilities
::~
CudaBondedUtilities
()
{
CudaBondedUtilities
::~
CudaBondedUtilities
()
{
...
@@ -48,6 +48,7 @@ void CudaBondedUtilities::addInteraction(const vector<vector<int> >& atoms, cons
...
@@ -48,6 +48,7 @@ void CudaBondedUtilities::addInteraction(const vector<vector<int> >& atoms, cons
forceAtoms
.
push_back
(
atoms
);
forceAtoms
.
push_back
(
atoms
);
forceSource
.
push_back
(
source
);
forceSource
.
push_back
(
source
);
forceGroup
.
push_back
(
group
);
forceGroup
.
push_back
(
group
);
allGroups
|=
1
<<
group
;
}
}
}
}
...
@@ -152,6 +153,8 @@ string CudaBondedUtilities::createForceSource(int forceIndex, int numBonds, int
...
@@ -152,6 +153,8 @@ string CudaBondedUtilities::createForceSource(int forceIndex, int numBonds, int
}
}
void
CudaBondedUtilities
::
computeInteractions
(
int
groups
)
{
void
CudaBondedUtilities
::
computeInteractions
(
int
groups
)
{
if
((
groups
&
allGroups
)
==
0
)
return
;
if
(
!
hasInitializedKernels
)
{
if
(
!
hasInitializedKernels
)
{
hasInitializedKernels
=
true
;
hasInitializedKernels
=
true
;
kernelArgs
.
push_back
(
&
context
.
getForce
().
getDevicePointer
());
kernelArgs
.
push_back
(
&
context
.
getForce
().
getDevicePointer
());
...
...
platforms/cuda/src/CudaKernels.cpp
View file @
ef627240
...
@@ -5877,8 +5877,10 @@ void CudaIntegrateCustomStepKernel::prepareForComputation(ContextImpl& context,
...
@@ -5877,8 +5877,10 @@ void CudaIntegrateCustomStepKernel::prepareForComputation(ContextImpl& context,
// Determine how each step will represent the position (as just a value, or a value plus a delta).
// Determine how each step will represent the position (as just a value, or a value plus a delta).
hasAnyConstraints
=
(
context
.
getSystem
().
getNumConstraints
()
>
0
);
vector
<
bool
>
storePosAsDelta
(
numSteps
,
false
);
vector
<
bool
>
storePosAsDelta
(
numSteps
,
false
);
vector
<
bool
>
loadPosAsDelta
(
numSteps
,
false
);
vector
<
bool
>
loadPosAsDelta
(
numSteps
,
false
);
if
(
hasAnyConstraints
)
{
bool
beforeConstrain
=
false
;
bool
beforeConstrain
=
false
;
for
(
int
step
=
numSteps
-
1
;
step
>=
0
;
step
--
)
{
for
(
int
step
=
numSteps
-
1
;
step
>=
0
;
step
--
)
{
if
(
stepType
[
step
]
==
CustomIntegrator
::
ConstrainPositions
)
if
(
stepType
[
step
]
==
CustomIntegrator
::
ConstrainPositions
)
...
@@ -5894,6 +5896,7 @@ void CudaIntegrateCustomStepKernel::prepareForComputation(ContextImpl& context,
...
@@ -5894,6 +5896,7 @@ void CudaIntegrateCustomStepKernel::prepareForComputation(ContextImpl& context,
if
(
stepType
[
step
]
==
CustomIntegrator
::
ConstrainPositions
)
if
(
stepType
[
step
]
==
CustomIntegrator
::
ConstrainPositions
)
storedAsDelta
=
false
;
storedAsDelta
=
false
;
}
}
}
// Identify steps that can be merged into a single kernel.
// Identify steps that can be merged into a single kernel.
...
@@ -6214,9 +6217,11 @@ void CudaIntegrateCustomStepKernel::execute(ContextImpl& context, CustomIntegrat
...
@@ -6214,9 +6217,11 @@ void CudaIntegrateCustomStepKernel::execute(ContextImpl& context, CustomIntegrat
context
.
updateContextState
();
context
.
updateContextState
();
}
}
else
if
(
stepType
[
step
]
==
CustomIntegrator
::
ConstrainPositions
)
{
else
if
(
stepType
[
step
]
==
CustomIntegrator
::
ConstrainPositions
)
{
if
(
hasAnyConstraints
)
{
cu
.
getIntegrationUtilities
().
applyConstraints
(
integrator
.
getConstraintTolerance
());
cu
.
getIntegrationUtilities
().
applyConstraints
(
integrator
.
getConstraintTolerance
());
kernelArgs
[
step
][
0
][
1
]
=
&
posCorrection
;
kernelArgs
[
step
][
0
][
1
]
=
&
posCorrection
;
cu
.
executeKernel
(
kernels
[
step
][
0
],
&
kernelArgs
[
step
][
0
][
0
],
numAtoms
);
cu
.
executeKernel
(
kernels
[
step
][
0
],
&
kernelArgs
[
step
][
0
][
0
],
numAtoms
);
}
cu
.
getIntegrationUtilities
().
computeVirtualSites
();
cu
.
getIntegrationUtilities
().
computeVirtualSites
();
}
}
else
if
(
stepType
[
step
]
==
CustomIntegrator
::
ConstrainVelocities
)
{
else
if
(
stepType
[
step
]
==
CustomIntegrator
::
ConstrainVelocities
)
{
...
...
platforms/opencl/include/OpenCLBondedUtilities.h
View file @
ef627240
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2011 Stanford University and the Authors.
*
* Portions copyright (c) 2011
-2015
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -137,7 +137,7 @@ private:
...
@@ -137,7 +137,7 @@ private:
std
::
vector
<
OpenCLArray
*>
atomIndices
;
std
::
vector
<
OpenCLArray
*>
atomIndices
;
std
::
vector
<
OpenCLArray
*>
bufferIndices
;
std
::
vector
<
OpenCLArray
*>
bufferIndices
;
std
::
vector
<
std
::
string
>
prefixCode
;
std
::
vector
<
std
::
string
>
prefixCode
;
int
numForceBuffers
,
maxBonds
;
int
numForceBuffers
,
maxBonds
,
allGroups
;
bool
hasInitializedKernels
;
bool
hasInitializedKernels
;
};
};
...
...
platforms/opencl/include/OpenCLKernels.h
View file @
ef627240
...
@@ -1283,7 +1283,7 @@ private:
...
@@ -1283,7 +1283,7 @@ private:
double
prevStepSize
,
energy
;
double
prevStepSize
,
energy
;
float
energyFloat
;
float
energyFloat
;
int
numGlobalVariables
;
int
numGlobalVariables
;
bool
hasInitializedKernels
,
deviceValuesAreCurrent
,
deviceGlobalsAreCurrent
,
modifiesParameters
,
keNeedsForce
;
bool
hasInitializedKernels
,
deviceValuesAreCurrent
,
deviceGlobalsAreCurrent
,
modifiesParameters
,
keNeedsForce
,
hasAnyConstraints
;
mutable
bool
localValuesAreCurrent
;
mutable
bool
localValuesAreCurrent
;
OpenCLArray
*
globalValues
;
OpenCLArray
*
globalValues
;
OpenCLArray
*
sumBuffer
;
OpenCLArray
*
sumBuffer
;
...
...
platforms/opencl/src/OpenCLBondedUtilities.cpp
View file @
ef627240
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* *
* Portions copyright (c) 2011-201
2
Stanford University and the Authors. *
* Portions copyright (c) 2011-201
5
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -33,7 +33,7 @@
...
@@ -33,7 +33,7 @@
using
namespace
OpenMM
;
using
namespace
OpenMM
;
using
namespace
std
;
using
namespace
std
;
OpenCLBondedUtilities
::
OpenCLBondedUtilities
(
OpenCLContext
&
context
)
:
context
(
context
),
numForceBuffers
(
0
),
maxBonds
(
0
),
hasInitializedKernels
(
false
)
{
OpenCLBondedUtilities
::
OpenCLBondedUtilities
(
OpenCLContext
&
context
)
:
context
(
context
),
numForceBuffers
(
0
),
maxBonds
(
0
),
allGroups
(
0
),
hasInitializedKernels
(
false
)
{
}
}
OpenCLBondedUtilities
::~
OpenCLBondedUtilities
()
{
OpenCLBondedUtilities
::~
OpenCLBondedUtilities
()
{
...
@@ -48,6 +48,7 @@ void OpenCLBondedUtilities::addInteraction(const vector<vector<int> >& atoms, co
...
@@ -48,6 +48,7 @@ void OpenCLBondedUtilities::addInteraction(const vector<vector<int> >& atoms, co
forceAtoms
.
push_back
(
atoms
);
forceAtoms
.
push_back
(
atoms
);
forceSource
.
push_back
(
source
);
forceSource
.
push_back
(
source
);
forceGroup
.
push_back
(
group
);
forceGroup
.
push_back
(
group
);
allGroups
|=
1
<<
group
;
int
width
=
1
;
int
width
=
1
;
while
(
width
<
(
int
)
atoms
[
0
].
size
())
while
(
width
<
(
int
)
atoms
[
0
].
size
())
width
*=
2
;
width
*=
2
;
...
@@ -73,7 +74,7 @@ void OpenCLBondedUtilities::initialize(const System& system) {
...
@@ -73,7 +74,7 @@ void OpenCLBondedUtilities::initialize(const System& system) {
if
(
numForces
==
0
)
if
(
numForces
==
0
)
return
;
return
;
// Build the lists of atom indic
s
e and buffer indices.
// Build the lists of atom indice
s
and buffer indices.
vector
<
vector
<
cl_uint
>
>
bufferVec
(
numForces
);
vector
<
vector
<
cl_uint
>
>
bufferVec
(
numForces
);
vector
<
vector
<
int
>
>
bufferCounter
(
numForces
,
vector
<
int
>
(
system
.
getNumParticles
(),
0
));
vector
<
vector
<
int
>
>
bufferCounter
(
numForces
,
vector
<
int
>
(
system
.
getNumParticles
(),
0
));
...
@@ -253,6 +254,8 @@ string OpenCLBondedUtilities::createForceSource(int forceIndex, int numBonds, in
...
@@ -253,6 +254,8 @@ string OpenCLBondedUtilities::createForceSource(int forceIndex, int numBonds, in
}
}
void
OpenCLBondedUtilities
::
computeInteractions
(
int
groups
)
{
void
OpenCLBondedUtilities
::
computeInteractions
(
int
groups
)
{
if
((
groups
&
allGroups
)
==
0
)
return
;
if
(
!
hasInitializedKernels
)
{
if
(
!
hasInitializedKernels
)
{
hasInitializedKernels
=
true
;
hasInitializedKernels
=
true
;
for
(
int
i
=
0
;
i
<
(
int
)
forceSets
.
size
();
i
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
forceSets
.
size
();
i
++
)
{
...
...
platforms/opencl/src/OpenCLKernels.cpp
View file @
ef627240
...
@@ -6141,8 +6141,10 @@ void OpenCLIntegrateCustomStepKernel::prepareForComputation(ContextImpl& context
...
@@ -6141,8 +6141,10 @@ void OpenCLIntegrateCustomStepKernel::prepareForComputation(ContextImpl& context
// Determine how each step will represent the position (as just a value, or a value plus a delta).
// Determine how each step will represent the position (as just a value, or a value plus a delta).
hasAnyConstraints
=
(
context
.
getSystem
().
getNumConstraints
()
>
0
);
vector
<
bool
>
storePosAsDelta
(
numSteps
,
false
);
vector
<
bool
>
storePosAsDelta
(
numSteps
,
false
);
vector
<
bool
>
loadPosAsDelta
(
numSteps
,
false
);
vector
<
bool
>
loadPosAsDelta
(
numSteps
,
false
);
if
(
hasAnyConstraints
)
{
bool
beforeConstrain
=
false
;
bool
beforeConstrain
=
false
;
for
(
int
step
=
numSteps
-
1
;
step
>=
0
;
step
--
)
{
for
(
int
step
=
numSteps
-
1
;
step
>=
0
;
step
--
)
{
if
(
stepType
[
step
]
==
CustomIntegrator
::
ConstrainPositions
)
if
(
stepType
[
step
]
==
CustomIntegrator
::
ConstrainPositions
)
...
@@ -6158,6 +6160,7 @@ void OpenCLIntegrateCustomStepKernel::prepareForComputation(ContextImpl& context
...
@@ -6158,6 +6160,7 @@ void OpenCLIntegrateCustomStepKernel::prepareForComputation(ContextImpl& context
if
(
stepType
[
step
]
==
CustomIntegrator
::
ConstrainPositions
)
if
(
stepType
[
step
]
==
CustomIntegrator
::
ConstrainPositions
)
storedAsDelta
=
false
;
storedAsDelta
=
false
;
}
}
}
// Identify steps that can be merged into a single kernel.
// Identify steps that can be merged into a single kernel.
...
@@ -6478,8 +6481,10 @@ void OpenCLIntegrateCustomStepKernel::execute(ContextImpl& context, CustomIntegr
...
@@ -6478,8 +6481,10 @@ void OpenCLIntegrateCustomStepKernel::execute(ContextImpl& context, CustomIntegr
context
.
updateContextState
();
context
.
updateContextState
();
}
}
else
if
(
stepType
[
step
]
==
CustomIntegrator
::
ConstrainPositions
)
{
else
if
(
stepType
[
step
]
==
CustomIntegrator
::
ConstrainPositions
)
{
if
(
hasAnyConstraints
)
{
cl
.
getIntegrationUtilities
().
applyConstraints
(
integrator
.
getConstraintTolerance
());
cl
.
getIntegrationUtilities
().
applyConstraints
(
integrator
.
getConstraintTolerance
());
cl
.
executeKernel
(
kernels
[
step
][
0
],
numAtoms
);
cl
.
executeKernel
(
kernels
[
step
][
0
],
numAtoms
);
}
cl
.
getIntegrationUtilities
().
computeVirtualSites
();
cl
.
getIntegrationUtilities
().
computeVirtualSites
();
}
}
else
if
(
stepType
[
step
]
==
CustomIntegrator
::
ConstrainVelocities
)
{
else
if
(
stepType
[
step
]
==
CustomIntegrator
::
ConstrainVelocities
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment