gfx936-dtk26.04.patch 32.6 KB
Newer Older
one's avatar
one committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
diff --git a/examples/benchmarks/benchmark.py b/examples/benchmarks/benchmark.py
index f3eb95a88..f9fea45c2 100644
--- a/examples/benchmarks/benchmark.py
+++ b/examples/benchmarks/benchmark.py
@@ -354,6 +354,8 @@ def runOneTest(testName, options):
             initialSteps = 250
     if options.disable_pme_stream:
         properties['DisablePmeStream'] = 'true'
+    if options.platform == 'HIP' and options.fft_backend is not None and 'FFTBackend' in platform.getPropertyNames():
+        properties['FFTBackend'] = options.fft_backend
     if options.opencl_platform is not None and 'OpenCLPlatformIndex' in platform.getPropertyNames():
         properties['OpenCLPlatformIndex'] = options.opencl_platform
     if (options.precision is not None) and ('Precision' in platform.getPropertyNames()):
@@ -481,6 +483,7 @@ parser.add_argument('--polarization', default='mutual', dest='polarization', cho
 parser.add_argument('--mutual-epsilon', default=1e-5, dest='epsilon', type=float, help='mutual induced epsilon for AMOEBA [default: 1e-5]')
 parser.add_argument('--bond-constraints', default='hbonds', dest='bond_constraints', help=f'hbonds: constrain bonds to hydrogen, use 1.5*amu H mass; allbonds: constrain all bonds, use 4*amu H mass, and use larger timestep. This option is ignored for AMOEBA: {BOND_CONSTRAINTS} [default: hbonds]')
 parser.add_argument('--disable-pme-stream', default=False, action='store_true', dest='disable_pme_stream', help='disable use of a separate GPU stream for PME')
+parser.add_argument('--fft-backend', default=None, dest='fft_backend', help='FFT backend for HIP platform (for example: vkfft or hipfft)')
 parser.add_argument('--device', default=None, dest='device', help='device index for CUDA, HIP, or OpenCL')
 parser.add_argument('--opencl-platform', default=None, dest='opencl_platform', help='platform index for OpenCL')
 parser.add_argument('--precision', default='single', dest='precision', help=f'precision modes for CUDA, HIP, or OpenCL: {PRECISIONS} [default: single]')
one's avatar
one committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
diff --git a/platforms/common/include/openmm/common/CommonCalcNonbondedForce.h b/platforms/common/include/openmm/common/CommonCalcNonbondedForce.h
index 91416216e..e5fd1f6ec 100644
--- a/platforms/common/include/openmm/common/CommonCalcNonbondedForce.h
+++ b/platforms/common/include/openmm/common/CommonCalcNonbondedForce.h
@@ -45,7 +45,7 @@ namespace OpenMM {
 class CommonCalcNonbondedForceKernel : public CalcNonbondedForceKernel {
 public:
     CommonCalcNonbondedForceKernel(std::string name, const Platform& platform, ComputeContext& cc, const System& system) : CalcNonbondedForceKernel(name, platform),
-            hasInitializedKernel(false), cc(cc), pmeio(NULL), stepsToSort(0) {
+            hasInitializedKernel(false), cc(cc), pmeio(NULL), stepsToSort(0), dispersionStepsToSort(0) {
     }
     ~CommonCalcNonbondedForceKernel();
     /**
@@ -140,6 +140,7 @@ private:
     ComputeArray pmeDispersionBsplineModuliY;
     ComputeArray pmeDispersionBsplineModuliZ;
     ComputeArray pmeAtomGridIndex;
+    ComputeArray pmeDispersionAtomGridIndex;
     ComputeArray pmeEnergyBuffer;
     ComputeArray chargeBuffer;
     ComputeSort sort;
@@ -167,6 +168,7 @@ private:
     int gridSizeX, gridSizeY, gridSizeZ;
     int dispersionGridSizeX, dispersionGridSizeY, dispersionGridSizeZ;
     int stepsToSort;
+    int dispersionStepsToSort;
     bool usePmeQueue, deviceIsCpu, useFixedPointChargeSpreading, useCpuPme;
     bool hasCoulomb, hasLJ, doLJPME, usePosqCharges, recomputeParams, hasOffsets;
     NonbondedMethod nonbondedMethod;
one's avatar
one committed
51
diff --git a/platforms/common/src/CommonCalcNonbondedForce.cpp b/platforms/common/src/CommonCalcNonbondedForce.cpp
one's avatar
one committed
52
index bab0679b7..27277ebfc 100644
one's avatar
one committed
53
54
--- a/platforms/common/src/CommonCalcNonbondedForce.cpp
+++ b/platforms/common/src/CommonCalcNonbondedForce.cpp
one's avatar
one committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
@@ -457,6 +457,8 @@ void CommonCalcNonbondedForceKernel::commonInitialize(const System& system, cons
                     pmeDispersionBsplineModuliZ.initialize(cc, dispersionGridSizeZ, elementSize, "pmeDispersionBsplineModuliZ");
                 }
                 pmeAtomGridIndex.initialize<mm_int2>(cc, numParticles, "pmeAtomGridIndex");
+                if (doLJPME)
+                    pmeDispersionAtomGridIndex.initialize<mm_int2>(cc, numParticles, "pmeDispersionAtomGridIndex");
                 int energyElementSize = (cc.getUseDoublePrecision() || cc.getUseMixedPrecision() ? sizeof(double) : sizeof(float));
                 pmeEnergyBuffer.initialize(cc, cc.getNumThreadBlocks()*ComputeContext::ThreadBlockSize, energyElementSize, "pmeEnergyBuffer");
                 cc.clearBuffer(pmeEnergyBuffer);
@@ -836,7 +838,7 @@ double CommonCalcNonbondedForceKernel::execute(ContextImpl& context, bool includ
                 pmeDispersionEvalEnergyKernel = program->createKernel("gridEvaluateEnergy");
                 pmeDispersionInterpolateForceKernel = program->createKernel("gridInterpolateForce");
                 pmeDispersionGridIndexKernel->addArg(cc.getPosq());
-                pmeDispersionGridIndexKernel->addArg(pmeAtomGridIndex);
+                pmeDispersionGridIndexKernel->addArg(pmeDispersionAtomGridIndex);
                 for (int i = 0; i < 8; i++)
                     pmeDispersionGridIndexKernel->addArg();
                 pmeDispersionSpreadChargeKernel->addArg(cc.getPosq());
@@ -846,7 +848,7 @@ double CommonCalcNonbondedForceKernel::execute(ContextImpl& context, bool includ
                     pmeDispersionSpreadChargeKernel->addArg(pmeGrid1);
                 for (int i = 0; i < 8; i++)
                     pmeDispersionSpreadChargeKernel->addArg();
-                pmeDispersionSpreadChargeKernel->addArg(pmeAtomGridIndex);
+                pmeDispersionSpreadChargeKernel->addArg(pmeDispersionAtomGridIndex);
                 pmeDispersionSpreadChargeKernel->addArg(sigmaEpsilon);
                 pmeDispersionConvolutionKernel->addArg(pmeGrid2);
                 pmeDispersionConvolutionKernel->addArg(pmeDispersionBsplineModuliX);
@@ -869,7 +871,7 @@ double CommonCalcNonbondedForceKernel::execute(ContextImpl& context, bool includ
                 pmeDispersionInterpolateForceKernel->addArg(pmeGrid1);
                 for (int i = 0; i < 8; i++)
                     pmeDispersionInterpolateForceKernel->addArg();
-                pmeDispersionInterpolateForceKernel->addArg(pmeAtomGridIndex);
+                pmeDispersionInterpolateForceKernel->addArg(pmeDispersionAtomGridIndex);
                 pmeDispersionInterpolateForceKernel->addArg(sigmaEpsilon);
                 if (useFixedPointChargeSpreading) {
                     pmeDispersionFinishSpreadChargeKernel = program->createKernel("finishSpreadCharge");
@@ -962,7 +964,7 @@ double CommonCalcNonbondedForceKernel::execute(ContextImpl& context, bool includ
one's avatar
one committed
92
93
94
95
         // Execute the reciprocal space kernels.
 
         if (hasCoulomb) {
-            if (stepsToSort <= 0 || doLJPME || cc.getNumAtoms() > 15000) {
one's avatar
one committed
96
+            if (stepsToSort <= 0) {
one's avatar
one committed
97
98
99
                 setPeriodicBoxArgs(cc, pmeGridIndexKernel, 2);
                 if (cc.getUseDoublePrecision()) {
                     pmeGridIndexKernel->setArg(7, recipBoxVectors[0]);
one's avatar
one committed
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
@@ -1033,19 +1035,24 @@ double CommonCalcNonbondedForceKernel::execute(ContextImpl& context, bool includ
         }
 
         if (doLJPME && hasLJ) {
-            setPeriodicBoxArgs(cc, pmeDispersionGridIndexKernel, 2);
-            if (cc.getUseDoublePrecision()) {
-                pmeDispersionGridIndexKernel->setArg(7, recipBoxVectors[0]);
-                pmeDispersionGridIndexKernel->setArg(8, recipBoxVectors[1]);
-                pmeDispersionGridIndexKernel->setArg(9, recipBoxVectors[2]);
-            }
-            else {
-                pmeDispersionGridIndexKernel->setArg(7, recipBoxVectorsFloat[0]);
-                pmeDispersionGridIndexKernel->setArg(8, recipBoxVectorsFloat[1]);
-                pmeDispersionGridIndexKernel->setArg(9, recipBoxVectorsFloat[2]);
+            if (dispersionStepsToSort <= 0) {
+                setPeriodicBoxArgs(cc, pmeDispersionGridIndexKernel, 2);
+                if (cc.getUseDoublePrecision()) {
+                    pmeDispersionGridIndexKernel->setArg(7, recipBoxVectors[0]);
+                    pmeDispersionGridIndexKernel->setArg(8, recipBoxVectors[1]);
+                    pmeDispersionGridIndexKernel->setArg(9, recipBoxVectors[2]);
+                }
+                else {
+                    pmeDispersionGridIndexKernel->setArg(7, recipBoxVectorsFloat[0]);
+                    pmeDispersionGridIndexKernel->setArg(8, recipBoxVectorsFloat[1]);
+                    pmeDispersionGridIndexKernel->setArg(9, recipBoxVectorsFloat[2]);
+                }
+                pmeDispersionGridIndexKernel->execute(cc.getNumAtoms());
+                sort->sort(pmeDispersionAtomGridIndex);
+                dispersionStepsToSort = 3;
             }
-            pmeDispersionGridIndexKernel->execute(cc.getNumAtoms());
-            sort->sort(pmeAtomGridIndex);
+            else
+                dispersionStepsToSort--;
             if (useFixedPointChargeSpreading)
                 cc.clearBuffer(pmeGrid2);
             else
one's avatar
one committed
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
diff --git a/platforms/hip/CMakeLists.txt b/platforms/hip/CMakeLists.txt
index 7c8dfca8f..2ca6f35d7 100644
--- a/platforms/hip/CMakeLists.txt
+++ b/platforms/hip/CMakeLists.txt
@@ -12,7 +12,23 @@
 #   libOpenMMHIP_static.a
 #----------------------------------------------------
 
-FIND_PACKAGE(HIPRTC CONFIG)
+IF(NOT TARGET hiprtc::hiprtc)
+    add_library(hiprtc::hiprtc SHARED IMPORTED)
+    set_target_properties(hiprtc::hiprtc PROPERTIES
+        IMPORTED_LOCATION "/opt/dtk/hip/lib/libhiprtc.so"
+        INTERFACE_INCLUDE_DIRECTORIES "/opt/dtk/hip/include"
+    )
+ENDIF()
+
+FIND_PACKAGE(HIPFFT CONFIG QUIET)
+
+IF(NOT TARGET hiprtc::hiprtc)
+    add_library(hiprtc::hiprtc SHARED IMPORTED)
+    set_target_properties(hiprtc::hiprtc PROPERTIES
+        IMPORTED_LOCATION "/opt/dtk/hip/lib/libhiprtc.so"
+        INTERFACE_INCLUDE_DIRECTORIES "/opt/dtk/hip/include"
+    )
+ENDIF()
 
 SET(OPENMM_BUILD_HIP_TESTS TRUE CACHE BOOL "Whether to build HIP test cases")
 IF(BUILD_TESTING AND OPENMM_BUILD_HIP_TESTS)
@@ -103,6 +119,10 @@ IF(OPENMM_BUILD_SHARED_LIB)
     TARGET_LINK_LIBRARIES(${SHARED_TARGET} PUBLIC ${OPENMM_LIBRARY_NAME} hip::host hiprtc::hiprtc)
     SET_TARGET_PROPERTIES(${SHARED_TARGET} PROPERTIES COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -DOPENMM_COMMON_BUILDING_SHARED_LIBRARY")
     SET_TARGET_PROPERTIES(${SHARED_TARGET} PROPERTIES LINK_FLAGS "${EXTRA_LINK_FLAGS}")
+    IF(HIPFFT_FOUND)
+        TARGET_LINK_LIBRARIES(${SHARED_TARGET} PUBLIC hip::hipfft)
+        TARGET_COMPILE_OPTIONS(${SHARED_TARGET} PUBLIC "-DOPENMM_HIP_WITH_HIPFFT")
+    ENDIF()
 
     INSTALL_TARGETS(/lib/plugins RUNTIME_DIRECTORY /lib/plugins ${SHARED_TARGET})
 ENDIF(OPENMM_BUILD_SHARED_LIB)
@@ -116,6 +136,10 @@ IF(OPENMM_BUILD_STATIC_LIB)
     TARGET_LINK_LIBRARIES(${STATIC_TARGET} ${OPENMM_LIBRARY_NAME} hip::host hiprtc::hiprtc)
     SET_TARGET_PROPERTIES(${STATIC_TARGET} PROPERTIES COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -DOPENMM_COMMON_BUILDING_STATIC_LIBRARY")
     SET_TARGET_PROPERTIES(${STATIC_TARGET} PROPERTIES LINK_FLAGS "${EXTRA_LINK_FLAGS}")
+    IF(HIPFFT_FOUND)
+        TARGET_LINK_LIBRARIES(${STATIC_TARGET} PUBLIC hip::hipfft)
+        TARGET_COMPILE_OPTIONS(${STATIC_TARGET} PUBLIC "-DOPENMM_HIP_WITH_HIPFFT")
+    ENDIF()
 
     INSTALL_TARGETS(/lib/plugins RUNTIME_DIRECTORY /lib/plugins ${STATIC_TARGET})
 ENDIF(OPENMM_BUILD_STATIC_LIB)
diff --git a/platforms/hip/include/HipHipFFT3D.h b/platforms/hip/include/HipHipFFT3D.h
new file mode 100644
index 000000000..af509e4fc
--- /dev/null
+++ b/platforms/hip/include/HipHipFFT3D.h
@@ -0,0 +1,60 @@
+#ifndef __OPENMM_HIPHIPFFT3D_H__
+#define __OPENMM_HIPHIPFFT3D_H__
+
+/* -------------------------------------------------------------------------- *
+ *                                   OpenMM                                   *
+ * -------------------------------------------------------------------------- *
+ * This is part of the OpenMM molecular simulation toolkit.                   *
+ * See https://openmm.org/development.                                        *
+ *                                                                            *
+ * Portions copyright (c) 2009-2026 Stanford University and the Authors.      *
+ * Contributors:                                                              *
+ *                                                                            *
+ * This program is free software: you can redistribute it and/or modify       *
+ * it under the terms of the GNU Lesser General Public License as published   *
+ * by the Free Software Foundation, either version 3 of the License, or       *
+ * (at your option) any later version.                                        *
+ *                                                                            *
+ * This program is distributed in the hope that it will be useful,            *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
+ * GNU Lesser General Public License for more details.                        *
+ *                                                                            *
+ * You should have received a copy of the GNU Lesser General Public License   *
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.      *
+ * -------------------------------------------------------------------------- */
+
+#include "openmm/common/windowsExportCommon.h"
+#include "openmm/common/FFT3D.h"
+#include "openmm/common/ArrayInterface.h"
+
+#ifdef OPENMM_HIP_WITH_HIPFFT
+#if __has_include(<hipfft/hipfft.h>)
+#include <hipfft/hipfft.h>
+#else
+#include <hipfft.h>
+#endif
+#endif
+
+namespace OpenMM {
+
+class HipContext;
+
+class OPENMM_EXPORT_COMMON HipHipFFT3D : public FFT3DImpl {
+public:
+    HipHipFFT3D(HipContext& context, int xsize, int ysize, int zsize, bool realToComplex);
+    ~HipHipFFT3D();
+    void execFFT(ArrayInterface& in, ArrayInterface& out, bool forward=true) override;
+private:
+    HipContext& context;
+    bool realToComplex;
+    bool doublePrecision;
+#ifdef OPENMM_HIP_WITH_HIPFFT
+    hipfftHandle forwardPlan;
+    hipfftHandle backwardPlan;
+#endif
+};
+
+} // namespace OpenMM
+
+#endif // __OPENMM_HIPHIPFFT3D_H__
diff --git a/platforms/hip/include/HipPlatform.h b/platforms/hip/include/HipPlatform.h
index a0665d45c..43eba16af 100644
--- a/platforms/hip/include/HipPlatform.h
+++ b/platforms/hip/include/HipPlatform.h
@@ -111,13 +111,21 @@ public:
         static const std::string key = "DeterministicForces";
         return key;
     }
+    /**
+     * This is the name of the parameter for selecting which FFT backend to use.
+     */
+    static const std::string& HipFFTBackend() {
+        static const std::string key = "FFTBackend";
+        return key;
+    }
 };
 
 class OPENMM_EXPORT_COMMON HipPlatform::PlatformData {
 public:
     PlatformData(ContextImpl* context, const System& system, const std::string& deviceIndexProperty, const std::string& blockingProperty, const std::string& precisionProperty,
             const std::string& cpuPmeProperty, const std::string& tempProperty,
-            const std::string& pmeStreamProperty, const std::string& deterministicForcesProperty, int numThreads, ContextImpl* originalContext);
+            const std::string& pmeStreamProperty, const std::string& deterministicForcesProperty, const std::string& fftBackendProperty,
+            int numThreads, ContextImpl* originalContext);
     ~PlatformData();
     void initializeContexts(const System& system);
     void syncContexts();
diff --git a/platforms/hip/src/HipContext.cpp b/platforms/hip/src/HipContext.cpp
index 0050a8c46..dc4290b3c 100644
--- a/platforms/hip/src/HipContext.cpp
+++ b/platforms/hip/src/HipContext.cpp
@@ -31,6 +31,7 @@
 #include "HipBondedUtilities.h"
 #include "HipEvent.h"
 #include "HipFFT3D.h"
+#include "HipHipFFT3D.h"
 #include "HipIntegrationUtilities.h"
 #include "HipKernels.h"
 #include "HipKernelSources.h"
@@ -80,6 +81,12 @@
 using namespace OpenMM;
 using namespace std;
 
+static string normalizeFftBackendName(const string& value) {
+    string result = value;
+    transform(result.begin(), result.end(), result.begin(), ::tolower);
+    return result;
+}
+
 const int HipContext::ThreadBlockSize = 64;
 const int HipContext::TileSize = 32;
 bool HipContext::hasInitializedHip = false;
@@ -712,7 +719,12 @@ ComputeSort HipContext::createSort(ComputeSortImpl::SortTrait* trait, unsigned i
 }
 
 FFT3D HipContext::createFFT(int xsize, int ysize, int zsize, bool realToComplex) {
-    return FFT3D(new HipFFT3D(*this, xsize, ysize, zsize, realToComplex));
+    string backend = normalizeFftBackendName(platformData.propertyValues[HipPlatform::HipFFTBackend()]);
+    if (backend.empty() || backend == "vkfft")
+        return FFT3D(new HipFFT3D(*this, xsize, ysize, zsize, realToComplex));
+    if (backend == "hipfft")
+        return FFT3D(new HipHipFFT3D(*this, xsize, ysize, zsize, realToComplex));
+    throw OpenMMException("Illegal value for FFTBackend: "+backend);
 }
 
 int HipContext::findLegalFFTDimension(int minimum) {
diff --git a/platforms/hip/src/HipHipFFT3D.cpp b/platforms/hip/src/HipHipFFT3D.cpp
new file mode 100644
index 000000000..a0a408c00
--- /dev/null
+++ b/platforms/hip/src/HipHipFFT3D.cpp
@@ -0,0 +1,100 @@
+/* -------------------------------------------------------------------------- *
+ *                                   OpenMM                                   *
+ * -------------------------------------------------------------------------- *
+ * This is part of the OpenMM molecular simulation toolkit.                   *
+ * See https://openmm.org/development.                                        *
+ *                                                                            *
+ * Portions copyright (c) 2009-2026 Stanford University and the Authors.      *
+ * Contributors:                                                              *
+ *                                                                            *
+ * This program is free software: you can redistribute it and/or modify       *
+ * it under the terms of the GNU Lesser General Public License as published   *
+ * by the Free Software Foundation, either version 3 of the License, or       *
+ * (at your option) any later version.                                        *
+ *                                                                            *
+ * This program is distributed in the hope that it will be useful,            *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
+ * GNU Lesser General Public License for more details.                        *
+ *                                                                            *
+ * You should have received a copy of the GNU Lesser General Public License   *
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.      *
+ * -------------------------------------------------------------------------- */
+
+#include "HipHipFFT3D.h"
+#include "HipContext.h"
+#include "openmm/OpenMMException.h"
+
+using namespace OpenMM;
+using namespace std;
+
+HipHipFFT3D::HipHipFFT3D(HipContext& context, int xsize, int ysize, int zsize, bool realToComplex) :
+        context(context), realToComplex(realToComplex), doublePrecision(context.getUseDoublePrecision())
+#ifdef OPENMM_HIP_WITH_HIPFFT
+        , forwardPlan(0), backwardPlan(0)
+#endif
+{
+#ifndef OPENMM_HIP_WITH_HIPFFT
+    throw OpenMMException("hipFFT backend requested but OpenMM was built without HIPFFT support");
+#else
+    hipfftType forwardType, backwardType;
+    if (realToComplex) {
+        forwardType = doublePrecision ? HIPFFT_D2Z : HIPFFT_R2C;
+        backwardType = doublePrecision ? HIPFFT_Z2D : HIPFFT_C2R;
+    }
+    else {
+        forwardType = doublePrecision ? HIPFFT_Z2Z : HIPFFT_C2C;
+        backwardType = forwardType;
+    }
+    hipfftResult result = hipfftPlan3d(&forwardPlan, xsize, ysize, zsize, forwardType);
+    if (result != HIPFFT_SUCCESS)
+        throw OpenMMException("Error initializing hipFFT forward plan: "+context.intToString(result));
+    result = hipfftPlan3d(&backwardPlan, xsize, ysize, zsize, backwardType);
+    if (result != HIPFFT_SUCCESS) {
+        hipfftDestroy(forwardPlan);
+        throw OpenMMException("Error initializing hipFFT backward plan: "+context.intToString(result));
+    }
+#endif
+}
+
+HipHipFFT3D::~HipHipFFT3D() {
+#ifdef OPENMM_HIP_WITH_HIPFFT
+    if (forwardPlan != 0)
+        hipfftDestroy(forwardPlan);
+    if (backwardPlan != 0)
+        hipfftDestroy(backwardPlan);
+#endif
+}
+
+void HipHipFFT3D::execFFT(ArrayInterface& in, ArrayInterface& out, bool forward) {
+#ifndef OPENMM_HIP_WITH_HIPFFT
+    throw OpenMMException("hipFFT backend requested but OpenMM was built without HIPFFT support");
+#else
+    hipfftHandle plan = forward ? forwardPlan : backwardPlan;
+    hipfftResult result = hipfftSetStream(plan, context.getCurrentStream());
+    if (result != HIPFFT_SUCCESS)
+        throw OpenMMException("Error setting hipFFT stream: "+context.intToString(result));
+    if (realToComplex) {
+        if (forward) {
+            if (doublePrecision)
+                result = hipfftExecD2Z(plan, (double*) context.unwrap(in).getDevicePointer(), (double2*) context.unwrap(out).getDevicePointer());
+            else
+                result = hipfftExecR2C(plan, (float*) context.unwrap(in).getDevicePointer(), (float2*) context.unwrap(out).getDevicePointer());
+        }
+        else {
+            if (doublePrecision)
+                result = hipfftExecZ2D(plan, (double2*) context.unwrap(in).getDevicePointer(), (double*) context.unwrap(out).getDevicePointer());
+            else
+                result = hipfftExecC2R(plan, (float2*) context.unwrap(in).getDevicePointer(), (float*) context.unwrap(out).getDevicePointer());
+        }
+    }
+    else {
+        if (doublePrecision)
+            result = hipfftExecZ2Z(plan, (double2*) context.unwrap(in).getDevicePointer(), (double2*) context.unwrap(out).getDevicePointer(), forward ? HIPFFT_FORWARD : HIPFFT_BACKWARD);
+        else
+            result = hipfftExecC2C(plan, (float2*) context.unwrap(in).getDevicePointer(), (float2*) context.unwrap(out).getDevicePointer(), forward ? HIPFFT_FORWARD : HIPFFT_BACKWARD);
+    }
+    if (result != HIPFFT_SUCCESS)
+        throw OpenMMException("Error executing hipFFT: "+context.intToString(result));
+#endif
+}
diff --git a/platforms/hip/src/HipNonbondedUtilities.cpp b/platforms/hip/src/HipNonbondedUtilities.cpp
index 01cc7f826..60548054d 100644
--- a/platforms/hip/src/HipNonbondedUtilities.cpp
+++ b/platforms/hip/src/HipNonbondedUtilities.cpp
@@ -65,16 +65,15 @@ HipNonbondedUtilities::HipNonbondedUtilities(HipContext& context) : context(cont
     string errorMessage = "Error initializing nonbonded utilities";
     CHECK_RESULT(hipEventCreateWithFlags(&downloadCountEvent, context.getEventFlags()));
     CHECK_RESULT(hipHostMalloc((void**) &pinnedCountBuffer, 2*sizeof(unsigned int), context.getHostMallocFlags()));
-    numForceThreadBlocks = 5*4*context.getMultiprocessors();
-    forceThreadBlockSize = 64;
-    findInteractingBlocksThreadBlockSize = context.getSIMDWidth();
+    numForceThreadBlocks = 16*4*context.getMultiprocessors();
+    forceThreadBlockSize = 256;
+    findInteractingBlocksThreadBlockSize = 128;
 
     // When building the neighbor list, we can optionally use large blocks (32 * warpSize atoms) to
     // accelerate the process.  This makes building the neighbor list faster, but it prevents
     // us from sorting atom blocks by size, which leads to a slightly less efficient neighbor
     // list.  We guess based on system size which will be faster.
-
-    useLargeBlocks = (context.getNumAtoms() > 90000);
+    useLargeBlocks = false;
     setKernelSource(HipKernelSources::nonbonded);
 }
 
@@ -400,7 +399,7 @@ double HipNonbondedUtilities::getMaxCutoffDistance() {
 }
 
 double HipNonbondedUtilities::padCutoff(double cutoff) {
-    double padding = (usePadding ? 0.08*cutoff : 0.0);
+    double padding = (usePadding ? 0.12*cutoff : 0.0);
     return cutoff+padding;
 }
 
diff --git a/platforms/hip/src/HipPlatform.cpp b/platforms/hip/src/HipPlatform.cpp
index e6e68e2dd..3c3936da6 100644
--- a/platforms/hip/src/HipPlatform.cpp
+++ b/platforms/hip/src/HipPlatform.cpp
@@ -69,6 +69,7 @@ HipPlatform::HipPlatform() {
     deprecatedPropertyReplacements["HipTempDirectory"] = HipTempDirectory();
     deprecatedPropertyReplacements["HipDisablePmeStream"] = HipDisablePmeStream();
     deprecatedPropertyReplacements["HipDeterministicForces"] = HipDeterministicForces();
+    deprecatedPropertyReplacements["HipFFTBackend"] = HipFFTBackend();
     HipKernelFactory* factory = new HipKernelFactory();
     registerKernelFactory(CalcForcesAndEnergyKernel::Name(), factory);
     registerKernelFactory(UpdateStateDataKernel::Name(), factory);
@@ -122,6 +123,7 @@ HipPlatform::HipPlatform() {
     platformProperties.push_back(HipTempDirectory());
     platformProperties.push_back(HipDisablePmeStream());
     platformProperties.push_back(HipDeterministicForces());
+    platformProperties.push_back(HipFFTBackend());
     setPropertyDefaultValue(HipDeviceIndex(), "");
     setPropertyDefaultValue(HipDeviceName(), "");
     setPropertyDefaultValue(HipUseBlockingSync(), "true");
@@ -129,6 +131,7 @@ HipPlatform::HipPlatform() {
     setPropertyDefaultValue(HipUseCpuPme(), "false");
     setPropertyDefaultValue(HipDisablePmeStream(), "false");
     setPropertyDefaultValue(HipDeterministicForces(), "false");
+    setPropertyDefaultValue(HipFFTBackend(), "vkfft");
 #ifdef _MSC_VER
     setPropertyDefaultValue(HipTempDirectory(), string(getenv("TEMP")));
 #else
@@ -213,11 +216,14 @@ void HipPlatform::contextCreated(ContextImpl& context, const map<string, string>
             getPropertyDefaultValue(HipDisablePmeStream()) : properties.find(HipDisablePmeStream())->second);
     string deterministicForcesValue = (properties.find(HipDeterministicForces()) == properties.end() ?
             getPropertyDefaultValue(HipDeterministicForces()) : properties.find(HipDeterministicForces())->second);
+    string fftBackendValue = (properties.find(HipFFTBackend()) == properties.end() ?
+            getPropertyDefaultValue(HipFFTBackend()) : properties.find(HipFFTBackend())->second);
     transform(blockingPropValue.begin(), blockingPropValue.end(), blockingPropValue.begin(), ::tolower);
     transform(precisionPropValue.begin(), precisionPropValue.end(), precisionPropValue.begin(), ::tolower);
     transform(cpuPmePropValue.begin(), cpuPmePropValue.end(), cpuPmePropValue.begin(), ::tolower);
     transform(pmeStreamPropValue.begin(), pmeStreamPropValue.end(), pmeStreamPropValue.begin(), ::tolower);
     transform(deterministicForcesValue.begin(), deterministicForcesValue.end(), deterministicForcesValue.begin(), ::tolower);
+    transform(fftBackendValue.begin(), fftBackendValue.end(), fftBackendValue.begin(), ::tolower);
     vector<string> pmeKernelName;
     pmeKernelName.push_back(CalcPmeReciprocalForceKernel::Name());
     if (!supportsKernels(pmeKernelName))
@@ -227,7 +233,7 @@ void HipPlatform::contextCreated(ContextImpl& context, const map<string, string>
     if (threadsEnv != NULL)
         stringstream(threadsEnv) >> threads;
     context.setPlatformData(new PlatformData(&context, context.getSystem(), devicePropValue, blockingPropValue, precisionPropValue, cpuPmePropValue, tempPropValue,
-            pmeStreamPropValue, deterministicForcesValue, threads, NULL));
+            pmeStreamPropValue, deterministicForcesValue, fftBackendValue, threads, NULL));
 }
 
 void HipPlatform::linkedContextCreated(ContextImpl& context, ContextImpl& originalContext) const {
@@ -239,9 +245,10 @@ void HipPlatform::linkedContextCreated(ContextImpl& context, ContextImpl& origin
     string tempPropValue = platform.getPropertyValue(originalContext.getOwner(), HipTempDirectory());
     string pmeStreamPropValue = platform.getPropertyValue(originalContext.getOwner(), HipDisablePmeStream());
     string deterministicForcesValue = platform.getPropertyValue(originalContext.getOwner(), HipDeterministicForces());
+    string fftBackendValue = platform.getPropertyValue(originalContext.getOwner(), HipFFTBackend());
     int threads = reinterpret_cast<PlatformData*>(originalContext.getPlatformData())->threads.getNumThreads();
     context.setPlatformData(new PlatformData(&context, context.getSystem(), devicePropValue, blockingPropValue, precisionPropValue, cpuPmePropValue, tempPropValue,
-            pmeStreamPropValue, deterministicForcesValue, threads, &originalContext));
+            pmeStreamPropValue, deterministicForcesValue, fftBackendValue, threads, &originalContext));
 }
 
 void HipPlatform::contextDestroyed(ContextImpl& context) const {
@@ -250,8 +257,8 @@ void HipPlatform::contextDestroyed(ContextImpl& context) const {
 }
 
 HipPlatform::PlatformData::PlatformData(ContextImpl* context, const System& system, const string& deviceIndexProperty, const string& blockingProperty, const string& precisionProperty,
-            const string& cpuPmeProperty, const string& tempProperty, const string& pmeStreamProperty,
-            const string& deterministicForcesProperty, int numThreads, ContextImpl* originalContext) :
+              const string& cpuPmeProperty, const string& tempProperty, const string& pmeStreamProperty,
+              const string& deterministicForcesProperty, const string& fftBackendProperty, int numThreads, ContextImpl* originalContext) :
                 context(context), removeCM(false), stepCount(0), computeForceCount(0), time(0.0), hasInitializedContexts(false),
                 threads(numThreads) {
     bool blocking = (blockingProperty == "true");
@@ -306,6 +313,7 @@ HipPlatform::PlatformData::PlatformData(ContextImpl* context, const System& syst
     propertyValues[HipPlatform::HipTempDirectory()] = tempProperty;
     propertyValues[HipPlatform::HipDisablePmeStream()] = disablePmeStream ? "true" : "false";
     propertyValues[HipPlatform::HipDeterministicForces()] = deterministicForces ? "true" : "false";
+    propertyValues[HipPlatform::HipFFTBackend()] = fftBackendProperty;
     contextEnergy.resize(contexts.size());
 
     // Determine whether peer-to-peer copying is supported, and enable it if so.
diff --git a/platforms/hip/tests/TestHipFFT3D.cpp b/platforms/hip/tests/TestHipFFT3D.cpp
index 170ad1fe0..8aff3112e 100644
--- a/platforms/hip/tests/TestHipFFT3D.cpp
+++ b/platforms/hip/tests/TestHipFFT3D.cpp
@@ -58,7 +58,8 @@ void testTransform(bool realToComplex, int xsize, int ysize, int zsize, double e
     system.addParticle(0.0);
     HipPlatform::PlatformData platformData(NULL, system, "", "true", platform.getPropertyDefaultValue("HipPrecision"), "false",
             platform.getPropertyDefaultValue(HipPlatform::HipTempDirectory()),
-            platform.getPropertyDefaultValue(HipPlatform::HipDisablePmeStream()), "false", 1, NULL);
+            platform.getPropertyDefaultValue(HipPlatform::HipDisablePmeStream()), "false",
+            platform.getPropertyDefaultValue(HipPlatform::HipFFTBackend()), 1, NULL);
     HipContext& context = *platformData.contexts[0];
     context.initialize();
     context.setAsCurrent();
diff --git a/platforms/hip/tests/TestHipRandom.cpp b/platforms/hip/tests/TestHipRandom.cpp
index 94212702c..54f869b35 100644
--- a/platforms/hip/tests/TestHipRandom.cpp
+++ b/platforms/hip/tests/TestHipRandom.cpp
@@ -55,7 +55,8 @@ void testGaussian() {
         system.addParticle(1.0);
     HipPlatform::PlatformData platformData(NULL, system, "", "true", platform.getPropertyDefaultValue("HipPrecision"), "false",
             platform.getPropertyDefaultValue(HipPlatform::HipTempDirectory()),
-            platform.getPropertyDefaultValue(HipPlatform::HipDisablePmeStream()), "false", 1, NULL);
+            platform.getPropertyDefaultValue(HipPlatform::HipDisablePmeStream()), "false",
+            platform.getPropertyDefaultValue(HipPlatform::HipFFTBackend()), 1, NULL);
     HipContext& context = *platformData.contexts[0];
     context.initialize();
     context.setAsCurrent();
diff --git a/platforms/hip/tests/TestHipSort.cpp b/platforms/hip/tests/TestHipSort.cpp
index fe8b1c56a..03e7ee2c5 100644
--- a/platforms/hip/tests/TestHipSort.cpp
+++ b/platforms/hip/tests/TestHipSort.cpp
@@ -65,7 +65,8 @@ void verifySorting(vector<float> array, bool uniform) {
     system.addParticle(0.0);
     HipPlatform::PlatformData platformData(NULL, system, "", "true", platform.getPropertyDefaultValue("HipPrecision"), "false",
             platform.getPropertyDefaultValue(HipPlatform::HipTempDirectory()),
-            platform.getPropertyDefaultValue(HipPlatform::HipDisablePmeStream()), "false", 1, NULL);
+            platform.getPropertyDefaultValue(HipPlatform::HipDisablePmeStream()), "false",
+            platform.getPropertyDefaultValue(HipPlatform::HipFFTBackend()), 1, NULL);
     HipContext& context = *platformData.contexts[0];
     context.initialize();
     context.setAsCurrent();