/* -------------------------------------------------------------------------- * * OpenMM * * -------------------------------------------------------------------------- * * This is part of the OpenMM molecular simulation toolkit originating from * * Simbios, the NIH National Center for Physics-Based Simulation of * * Biological Structures at Stanford, funded under the NIH Roadmap for * * Medical Research, grant U54 GM072970. See https://simtk.org. * * * * Portions copyright (c) 2009 Stanford University and the Authors. * * Authors: Peter Eastman * * 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 . * * -------------------------------------------------------------------------- */ #include "OpenCLFFT3D.h" #include "OpenCLExpressionUtilities.h" #include "OpenCLExpressionUtilities.h" #include "../src/SimTKUtilities/SimTKOpenMMRealType.h" #include #include #include using namespace OpenMM; using namespace std; OpenCLFFT3D::OpenCLFFT3D(OpenCLContext& context, int xsize, int ysize, int zsize) : context(context), xsize(xsize), ysize(ysize), zsize(zsize) { xkernel = createKernel(xsize); ykernel = createKernel(ysize); zkernel = createKernel(zsize); } OpenCLFFT3D::~OpenCLFFT3D() { } void OpenCLFFT3D::execFFT(OpenCLArray& data, bool forward) { xkernel.setArg(0, data.getDeviceBuffer()); xkernel.setArg(1, forward ? 1.0f : -1.0f); context.executeKernel(xkernel, xsize, xsize); } cl::Kernel OpenCLFFT3D::createKernel(int size) { map replacements; replacements["SIZE"] = OpenCLExpressionUtilities::intToString(size); replacements["M_PI"] = OpenCLExpressionUtilities::doubleToString(M_PI); stringstream source; int unfactored = size; int stage = 0; int L = size; int m = 1; while (unfactored > 1) { int input = stage%2; int output = 1-input; source<<"{\n"; if (unfactored%5 == 0) { L = L/5; source<<"// Pass "<<(stage+1)<<" (radix 5)\n"; source<<"int j = i/"<