public class Gpu
extends java.lang.Object
gpu()
method to get a Gpu object.
Study the source code of the classes in package edu.rit.pj2.example to see examples of Parallel Java 2 GPU programs.
Note: Class Gpu is not multiple thread safe. It is assumed that only one thread at a time will call methods on a Gpu object.
Modifier and Type | Field and Description |
---|---|
static boolean |
debug
Debug flag.
|
Modifier and Type | Method and Description |
---|---|
static int |
allowedDeviceCount()
Get the number of GPU devices this process is allowed to use.
|
static int |
deviceCount()
Get the number of GPU devices in the system.
|
void |
ensureComputeCapability(int major,
int minor)
Ensure that this Gpu object supports at least the given compute
capability.
|
protected void |
finalize()
Finalize this Gpu object.
|
GpuByteArray |
getByteArray(int len)
Create a new dynamically allocated GPU byte array.
|
GpuByteArray |
getByteArray(int len,
int cpulen)
Create a new dynamically allocated GPU byte array, of which the given
portion is mirrored in the CPU.
|
GpuByteMatrix |
getByteMatrix(int rows,
int cols)
Create a new dynamically allocated GPU byte matrix.
|
GpuByteMatrix |
getByteMatrix(int rows,
int cols,
int cpurows,
int cpucols)
Create a new dynamically allocated GPU byte matrix, of which the given
portion is mirrored in the CPU.
|
CacheConfig |
getCacheConfig()
Get this GPU's cache configuration.
|
java.lang.String |
getDeviceName()
Get the device name of this GPU.
|
int |
getDeviceNumber()
Get the device number of this GPU.
|
GpuDoubleArray |
getDoubleArray(int len)
Create a new dynamically allocated GPU double array.
|
GpuDoubleArray |
getDoubleArray(int len,
int cpulen)
Create a new dynamically allocated GPU double array, of which the given
portion is mirrored in the CPU.
|
GpuDoubleMatrix |
getDoubleMatrix(int rows,
int cols)
Create a new dynamically allocated GPU double matrix.
|
GpuDoubleMatrix |
getDoubleMatrix(int rows,
int cols,
int cpurows,
int cpucols)
Create a new dynamically allocated GPU double matrix, of which the given
portion is mirrored in the CPU.
|
GpuFloatArray |
getFloatArray(int len)
Create a new dynamically allocated GPU float array.
|
GpuFloatArray |
getFloatArray(int len,
int cpulen)
Create a new dynamically allocated GPU float array, of which the given
portion is mirrored in the CPU.
|
GpuFloatMatrix |
getFloatMatrix(int rows,
int cols)
Create a new dynamically allocated GPU float matrix.
|
GpuFloatMatrix |
getFloatMatrix(int rows,
int cols,
int cpurows,
int cpucols)
Create a new dynamically allocated GPU float matrix, of which the given
portion is mirrored in the CPU.
|
GpuIntArray |
getIntArray(int len)
Create a new dynamically allocated GPU integer array.
|
GpuIntArray |
getIntArray(int len,
int cpulen)
Create a new dynamically allocated GPU integer array, of which the given
portion is mirrored in the CPU.
|
GpuIntMatrix |
getIntMatrix(int rows,
int cols)
Create a new dynamically allocated GPU integer matrix.
|
GpuIntMatrix |
getIntMatrix(int rows,
int cols,
int cpurows,
int cpucols)
Create a new dynamically allocated GPU integer matrix, of which the given
portion is mirrored in the CPU.
|
GpuLongArray |
getLongArray(int len)
Create a new dynamically allocated GPU long integer array.
|
GpuLongArray |
getLongArray(int len,
int cpulen)
Create a new dynamically allocated GPU long integer array, of which the
given portion is mirrored in the CPU.
|
GpuLongMatrix |
getLongMatrix(int rows,
int cols)
Create a new dynamically allocated GPU long integer matrix.
|
GpuLongMatrix |
getLongMatrix(int rows,
int cols,
int cpurows,
int cpucols)
Create a new dynamically allocated GPU long integer matrix, of which the
given portion is mirrored in the CPU.
|
long |
getMallocHeapSize()
Get this GPU's malloc() heap size limit.
|
Module |
getModule(java.lang.String name)
Get a module containing GPU functions and data.
|
int |
getMultiprocessorCount()
Get the number of multiprocessors in this GPU.
|
long |
getPrintfFifoSize()
Get this GPU's printf() FIFO size limit.
|
GpuShortArray |
getShortArray(int len)
Create a new dynamically allocated GPU short integer array.
|
GpuShortArray |
getShortArray(int len,
int cpulen)
Create a new dynamically allocated GPU short integer array, of which the
given portion is mirrored in the CPU.
|
GpuShortMatrix |
getShortMatrix(int rows,
int cols)
Create a new dynamically allocated GPU short integer matrix.
|
GpuShortMatrix |
getShortMatrix(int rows,
int cols,
int cpurows,
int cpucols)
Create a new dynamically allocated GPU short integer matrix, of which the
given portion is mirrored in the CPU.
|
<T extends Struct> |
getStructArray(java.lang.Class<T> type,
int len)
Create a new dynamically allocated GPU struct array.
|
<T extends Struct> |
getStructArray(java.lang.Class<T> type,
int len,
int cpulen)
Create a new dynamically allocated GPU struct array, of which the given
portion is mirrored in the CPU.
|
<T extends Struct> |
getStructMatrix(java.lang.Class<T> type,
int rows,
int cols)
Create a new dynamically allocated GPU struct matrix.
|
<T extends Struct> |
getStructMatrix(java.lang.Class<T> type,
int rows,
int cols,
int cpurows,
int cpucols)
Create a new dynamically allocated GPU struct matrix, of which the given
portion is mirrored in the CPU.
|
<T extends Struct> |
getStructVbl(java.lang.Class<T> type)
Create a new dynamically allocated GPU struct variable.
|
long |
getThreadStackSize()
Get this GPU's thread stack size limit.
|
static Gpu |
gpu()
Construct a new Gpu object.
|
static Gpu |
gpu(CtxSched ctxSched)
Construct a new Gpu object.
|
void |
setCacheConfig(CacheConfig config)
Set this GPU's cache configuration.
|
static void |
setDeviceNumbers(int[] devnum)
Specify the GPU device number or numbers this process is allowed to use.
|
void |
setMallocHeapSize(long value)
Set this GPU's malloc() heap size limit.
|
void |
setPrintfFifoSize(long value)
Set this GPU's printf() FIFO size limit.
|
void |
setThreadStackSize(long value)
Set this GPU's thread stack size limit.
|
java.lang.String |
toString()
Returns a string version of this Gpu object.
|
public static boolean debug
public static int deviceCount()
GpuException
- (unchecked exception) Thrown if a GPU error occurred.public static void setDeviceNumbers(int[] devnum)
Warning: The setDeviceNumbers() method is intended
to be called only by the pj2
launcher program. Do not call
the setDeviceNumbers() method yourself.
devnum
- Array of zero or more device numbers. Each must be in the range 0
through deviceCount()
−1. If
devnum is null, this process is allowed to use all devices.
If devnum is zero length, this process is not allowed to use
any devices.java.lang.IndexOutOfBoundsException
- (unchecked exception) Thrown if any device number is out of bounds.GpuException
- (unchecked exception) Thrown if a GPU error occurred.public static int allowedDeviceCount()
GpuException
- (unchecked exception) Thrown if a GPU error occurred.public static Gpu gpu()
CU_CTX_SCHED_BLOCKING_SYNC
is used.java.lang.IllegalStateException
- (unchecked exception) Thrown if there are no available GPU devices.GpuException
- (unchecked exception) Thrown if a GPU error occurred.public static Gpu gpu(CtxSched ctxSched)
ctxSched
- Context scheduling flag.java.lang.IllegalStateException
- (unchecked exception) Thrown if there are no available GPU devices.GpuException
- (unchecked exception) Thrown if a GPU error occurred.CtxSched
public void ensureComputeCapability(int major, int minor)
major
- Required compute capability major version.minor
- Required compute capability minor version.GpuException
- (unchecked exception) Thrown if this Gpu object does not support at
least the given compute capability. Thrown if a GPU error occurred.public int getDeviceNumber()
public java.lang.String getDeviceName()
public int getMultiprocessorCount()
public void setCacheConfig(CacheConfig config)
config
- Cache configuration.java.lang.NullPointerException
- (unchecked exception) Thrown if config is null.GpuException
- (unchecked exception) Thrown if a GPU error occurred.public CacheConfig getCacheConfig()
GpuException
- (unchecked exception) Thrown if a GPU error occurred.public void setThreadStackSize(long value)
value
- Thread stack size limit.GpuException
- (unchecked exception) Thrown if a GPU error occurred.public long getThreadStackSize()
GpuException
- (unchecked exception) Thrown if a GPU error occurred.public void setPrintfFifoSize(long value)
value
- printf() FIFO size limit.GpuException
- (unchecked exception) Thrown if a GPU error occurred.public long getPrintfFifoSize()
GpuException
- (unchecked exception) Thrown if a GPU error occurred.public void setMallocHeapSize(long value)
value
- malloc() heap size limit.GpuException
- (unchecked exception) Thrown if a GPU error occurred.public long getMallocHeapSize()
GpuException
- (unchecked exception) Thrown if a GPU error occurred.public GpuByteArray getByteArray(int len)
item
field's elements, are initialized to
zeroes. The array elements in GPU memory are not initialized.len
- Number of array elements (≥ 1).java.lang.IllegalArgumentException
- (unchecked exception) Thrown if len < 1.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getByteArray(int,int)
public GpuByteArray getByteArray(int len, int cpulen)
item
field's elements, are initialized to
zeroes. The array elements in GPU memory are not initialized.len
- Number of array elements (≥ 1).cpulen
- Number of array elements to mirror in the CPU.java.lang.IllegalArgumentException
- (unchecked exception) Thrown if len < 1, cpulen
< 0, or cpulen > len.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getByteArray(int)
public GpuShortArray getShortArray(int len)
item
field's elements, are
initialized to zeroes. The array elements in GPU memory are not
initialized.len
- Number of array elements (≥ 1).java.lang.IllegalArgumentException
- (unchecked exception) Thrown if len < 1.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getShortArray(int,int)
public GpuShortArray getShortArray(int len, int cpulen)
item
field's elements, are
initialized to zeroes. The array elements in GPU memory are not
initialized.len
- Number of array elements (≥ 1).cpulen
- Number of array elements to mirror in the CPU.java.lang.IllegalArgumentException
- (unchecked exception) Thrown if len < 1, cpulen
< 0, or cpulen > len.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getShortArray(int)
public GpuIntArray getIntArray(int len)
item
field's elements, are initialized to
zeroes. The array elements in GPU memory are not initialized.len
- Number of array elements (≥ 1).java.lang.IllegalArgumentException
- (unchecked exception) Thrown if len < 1.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getIntArray(int,int)
public GpuIntArray getIntArray(int len, int cpulen)
item
field's elements, are initialized to
zeroes. The array elements in GPU memory are not initialized.len
- Number of array elements (≥ 1).cpulen
- Number of array elements to mirror in the CPU.java.lang.IllegalArgumentException
- (unchecked exception) Thrown if len < 1, cpulen
< 0, or cpulen > len.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getIntArray(int)
public GpuLongArray getLongArray(int len)
item
field's elements, are initialized to
zeroes. The array elements in GPU memory are not initialized.len
- Number of array elements (≥ 1).java.lang.IllegalArgumentException
- (unchecked exception) Thrown if len < 1.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getLongArray(int,int)
public GpuLongArray getLongArray(int len, int cpulen)
item
field's elements, are
initialized to zeroes. The array elements in GPU memory are not
initialized.len
- Number of array elements (≥ 1).cpulen
- Number of array elements to mirror in the CPU.java.lang.IllegalArgumentException
- (unchecked exception) Thrown if len < 1, cpulen
< 0, or cpulen > len.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getLongArray(int)
public GpuFloatArray getFloatArray(int len)
item
field's elements, are initialized to
zeroes. The array elements in GPU memory are not initialized.len
- Number of array elements (≥ 1).java.lang.IllegalArgumentException
- (unchecked exception) Thrown if len < 1.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getFloatArray(int,int)
public GpuFloatArray getFloatArray(int len, int cpulen)
item
field's elements, are initialized to
zeroes. The array elements in GPU memory are not initialized.len
- Number of array elements (≥ 1).cpulen
- Number of array elements to mirror in the CPU.java.lang.IllegalArgumentException
- (unchecked exception) Thrown if len < 1, cpulen
< 0, or cpulen > len.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getFloatArray(int)
public GpuDoubleArray getDoubleArray(int len)
item
field's elements, are initialized to
zeroes. The array elements in GPU memory are not initialized.len
- Number of array elements (≥ 1).java.lang.IllegalArgumentException
- (unchecked exception) Thrown if len < 1.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getDoubleArray(int,int)
public GpuDoubleArray getDoubleArray(int len, int cpulen)
item
field's elements, are initialized to
zeroes. The array elements in GPU memory are not initialized.len
- Number of array elements (≥ 1).cpulen
- Number of array elements to mirror in the CPU.java.lang.IllegalArgumentException
- (unchecked exception) Thrown if len < 1, cpulen
< 0, or cpulen > len.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getDoubleArray(int)
public GpuByteMatrix getByteMatrix(int rows, int cols)
item
field's elements, are initialized to
zeroes. The matrix elements in GPU memory are not initialized.rows
- Number of matrix rows (≥ 1).cols
- Number of matrix columns (≥ 1).java.lang.IllegalArgumentException
- (unchecked exception) Thrown if rows < 1 or cols
< 1.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getByteMatrix(int,int,int,int)
public GpuByteMatrix getByteMatrix(int rows, int cols, int cpurows, int cpucols)
item
field's elements, are initialized to zeroes. The matrix elements in
GPU memory are not initialized.rows
- Number of matrix rows (≥ 1).cols
- Number of matrix columns (≥ 1).cpurows
- Number of matrix rows to mirror in the CPU.cpucols
- Number of matrix columns to mirror in the CPU.java.lang.IllegalArgumentException
- (unchecked exception) Thrown if rows < 1, cols
< 1, cpurows < 0, cpurows > rows,
cpucols < 0, or cpucols > cols.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getByteMatrix(int,int)
public GpuShortMatrix getShortMatrix(int rows, int cols)
item
field's elements, are
initialized to zeroes. The matrix elements in GPU memory are not
initialized.rows
- Number of matrix rows (≥ 1).cols
- Number of matrix columns (≥ 1).java.lang.IllegalArgumentException
- (unchecked exception) Thrown if rows < 1 or cols
< 1.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getShortMatrix(int,int,int,int)
public GpuShortMatrix getShortMatrix(int rows, int cols, int cpurows, int cpucols)
item
field's elements, are initialized to zeroes. The matrix elements
in GPU memory are not initialized.rows
- Number of matrix rows (≥ 1).cols
- Number of matrix columns (≥ 1).cpurows
- Number of matrix rows to mirror in the CPU.cpucols
- Number of matrix columns to mirror in the CPU.java.lang.IllegalArgumentException
- (unchecked exception) Thrown if rows < 1, cols
< 1, cpurows < 0, cpurows > rows,
cpucols < 0, or cpucols > cols.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getShortMatrix(int,int)
public GpuIntMatrix getIntMatrix(int rows, int cols)
item
field's elements, are initialized to
zeroes. The matrix elements in GPU memory are not initialized.rows
- Number of matrix rows (≥ 1).cols
- Number of matrix columns (≥ 1).java.lang.IllegalArgumentException
- (unchecked exception) Thrown if rows < 1 or cols
< 1.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getIntMatrix(int,int,int,int)
public GpuIntMatrix getIntMatrix(int rows, int cols, int cpurows, int cpucols)
item
field's elements, are initialized to zeroes. The matrix elements in
GPU memory are not initialized.rows
- Number of matrix rows (≥ 1).cols
- Number of matrix columns (≥ 1).cpurows
- Number of matrix rows to mirror in the CPU.cpucols
- Number of matrix columns to mirror in the CPU.java.lang.IllegalArgumentException
- (unchecked exception) Thrown if rows < 1, cols
< 1, cpurows < 0, cpurows > rows,
cpucols < 0, or cpucols > cols.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getIntMatrix(int,int)
public GpuLongMatrix getLongMatrix(int rows, int cols)
item
field's elements, are
initialized to zeroes. The matrix elements in GPU memory are not
initialized.rows
- Number of matrix rows (≥ 1).cols
- Number of matrix columns (≥ 1).java.lang.IllegalArgumentException
- (unchecked exception) Thrown if rows < 1 or cols
< 1.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getLongMatrix(int,int,int,int)
public GpuLongMatrix getLongMatrix(int rows, int cols, int cpurows, int cpucols)
item
field's elements, are initialized to zeroes. The matrix elements in
GPU memory are not initialized.rows
- Number of matrix rows (≥ 1).cols
- Number of matrix columns (≥ 1).cpurows
- Number of matrix rows to mirror in the CPU.cpucols
- Number of matrix columns to mirror in the CPU.java.lang.IllegalArgumentException
- (unchecked exception) Thrown if rows < 1, cols
< 1, cpurows < 0, cpurows > rows,
cpucols < 0, or cpucols > cols.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getLongMatrix(int,int)
public GpuFloatMatrix getFloatMatrix(int rows, int cols)
item
field's elements, are initialized to
zeroes. The matrix elements in GPU memory are not initialized.rows
- Number of matrix rows (≥ 1).cols
- Number of matrix columns (≥ 1).java.lang.IllegalArgumentException
- (unchecked exception) Thrown if rows < 1 or cols
< 1.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getFloatMatrix(int,int,int,int)
public GpuFloatMatrix getFloatMatrix(int rows, int cols, int cpurows, int cpucols)
item
field's elements, are initialized to zeroes. The matrix elements
in GPU memory are not initialized.rows
- Number of matrix rows (≥ 1).cols
- Number of matrix columns (≥ 1).cpurows
- Number of matrix rows to mirror in the CPU.cpucols
- Number of matrix columns to mirror in the CPU.java.lang.IllegalArgumentException
- (unchecked exception) Thrown if rows < 1, cols
< 1, cpurows < 0, cpurows > rows,
cpucols < 0, or cpucols > cols.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getFloatMatrix(int,int)
public GpuDoubleMatrix getDoubleMatrix(int rows, int cols)
item
field's elements, are initialized
to zeroes. The matrix elements in GPU memory are not initialized.rows
- Number of matrix rows (≥ 1).cols
- Number of matrix columns (≥ 1).java.lang.IllegalArgumentException
- (unchecked exception) Thrown if rows < 1 or cols
< 1.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getDoubleMatrix(int,int,int,int)
public GpuDoubleMatrix getDoubleMatrix(int rows, int cols, int cpurows, int cpucols)
item
field's elements, are initialized to zeroes. The matrix elements
in GPU memory are not initialized.rows
- Number of matrix rows (≥ 1).cols
- Number of matrix columns (≥ 1).cpurows
- Number of matrix rows to mirror in the CPU.cpucols
- Number of matrix columns to mirror in the CPU.java.lang.IllegalArgumentException
- (unchecked exception) Thrown if rows < 1, cols
< 1, cpurows < 0, cpurows > rows,
cpucols < 0, or cpucols > cols.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getDoubleMatrix(int,int)
public <T extends Struct> GpuStructVbl<T> getStructVbl(java.lang.Class<T> type)
item
field, is
initialized to null. The variable in GPU memory is not
initialized.T
- Java data type. Class T must extend class
Struct.type
- Class object for Java data type.java.lang.NullPointerException
- (unchecked exception) Thrown if type is null.GpuException
- (unchecked exception) Thrown if a GPU error occurred.public <T extends Struct> GpuStructArray<T> getStructArray(java.lang.Class<T> type, int len)
item
field's elements, are initialized to
null. The array elements in GPU memory are not initialized.T
- Java data type. Class T must extend class
Struct.type
- Class object for Java data type.len
- Number of array elements (≥ 1).java.lang.NullPointerException
- (unchecked exception) Thrown if type is null.java.lang.IllegalArgumentException
- (unchecked exception) Thrown if len < 1.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getStructArray(Class,int,int)
public <T extends Struct> GpuStructArray<T> getStructArray(java.lang.Class<T> type, int len, int cpulen)
item
field's elements, are initialized to
null. The array elements in GPU memory are not initialized.T
- Java data type. Class T must extend class
Struct.type
- Class object for Java data type.len
- Number of array elements (≥ 1).cpulen
- Number of array elements to mirror in the CPU.java.lang.NullPointerException
- (unchecked exception) Thrown if type is null.java.lang.IllegalArgumentException
- (unchecked exception) Thrown if len < 1, cpulen
< 0, or cpulen > len.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getStructArray(Class,int)
public <T extends Struct> GpuStructMatrix<T> getStructMatrix(java.lang.Class<T> type, int rows, int cols)
item
field's elements, are initialized
to null. The matrix elements in GPU memory are not initialized.T
- Java data type. Class T must extend class
Struct.type
- Class object for Java data type.rows
- Number of matrix rows (≥ 1).cols
- Number of matrix columns (≥ 1).java.lang.NullPointerException
- (unchecked exception) Thrown if type is null.java.lang.IllegalArgumentException
- (unchecked exception) Thrown if rows < 1 or cols
< 1.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getStructMatrix(Class,int,int,int,int)
public <T extends Struct> GpuStructMatrix<T> getStructMatrix(java.lang.Class<T> type, int rows, int cols, int cpurows, int cpucols)
item
field's elements, are initialized to null. The matrix elements
in GPU memory are not initialized.T
- Java data type. Class T must extend class
Struct.type
- Class object for Java data type.rows
- Number of matrix rows (≥ 1).cols
- Number of matrix columns (≥ 1).cpurows
- Number of matrix rows to mirror in the CPU.cpucols
- Number of matrix columns to mirror in the CPU.java.lang.NullPointerException
- (unchecked exception) Thrown if type is null.java.lang.IllegalArgumentException
- (unchecked exception) Thrown if rows < 1, cols
< 1, cpurows < 0, cpurows > rows,
cpucols < 0, or cpucols > cols.GpuException
- (unchecked exception) Thrown if a GPU error occurred.getStructMatrix(Class,int,int)
public Module getModule(java.lang.String name) throws java.io.IOException
name
- Module resource name relative to the Java class path.java.io.IOException
- Thrown if an I/O error occurred.GpuException
- (unchecked exception) Thrown if a GPU error occurred.public java.lang.String toString()
toString
in class java.lang.Object
protected void finalize()
finalize
in class java.lang.Object
Copyright © 2013–2018 by Alan Kaminsky. All rights reserved. Send comments to ark@cs.rit.edu.