本文整理汇总了Java中jcuda.runtime.JCuda类的典型用法代码示例。如果您正苦于以下问题:Java JCuda类的具体用法?Java JCuda怎么用?Java JCuda使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JCuda类属于jcuda.runtime包,在下文中一共展示了JCuda类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: 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);
}
开发者ID:jcuda,项目名称:jcuda-samples,代码行数:17,代码来源:JCusolverSp_LinearSolver_Direct.java
示例2: 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();
}
开发者ID:minhhn2910,项目名称:g-mason,代码行数:17,代码来源:HeatBugs.java
示例3: 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();
}
}
开发者ID:minhhn2910,项目名称:g-mason,代码行数:23,代码来源:Students.java
示例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 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);
}
}
开发者ID:minhhn2910,项目名称:g-mason,代码行数:23,代码来源:HeatBugs.java
示例5: 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();
}
开发者ID:akmaier,项目名称:CONRAD,代码行数:24,代码来源:CUDAVolumeOperator.java
示例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();
}
}
开发者ID:Maghoumi,项目名称:TransScale,代码行数:21,代码来源:TransScale.java
示例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);
}
开发者ID:cycentum,项目名称:birdsong-recognition,代码行数:10,代码来源:Cuda.java
示例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);
}
开发者ID:naxos-simulator,项目名称:NaxosSimulator,代码行数:10,代码来源:CudaTest.java
示例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);
}
开发者ID:jcuda,项目名称:jcuda-samples,代码行数:15,代码来源:JCusolverDn_LinearSolver_Direct.java
示例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);
}
开发者ID:jcuda,项目名称:jcuda-samples,代码行数:37,代码来源:JCurandSample.java
示例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();
}
开发者ID:jcuda,项目名称:jcuda-samples,代码行数:34,代码来源:JCudnnMnist.java
示例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);
}
开发者ID:tberg12,项目名称:murphy,代码行数:9,代码来源:CublasUtil.java
示例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();
}
开发者ID:tberg12,项目名称:murphy,代码行数:32,代码来源:CublasUtil.java
示例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();
}
开发者ID:tberg12,项目名称:murphy,代码行数:29,代码来源:CublasUtil.java
示例16: testGetByteBuffer
import jcuda.runtime.JCuda; //导入依赖的package包/类
@Test
public void testGetByteBuffer()
{
Pointer pointer = new Pointer();
JCuda.cudaMallocHost(pointer, 1000);
ByteBuffer byteBuffer = pointer.getByteBuffer();
assertNotNull(byteBuffer);
assertEquals(0, byteBuffer.position());
assertEquals(1000, byteBuffer.limit());
}
开发者ID:jcuda,项目名称:jcuda,代码行数:12,代码来源:TestPointerGetByteBuffer.java
示例17: testGetByteBufferWithOffsetAndSize
import jcuda.runtime.JCuda; //导入依赖的package包/类
@Test
public void testGetByteBufferWithOffsetAndSize()
{
Pointer pointer = new Pointer();
JCuda.cudaMallocHost(pointer, 1000);
ByteBuffer byteBuffer = pointer.getByteBuffer(100, 800);
assertNotNull(byteBuffer);
assertEquals(0, byteBuffer.position());
assertEquals(800, byteBuffer.limit());
}
开发者ID:jcuda,项目名称:jcuda,代码行数:12,代码来源:TestPointerGetByteBuffer.java
示例18: testGetByteBufferEndianness
import jcuda.runtime.JCuda; //导入依赖的package包/类
@Test
public void testGetByteBufferEndianness()
{
Pointer pointer = new Pointer();
JCuda.cudaMallocHost(pointer, 1000);
ByteBuffer byteBuffer = pointer.getByteBuffer(100, 800);
assertEquals(ByteOrder.nativeOrder(), byteBuffer.order());
}
开发者ID:jcuda,项目名称:jcuda,代码行数:9,代码来源:TestPointerGetByteBuffer.java
示例19: testGetByteBufferWithInvalidOffset
import jcuda.runtime.JCuda; //导入依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void testGetByteBufferWithInvalidOffset()
{
Pointer pointer = new Pointer();
JCuda.cudaMallocHost(pointer, 1000);
pointer.getByteBuffer(-100, 800);
}
开发者ID:jcuda,项目名称:jcuda,代码行数:8,代码来源:TestPointerGetByteBuffer.java
示例20: testGetByteBufferWithInvalidSize
import jcuda.runtime.JCuda; //导入依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void testGetByteBufferWithInvalidSize()
{
Pointer pointer = new Pointer();
JCuda.cudaMallocHost(pointer, 1000);
pointer.getByteBuffer(100, 1000);
}
开发者ID:jcuda,项目名称:jcuda,代码行数:8,代码来源:TestPointerGetByteBuffer.java
注:本文中的jcuda.runtime.JCuda类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论