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


Java JCuda.setExceptionsEnabled方法代码示例

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


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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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);

	int n = numberOfFactors * numberOfPaths;

	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);

	// Allocate memory
	float[][][] brownianIncrementsArray = new float[timeDiscretization.getNumberOfTimeSteps()][numberOfFactors][numberOfPaths];        

	// Pre-calculate square roots of deltaT
	for(int timeIndex=0; timeIndex<timeDiscretization.getNumberOfTimeSteps(); timeIndex++) {
		float sqrtOfTimeStep = (float)Math.sqrt(timeDiscretization.getTimeStep(timeIndex));

		// Generate n floats on device 
		jcuda.jcurand.JCurand.curandGenerateNormal(generator, deviceData, n, 0.0f /* mean */, sqrtOfTimeStep /* stddev */);

		int offset = 0;
		for(int factor=0; factor<numberOfFactors; factor++) {
			// Copy device memory to host 
			cudaMemcpy(Pointer.to(brownianIncrementsArray[timeIndex][factor]), deviceData.withByteOffset(offset * Sizeof.FLOAT), 
					numberOfPaths * Sizeof.FLOAT, cudaMemcpyDeviceToHost);
			offset += numberOfPaths;
		}				
	}


	// Cleanup 
	curandDestroyGenerator(generator);
	cudaFree(deviceData);

	// Allocate memory for RandomVariable wrapper objects.
	brownianIncrements = new RandomVariableInterface[timeDiscretization.getNumberOfTimeSteps()][numberOfFactors];

	// Wrap the values in RandomVariable objects
	for(int timeIndex=0; timeIndex<timeDiscretization.getNumberOfTimeSteps(); timeIndex++) {
		double time = timeDiscretization.getTime(timeIndex+1);
		for(int factor=0; factor<numberOfFactors; factor++) {
			brownianIncrements[timeIndex][factor] = new RandomVariableLowMemory(time, brownianIncrementsArray[timeIndex][factor]);
			//						randomVariableFactory.createRandomVariable(time, brownianIncrementsArray[timeIndex][factor]);
		}
	}
}
 
开发者ID:finmath,项目名称:finmath-lib-cuda-extensions,代码行数:64,代码来源:BrownianMotionCudaWithHostRandomVariable.java

示例11: main

import jcuda.runtime.JCuda; //导入方法依赖的package包/类
/**
 * Entry point of this sample
 * 
 * @param args Not used
 */
public static void main(String args[])
{
    // Enable exceptions and subsequently omit error checks in this sample
    JCuda.setExceptionsEnabled(true);
    JCublas2.setExceptionsEnabled(true);
    JCusparse.setExceptionsEnabled(true);

    // Create the handle for the CUSPARSE context
    cusparseHandle cusparseHandle = new cusparseHandle();
    cusparseCreate(cusparseHandle);
    cusparseSetPointerMode(cusparseHandle, CUSPARSE_POINTER_MODE_HOST);

    // Create the handle for the CUBLAS context
    cublasHandle cublasHandle = new cublasHandle();
    cublasCreate(cublasHandle);
    cublasSetPointerMode(cublasHandle, CUBLAS_POINTER_MODE_HOST);

    // Create the input matrix: A random tridiagonal symmetric dense 
    // matrix that is stored in host memory
    int numRows = 1024;
    int numCols = numRows;
    FloatMatrixHostDense matrixHostDense = createMatrix(numRows, numCols);

    // Create the solver that implements the CG method 
    // and run the test
    CGSolverFloatDevice solverSimple = 
        CGSolversFloat.createSimple(cusparseHandle, cublasHandle);
    runTest(cusparseHandle, matrixHostDense, solverSimple);

    // Create the solver that implements the preconditioned CG method 
    // and run the test
    CGSolverFloatDevice solverPrecond = 
        CGSolversFloat.createPrecond(cusparseHandle, cublasHandle);
    runTest(cusparseHandle, matrixHostDense, solverPrecond);
    
    // Clean up
    solverSimple.dispose();
    solverPrecond.dispose();
    cusparseDestroy(cusparseHandle);
    cublasDestroy(cublasHandle);
}
 
开发者ID:jcuda,项目名称:jcuda-matrix-utils,代码行数:47,代码来源:CGSolverFloatSample.java

示例12: main

import jcuda.runtime.JCuda; //导入方法依赖的package包/类
/**
 * Entry point of this sample
 * 
 * @param args Not used
 */
public static void main(String args[])
{
    // Enable exceptions and subsequently omit error checks in this sample
    JCuda.setExceptionsEnabled(true);
    JCublas2.setExceptionsEnabled(true);
    JCusparse.setExceptionsEnabled(true);

    // Create the handle for the CUSPARSE context
    cusparseHandle cusparseHandle = new cusparseHandle();
    cusparseCreate(cusparseHandle);
    cusparseSetPointerMode(cusparseHandle, CUSPARSE_POINTER_MODE_HOST);

    // Create the handle for the CUBLAS context
    cublasHandle cublasHandle = new cublasHandle();
    cublasCreate(cublasHandle);
    cublasSetPointerMode(cublasHandle, CUBLAS_POINTER_MODE_HOST);

    // Create the input matrix: A random tridiagonal symmetric dense 
    // matrix that is stored in host memory
    int numRows = 1024;
    int numCols = numRows;
    DoubleMatrixHostDense matrixHostDense = createMatrix(numRows, numCols);

    // Create the solver that implements the CG method 
    // and run the test
    CGSolverDoubleDevice solverSimple = 
        CGSolversDouble.createSimple(cusparseHandle, cublasHandle);
    runTest(cusparseHandle, matrixHostDense, solverSimple);

    // Create the solver that implements the preconditioned CG method 
    // and run the test
    CGSolverDoubleDevice solverPrecond = 
        CGSolversDouble.createPrecond(cusparseHandle, cublasHandle);
    runTest(cusparseHandle, matrixHostDense, solverPrecond);
    
    // Clean up
    solverSimple.dispose();
    solverPrecond.dispose();
    cusparseDestroy(cusparseHandle);
    cublasDestroy(cublasHandle);
}
 
开发者ID:jcuda,项目名称:jcuda-matrix-utils,代码行数:47,代码来源:CGSolverDoubleSample.java

示例13: main

import jcuda.runtime.JCuda; //导入方法依赖的package包/类
public static void main(String[] args)
{
    JCublas2.setExceptionsEnabled(true);
    JCuda.setExceptionsEnabled(true);
    testSgemmBatched(10, 100);
}
 
开发者ID:jcuda,项目名称:jcuda-samples,代码行数:7,代码来源:JCublas2SgemmBatched.java

示例14: main

import jcuda.runtime.JCuda; //导入方法依赖的package包/类
/**
 * Entry point of this sample
 * 
 * @param args Not used
 */
public static void main(String args[])
{
    // Enable exceptions to quickly be informed about errors in this test
    JCuda.setExceptionsEnabled(true);
    JCublas2.setExceptionsEnabled(true);

    // Check if the device supports mapped host memory
    cudaDeviceProp deviceProperties = new cudaDeviceProp();
    cudaGetDeviceProperties(deviceProperties, 0);
    if (deviceProperties.canMapHostMemory == 0)
    {
        System.err.println("This device can not map host memory");
        System.err.println(deviceProperties.toFormattedString());
        return;
    }

    // Set the flag indicating that mapped memory will be used
    cudaSetDeviceFlags(cudaDeviceMapHost);

    // Allocate mappable host memory
    int n = 5;
    Pointer hostPointer = new Pointer();
    cudaHostAlloc(hostPointer, n * Sizeof.FLOAT, cudaHostAllocMapped);

    // Create a device pointer mapping the host memory
    Pointer devicePointer = new Pointer();
    cudaHostGetDevicePointer(devicePointer, hostPointer, 0);

    // Obtain a ByteBuffer for accessing the data in the host
    // pointer. Modifications in this ByteBuffer will be
    // visible in the device memory.
    ByteBuffer byteBuffer = hostPointer.getByteBuffer(0, n * Sizeof.FLOAT);

    // Set the byte order of the ByteBuffer
    byteBuffer.order(ByteOrder.nativeOrder());

    // For convenience, view the ByteBuffer as a FloatBuffer
    // and fill it with some sample data
    FloatBuffer floatBuffer = byteBuffer.asFloatBuffer();
    System.out.print("Input : ");
    for (int i = 0; i < n; i++)
    {
        floatBuffer.put(i, (float) i);
        System.out.print(floatBuffer.get(i) + ", ");
    }
    System.out.println();

    // Apply a CUBLAS routine to the device pointer. This will
    // modify the host data, which was mapped to the device.
    cublasHandle handle = new cublasHandle();
    cublasCreate(handle);
    Pointer two = Pointer.to(new float[] { 2.0f });
    cublasSscal(handle, n, two, devicePointer, 1);
    cublasDestroy(handle);
    cudaDeviceSynchronize();

    // Print the contents of the host memory after the
    // modification via the mapped pointer.
    System.out.print("Output: ");
    for (int i = 0; i < n; i++)
    {
        System.out.print(floatBuffer.get(i) + ", ");
    }
    System.out.println();

    // Clean up
    cudaFreeHost(hostPointer);
}
 
开发者ID:jcuda,项目名称:jcuda-samples,代码行数:74,代码来源:JCudaRuntimeMappedMemory.java

示例15: main

import jcuda.runtime.JCuda; //导入方法依赖的package包/类
public static void main(String[] args)
{
    JCuda.setExceptionsEnabled(true);
    JCublas.setExceptionsEnabled(true);
    
    // Check if the device supports managed memory
    int supported[] = { 0 };
    cudaDeviceGetAttribute(supported, cudaDevAttrManagedMemory, 0);
    if (supported[0] == 0)
    {
        System.err.println("Device does not support managed memory");
        return;
    }

    // Allocate managed memory that is accessible to the host
    int n = 10;
    long size = n * Sizeof.FLOAT;
    Pointer p = new Pointer();
    cudaMallocManaged(p, size, cudaMemAttachHost);

    // Obtain the byte buffer from the pointer. This is supported only
    // for memory that was allocated to be accessible on the host:
    ByteBuffer bb = p.getByteBuffer(0, size);
    
    System.out.println("Buffer on host side: " + bb);

    // Fill the buffer with sample data
    FloatBuffer fb = bb.order(ByteOrder.nativeOrder()).asFloatBuffer();
    for (int i = 0; i < n; i++)
    {
        fb.put(i, i);
    }

    // Make the buffer accessible to all devices
    cudaStreamAttachMemAsync(null, p, 0, cudaMemAttachGlobal);
    cudaStreamSynchronize(null);

    // Use the pointer in a device operation (here, a dot product with 
    // JCublas, for example). The data that was filled in by the host
    // will now be used by the device.
    cublasHandle handle = new cublasHandle();
    cublasCreate(handle);
    float result[] = { -1.0f };
    cublasSdot(handle, n, p, 1, p, 1, Pointer.to(result));
    System.out.println("Result: " + result[0]);
}
 
开发者ID:jcuda,项目名称:jcuda-samples,代码行数:47,代码来源:JCudaRuntimeUnifiedMemory.java


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