Package net.finmath.montecarlo.opencl
Class RandomVariableOpenCL.DeviceMemoryPool
- java.lang.Object
-
- net.finmath.montecarlo.opencl.RandomVariableOpenCL.DeviceMemoryPool
-
- Enclosing class:
- RandomVariableOpenCL
public static class RandomVariableOpenCL.DeviceMemoryPool extends Object
A memory pool for the GPU vectors. The memory pool is provided for vectors of different length. Implementation details: The map vectorsToRecycleReferenceQueueMap maps each vector length to a ReferenceQueue<DevicePointerReference> holding reference of recycleable vectors. The map vectorsInUseReferenceMap maps this weak reference to a Cuda vector.- Author:
- Christian Fries
-
-
Field Summary
Fields Modifier and Type Field Description static Map<WeakReference<RandomVariableOpenCL.DevicePointerReference>,org.jocl.cl_mem>
vectorsInUseReferenceMap
This map allow to recover the device pointer for a givenWeakReference<DevicePointerReference>
.
-
Constructor Summary
Constructors Constructor Description DeviceMemoryPool()
-
Method Summary
-
-
-
Field Detail
-
vectorsInUseReferenceMap
public static final Map<WeakReference<RandomVariableOpenCL.DevicePointerReference>,org.jocl.cl_mem> vectorsInUseReferenceMap
This map allow to recover the device pointer for a givenWeakReference<DevicePointerReference>
.
-
-
Method Detail
-
getDevicePointer
public RandomVariableOpenCL.DevicePointerReference getDevicePointer(long size)
Get a Java object (RandomVariableOpenCL.DevicePointerReference
) representing a vector allocated on the GPU memory (device memory). If this object is the wrapped into aRandomVariableOpenCL
viaRandomVariableOpenCL.of(double, DevicePointerReference, long)
you may perform arithmetic operations on it. Note: You will likely not use this method directly. Instead usegetDevicePointer(float[])
which will call this method and initialize the vector to the given values. The object is "managed" in the sense the once the object is dereferenced the GPU memory will be marked for re-use (or freed at a later time).- Parameters:
size
- The size of the vector as multiples of sizeof(float). (To allocated a double vector use twice the size).- Returns:
- An object representing a vector allocated on the GPU memory.
-
clean
public void clean()
Free all unused device memory.
-
purge
public void purge()
-
getDevicePointer
public RandomVariableOpenCL.DevicePointerReference getDevicePointer(float[] values)
Create a vector on device and copy host vector to it.- Parameters:
values
- Host vector.- Returns:
- Pointer to device vector.
-
getValuesAsFloat
public float[] getValuesAsFloat(RandomVariableOpenCL.DevicePointerReference devicePtr, int size)
-
callFunctionv1s0
public RandomVariableOpenCL.DevicePointerReference callFunctionv1s0(org.jocl.cl_kernel function, long resultSize, RandomVariableOpenCL.DevicePointerReference argument1)
-
callFunctionv2s0
public RandomVariableOpenCL.DevicePointerReference callFunctionv2s0(org.jocl.cl_kernel function, long resultSize, RandomVariableOpenCL.DevicePointerReference argument1, RandomVariableOpenCL.DevicePointerReference argument2)
-
callFunctionv3s0
public RandomVariableOpenCL.DevicePointerReference callFunctionv3s0(org.jocl.cl_kernel function, long resultSize, RandomVariableOpenCL.DevicePointerReference argument1, RandomVariableOpenCL.DevicePointerReference argument2, RandomVariableOpenCL.DevicePointerReference argument3)
-
callFunctionv1s1
public RandomVariableOpenCL.DevicePointerReference callFunctionv1s1(org.jocl.cl_kernel function, long resultSize, RandomVariableOpenCL.DevicePointerReference argument1, double value)
-
callFunctionv2s1
public RandomVariableOpenCL.DevicePointerReference callFunctionv2s1(org.jocl.cl_kernel function, long resultSize, RandomVariableOpenCL.DevicePointerReference argument1, RandomVariableOpenCL.DevicePointerReference argument2, double value)
-
callFunction
public void callFunction(org.jocl.cl_kernel function, long resultSize, org.jocl.Pointer[] arguments, int[] argumentSizes)
-
callFunction
public void callFunction(org.jocl.cl_kernel function, org.jocl.Pointer[] arguments, int[] argumentSizes, int gridSizeX, int blockSizeX, int sharedMemorySize)
-
-