• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java CUcontext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中jcuda.driver.CUcontext的典型用法代码示例。如果您正苦于以下问题:Java CUcontext类的具体用法?Java CUcontext怎么用?Java CUcontext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: initJCuda

import jcuda.driver.CUcontext; //导入依赖的package包/类
/**
 * Initialize the JCudaDriver. Note that this has to be done from the
 * same thread that will later use the JCudaDriver API
 */
private void initJCuda()
{
    JCudaDriver.setExceptionsEnabled(true);

    // Create a device and a context
    cuInit(0);
    CUdevice device = new CUdevice();
    cuDeviceGet(device, 0);
    CUcontext context = new CUcontext();
    cuCtxCreate(context, 0, device);

    // Prepare the PTX file containing the kernel
    String ptxFileName = JCudaSamplesUtils.preparePtxFile(
        "src/main/resources/kernels/JCudaDriverSimpleGLKernel.cu");
    
    // Load the PTX file containing the kernel
    CUmodule module = new CUmodule();
    cuModuleLoad(module, ptxFileName);

    // Obtain a function pointer to the kernel function. This function
    // will later be called during the animation, in the display 
    // method of this GLEventListener.
    function = new CUfunction();
    cuModuleGetFunction(function, module, "simple_vbo_kernel");
}
 
开发者ID:jcuda,项目名称:jcuda-samples,代码行数:30,代码来源:JCudaDriverSimpleLWJGL.java


示例2: testPrimaryContextCreation

import jcuda.driver.CUcontext; //导入依赖的package包/类
@Test
public void testPrimaryContextCreation()
{
    JCudaDriver.setExceptionsEnabled(true);
    
    cuInit(0);

    CUdevice device = new CUdevice();
    cuDeviceGet(device, 0);
    
    CUcontext context = new CUcontext();
    cuDevicePrimaryCtxRetain(context, device);
    
    CUcontext nullContext = new CUcontext();
    assertFalse(context.equals(nullContext));
}
 
开发者ID:jcuda,项目名称:jcuda,代码行数:17,代码来源:JCudaDriverPrimaryContextTest.java


示例3: initialize

import jcuda.driver.CUcontext; //导入依赖的package包/类
/**
 * Tries to compile the specified .CU file into a PTX file, loads this
 * PTX file as a module, obtains the specified function from this module
 * and returns it.
 * 
 * @param cuFileName The .CU file name
 * @param functionName The kernel function name
 * @return The function
 * @throws CudaException If an error occurs
 */
protected final CUfunction initialize(
    String cuFileName, String functionName)
{
    // Enable exceptions and omit all subsequent error checks
    JCudaDriver.setExceptionsEnabled(true);
   
    // Initialize the driver and create a context for the first device.
    cuInit(0);
    CUdevice device = new CUdevice();
    cuDeviceGet(device, 0);
    CUcontext context = new CUcontext();
    cuCtxCreate(context, 0, device);

    String ptxFileName = JCudaTestUtils.preparePtxFile(cuFileName);
    
    // Load the ptx file.
    CUmodule module = new CUmodule();
    cuModuleLoad(module, ptxFileName);

    // Obtain a function pointer to the kernel function.
    CUfunction function = new CUfunction();
    cuModuleGetFunction(function, module, functionName);
    
    return function;
}
 
开发者ID:jcuda,项目名称:jcuda,代码行数:36,代码来源:JCudaAbstractKernelTest.java


示例4: CudaDriver

import jcuda.driver.CUcontext; //导入依赖的package包/类
public CudaDriver() throws CudaException
{
	JCudaDriver.cuInit(0);
	CUdevice device = new CUdevice();
	checkError(JCudaDriver.cuDeviceGet(device, 0));
	context = new CUcontext();
	checkError(JCudaDriver.cuCtxCreate(context, 0, device));
	module = new CUmodule();
}
 
开发者ID:cycentum,项目名称:birdsong-recognition,代码行数:10,代码来源:CudaDriver.java


示例5: initialize

import jcuda.driver.CUcontext; //导入依赖的package包/类
/**
 * Initialize the driver API, the {@link #context} and the 
 * kernel {@link #function} 
 */
private static void initialize()
{
    System.out.println("Initializing...");
    
    JCudaDriver.setExceptionsEnabled(true);
    JNvrtc.setExceptionsEnabled(true);

    cuInit(0);
    CUdevice device = new CUdevice();
    cuDeviceGet(device, 0);
    context = new CUcontext();
    cuCtxCreate(context, 0, device);

    nvrtcProgram program = new nvrtcProgram();
    nvrtcCreateProgram(
        program, programSourceCode, null, 0, null, null);
    nvrtcCompileProgram(program, 0, null);
    
    String[] ptx = new String[1];
    nvrtcGetPTX(program, ptx);
    nvrtcDestroyProgram(program);

    CUmodule module = new CUmodule();
    cuModuleLoadData(module, ptx[0]);

    function = new CUfunction();
    cuModuleGetFunction(function, module, "example");
    
    System.out.println("Initializing DONE");
}
 
开发者ID:jcuda,项目名称:jcuda-samples,代码行数:35,代码来源:JCudaDriverStreamCallbacks.java


示例6: startup

import jcuda.driver.CUcontext; //导入依赖的package包/类
public static void startup(int deviceId) {
       JCudaDriver.setExceptionsEnabled(true);
       JCudaDriver.cuInit(0);
       device = new CUdevice();
       cuDeviceGet(device, deviceId);
       context = new CUcontext();
       cuCtxCreate(context, 0, device);
}
 
开发者ID:tberg12,项目名称:murphy,代码行数:9,代码来源:CudaUtil.java


示例7: testTextures

import jcuda.driver.CUcontext; //导入依赖的package包/类
@Test
public void testTextures()
{
    JCudaDriver.setExceptionsEnabled(true);

    // Create the PTX file by calling the NVCC
    String ptxFileName = JCudaTestUtils.preparePtxFile(
        "src/test/resources/kernels/JCudaDriverTextureTestKernels.cu");

    // Initialize the driver and create a context for the first device.
    cuInit(0);
    CUcontext pctx = new CUcontext();
    CUdevice dev = new CUdevice();
    cuDeviceGet(dev, 0);
    cuCtxCreate(pctx, 0, dev);

    // Load the file containing the kernels
    module = new CUmodule();
    cuModuleLoad(module, ptxFileName);

    // Initialize the host input data
    initInputHost();

    // Perform the tests
    assertTrue(test_float_1D());
    assertTrue(test_float_2D());
    assertTrue(test_float_3D());
    assertTrue(test_float4_1D());
    assertTrue(test_float4_2D());
    assertTrue(test_float4_3D());
}
 
开发者ID:jcuda,项目名称:jcuda,代码行数:32,代码来源:JCudaDriverTextureTest.java


示例8: initCUDA

import jcuda.driver.CUcontext; //导入依赖的package包/类
public void initCUDA(){
	if (!inited) {
		// Initialize the JCudaDriver. Note that this has to be done from 
		// the same thread that will later use the JCudaDriver API.
		JCudaDriver.setExceptionsEnabled(true);
		JCudaDriver.cuInit(0);
		CUdevice dev = CUDAUtil.getBestDevice();
		cuCtx = new CUcontext();
		JCudaDriver.cuCtxCreate(cuCtx, 0, dev);
		// check space on device:
		int [] memory = new int [1]; 
		JCudaDriver.cuDeviceTotalMem(memory, dev);
		int availableMemory = (int) (CUDAUtil.correctMemoryValue(memory[0]) / ((long)1024 * 1024));
		if (debug) {
			System.out.println("Total available Memory on CUDA card:" + availableMemory);
		}
		if (debug) {
			CUdevprop prop = new CUdevprop();
			JCudaDriver.cuDeviceGetProperties(prop, dev);
			System.out.println(prop.toFormattedString());
		}
		// Load the CUBIN file containing the kernel
		module = new CUmodule();
		JCudaDriver.cuModuleLoad(module, "CUDAVolumeFunctions.sm_10.cubin");

		// Obtain a function pointer to the kernel function. This function
		// will later be called. 
		// 
		if (debug) System.out.println("Initialized.");
		inited = true;
	}
}
 
开发者ID:akmaier,项目名称:CONRAD,代码行数:33,代码来源:CUDAVolumeOperator.java


示例9: main

import jcuda.driver.CUcontext; //导入依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) throws Exception {
	JCudaDriver.setExceptionsEnabled(true);
	cuInit(0);
	CUdevice device = new CUdevice();
	cuDeviceGet(device, 0);
	CUcontext context = new CUcontext();
	cuCtxCreate(context, 0, device);
	
	CUmodule module = new CUmodule();
	cuModuleLoad(module, "jcuda/Rule184.ptx");
	CUfunction function = new CUfunction();
	cuModuleGetFunction(function, module, "move");
	
	
	int MAX = 1024 * 1023 / 2;
	/*
	int hostArr[] = new int[MAX];
	float treshold = GlobalConfiguration.getInstance().getFloat(SettingsKeys.VEHICLE_DENSITY);
	for (int i = 0; i < hostArr.length; i++) {
		if (Math.random() < treshold) {
			hostArr[i] = 1;
		} else {
			hostArr[i] = 0;
		}
	}
	*/
	//logger.info(Arrays.toString(hostArr));
	CUdeviceptr devPtr = new CUdeviceptr();
	int deviceSize = MAX * Sizeof.INT;
	cuMemAlloc(devPtr, deviceSize);
	//cuMemcpyHtoD(devPtr, Pointer.to(hostArr), deviceSize);
	
	int[] time = {0};

	int blockSizeX = 256;
	int gridSizeX = (int)Math.ceil((double)MAX / 2 / blockSizeX);

	//boolean onlyFirstAndLast = !true;
	//StringBuffer sb = new StringBuffer();
	long start = System.currentTimeMillis();
	int iterations = 10 * 60 * 16 * 2; //16 m/s - ten minutes
	for (int i = 0; i < iterations; i++) {
		Pointer kernelParameters = Pointer.to(Pointer.to(new int[] {MAX}), 
				Pointer.to(time),
				Pointer.to(devPtr));
		cuLaunchKernel(function, 
				gridSizeX, 1, 1,
				blockSizeX, 1, 1,
				0, null,
				kernelParameters, null);
		cuCtxSynchronize();

		/*
		if (!onlyFirstAndLast || i == 0 || i == MAX / 2 - 1) {
			cuMemcpyDtoH(Pointer.to(hostArr), devPtr, deviceSize);
			for (int j = 0; j < MAX / 2; j++) {
				sb.append(hostArr[2 * j + time[0]] > 0 ? 'o' : '.');
			}
			logger.info(sb.toString());
			sb.setLength(0);
		}
		*/
		time[0] = 1 - time[0];
	}
	long stop = System.currentTimeMillis();
	logger.info((stop - start)+"ms vehicles: "+MAX+" iterations: "+iterations+" single iteration ms "+((double)stop-start) / iterations);
	cuMemFree(devPtr);

}
 
开发者ID:naxos-simulator,项目名称:NaxosSimulator,代码行数:73,代码来源:CudaTest.java


示例10: main

import jcuda.driver.CUcontext; //导入依赖的package包/类
public static void main(String[] args)
{
    // Enable exceptions and omit all subsequent error checks
    JCudaDriver.setExceptionsEnabled(true);

    // Initialize the driver and create a context for the first device.
    cuInit(0);
    CUdevice device = new CUdevice();
    cuDeviceGet(device, 0);
    CUcontext context = new CUcontext();
    cuCtxCreate(context, 0, device);

    // Afterwards, initialize the vector library, which will
    // attach to the current context
    VecFloat.init();
    
    // Allocate and fill the host input data
    int n = 50000;
    float hostX[] = new float[n];
    float hostY[] = new float[n];
    for(int i = 0; i < n; i++)
    {
        hostX[i] = (float)i;
        hostY[i] = (float)i;
    }

    // Allocate the device pointers, and copy the
    // host input data to the device
    CUdeviceptr deviceX = new CUdeviceptr();
    cuMemAlloc(deviceX, n * Sizeof.FLOAT);
    cuMemcpyHtoD(deviceX, Pointer.to(hostX), n * Sizeof.FLOAT);

    CUdeviceptr deviceY = new CUdeviceptr();
    cuMemAlloc(deviceY, n * Sizeof.FLOAT); 
    cuMemcpyHtoD(deviceY, Pointer.to(hostY), n * Sizeof.FLOAT);

    CUdeviceptr deviceResult = new CUdeviceptr();
    cuMemAlloc(deviceResult, n * Sizeof.FLOAT);

    // Perform the vector operations
    VecFloat.cos(n, deviceX, deviceX);               // x = cos(x)  
    VecFloat.mul(n, deviceX, deviceX, deviceX);      // x = x*x
    VecFloat.sin(n, deviceY, deviceY);               // y = sin(y)
    VecFloat.mul(n, deviceY, deviceY, deviceY);      // y = y*y
    VecFloat.add(n, deviceResult, deviceX, deviceY); // result = x+y

    // Allocate host output memory and copy the device output
    // to the host.
    float hostResult[] = new float[n];
    cuMemcpyDtoH(Pointer.to(hostResult), deviceResult, n * Sizeof.FLOAT);

    // Verify the result
    boolean passed = true;
    for(int i = 0; i < n; i++)
    {
        float expected = (float)(
            Math.cos(hostX[i])*Math.cos(hostX[i])+
            Math.sin(hostY[i])*Math.sin(hostY[i]));
        if (Math.abs(hostResult[i] - expected) > 1e-5)
        {
            System.out.println(
                "At index "+i+ " found "+hostResult[i]+
                " but expected "+expected);
            passed = false;
            break;
        }
    }
    System.out.println("Test "+(passed?"PASSED":"FAILED"));

    // Clean up.
    cuMemFree(deviceX);
    cuMemFree(deviceY);
    cuMemFree(deviceResult);
    VecFloat.shutdown();
}
 
开发者ID:jcuda,项目名称:jcuda-samples,代码行数:76,代码来源:VecFloatSample.java


示例11: main

import jcuda.driver.CUcontext; //导入依赖的package包/类
public static void main(String[] args)
{
    // Enable exceptions and omit all subsequent error checks
    JCudaDriver.setExceptionsEnabled(true);

    // Initialize the driver and create a context for the first device.
    cuInit(0);
    CUdevice device = new CUdevice();
    cuDeviceGet(device, 0);
    CUcontext context = new CUcontext();
    cuCtxCreate(context, 0, device);

    // Afterwards, initialize the vector library, which will
    // attach to the current context
    VecDouble.init();
    
    // Allocate and fill the host input data
    int n = 50000;
    double hostX[] = new double[n];
    double hostY[] = new double[n];
    for(int i = 0; i < n; i++)
    {
        hostX[i] = (double)i;
        hostY[i] = (double)i;
    }

    // Allocate the device pointers, and copy the
    // host input data to the device
    CUdeviceptr deviceX = new CUdeviceptr();
    cuMemAlloc(deviceX, n * Sizeof.DOUBLE);
    cuMemcpyHtoD(deviceX, Pointer.to(hostX), n * Sizeof.DOUBLE);

    CUdeviceptr deviceY = new CUdeviceptr();
    cuMemAlloc(deviceY, n * Sizeof.DOUBLE); 
    cuMemcpyHtoD(deviceY, Pointer.to(hostY), n * Sizeof.DOUBLE);

    CUdeviceptr deviceResult = new CUdeviceptr();
    cuMemAlloc(deviceResult, n * Sizeof.DOUBLE);

    // Perform the vector operations
    VecDouble.cos(n, deviceX, deviceX);               // x = cos(x)  
    VecDouble.mul(n, deviceX, deviceX, deviceX);      // x = x*x
    VecDouble.sin(n, deviceY, deviceY);               // y = sin(y)
    VecDouble.mul(n, deviceY, deviceY, deviceY);      // y = y*y
    VecDouble.add(n, deviceResult, deviceX, deviceY); // result = x+y

    // Allocate host output memory and copy the device output
    // to the host.
    double hostResult[] = new double[n];
    cuMemcpyDtoH(Pointer.to(hostResult), deviceResult, n * Sizeof.DOUBLE);

    // Verify the result
    boolean passed = true;
    for(int i = 0; i < n; i++)
    {
        double expected = 
            Math.cos(hostX[i])*Math.cos(hostX[i])+
            Math.sin(hostY[i])*Math.sin(hostY[i]);
        if (Math.abs(hostResult[i] - expected) > 1e-14)
        {
            System.out.println(
                "At index "+i+ " found "+hostResult[i]+
                " but expected "+expected);
            passed = false;
            break;
        }
    }
    System.out.println("Test "+(passed?"PASSED":"FAILED"));

    // Clean up.
    cuMemFree(deviceX);
    cuMemFree(deviceY);
    cuMemFree(deviceResult);
    VecDouble.shutdown();
}
 
开发者ID:jcuda,项目名称:jcuda-samples,代码行数:76,代码来源:VecDoubleSample.java


示例12: main

import jcuda.driver.CUcontext; //导入依赖的package包/类
public static void main(String[] args)
{
    JCudaDriver.setExceptionsEnabled(true);

    // Initialize a context for the first device
    cuInit(0);
    CUcontext context = new CUcontext();
    CUdevice device = new CUdevice();
    cuDeviceGet(device, 0);
    cuCtxCreate(context, 0, device);

    // Create the CUBIN file by calling the NVCC. 
    // See the prepareDefaultCubinFile method for the details about
    // the NVCC parameters that are used here. 
    String cubinFileName = JCudaSamplesUtils.prepareDefaultCubinFile(
        "src/main/resources/kernels/JCudaDynamicParallelismKernel.cu");

    // Load the CUBIN file 
    CUmodule module = new CUmodule();
    cuModuleLoad(module, cubinFileName);

    // Obtain a function pointer to the "parentKernel" function.
    CUfunction function = new CUfunction();
    cuModuleGetFunction(function, module, "parentKernel");

    // Define the nesting structure. 
    // 
    // NOTE: The number of child threads MUST match the value that 
    // is used in the kernel, for the childKernel<<<1, 8>>> call!
    // 
    int numParentThreads = 8;
    int numChildThreads = 8;

    // Allocate the device data that will be filled by the kernel
    int numElements = numParentThreads * numChildThreads;
    CUdeviceptr deviceData = new CUdeviceptr();
    cuMemAlloc(deviceData, numElements * Sizeof.FLOAT);

    // Set up the kernel parameters: A pointer to an array
    // of pointers which point to the actual values.
    Pointer kernelParameters = Pointer.to(
        Pointer.to(new int[] { numElements }),
        Pointer.to(deviceData)
    );

    // Call the kernel function.
    int blockSizeX = numParentThreads;
    int gridSizeX = (numElements + numElements - 1) / blockSizeX;
    cuLaunchKernel(function,
        gridSizeX,  1, 1,      // Grid dimension
        blockSizeX, 1, 1,      // Block dimension
        0, null,               // Shared memory size and stream
        kernelParameters, null // Kernel- and extra parameters
    );
    cuCtxSynchronize();

    // Copy the device data to the host
    float hostData[] = new float[numElements];
    for(int i = 0; i < numElements; i++)
    {
        hostData[i] = i;
    }
    cuMemcpyDtoH(Pointer.to(hostData), 
        deviceData, numElements * Sizeof.FLOAT);

    // Compare the host data with the expected values
    float hostDataRef[] = new float[numElements];
    for(int i = 0; i < numParentThreads; i++)
    {
        for (int j=0; j < numChildThreads; j++)
        {
            hostDataRef[i * numChildThreads + j] = i + 0.1f * j;
        }
    }
    System.out.println("Result: "+Arrays.toString(hostData));
    boolean passed = Arrays.equals(hostData, hostDataRef);
    System.out.println(passed ? "PASSED" : "FAILED");

    // Clean up.
    cuMemFree(deviceData);
}
 
开发者ID:jcuda,项目名称:jcuda-samples,代码行数:82,代码来源:JCudaDynamicParallelism.java


示例13: main

import jcuda.driver.CUcontext; //导入依赖的package包/类
public static void main(String[] args)
{
    JCudaDriver.setExceptionsEnabled(true);
    JCublas.setExceptionsEnabled(true);
    
    // Initialize the driver and create a context for the first device.
    cuInit(0);
    CUdevice device = new CUdevice();
    cuDeviceGet(device, 0);
    CUcontext context = new CUcontext();
    cuCtxCreate(context, 0, device);
    
    // Check if the device supports managed memory
    int supported[] = { 0 };
    cuDeviceGetAttribute(supported, 
        CU_DEVICE_ATTRIBUTE_MANAGED_MEMORY, device);
    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;
    CUdeviceptr p = new CUdeviceptr();
    cuMemAllocManaged(p, size, CU_MEM_ATTACH_HOST);

    // 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
    cuStreamAttachMemAsync(null, p, 0,  CU_MEM_ATTACH_GLOBAL);
    cuStreamSynchronize(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,代码行数:55,代码来源:JCudaDriverUnifiedMemory.java


示例14: testMemRangeAttribute

import jcuda.driver.CUcontext; //导入依赖的package包/类
@Test
public void testMemRangeAttribute()
{
    JCudaDriver.setExceptionsEnabled(true);
    
    cuInit(0);
    CUcontext contest = new CUcontext();
    CUdevice device = new CUdevice();
    cuDeviceGet(device, 0);
    cuCtxCreate(contest, 0, device);
    
    int size = 64;
    CUdeviceptr deviceData = new CUdeviceptr();
    cuMemAllocManaged(deviceData, size, CU_MEM_ATTACH_HOST);
    
    int readMostly[] = { 12345 };
    int lastPrefetchLocation[] = { 12345 };
    int preferredLocation[] = { 12345 };
    int accessedBy[] = { 12345, 12345, 12345 };
    
    cuMemRangeGetAttribute(Pointer.to(readMostly), Sizeof.INT, 
        CU_MEM_RANGE_ATTRIBUTE_READ_MOSTLY, deviceData, size);

    cuMemRangeGetAttribute(Pointer.to(lastPrefetchLocation), Sizeof.INT, 
        CU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION, deviceData, size);

    cuMemRangeGetAttribute(Pointer.to(preferredLocation), Sizeof.INT, 
        CU_MEM_RANGE_ATTRIBUTE_PREFERRED_LOCATION, deviceData, size);

    cuMemRangeGetAttribute(
        Pointer.to(accessedBy), Sizeof.INT * accessedBy.length, 
        CU_MEM_RANGE_ATTRIBUTE_ACCESSED_BY, deviceData, size);

    boolean printResults = false;
    //printResults = true;
    if (printResults)
    {
        System.out.println("readMostly          : " + 
            Arrays.toString(lastPrefetchLocation));
        System.out.println("lastPrefetchLocation: " + 
            Arrays.toString(lastPrefetchLocation));
        System.out.println("preferredLocation   : " + 
            Arrays.toString(preferredLocation));
        System.out.println("accessedBy          : " + 
            Arrays.toString(accessedBy));
    }
}
 
开发者ID:jcuda,项目名称:jcuda,代码行数:48,代码来源:JCudaDriverMemRangeTest.java


示例15: testMemRangeAttributes

import jcuda.driver.CUcontext; //导入依赖的package包/类
@Test
public void testMemRangeAttributes()
{
    JCudaDriver.setExceptionsEnabled(true);
    
    cuInit(0);
    CUcontext contest = new CUcontext();
    CUdevice device = new CUdevice();
    cuDeviceGet(device, 0);
    cuCtxCreate(contest, 0, device);
    
    int size = 64;
    CUdeviceptr deviceData = new CUdeviceptr();
    cuMemAllocManaged(deviceData, size, CU_MEM_ATTACH_HOST);
    
    int readMostly[] = { 12345 };
    int lastPrefetchLocation[] = { 12345 };
    int preferredLocation[] = { 12345 };
    int accessedBy[] = { 12345, 12345, 12345 };
    
    Pointer data[] =  
    {
        Pointer.to(readMostly),
        Pointer.to(lastPrefetchLocation),
        Pointer.to(preferredLocation),
        Pointer.to(accessedBy) 
    };
    long dataSizes[] = 
    {
        Sizeof.INT, 
        Sizeof.INT, 
        Sizeof.INT, 
        Sizeof.INT * accessedBy.length
    };
    int attributes[] =  
    {
        CU_MEM_RANGE_ATTRIBUTE_READ_MOSTLY,
        CU_MEM_RANGE_ATTRIBUTE_LAST_PREFETCH_LOCATION,
        CU_MEM_RANGE_ATTRIBUTE_PREFERRED_LOCATION,
        CU_MEM_RANGE_ATTRIBUTE_ACCESSED_BY,
    };
    cuMemRangeGetAttributes(data, dataSizes, 
        attributes, attributes.length, deviceData, size);
    
    boolean printResults = false;
    //printResults = true;
    if (printResults)
    {
        System.out.println("readMostly          : " + 
            Arrays.toString(lastPrefetchLocation));
        System.out.println("lastPrefetchLocation: " + 
            Arrays.toString(lastPrefetchLocation));
        System.out.println("preferredLocation   : " + 
            Arrays.toString(preferredLocation));
        System.out.println("accessedBy          : " + 
            Arrays.toString(accessedBy));
    }
}
 
开发者ID:jcuda,项目名称:jcuda,代码行数:59,代码来源:JCudaDriverMemRangeTest.java


示例16: init

import jcuda.driver.CUcontext; //导入依赖的package包/类
@Override
public void init(GLAutoDrawable drawable)
{
	if (multiFrameMode) {
		// Perform the default GL initialization
		GL gl = drawable.getGL();
		gl.setSwapInterval(0);
		gl.glEnable(GL.GL_DEPTH_TEST);
		gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
		setupView(drawable);

		// Initialize the GL_ARB_pixel_buffer_object extension
		if (!gl.isExtensionAvailable("GL_ARB_pixel_buffer_object"))
		{
			new Thread(new Runnable()
			{
				public void run()
				{
					JOptionPane.showMessageDialog(null,
							"GL_ARB_pixel_buffer_object extension not available",
							"Unavailable extension", JOptionPane.ERROR_MESSAGE);
					runExit();
				}
			}).start();
		}

		// Create a TextRenderer for the status messages
		renderer = new TextRenderer(new Font("SansSerif", Font.PLAIN, 12));

		if (initialized)
		{
			return;
		}

		// Initialize the JCudaDriver. Note that this has to be done from 
		// the same thread that will later use the JCudaDriver API.
		JCudaDriver.setExceptionsEnabled(true);
		JCudaDriver.cuInit(0);
		CUdevice dev = new CUdevice();
		JCudaDriver.cuDeviceGet(dev, 0);
		glCtx = new CUcontext();
		JCudaDriver.cuGLCtxCreate(glCtx, 0, dev);

		// Load the CUBIN file containing the kernel
		JCudaDriver.cuModuleLoad(module, "volumeRender_kernel.sm_10.cubin");

		// Obtain the global pointer to the inverted view matrix from 
		// the module
		JCudaDriver.cuModuleGetGlobal(c_invViewMatrix, new int[1], module,
		"c_invViewMatrix");

		// Obtain a function pointer to the kernel function. This function
		// will later be called in the display method of this 
		// GLEventListener.
		function = new CUfunction();
		JCudaDriver.cuModuleGetFunction(function, module,
		"_Z16d_render_texturePjjjffffi");

		// Initialize CUDA with the current volume data
		initCuda();

		// Initialize the OpenGL pixel buffer object
		initPBO(gl);

		initialized = true;
	} else {
		super.init(drawable);
	}
}
 
开发者ID:akmaier,项目名称:CONRAD,代码行数:70,代码来源:ImagePlusVolumeRenderer.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java GLProfiler类代码示例发布时间:2022-05-22
下一篇:
Java CommunicationsException类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap