本文整理汇总了Java中jcuda.runtime.JCuda类的典型用法代码示例。如果您正苦于以下问题:Java JCuda类的具体用法?Java JCuda怎么用?Java JCuda使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JCuda类属于jcuda.runtime包,在下文中一共展示了JCuda类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fill
import jcuda.runtime.JCuda; //导入依赖的package包/类
public void fill(Volume3D vol, float number){
initCUDA();
CUdeviceptr sizePointer = CUDAUtil.copyToDeviceMemory(vol.size);
CUfunction function = new CUfunction();
JCudaDriver.cuModuleGetFunction(function, module,
"_Z4fillPfPifi");
ArrayList<Object> arguments = new ArrayList<Object>();
arguments.add(((CUDAVolume3D) vol).getDevicePointer());
arguments.add(sizePointer);
arguments.add(new Float(number));
arguments.add(new Integer(vol.getInternalDimension()));
// Calculate new grid size
gridSize = getGrid(vol.size);
if (debug) System.out.println("Calling.");
callCUDAFunction(function, arguments);
if (debug) System.out.println("Freeing.");
JCuda.cudaFree(sizePointer);
//((CUDAVolume3D) vol).fetch();
}
示例2: main
import jcuda.runtime.JCuda; //导入依赖的package包/类
public static void main(String[] args)
{
JCuda.setExceptionsEnabled(true);;
JCusparse.setExceptionsEnabled(true);
JCusolver.setExceptionsEnabled(true);
String path = "src/main/resources/data/jcusolver/";
String fileName = path + "lap2D_5pt_n100.mtx";
String testFunc = "chol"; // "chol", "lu", "qr"
String reorder = "symrcm"; // "symrcm", "symamd", null
runTest(
"-F="+fileName,
"-R="+testFunc,
"-P="+reorder);
}
示例3: cuda_init
import jcuda.runtime.JCuda; //导入依赖的package包/类
public void cuda_init()
{
JCudaDriver.setExceptionsEnabled(true);
JCuda.setExceptionsEnabled(true);
JCurand.setExceptionsEnabled(true);
cudaDeviceReset();
cuInit(0);
context = new HeatBugsGPUContext(0,0);
context.InitHeatBugsConstant(gridWidth,gridHeight, MAX_HEAT, randomMovementProbability, evaporationRate,diffusionRate, bugCount);
context.InitModule(1234,bugCount,0);
context.InitMemory(locationPointer, idealTemp, heatOutput);
context.InitKernelParameters();
}
示例4: cuda_init
import jcuda.runtime.JCuda; //导入依赖的package包/类
public void cuda_init()
{
JCudaDriver.setExceptionsEnabled(true);
JCuda.setExceptionsEnabled(true);
JCurand.setExceptionsEnabled(true);
cudaDeviceReset();
cuInit(0);
// int numElements = numStudents;
Devices = new StudentsGPUContext[numDevices]; //array of GPU contexts, can be applied to multiple GPUs
int numElements = numStudents/numDevices;
// int lastNumElements = 0;
for(int i =0; i<numDevices ;i++)
{
Devices[i] = new StudentsGPUContext(i,i);
Devices[i].InitStudentsConstant(forceToSchoolMultiplier ,randomMultiplier, yard.getWidth(),yard.getHeight());
Devices[i].InitModule(1234, numElements, numStudents, numDevices);
Devices[i].InitMemory(locationPointer, buddies);
Devices[i].InitKernelParameters();
}
}
示例5: cuda_init
import jcuda.runtime.JCuda; //导入依赖的package包/类
public void cuda_init()
{
JCudaDriver.setExceptionsEnabled(true);
JCuda.setExceptionsEnabled(true);
JCurand.setExceptionsEnabled(true);
cudaDeviceReset();
cuInit(0);
int numCells = (gridHeight*gridWidth)/numDevices;
// int numBugs = bugCount/numDevices;
for(int i = 0;i <numDevices ;i++)
{
contexts[i] = new HeatBugsGPUContext(i,i);
contexts[i].InitHeatBugsConstant(gridWidth,gridHeight,i*gridHeight/numDevices,(i+1)*gridHeight/numDevices -1, MAX_HEAT, randomMovementProbability, evaporationRate,diffusionRate, bugCount,numDevices);
contexts[i].InitModule(1234,numCells,i*(gridWidth*gridHeight)/numDevices);
contexts[i].InitMemory(locationPointer, idealTemp, heatOutput);
contexts[i].InitKernelParameters();
System.out.println("device " + contexts[i].index + " begin " + contexts[i].begin_row + " endrow " + contexts[i].end_row + " gridoffset "+ contexts[i].gridOffset + " numCells " +contexts[i].numCells);
}
}
示例6: TransScale
import jcuda.runtime.JCuda; //导入依赖的package包/类
private TransScale() {
JCudaDriver.setExceptionsEnabled(true);
JCuda.setExceptionsEnabled(true);
cuInit(0);
// Get the number of devices
int[] numDevicesArray = { 0 };
cuDeviceGetCount(numDevicesArray);
this.numDevices = numDevicesArray[0];
this.availableDevs = new ArrayBlockingQueue<>(numDevices);
this.daemonThreads = new DeviceThread[numDevices];
// Fill arrays and start the daemon thread
for (int i = 0 ; i < numDevices ; i++) {
this.daemonThreads[i] = new DeviceThread(this, i);
this.daemonThreads[i].setName("DeviceThread#" + i);
availableDevs.add(this.daemonThreads[i]); // Add to available queue
this.daemonThreads[i].start();
}
}
示例7: doGenerateBrownianMotion
import jcuda.runtime.JCuda; //导入依赖的package包/类
/**
* Lazy initialization of brownianIncrement. Synchronized to ensure thread safety of lazy init.
*/
private void doGenerateBrownianMotion() {
if(brownianIncrements != null) return; // Nothing to do
// Enable exceptions and omit all subsequent error checks
JCuda.setExceptionsEnabled(true);
JCurand.setExceptionsEnabled(true);
JCuda.setLogLevel(LogLevel.LOG_DEBUG);
// Hack: It is important to init the context first. - Clean up.
RandomVariableInterface rv = new RandomVariableCuda(0.0);
curandGenerator generator = new curandGenerator();
// Create pseudo-random number generator
curandCreateGenerator(generator, CURAND_RNG_PSEUDO_DEFAULT);
// Set seed
curandSetPseudoRandomGeneratorSeed(generator, 1234);
// Allocate memory for RandomVariable wrapper objects.
brownianIncrements = new RandomVariableInterface[timeDiscretization.getNumberOfTimeSteps()][numberOfFactors];
// Pre-calculate square roots of deltaT
for(int timeIndex=0; timeIndex<timeDiscretization.getNumberOfTimeSteps(); timeIndex++) {
double time = timeDiscretization.getTime(timeIndex+1);
float sqrtOfTimeStep = (float)Math.sqrt(timeDiscretization.getTimeStep(timeIndex));
for(int factor=0; factor<numberOfFactors; factor++) {
// Generate n floats on device
CUdeviceptr realizations = RandomVariableCuda.getCUdeviceptr((long)numberOfPaths);
jcuda.jcurand.JCurand.curandGenerateNormal(generator, realizations, numberOfPaths, 0.0f /* mean */, sqrtOfTimeStep /* stddev */);
brownianIncrements[timeIndex][factor] = new RandomVariableCuda(time, realizations, numberOfPaths);
}
}
// Cleanup
curandDestroyGenerator(generator);
}
开发者ID:finmath,项目名称:finmath-lib-cuda-extensions,代码行数:43,代码来源:BrownianMotionCudaWithRandomVariableCuda.java
示例8: malloc
import jcuda.runtime.JCuda; //导入依赖的package包/类
/**
* @param size in bytes
*/
public static cudnn.Pointer malloc(long size) throws CudaException
{
Pointer deviceData=new Pointer();
checkError(JCuda.cudaMalloc(deviceData, size));
return cudnn.Pointer.fromJcuda(deviceData);
}
示例9: 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);
}
示例10: main
import jcuda.runtime.JCuda; //导入依赖的package包/类
public static void main(String args[])
{
JCuda.setExceptionsEnabled(true);;
JCusparse.setExceptionsEnabled(true);
JCusolver.setExceptionsEnabled(true);
String path = "src/main/resources/data/jcusolver/";
String fileName = path + "gr_900_900_crg.mtx";
String testFunc = "chol"; // "chol", "lu", "qr"
runTest(
"-F="+fileName,
"-R="+testFunc);
}
示例11: main
import jcuda.runtime.JCuda; //导入依赖的package包/类
public static void main(String args[])
{
// Enable exceptions and omit all subsequent error checks
JCuda.setExceptionsEnabled(true);
JCurand.setExceptionsEnabled(true);
int n = 100;
curandGenerator generator = new curandGenerator();
// Allocate n floats on host
float hostData[] = new float[n];
// Allocate n floats on device
Pointer deviceData = new Pointer();
cudaMalloc(deviceData, n * Sizeof.FLOAT);
// Create pseudo-random number generator
curandCreateGenerator(generator, CURAND_RNG_PSEUDO_DEFAULT);
// Set seed
curandSetPseudoRandomGeneratorSeed(generator, 1234);
// Generate n floats on device
curandGenerateUniform(generator, deviceData, n);
// Copy device memory to host
cudaMemcpy(Pointer.to(hostData), deviceData,
n * Sizeof.FLOAT, cudaMemcpyDeviceToHost);
// Show result
System.out.println(Arrays.toString(hostData));
// Cleanup
curandDestroyGenerator(generator);
cudaFree(deviceData);
}
示例12: main
import jcuda.runtime.JCuda; //导入依赖的package包/类
public static void main(String args[])
{
JCuda.setExceptionsEnabled(true);
JCudnn.setExceptionsEnabled(true);
JCublas2.setExceptionsEnabled(true);
int version = (int) cudnnGetVersion();
System.out.printf("cudnnGetVersion() : %d , " +
"CUDNN_VERSION from cudnn.h : %d\n",
version, CUDNN_VERSION);
System.out.println("Creating network and layers...");
Network mnist = new Network();
System.out.println("Classifying...");
int i1 = mnist.classifyExample(dataDirectory + first_image);
int i2 = mnist.classifyExample(dataDirectory + second_image);
mnist.setConvolutionAlgorithm(CUDNN_CONVOLUTION_FWD_ALGO_FFT);
int i3 = mnist.classifyExample(dataDirectory + third_image);
System.out.println(
"\nResult of classification: " + i1 + " " + i2 + " " + i3);
if (i1 != 1 || i2 != 3 || i3 != 5)
{
System.out.println("\nTest failed!\n");
}
else
{
System.out.println("\nTest passed!\n");
}
mnist.destroy();
}
示例13: Matrix
import jcuda.runtime.JCuda; //导入依赖的package包/类
public Matrix(int rows, int cols) {
this.dontFree = false;
this.rows = rows;
this.cols = cols;
this.data_d = new Pointer();
JCuda.cudaMalloc(data_d, rows*cols * Sizeof.FLOAT);
CublasUtil.allocated.add(this);
}
示例14: getrfGetriBatched
import jcuda.runtime.JCuda; //导入依赖的package包/类
private static void getrfGetriBatched(List<Matrix> A, List<Matrix> B) {
Pointer[] Apointers = new Pointer[A.size()];
Pointer[] Bpointers = new Pointer[B.size()];
for (int i=0; i<A.size(); ++i) {
Apointers[i] = A.get(i).data_d;
Bpointers[i] = B.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 info_d = new Pointer();
JCuda.cudaMalloc(info_d, A.size() * Sizeof.INT);
Pointer pivots_d = new Pointer();
JCuda.cudaMalloc(pivots_d, A.get(0).rows * A.size() * Sizeof.INT);
if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize();
JCublas2.cublasSgetrfBatched(cublasHandle, A.get(0).rows, Apointers_d, A.get(0).rows, pivots_d, info_d, A.size());
if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize();
JCublas2.cublasSgetriBatched(cublasHandle, A.get(0).rows, Apointers_d, A.get(0).rows, pivots_d, Bpointers_d, B.get(0).rows, info_d, A.size());
if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize();
JCuda.cudaFree(Apointers_d);
JCuda.cudaFree(Bpointers_d);
JCuda.cudaFree(info_d);
JCuda.cudaFree(pivots_d);
if (DEBUG_SYNC) JCudaDriver.cuCtxSynchronize();
}
示例15: 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();
}