public class GPUContext extends Object
Modifier and Type | Class and Description |
---|---|
static class |
GPUContext.EvictionPolicy
Eviction policies for
evict(long) . |
Modifier and Type | Field and Description |
---|---|
GPUContext.EvictionPolicy |
evictionPolicy
currently employed eviction policy
|
double |
GPU_MEMORY_UTILIZATION_FACTOR |
protected static org.apache.commons.logging.Log |
LOG |
Modifier | Constructor and Description |
---|---|
protected |
GPUContext(int deviceNum) |
Modifier and Type | Method and Description |
---|---|
jcuda.Pointer |
allocate(long size)
Convenience method for
allocate(String, long, int) , defaults statsCount to 1. |
jcuda.Pointer |
allocate(String instructionName,
long size)
Convenience method for
allocate(String, long, int) , defaults statsCount to 1. |
jcuda.Pointer |
allocate(String instructionName,
long size,
int statsCount)
Allocates temporary space on the device.
|
void |
clearMemory()
Clears all memory used by this
GPUContext . |
void |
clearTemporaryMemory()
Clears up the memory used to optimize cudaMalloc/cudaFree calls.
|
GPUObject |
createGPUObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject mo)
Instantiates a new
GPUObject initialized with the given MatrixObject . |
void |
cudaFreeHelper(jcuda.Pointer toFree)
Does lazy cudaFree calls.
|
void |
cudaFreeHelper(jcuda.Pointer toFree,
boolean eager)
Does lazy/eager cudaFree calls.
|
void |
cudaFreeHelper(String instructionName,
jcuda.Pointer toFree)
Does lazy cudaFree calls.
|
void |
cudaFreeHelper(String instructionName,
jcuda.Pointer toFree,
boolean eager)
Does cudaFree calls, lazily.
|
static int |
cudaGetDevice()
Returns which device is currently being used.
|
void |
destroy()
Destroys this GPUContext object.
|
void |
ensureComputeCapability()
Makes sure that GPU that SystemML is trying to use has the minimum compute capability needed.
|
protected void |
evict(long GPUSize)
Convenience wrapper over
evict(String, long) . |
protected void |
evict(String instructionName,
long neededSize)
Memory on the GPU is tried to be freed up until either a chunk of needed size is freed up
or it fails.
|
long |
getAvailableMemory()
Gets the available memory on GPU that SystemML can use.
|
jcuda.jcublas.cublasHandle |
getCublasHandle()
Returns cublasHandle for BLAS operations on the GPU.
|
jcuda.jcudnn.cudnnHandle |
getCudnnHandle()
Returns the cudnnHandle for Deep Neural Network operations on the GPU.
|
jcuda.jcusolver.cusolverDnHandle |
getCusolverDnHandle()
Returns cusolverDnHandle for invoking solve() function on dense matrices on the GPU.
|
jcuda.jcusolver.cusolverSpHandle |
getCusolverSpHandle()
Returns cusolverSpHandle for invoking solve() function on sparse matrices on the GPU.
|
jcuda.jcusparse.cusparseHandle |
getCusparseHandle()
Returns cusparseHandle for certain sparse BLAS operations on the GPU.
|
int |
getDeviceNum()
Returns which device is assigned to this GPUContext instance.
|
jcuda.runtime.cudaDeviceProp |
getGPUProperties()
Gets the device properties for the active GPU (set with cudaSetDevice()).
|
JCudaKernels |
getKernels()
Returns utility class used to launch custom CUDA kernel, specific to the active GPU for this GPUContext.
|
int |
getMaxBlocks()
Gets the maximum number of blocks supported by the active cuda device.
|
long |
getMaxSharedMemory()
Gets the shared memory per block supported by the active cuda device.
|
int |
getMaxThreadsPerBlock()
Gets the maximum number of threads per block for "active" GPU.
|
int |
getWarpSize()
Gets the warp size supported by the active cuda device.
|
void |
initializeThread()
Sets the device for the calling thread.
|
boolean |
isBlockRecorded(GPUObject o)
Whether the GPU associated with this
GPUContext has recorded the usage of a certain block. |
void |
recordBlockUsage(GPUObject o) |
void |
removeRecordedUsage(GPUObject o) |
String |
toString() |
protected static final org.apache.commons.logging.Log LOG
public final GPUContext.EvictionPolicy evictionPolicy
public double GPU_MEMORY_UTILIZATION_FACTOR
protected GPUContext(int deviceNum) throws DMLRuntimeException
DMLRuntimeException
public static int cudaGetDevice()
public int getDeviceNum()
public void initializeThread() throws DMLRuntimeException
ExecutionContext.getGPUContext(int)
If in a multi-threaded environment like parfor, this method must be called when in the
appropriate thread.DMLRuntimeException
- if DMLRuntimeException occurspublic jcuda.Pointer allocate(long size) throws DMLRuntimeException
allocate(String, long, int)
, defaults statsCount to 1.size
- size of data (in bytes) to allocateDMLRuntimeException
- if DMLRuntimeException occurspublic jcuda.Pointer allocate(String instructionName, long size) throws DMLRuntimeException
allocate(String, long, int)
, defaults statsCount to 1.instructionName
- name of instruction for which to record per instruction performance statistics, null if don't want to recordsize
- size of data (in bytes) to allocateDMLRuntimeException
- if DMLRuntimeException occurspublic jcuda.Pointer allocate(String instructionName, long size, int statsCount) throws DMLRuntimeException
instructionName
- name of instruction for which to record per instruction performance statistics, null if don't want to recordsize
- Size of data (in bytes) to allocatestatsCount
- amount to increment the cudaAllocCount byDMLRuntimeException
- if DMLRuntimeException occurspublic void cudaFreeHelper(jcuda.Pointer toFree)
toFree
- Pointer
instance to be freedpublic void cudaFreeHelper(jcuda.Pointer toFree, boolean eager)
toFree
- Pointer
instance to be freedeager
- true if to be done eagerlypublic void cudaFreeHelper(String instructionName, jcuda.Pointer toFree)
instructionName
- name of the instruction for which to record per instruction free time, null if do not want to recordtoFree
- Pointer
instance to be freedpublic void cudaFreeHelper(String instructionName, jcuda.Pointer toFree, boolean eager)
instructionName
- name of the instruction for which to record per instruction free time, null if do not want to recordtoFree
- Pointer
instance to be freedeager
- true if to be done eagerlyprotected void evict(long GPUSize) throws DMLRuntimeException
evict(String, long)
.GPUSize
- Desired size to be freed up on the GPUDMLRuntimeException
- If no blocks to free up or if not enough blocks with zero locks on them.protected void evict(String instructionName, long neededSize) throws DMLRuntimeException
GPUObject
instances. Sorting is based on
number of (read) locks that have been obtained on it (reverse order). It repeatedly frees up
blocks on which there are zero locks until the required size has been freed up.
// TODO: update it with hybrid policyinstructionName
- name of the instruction for which performance measurements are madeneededSize
- desired size to be freed up on the GPUDMLRuntimeException
- If no reusable memory blocks to free up or if not enough matrix blocks with zero locks on them.public boolean isBlockRecorded(GPUObject o)
GPUContext
has recorded the usage of a certain block.o
- the blockpublic void recordBlockUsage(GPUObject o)
o
- GPUObject
instance to recordRecords the usage of a matrix block
public void removeRecordedUsage(GPUObject o)
o
- GPUObject
instance to remove from the list of allocated GPU objectsRecords that a block is not used anymore
public long getAvailableMemory()
public void ensureComputeCapability() throws DMLRuntimeException
DMLRuntimeException
- if the compute capability is less than what is requiredpublic GPUObject createGPUObject(org.apache.sysml.runtime.controlprogram.caching.MatrixObject mo)
GPUObject
initialized with the given MatrixObject
.mo
- a MatrixObject
that represents a matrixGPUObject
instancepublic jcuda.runtime.cudaDeviceProp getGPUProperties() throws DMLRuntimeException
DMLRuntimeException
- ?public int getMaxThreadsPerBlock() throws DMLRuntimeException
DMLRuntimeException
- ?public int getMaxBlocks() throws DMLRuntimeException
DMLRuntimeException
- ?public long getMaxSharedMemory() throws DMLRuntimeException
DMLRuntimeException
- ?public int getWarpSize() throws DMLRuntimeException
DMLRuntimeException
- ?public jcuda.jcudnn.cudnnHandle getCudnnHandle()
public jcuda.jcublas.cublasHandle getCublasHandle()
public jcuda.jcusparse.cusparseHandle getCusparseHandle()
public jcuda.jcusolver.cusolverDnHandle getCusolverDnHandle()
public jcuda.jcusolver.cusolverSpHandle getCusolverSpHandle()
public JCudaKernels getKernels()
JCudaKernels
for current threadpublic void destroy() throws DMLRuntimeException
DMLRuntimeException
- if errorpublic void clearMemory() throws DMLRuntimeException
GPUContext
.
Be careful to ensure that no memory is currently being used in the temporary memory before invoking this.
If memory is being used between MLContext invocations, they are pointed to by a GPUObject
instance
which would be part of the MatrixObject
. The cleanup of that MatrixObject
instance will
cause the memory associated with that block on the GPU to be freed up.DMLRuntimeException
- ?public void clearTemporaryMemory()
Copyright © 2017 The Apache Software Foundation. All rights reserved.