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
1c528ca8
Unverified
Commit
1c528ca8
authored
Mar 27, 2026
by
Evan Pretti
Committed by
GitHub
Mar 27, 2026
Browse files
Take line search energy difference on CPU before reducing precision (#5242)
parent
26df7a87
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
22 deletions
+11
-22
platforms/common/include/openmm/common/CommonMinimizeKernel.h
...forms/common/include/openmm/common/CommonMinimizeKernel.h
+1
-1
platforms/common/src/CommonMinimizeKernel.cpp
platforms/common/src/CommonMinimizeKernel.cpp
+5
-12
platforms/common/src/kernels/minimize.cc
platforms/common/src/kernels/minimize.cc
+5
-9
No files found.
platforms/common/include/openmm/common/CommonMinimizeKernel.h
View file @
1c528ca8
...
...
@@ -98,7 +98,7 @@ private:
int
maxIterations
;
MinimizationReporter
*
reporter
;
double
kRestraint
,
energy
;
double
kRestraint
,
energy
,
energyStart
;
bool
largeGrad
;
ComputeArray
constraintIndices
,
constraintDistances
;
...
...
platforms/common/src/CommonMinimizeKernel.cpp
View file @
1c528ca8
...
...
@@ -173,8 +173,8 @@ void CommonMinimizeKernel::setup(ContextImpl& context) {
returnFlag
.
initialize
<
int
>
(
cc
,
1
,
"returnFlag"
);
returnValue
.
initialize
(
cc
,
1
,
elementSize
,
"returnValue"
);
gradNorm
.
initialize
(
cc
,
1
,
elementSize
,
"gradNorm"
);
lineSearchData
.
initialize
(
cc
,
4
,
elementSize
,
"lineSearchData"
);
lineSearchDataBackup
.
initialize
(
cc
,
4
,
elementSize
,
"lineSearchDataBackup"
);
lineSearchData
.
initialize
(
cc
,
3
,
elementSize
,
"lineSearchData"
);
lineSearchDataBackup
.
initialize
(
cc
,
3
,
elementSize
,
"lineSearchDataBackup"
);
// Compile kernels and set arguments.
...
...
@@ -341,7 +341,6 @@ void CommonMinimizeKernel::setup(ContextImpl& context) {
lineSearchSetupKernel
->
addArg
(
gradNorm
);
lineSearchSetupKernel
->
addArg
(
lineSearchData
);
lineSearchSetupKernel
->
addArg
(
numVariables
);
lineSearchSetupKernel
->
addArg
();
// energyStart
lineSearchStepKernel
=
program
->
createKernel
(
"lineSearchStep"
);
lineSearchStepKernel
->
addArg
(
x
);
...
...
@@ -405,12 +404,7 @@ void CommonMinimizeKernel::lbfgs(ContextImpl& context) {
for
(
int
iteration
=
1
,
end
=
0
;;)
{
// Prepare for a line search.
if
(
mixedIsDouble
)
{
lineSearchSetupKernel
->
setArg
(
9
,
energy
);
}
else
{
lineSearchSetupKernel
->
setArg
(
9
,
(
float
)
energy
);
}
energyStart
=
energy
;
lineSearchSetupKernel
->
execute
(
numVariables
);
// Take line search steps.
...
...
@@ -746,11 +740,10 @@ double CommonMinimizeKernel::downloadGradNormSync() {
void
CommonMinimizeKernel
::
runLineSearchKernels
()
{
if
(
mixedIsDouble
)
{
lineSearchDotKernel
->
setArg
(
6
,
isfinite
(
energy
)
?
energy
:
(
double
)
std
::
numeric_limits
<
float
>::
max
());
lineSearchDotKernel
->
setArg
(
6
,
isfinite
(
energy
)
?
energy
-
energyStart
:
(
double
)
std
::
numeric_limits
<
float
>::
max
());
}
else
{
float
hostEnergy
=
(
float
)
energy
;
lineSearchDotKernel
->
setArg
(
6
,
isfinite
(
hostEnergy
)
?
hostEnergy
:
std
::
numeric_limits
<
float
>::
max
());
lineSearchDotKernel
->
setArg
(
6
,
isfinite
((
float
)
energy
)
?
(
float
)
(
energy
-
energyStart
)
:
std
::
numeric_limits
<
float
>::
max
());
}
lineSearchDotKernel
->
execute
(
numVariables
);
lineSearchContinueKernel
->
execute
(
1
);
...
...
platforms/common/src/kernels/minimize.cc
View file @
1c528ca8
#define LS_DOT_START 0
#define LS_DOT 1
#define LS_ENERGY 2
#define LS_STEP 3
#define LS_STEP 2
#define LS_FAIL 0
#define LS_SUCCEED 1
...
...
@@ -668,8 +667,7 @@ KERNEL void lineSearchSetup(
GLOBAL
int
*
RESTRICT
returnFlag
,
GLOBAL
mixed
*
RESTRICT
gradNorm
,
GLOBAL
mixed
*
RESTRICT
lineSearchData
,
const
int
numVariables
,
const
mixed
energyStart
const
int
numVariables
)
{
LOCAL
volatile
mixed
temp
[
TEMP_SIZE
];
...
...
@@ -694,7 +692,6 @@ KERNEL void lineSearchSetup(
if
(
GLOBAL_ID
==
0
)
{
*
returnFlag
=
LS_CONTINUE
;
*
gradNorm
=
0
;
lineSearchData
[
LS_ENERGY
]
=
energyStart
;
}
}
...
...
@@ -758,7 +755,6 @@ KERNEL void lineSearchStep(
lineSearchDataBackup
[
LS_DOT_START
]
=
lineSearchData
[
LS_DOT_START
];
lineSearchDataBackup
[
LS_DOT
]
=
lineSearchData
[
LS_DOT
]
=
0
;
lineSearchDataBackup
[
LS_ENERGY
]
=
lineSearchData
[
LS_ENERGY
];
lineSearchDataBackup
[
LS_STEP
]
=
lineSearchData
[
LS_STEP
];
}
}
...
...
@@ -770,7 +766,7 @@ KERNEL void lineSearchDot(
GLOBAL
int
*
RESTRICT
returnFlag
,
GLOBAL
const
mixed
*
RESTRICT
returnValue
,
const
int
numVariables
,
mixed
e
nergy
mixed
deltaE
nergy
)
{
LOCAL
volatile
mixed
temp
[
TEMP_SIZE
];
...
...
@@ -781,13 +777,13 @@ KERNEL void lineSearchDot(
// Any restraint energy in returnValue hasn't been downloaded yet to be
// passed back up in the energy parameter, so add it in here.
e
nergy
+=
*
returnValue
;
deltaE
nergy
+=
*
returnValue
;
// The energy may be such that we don't need to do a dot product and can
// immediately decide to scale the step, so mark this case with LS_SUCCEED.
// This will be checked in the following kernel.
if
(
!
(
FABS_MIXED
(
e
nergy
)
<
FLT_MAX
)
||
e
nergy
>
lineSearchData
[
LS_ENERGY
]
+
lineSearchData
[
LS_STEP
]
*
LBFGS_FTOL
*
lineSearchData
[
LS_DOT_START
])
{
if
(
!
(
FABS_MIXED
(
deltaE
nergy
)
<
FLT_MAX
)
||
deltaE
nergy
>
lineSearchData
[
LS_STEP
]
*
LBFGS_FTOL
*
lineSearchData
[
LS_DOT_START
])
{
if
(
GLOBAL_ID
==
0
)
{
*
returnFlag
=
LS_SUCCEED
;
}
...
...
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