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


Java CUmodule类代码示例

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


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

示例1: initJCuda

import jcuda.driver.CUmodule; //导入依赖的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: initialize

import jcuda.driver.CUmodule; //导入依赖的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

示例3: CudaDriver

import jcuda.driver.CUmodule; //导入依赖的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

示例4: initialize

import jcuda.driver.CUmodule; //导入依赖的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

示例5: testTextures

import jcuda.driver.CUmodule; //导入依赖的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

示例6: initCUDA

import jcuda.driver.CUmodule; //导入依赖的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

示例7: main

import jcuda.driver.CUmodule; //导入依赖的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

示例8: main

import jcuda.driver.CUmodule; //导入依赖的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

示例9: compileAndLoad

import jcuda.driver.CUmodule; //导入依赖的package包/类
public static CUmodule compileAndLoad(String kernelName, String kernelSrc, boolean forceCompile) {
	return loadModule(preparePtxFile(kernelName, kernelSrc, forceCompile));
}
 
开发者ID:tberg12,项目名称:murphy,代码行数:4,代码来源:CudaUtil.java

示例10: loadModule

import jcuda.driver.CUmodule; //导入依赖的package包/类
public static CUmodule loadModule(String name) {
       CUmodule module = new CUmodule();
       cuModuleLoad(module, name);
       return module;
}
 
开发者ID:tberg12,项目名称:murphy,代码行数:6,代码来源:CudaUtil.java

示例11: copyFloatArrayToDevice

import jcuda.driver.CUmodule; //导入依赖的package包/类
public static CUdeviceptr copyFloatArrayToDevice(float [] array, CUmodule module, String nameInCode) {
	CUdeviceptr devptr = new CUdeviceptr();
	JCudaDriver.cuModuleGetGlobal(devptr, new int[1], module, nameInCode);
	JCudaDriver.cuMemcpyHtoD(devptr, Pointer.to(array), Sizeof.FLOAT * array.length);
	return devptr;
}
 
开发者ID:akmaier,项目名称:CONRAD,代码行数:7,代码来源:CUDAUtil.java

示例12: updateFloatArrayOnDevice

import jcuda.driver.CUmodule; //导入依赖的package包/类
public static void updateFloatArrayOnDevice(CUdeviceptr devptr, float [] array, CUmodule module) {
	//JCudaDriver.cuModuleGetGlobal(devptr, new int[1], module, nameInCode);
	JCudaDriver.cuMemcpyHtoD(devptr, Pointer.to(array), Sizeof.FLOAT * array.length);
}
 
开发者ID:akmaier,项目名称:CONRAD,代码行数:5,代码来源:CUDAUtil.java

示例13: Invokable

import jcuda.driver.CUmodule; //导入依赖的package包/类
public Invokable(CUmodule module, CUfunction function) {
	this.module = module;
	this.function = function;
}
 
开发者ID:Maghoumi,项目名称:TransScale,代码行数:5,代码来源:Invokable.java

示例14: JCudaKernels

import jcuda.driver.CUmodule; //导入依赖的package包/类
/**
 * Loads the kernels in the file ptxFileName. Though cubin files are also supported, we will stick with
 * ptx file as they are target-independent similar to Java's .class files.
 *
 * @throws DMLRuntimeException if DMLRuntimeException occurs
 */
JCudaKernels() throws DMLRuntimeException {
	module = new CUmodule();
	// Load the kernels specified in the ptxFileName file
	checkResult(cuModuleLoadDataEx(module, initKernels(ptxFileName), 0, new int[0], Pointer.to(new int[0])));
}
 
开发者ID:apache,项目名称:systemml,代码行数:12,代码来源:JCudaKernels.java

示例15: doTask

import jcuda.driver.CUmodule; //导入依赖的package包/类
/**
 * Called when a CUDA kernel is about to happen or has already happened
 * The framework that calls this function must also provide some CUDA related
 * environment object. Such as the module that the code is working on so that in case
 * the clients want to make API calls that require specific CUDA environment objects 
 * they can. 
 * @param module	The CUmodule object that this trigger is called on
 */
public void doTask(CUmodule module);
 
开发者ID:Maghoumi,项目名称:TransScale,代码行数:10,代码来源:Trigger.java


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