Click here to Skip to main content
12,075,066 members (65,495 online)
Click here to Skip to main content

Stats

45.5K views
523 downloads
23 bookmarked
Posted

GPU Computing Using CUDA, Eclipse, and Java with JCuda

, 21 Sep 2013 CPOL
Tutorial: GPU computing with JCuda and Nsight (Eclipse)
codeprojectmbishop_12_22_2012.zip
CodeProjectMBishop_12_22_2012
JCudaFftDemo
bin
CaxpyGpu.class
ComplexCalcFloat.class
ComplexFloat.class
FftCpuFloat.class
FftGpuFloat.class
Main.class
Stopwatch.class
src
Notes
/**
 * Adaption of JCuda.org example.
 * Author Mark Bishop; 2012
 * License GNU v3; 
 * This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import jcuda.jcufft.JCufft;
import jcuda.jcufft.cufftHandle;
import jcuda.jcufft.cufftType;

/**
 * Computation class for FFT on Central Processor Unit. and related utilities.
 */

public class FftGpuFloat {

	/**
	 * 
	 * @param input
	 *            an interleaved array (ft)
	 * @return C2C FFT (hf)
	 */
	public static float[] C2C_1D(float[] input) {

		float outputJCufft[] = input.clone();

		// The plan uses the number of complex elements in the input array, i.e:
		// length/2.
		cufftHandle plan = new cufftHandle();
		JCufft.cufftPlan1d(plan, input.length / 2, cufftType.CUFFT_C2C, 1);
		JCufft.cufftExecC2C(plan, outputJCufft, outputJCufft,
				JCufft.CUFFT_FORWARD);
		JCufft.cufftDestroy(plan);

		return outputJCufft;
	}

	/**
	 * 
	 * @param input
	 *            an interleaved array (hf)
	 * @param isNormalize
	 *            Set true if result should be multiplied by 1/N
	 * @return C2C IFFT (ft)
	 */
	public static float[] InverseC2C_1D(float[] input, boolean isNormalize) {

		float outputJCufft[] = input.clone();

		// The plan uses the number of complex elements in the input array, i.e:
		// length/2.
		cufftHandle plan = new cufftHandle();
		JCufft.cufftPlan1d(plan, input.length / 2, cufftType.CUFFT_C2C, 1);
		JCufft.cufftExecC2C(plan, outputJCufft, outputJCufft,
				JCufft.CUFFT_INVERSE);
		JCufft.cufftDestroy(plan);

		// Normalization allows for amplitude reconstruction of the original
		// signal.
		if (isNormalize) {
			float normalize = 2 / (float) outputJCufft.length;
			outputJCufft = CaxpyGpu.CaxpyFloatScalar(normalize, outputJCufft);
		}

		return outputJCufft;
	}

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mark H Bishop
Founder PEI Watershed Alliance, Inc.
United States United States
I am an analytical chemist and an educator. I program primarily to perform matrix computations for regression analysis, process signals, acquire data from sensors, and to control devices.

I participate in many open source development communities and Linux user forums. I occasionally perform IT contract work, primarily focused on network design/deployment and penetration testing for small organizations.

I am a member of several community-interest groups such as the Prince Edward Island Watershed Alliance, the Lot 11 and Area Watershed Management Group, and the Petersham Historic Commission.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160208.1 | Last Updated 21 Sep 2013
Article Copyright 2012 by Mark H Bishop
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid