本文整理汇总了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);
}
示例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);
}
示例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();
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}
示例8: free
import jcuda.runtime.JCuda; //导入方法依赖的package包/类
public void free() {
setDontFree(false);
if (data_d != null) JCuda.cudaFree(data_d);
}
示例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();
}
}
示例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);
}
示例11: destroy
import jcuda.runtime.JCuda; //导入方法依赖的package包/类
/**
* releases the memory on the device for this volume.
*/
public void destroy(){
super.destroy();
JCuda.cudaFree(deviceX);
}
示例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);
}
示例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);
}
示例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);
}
示例15: destroy
import jcuda.runtime.JCuda; //导入方法依赖的package包/类
/**
* releases the memory on the device for this volume.
*/
public void destroy(){
JCuda.cudaFree(deviceX);
}