当前位置: 首页>>代码示例>>Java>>正文


Java JCuda.cudaFree方法代码示例

本文整理汇总了Java中jcuda.runtime.JCuda.cudaFree方法的典型用法代码示例。如果您正苦于以下问题:Java JCuda.cudaFree方法的具体用法?Java JCuda.cudaFree怎么用?Java JCuda.cudaFree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jcuda.runtime.JCuda的用法示例。


在下文中一共展示了JCuda.cudaFree方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main2

import jcuda.runtime.JCuda; //导入方法依赖的package包/类
/**
 * @param args
 */
public static void main2(String[] args) {
	Pointer devPtr = new Pointer();
	JCuda.cudaMalloc(devPtr, 1024 * 1024 * 1024);
	logger.info("Pointer: "+devPtr);
	JCuda.cudaFree(devPtr);
}
 
开发者ID:naxos-simulator,项目名称:NaxosSimulator,代码行数:10,代码来源:CudaTest.java

示例2: min

import jcuda.runtime.JCuda; //导入方法依赖的package包/类
@Override
public float min(Volume3D vol)
{
	/* defined for non-complex volumes only */

	if (vol.in_dim != 1) {
		fprintf("vol_max: Invalid dimension\n");
		return(0);
	}

	initCUDA();	

	gridSize = getGrid(vol.size);

	Pointer sizePointer = CUDAUtil.copyToDeviceMemory(vol.size);
	float [] results = new float [vol.size[2] * vol.size[1]];
	CUdeviceptr resultPointer = CUDAUtil.copyToDeviceMemory(results);

	CUfunction function = new CUfunction();
	JCudaDriver.cuModuleGetFunction(function, module,
			"_Z3minPfPiiS_");

	ArrayList<Object> arguments = new ArrayList<Object>();
	arguments.add(((CUDAVolume3D) vol).getDevicePointer());
	arguments.add(sizePointer);
	arguments.add(new Integer(vol.in_dim));
	arguments.add(resultPointer);

	callCUDAFunction(function, arguments);

	CUDAUtil.fetchFromDeviceMemory(results, resultPointer);
	JCuda.cudaFree(sizePointer);

	float m = results[0];
	for (int i = 1; i < results.length; i++){
		if (results[i] < m) m = results[i];
	}
	
	return(m); 
}
 
开发者ID:akmaier,项目名称:CONRAD,代码行数:41,代码来源:CUDAVolumeOperator.java

示例3: gemmBatched

import jcuda.runtime.JCuda; //导入方法依赖的package包/类
private static void gemmBatched(float alpha, List<Matrix> A, List<Matrix> B, float beta, List<Matrix> C) {
	Pointer[] Apointers = new Pointer[A.size()];
	Pointer[] Bpointers = new Pointer[B.size()];
	Pointer[] Cpointers = new Pointer[C.size()];
	for (int i=0; i<A.size(); ++i) {
		Apointers[i] = A.get(i).data_d;
		Bpointers[i] = B.get(i).data_d;
		Cpointers[i] = C.get(i).data_d;
	}
	Pointer Apointers_d = new Pointer();
	JCuda.cudaMalloc(Apointers_d, A.size() * Sizeof.POINTER);
	JCuda.cudaMemcpy(Apointers_d, Pointer.to(Apointers), A.size() * Sizeof.POINTER, cudaMemcpyKind.cudaMemcpyHostToDevice);
	Pointer Bpointers_d = new Pointer();
	JCuda.cudaMalloc(Bpointers_d, B.size() * Sizeof.POINTER);
	JCuda.cudaMemcpy(Bpointers_d, Pointer.to(Bpointers), B.size() * Sizeof.POINTER, cudaMemcpyKind.cudaMemcpyHostToDevice);
	Pointer Cpointers_d = new Pointer();
	JCuda.cudaMalloc(Cpointers_d, C.size() * Sizeof.POINTER);
	JCuda.cudaMemcpy(Cpointers_d, Pointer.to(Cpointers), C.size() * Sizeof.POINTER, cudaMemcpyKind.cudaMemcpyHostToDevice);
	if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize();
	
	JCublas2.cublasSgemmBatched(cublasHandle, cublasOperation.CUBLAS_OP_N, cublasOperation.CUBLAS_OP_N, C.get(0).rows, C.get(0).cols, B.get(0).rows, Pointer.to(new float[] {alpha}), Apointers_d, A.get(0).rows, Bpointers_d, B.get(0).rows, Pointer.to(new float[] {beta}), Cpointers_d, C.get(0).rows, A.size());
	if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize();
	
	JCuda.cudaFree(Apointers_d);
	JCuda.cudaFree(Bpointers_d);
	JCuda.cudaFree(Cpointers_d);
	if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize();
}
 
开发者ID:tberg12,项目名称:murphy,代码行数:29,代码来源:CublasUtil.java

示例4: fetchFromDeviceMemory

import jcuda.runtime.JCuda; //导入方法依赖的package包/类
/**
 * fetches a float data array from the device and frees the memory on the device.
 * @param data the float array to write to
 * @param deviceX the pointer to the device memory
 */
public static void fetchFromDeviceMemory(float [] data, CUdeviceptr deviceX){
	int memorySize = data.length * Sizeof.FLOAT;
	JCuda.cudaMemcpy(Pointer.to(data), deviceX, memorySize, 
			cudaMemcpyKind.cudaMemcpyDeviceToHost);
	JCuda.cudaFree(deviceX);
}
 
开发者ID:akmaier,项目名称:CONRAD,代码行数:12,代码来源:CUDAUtil.java

示例5: addScalar

import jcuda.runtime.JCuda; //导入方法依赖的package包/类
@Override
public int addScalar(Volume3D vol,
		float realPart, 
		float imagPart )
{

	if (DEBUG_FLAG)
		fprintf("vol_add_sc\n");


	if (imagPart!=0){
		makeComplex(vol);
	}

	initCUDA();	

	gridSize = getGrid(vol.size);

	Pointer sizePointer = CUDAUtil.copyToDeviceMemory(vol.size);

	CUfunction function = new CUfunction();
	JCudaDriver.cuModuleGetFunction(function, module,
			"_Z9addScalarPfPiiff");

	ArrayList<Object> arguments = new ArrayList<Object>();
	arguments.add(((CUDAVolume3D) vol).getDevicePointer());
	arguments.add(sizePointer);
	arguments.add(new Integer(vol.in_dim));
	arguments.add(new Float(realPart));
	arguments.add(new Float(imagPart));

	callCUDAFunction(function, arguments);

	JCuda.cudaFree(sizePointer);
	
	return(0);

}
 
开发者ID:akmaier,项目名称:CONRAD,代码行数:39,代码来源:CUDAVolumeOperator.java

示例6: createLowPassFilter

import jcuda.runtime.JCuda; //导入方法依赖的package包/类
@Override
public Volume3D createLowPassFilter(int dimensions, int size[], float dim [], float lp_upper){
	float [] f_max = new float [Volume3D.MAX_DIM];
	float [] f_delta = new float [Volume3D.MAX_DIM];
	CUDAVolume3D vol = (CUDAVolume3D) createVolume(size, dim, 1);
	/* calculate filter boudings */

	VolumeOperator.getFrequencyBoundings(dimensions, size, dim, f_max, f_delta);

	/* create LP filter */
	initCUDA();	

	// Calculate new grid size
	gridSize = getGrid(vol.size);

	Pointer sizePointer = CUDAUtil.copyToDeviceMemory(size);
	Pointer fDeltaPointer = CUDAUtil.copyToDeviceMemory(f_delta);
	Pointer fMaxPointer = CUDAUtil.copyToDeviceMemory(f_max);

	CUfunction function = new CUfunction();
	JCudaDriver.cuModuleGetFunction(function, module,
			"_Z19createLowPassFilterPfPiS_S_f");

	ArrayList<Object> arguments = new ArrayList<Object>();
	arguments.add(((CUDAVolume3D) vol).getDevicePointer());
	arguments.add(sizePointer);
	arguments.add(fDeltaPointer);
	arguments.add(fMaxPointer);
	arguments.add(new Float(lp_upper));

	callCUDAFunction(function, arguments);

	JCuda.cudaFree(sizePointer);
	JCuda.cudaFree(fDeltaPointer);
	JCuda.cudaFree(fMaxPointer);

	fftShift(vol);
	return vol;
}
 
开发者ID:akmaier,项目名称:CONRAD,代码行数:40,代码来源:CUDAVolumeOperator.java

示例7: testGPUInstallation

import jcuda.runtime.JCuda; //导入方法依赖的package包/类
/**
 * todo needs some more development/expansion
 */
private void testGPUInstallation(){
    try {
        jcuda.Pointer pointer = new jcuda.Pointer();
        JCuda.cudaMalloc(pointer, 4);
        JCuda.cudaFree(pointer);
    }
    catch (Exception e) {
        System.err.println("GPU/CUDA Installation Not Detected");
        System.err.println("Exiting HiCCUPS");
        System.exit(24);
    }
}
 
开发者ID:theaidenlab,项目名称:Juicebox,代码行数:16,代码来源:HiCCUPS_postproc.java

示例8: free

import jcuda.runtime.JCuda; //导入方法依赖的package包/类
public void free() {
	setDontFree(false);
	if (data_d != null) JCuda.cudaFree(data_d);
}
 
开发者ID:tberg12,项目名称:murphy,代码行数:5,代码来源:CublasUtil.java

示例9: forwardTransform

import jcuda.runtime.JCuda; //导入方法依赖的package包/类
@Override
public void forwardTransform(Volume3D vol)
{
	try{
		if (debug)
			System.out.println("CUDA vol_fft\n");

		operator.makeComplex(vol);  

		if (vol instanceof CUDAVolume3D){
			int [] fftsize = {vol.size[0], vol.size[1], vol.size[2]};
			
			forwardTransform(((CUDAVolume3D) vol).getDevicePointer(), fftsize);
		} else {
			CONRAD.gc();


			if(nativeCopy) {
				CUdeviceptr deviceX = CUDAUtil.allocateSpace(vol);
				CUDAUtil.moveToDevice(vol, deviceX);
				forwardTransform(deviceX, vol.size);
				CUDAUtil.fetchFromDevice(vol, deviceX);
				JCuda.cudaFree(deviceX);
			} else {
				float [] cuda = toCUDAFormat(vol.data);
				cufftHandle plan = new cufftHandle();
				
				int revan = JCufft.cufftPlan3d(plan, vol.size[0], vol.size[1], vol.size[2], cufftType.CUFFT_C2C);
				checkResult(revan);
				revan = JCufft.cufftExecC2C(plan, cuda, cuda, JCufft.CUFFT_FORWARD);
				checkResult(revan);
				//Clean up
				revan = JCufft.cufftDestroy(plan);
				checkResult(revan);
				vol.data = null;
				vol.data = toHostFormat(cuda, vol.size);
				cuda = null;
				CONRAD.gc();
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}


}
 
开发者ID:akmaier,项目名称:CONRAD,代码行数:47,代码来源:CUDAFFTVolumeHandle.java

示例10: addVolume

import jcuda.runtime.JCuda; //导入方法依赖的package包/类
@Override
public int addVolume(Volume3D vol1, Volume3D vol2, double weight)
{
	int  dim_loop;

	if (DEBUG_FLAG)
		fprintf("vol_add\n");

	for (dim_loop=0; dim_loop<vol1.in_dim; dim_loop++)
		if (vol1.size[dim_loop] != vol2.size[dim_loop]) {

			fprintf( "vol_add: Volumes have different sizes\n");
			return(-1);

		}

	/* OBS !!! borde inte behova konvertera vol2 . komplex */

	if (vol1.in_dim==2 &&  vol2.in_dim==1){ 
		makeComplex(vol2);
		CONRAD.gc();
	}

	if (vol1.in_dim==1 &&  vol2.in_dim==2){ 
		makeComplex(vol1);
		CONRAD.gc();
	}

	if (vol2.in_dim>2 || vol1.in_dim>2) {

		fprintf( "vol_add: Invalid dimension\n");
		return(-1);

	}

	initCUDA();	

	gridSize = getGrid(vol1.size);

	Pointer sizePointer = CUDAUtil.copyToDeviceMemory(vol1.size);

	CUfunction function = new CUfunction();
	JCudaDriver.cuModuleGetFunction(function, module,
			"_Z9addVolumePfS_Piif");

	ArrayList<Object> arguments = new ArrayList<Object>();
	arguments.add(((CUDAVolume3D) vol1).getDevicePointer());
	arguments.add(((CUDAVolume3D) vol2).getDevicePointer());
	arguments.add(sizePointer);
	arguments.add(new Integer(vol1.in_dim));
	arguments.add(new Float(weight));

	callCUDAFunction(function, arguments);

	JCuda.cudaFree(sizePointer);


	return(0);
}
 
开发者ID:akmaier,项目名称:CONRAD,代码行数:60,代码来源:CUDAVolumeOperator.java

示例11: destroy

import jcuda.runtime.JCuda; //导入方法依赖的package包/类
/**
 * releases the memory on the device for this volume.
 */
public void destroy(){
	super.destroy();
	JCuda.cudaFree(deviceX);
}
 
开发者ID:akmaier,项目名称:CONRAD,代码行数:8,代码来源:CUDAVolume3D.java

示例12: divideByVolume

import jcuda.runtime.JCuda; //导入方法依赖的package包/类
@Override
public int divideByVolume(Volume3D vol1, Volume3D vol2)
{
	int  dim_loop;
	
	if (DEBUG_FLAG)
		fprintf("vol_div\n");

	for (dim_loop=0; dim_loop<vol1.in_dim; dim_loop++)
		if (vol1.size[dim_loop] != vol2.size[dim_loop]) {

			fprintf( "vol_div: Volumes have different sizes\n");
			return(-1);

		}

	if (vol1.in_dim==2 &&  vol2.in_dim==1) {
		makeComplex(vol2);
		CONRAD.gc();
	}

	if (vol1.in_dim==1 &&  vol2.in_dim==2) {
		makeComplex(vol1);
		CONRAD.gc();
	}

	if (vol2.in_dim>2) {

		fprintf( "vol_div: Invalid dimension\n");
		return(0);

	}


	initCUDA();
	CUdeviceptr sizePointer = CUDAUtil.copyToDeviceMemory(vol1.size);
	CUfunction function = new CUfunction();
	JCudaDriver.cuModuleGetFunction(function, module,
	"_Z6dividePfS_Pii");

	ArrayList<Object> arguments = new ArrayList<Object>();
	arguments.add(((CUDAVolume3D) vol1).getDevicePointer());
	arguments.add(((CUDAVolume3D) vol2).getDevicePointer());
	arguments.add(sizePointer);
	arguments.add(new Integer(vol1.getInternalDimension()));

	// Calculate new grid size
	gridSize = getGrid(vol1.size);

	if (debug) System.out.println("Calling.");
	callCUDAFunction(function, arguments);
	if (debug) System.out.println("Freeing.");

	JCuda.cudaFree(sizePointer);

	return(0);

}
 
开发者ID:akmaier,项目名称:CONRAD,代码行数:59,代码来源:CUDAVolumeOperator.java

示例13: solveMaximumEigenvalue

import jcuda.runtime.JCuda; //导入方法依赖的package包/类
@Override
public Volume3D solveMaximumEigenvalue(Volume3D [][] structureTensor)
{
	CUDAVolume3D a11 = (CUDAVolume3D) structureTensor[0][0];
	CUDAVolume3D a12 = (CUDAVolume3D) structureTensor[0][1];
	CUDAVolume3D a13 = (CUDAVolume3D) structureTensor[0][2];
	CUDAVolume3D a22 = (CUDAVolume3D) structureTensor[1][1];
	CUDAVolume3D a23 = (CUDAVolume3D) structureTensor[1][2];
	CUDAVolume3D a33 = (CUDAVolume3D) structureTensor[2][2];
	CUDAVolume3D vol = (CUDAVolume3D) createVolume(a11.size, a11.spacing, a11.getInternalDimension());
	
	initCUDA();

	CUdeviceptr sizePointer = CUDAUtil.copyToDeviceMemory(vol.size);
	
	CUfunction function = new CUfunction();
	JCudaDriver.cuModuleGetFunction(function, module,
			"_Z25filt_solve_max_eigenvaluePfS_S_S_S_S_PiiS_");

	ArrayList<Object> arguments = new ArrayList<Object>();
	arguments.add(a11.getDevicePointer());
	arguments.add(a12.getDevicePointer());
	arguments.add(a13.getDevicePointer());
	arguments.add(a22.getDevicePointer());
	arguments.add(a23.getDevicePointer());
	arguments.add(a33.getDevicePointer());
	arguments.add(sizePointer);
	arguments.add(a11.getInternalDimension());
	arguments.add(vol.getDevicePointer());
	
	CUDAUtil.gridBlockSize[0] /= 2;
	
	gridSize = getGrid(vol.size);

	if (debug) System.out.println("Calling.");
	callCUDAFunction(function, arguments);
	if (debug) System.out.println("Freeing.");

	CUDAUtil.gridBlockSize[0] *= 2;
	
	JCuda.cudaFree(sizePointer);
	
	return(vol);
	
}
 
开发者ID:akmaier,项目名称:CONRAD,代码行数:46,代码来源:CUDAVolumeOperator.java

示例14: createDirectionalWeights

import jcuda.runtime.JCuda; //导入方法依赖的package包/类
@Override
public Volume3D createDirectionalWeights(int dimensions, int size[],
		float dim[], float dir[], int A, FILTER_TYPE t_filt)
{
	Volume3D vol = null;
	float [] f_max = new float [Volume3D.MAX_DIM];
	float [] f_delta = new float [Volume3D.MAX_DIM];
	float r_abs;
	int  dim_loop;


	if (DEBUG_FLAG)
		fprintf("filt_cos2\n"+t_filt);

	vol=createVolume(size, dim, 1);

	/* normalize filter direction */

	r_abs = 0.0f;
	r_abs += dir[0] * dir[0];
	r_abs += dir[1] * dir[1];
	r_abs += dir[2] * dir[2];
	r_abs = (float) Math.sqrt(r_abs);

	for (dim_loop=0; dim_loop<dimensions; dim_loop++)
		dir[dim_loop] /= r_abs;

	if (DEBUG_FLAG) {
		fprintf("  direction = ");
		for (dim_loop=0; dim_loop<dimensions; dim_loop++) {
			fprintf(dir[dim_loop]);
			if (dim_loop<dimensions-1)
				fprintf(", ");
		}
		fprintf("\n");
	}

	/* calculate filter boundings */

	getFrequencyBoundings(dimensions, size, dim, f_max, f_delta);

	// load CUDA stuff.
	initCUDA();

	CUdeviceptr sizePointer = CUDAUtil.copyToDeviceMemory(size);
	CUdeviceptr dirPointer = CUDAUtil.copyToDeviceMemory(dir);
	CUdeviceptr fDeltaPointer = CUDAUtil.copyToDeviceMemory(f_delta);
	CUdeviceptr fMaxPointer = CUDAUtil.copyToDeviceMemory(f_max);

	Integer filt = 0;
	if (t_filt == FILTER_TYPE.QUADRATIC) filt = new Integer(1);

	CUfunction function = new CUfunction();
	JCudaDriver.cuModuleGetFunction(function, module,
			"_Z9filt_cos2PfPiS_S_S_ii");

	ArrayList<Object> arguments = new ArrayList<Object>();
	arguments.add(((CUDAVolume3D) vol).getDevicePointer());
	arguments.add(sizePointer);
	arguments.add(dirPointer);
	arguments.add(fDeltaPointer);
	arguments.add(fMaxPointer);
	arguments.add(new Integer(A));
	arguments.add(filt);

	gridSize = getGrid(vol.size);

	if (debug) System.out.println("Calling.");
	callCUDAFunction(function, arguments);
	if (debug) System.out.println("Freeing.");

	JCuda.cudaFree(sizePointer);
	JCuda.cudaFree(dirPointer);
	JCuda.cudaFree(fDeltaPointer);
	JCuda.cudaFree(fMaxPointer);

	return(vol);
}
 
开发者ID:akmaier,项目名称:CONRAD,代码行数:79,代码来源:CUDAVolumeOperator.java

示例15: destroy

import jcuda.runtime.JCuda; //导入方法依赖的package包/类
/**
 * releases the memory on the device for this volume.
 */
public void destroy(){
	JCuda.cudaFree(deviceX);
}
 
开发者ID:akmaier,项目名称:CONRAD,代码行数:7,代码来源:CUDABSpline.java


注:本文中的jcuda.runtime.JCuda.cudaFree方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。