本文整理汇总了Java中jcuda.driver.JCudaDriver类的典型用法代码示例。如果您正苦于以下问题:Java JCudaDriver类的具体用法?Java JCudaDriver怎么用?Java JCudaDriver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JCudaDriver类属于jcuda.driver包,在下文中一共展示了JCudaDriver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initJCuda
import jcuda.driver.JCudaDriver; //导入依赖的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");
}
示例2: testPrimaryContextCreation
import jcuda.driver.JCudaDriver; //导入依赖的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));
}
示例3: initialize
import jcuda.driver.JCudaDriver; //导入依赖的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;
}
示例4: compute
import jcuda.driver.JCudaDriver; //导入依赖的package包/类
public void compute(final float[] scores, final float[] whiteObservations, final float[] blackObservations, final int sequenceLength) {
int gridSizeX = (int) Math.ceil(((double) sequenceLength) / (BLOCK_SIZE_X*ROLL_X));
int extendedSeqLength = gridSizeX * (BLOCK_SIZE_X*ROLL_X);
cuMemcpyHtoD(d_Ow, Pointer.to(CudaUtil.extendWithZeros(whiteObservations, (extendedSeqLength+maxTemplateWidth-1)*CharacterTemplate.LINE_HEIGHT)), (extendedSeqLength+maxTemplateWidth-1)*CharacterTemplate.LINE_HEIGHT * Sizeof.FLOAT);
cuMemcpyHtoD(d_Ob, Pointer.to(CudaUtil.extendWithZeros(blackObservations, (extendedSeqLength+maxTemplateWidth-1)*CharacterTemplate.LINE_HEIGHT)), (extendedSeqLength+maxTemplateWidth-1)*CharacterTemplate.LINE_HEIGHT * Sizeof.FLOAT);
for (int tw=minTemplateWidth; tw<=maxTemplateWidth; ++tw) {
if (templateNumIndices[tw-minTemplateWidth] > 0) {
CUfunction function = new CUfunction();
cuModuleGetFunction(function, cudaModule, "compute_emissions_"+tw);
JCudaDriver.cuFuncSetCacheConfig(function, CUfunc_cache.CU_FUNC_CACHE_PREFER_SHARED);
JCudaDriver.cuFuncSetSharedMemConfig(function, CUsharedconfig.CU_SHARED_MEM_CONFIG_FOUR_BYTE_BANK_SIZE);
Pointer kernelParameters = Pointer.to(Pointer.to(new int[] {templateIndicesOffsets[tw-minTemplateWidth]*sequenceLength}), Pointer.to(new int[] {sequenceLength}), Pointer.to(new int[] {templateNumIndices[tw-minTemplateWidth]}), Pointer.to(d_Tw[tw-minTemplateWidth]), Pointer.to(d_Tb[tw-minTemplateWidth]), Pointer.to(d_Ow), Pointer.to(d_Ob), Pointer.to(d_scores));
int gridSizeY = (int) Math.ceil(((double) templateNumIndices[tw-minTemplateWidth]) / BLOCK_SIZE_Y);
cuLaunchKernel(function,
gridSizeX, gridSizeY, 1, // Grid dimension
BLOCK_SIZE_X, BLOCK_SIZE_Y, 1, // Block dimension
0, null, // Shared memory size and stream
kernelParameters, null // Kernel- and extra parameters
);
}
}
cuMemcpyDtoH(Pointer.to(scores), d_scores, sequenceLength*totalTemplateNumIndices * Sizeof.FLOAT);
}
示例5: prepareProjection
import jcuda.driver.JCudaDriver; //导入依赖的package包/类
/**
* Load the inverted projection matrix for the current projection and resets the projection data.
* @param projectionNumber
*/
private void prepareProjection(int projectionNumber){
float [] cann = new float[3*4];
float [] invAR = new float[3*3];
float [] srcP = new float[3];
SimpleMatrix projMat = geometry.getProjectionMatrix(projectionNumber).computeP();
double [][] mat = new double [3][4];
projMat.copyTo(mat);
computeCanonicalProjectionMatrix(cann, invAR, srcP, new Jama.Matrix(mat));
if (gInvARmatrix == null){
gInvARmatrix = CUDAUtil.copyFloatArrayToDevice(invAR, module, "gInvARmatrix");
gSrcPoint = CUDAUtil.copyFloatArrayToDevice(srcP, module, "gSrcPoint");
} else {
CUDAUtil.updateFloatArrayOnDevice(gInvARmatrix, invAR, module);
CUDAUtil.updateFloatArrayOnDevice(gSrcPoint, srcP, module);
}
// reset Projection Data
JCudaDriver.cuMemsetD32(gProjection, 0, width * height);
}
示例6: fill
import jcuda.driver.JCudaDriver; //导入依赖的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();
}
示例7: getSmallestDevice
import jcuda.driver.JCudaDriver; //导入依赖的package包/类
public static CUdevice getSmallestDevice() {
CUdevice best = null;
long lastmem = Long.MAX_VALUE;
int [] count = new int[1];
JCudaDriver.cuDeviceGetCount(count);
for (int i = 0; i < count[0]; i++) {
CUdevice dev = new CUdevice();
JCudaDriver.cuDeviceGet(dev, i);
CUdevprop prop = new CUdevprop();
JCudaDriver.cuDeviceGetProperties(prop, dev);
//System.out.println(prop);
int [] memory = new int [1];
JCudaDriver.cuDeviceTotalMem(memory, dev);
long mem = correctMemoryValue(memory[0]);
//System.out.println("Memory " + mem);
if (mem < lastmem){
best = dev;
lastmem = mem;
}
}
return best;
}
示例8: getBestDevice
import jcuda.driver.JCudaDriver; //导入依赖的package包/类
public static CUdevice getBestDevice() {
CUdevice best = null;
long lastmem = Long.MIN_VALUE;
int [] count = new int[1];
JCudaDriver.cuDeviceGetCount(count);
for (int i = 0; i < count[0]; i++) {
CUdevice dev = new CUdevice();
JCudaDriver.cuDeviceGet(dev, i);
CUdevprop prop = new CUdevprop();
JCudaDriver.cuDeviceGetProperties(prop, dev);
//System.out.println(prop);
int [] memory = new int [1];
JCudaDriver.cuDeviceTotalMem(memory, dev);
long mem = correctMemoryValue(memory[0]);
//System.out.println("Memory " + mem);
if (mem > lastmem){
best = dev;
lastmem = mem;
}
}
return best;
}
示例9: runExit
import jcuda.driver.JCudaDriver; //导入依赖的package包/类
/**
* Stops the animator and calls System.exit() in a new Thread.
* (System.exit() may not be called synchronously inside one
* of the JOGL callbacks)
*/
protected void runExit()
{
if (pbo != 0)
{
//JCudaDriver.cuGLUnregisterBufferObject(pbo);
JCudaDriver.cuCtxDestroy(glCtx);
//gl.glDeleteBuffers(1, new int[]{ pbo }, 0);
pbo = 0;
}
new Thread(new Runnable()
{
public void run()
{
animatorL.stop();
if (animatorR != null)
{
animatorR.stop();
}
//System.exit(0);
}
}).start();
}
示例10: getCUdeviceptr
import jcuda.driver.JCudaDriver; //导入依赖的package包/类
public static CUdeviceptr getCUdeviceptr(long size) {
CUdeviceptr cuDevicePtr = new CUdeviceptr();
int succ = JCudaDriver.cuMemAlloc(cuDevicePtr, size * Sizeof.FLOAT);
if(succ != 0) {
cuDevicePtr = null;
logger.finest("Failed creating device vector "+ cuDevicePtr + " with size=" + size);
}
else {
logger.finest("Creating device vector "+ cuDevicePtr + " with size=" + size);
}
return cuDevicePtr;
}
示例11: createCUdeviceptr
import jcuda.driver.JCudaDriver; //导入依赖的package包/类
/**
* Create a vector on device and copy host vector to it.
*
* @param values Host vector.
* @return Pointer to device vector.
*/
private CUdeviceptr createCUdeviceptr(float[] values) {
CUdeviceptr cuDevicePtr = createCUdeviceptr((long)values.length);
JCudaDriver.cuMemcpyHtoD(cuDevicePtr, Pointer.to(values),
(long)values.length * Sizeof.FLOAT);
return cuDevicePtr;
}
示例12: createCUdeviceptr
import jcuda.driver.JCudaDriver; //导入依赖的package包/类
/**
* Create a vector on device and copy host vector to it.
*
* @param values Host vector.
* @return Pointer to device vector.
*/
private CUdeviceptr createCUdeviceptr(final float[] values) {
synchronized (vectorsInUseReferenceMap) {
final CUdeviceptr cuDevicePtr = createCUdeviceptr((long)values.length);
try {
deviceExecutor.submit(new Runnable() { public void run() {
JCudaDriver.cuMemcpyHtoD(cuDevicePtr, Pointer.to(values), (long)values.length * Sizeof.FLOAT);
}}).get();
} catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e.getCause()); }
return cuDevicePtr;
}
}
示例13: clean
import jcuda.driver.JCudaDriver; //导入依赖的package包/类
public static void clean() {
// Clean up all remaining pointers
for(ReferenceQueue<RandomVariableCuda> vectorsToRecycleReferenceQueue : vectorsToRecycleReferenceQueueMap.values()) {
Reference<? extends RandomVariableCuda> reference;
while((reference = vectorsToRecycleReferenceQueue.poll()) != null) {
final CUdeviceptr cuDevicePtr = vectorsInUseReferenceMap.remove(reference);
logger.fine("Freeing device pointer " + cuDevicePtr + " from " + reference);
try {
deviceExecutor.submit(new Runnable() { public void run() {
JCudaDriver.cuMemFree(cuDevicePtr);
}}).get();
} catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e.getCause()); }
}
}
}
示例14: CudaDriver
import jcuda.driver.JCudaDriver; //导入依赖的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();
}
示例15: initialize
import jcuda.driver.JCudaDriver; //导入依赖的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");
}