Class Range
- java.lang.Object
-
- com.aparapi.internal.jni.RangeJNI
-
- com.aparapi.Range
-
public class Range extends RangeJNI
A representation of 1, 2 or 3 dimensional range of execution. This class uses factory methods to allow one, two or three dimensional ranges to be created.
For a Kernel operating over the linear range 0..1024 without a specified groups size we would create a one dimensionalRangeusing
To request the same linear range but with a groupSize of 64 (range must be a multiple of group size!) we would useRange.create(1024);
To request a two dimensional range over a grid (0..width)x(0..height) where width==512 and height=256 we would useRange.create(1024,64);
Again the above does not specify the group size. One will be chosen for you. If you want to specify the groupSize (say 16x8; 16 wide by 8 high) useint width=512; int height=256; Range.create2D(width,height)
Finally we can request a three dimensional range usingint width=512; int height=256; int groupWidth=16; int groupHeight=8; Range.create2D(width, height, groupWidth, groupHeight);
And can specify a group size usingint width=512; int height=256; int depth=8; Range.create3D(width, height, depth);
int width=512; int height=256; int depth=8; int groupWidth=8; int groupHeight=4; int groupDepth=2 Range.create3D(width, height, depth, groupWidth, groupHeight, groupDepth);
-
-
Field Summary
Fields Modifier and Type Field Description private OpenCLDevicedevicestatic intMAX_GROUP_SIZEstatic intMAX_OPENCL_GROUP_SIZEprivate intmaxWorkGroupSizeprivate int[]maxWorkItemSizestatic intTHREADS_PER_CORE-
Fields inherited from class com.aparapi.internal.jni.RangeJNI
dims, globalSize_0, globalSize_1, globalSize_2, localIsDerived, localSize_0, localSize_1, localSize_2, valid
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Rangecreate(int _globalWidth)static Rangecreate(int _globalWidth, int _localWidth)static Rangecreate(Device _device, int _globalWidth)Create a one dimensional range0.._globalWidthwith an undefined group size.static Rangecreate(Device _device, int _globalWidth, int _localWidth)Create a one dimensional range0.._globalWidthwhich is processed in groups of size _localWidth.static Rangecreate2D(int _globalWidth, int _globalHeight)static Rangecreate2D(int _globalWidth, int _globalHeight, int _localWidth, int _localHeight)static Rangecreate2D(Device _device, int _globalWidth, int _globalHeight)Create a two dimensional range0.._globalWidth * 0.._globalHeightchoosing suitable values forlocalWidthandlocalHeight.static Rangecreate2D(Device _device, int _globalWidth, int _globalHeight, int _localWidth, int _localHeight)Create a two dimensional range 0.._globalWidth x 0.._globalHeight using a group which is _localWidth x _localHeight in size.static Rangecreate3D(int _globalWidth, int _globalHeight, int _globalDepth)static Rangecreate3D(int _globalWidth, int _globalHeight, int _globalDepth, int _localWidth, int _localHeight, int _localDepth)static Rangecreate3D(Device _device, int _globalWidth, int _globalHeight, int _globalDepth)Create a three dimensional range0.._globalWidth * 0.._globalHeight *0../_globalDepthchoosing suitable values forlocalWidth,localHeightandlocalDepth.static Rangecreate3D(Device _device, int _globalWidth, int _globalHeight, int _globalDepth, int _localWidth, int _localHeight, int _localDepth)Create a two dimensional range0.._globalWidth * 0.._globalHeight *0../_globalDepthin groups defined bylocalWidth*localHeight*localDepth.DevicegetDevice()intgetDims()Get the number of dims for this Range.private static int[]getFactors(int _value, int _max)Determine the set of factors for a given value.intgetGlobalSize(int _dim)Get the globalSize (of the range) given the requested dimensionintgetGlobalSize_0()intgetGlobalSize_1()intgetGlobalSize_2()intgetLocalSize(int _dim)Get the localSize (of the group) given the requested dimensionintgetLocalSize_0()intgetLocalSize_1()intgetLocalSize_2()intgetMaxWorkGroupSize()int[]getMaxWorkItemSize()intgetNumGroups(int _dim)Get the number of groups for the given dimension.intgetWorkGroupSize()booleanisLocalIsDerived()booleanisValid()voidsetDims(int dims)voidsetGlobalSize_0(int globalSize_0)voidsetGlobalSize_1(int globalSize_1)voidsetGlobalSize_2(int globalSize_2)voidsetLocalIsDerived(boolean localIsDerived)voidsetLocalSize_0(int localSize_0)voidsetLocalSize_1(int localSize_1)voidsetLocalSize_2(int localSize_2)voidsetMaxWorkGroupSize(int maxWorkGroupSize)voidsetMaxWorkItemSize(int[] maxWorkItemSize)voidsetValid(boolean valid)java.lang.StringtoString()OverridetoString()
-
-
-
Field Detail
-
THREADS_PER_CORE
public static final int THREADS_PER_CORE
- See Also:
- Constant Field Values
-
MAX_OPENCL_GROUP_SIZE
public static final int MAX_OPENCL_GROUP_SIZE
- See Also:
- Constant Field Values
-
MAX_GROUP_SIZE
public static final int MAX_GROUP_SIZE
-
device
private OpenCLDevice device
-
maxWorkGroupSize
private int maxWorkGroupSize
-
maxWorkItemSize
private int[] maxWorkItemSize
-
-
Constructor Detail
-
Range
public Range(Device _device, int _dims)
Minimal constructor- Parameters:
_device-_dims-
-
-
Method Detail
-
create
public static Range create(Device _device, int _globalWidth, int _localWidth)
Create a one dimensional range0.._globalWidthwhich is processed in groups of size _localWidth.
Note that for this range to be valid :_globalWidth > 0 && _localWidth > 0 && _localWidth < MAX_GROUP_SIZE && _globalWidth % _localWidth==0- Parameters:
_globalWidth- the overall range we wish to process_localWidth- the size of the group we wish to process.- Returns:
- A new Range with the requested dimensions
-
getFactors
private static int[] getFactors(int _value, int _max)Determine the set of factors for a given value.- Parameters:
_value- The value we wish to factorize._max- an upper bound on the value that can be chosen- Returns:
- and array of factors of _value
-
create
public static Range create(Device _device, int _globalWidth)
Create a one dimensional range0.._globalWidthwith an undefined group size.
Note that for this range to be valid :-_globalWidth > 0
The groupsize will be chosen such that _localWidth > 0 && _localWidth < MAX_GROUP_SIZE && _globalWidth % _localWidth==0 is true We extract the factors of _globalWidth and choose the highest value.- Parameters:
_globalWidth- the overall range we wish to process- Returns:
- A new Range with the requested dimensions
-
create
public static Range create(int _globalWidth, int _localWidth)
-
create
public static Range create(int _globalWidth)
-
create2D
public static Range create2D(Device _device, int _globalWidth, int _globalHeight, int _localWidth, int _localHeight)
Create a two dimensional range 0.._globalWidth x 0.._globalHeight using a group which is _localWidth x _localHeight in size.
Note that for this range to be valid _globalWidth > 0 && _globalHeight >0 && _localWidth>0 && _localHeight>0 && _localWidth*_localHeight < MAX_GROUP_SIZE && _globalWidth%_localWidth==0 && _globalHeight%_localHeight==0.- Parameters:
_globalWidth- the overall range we wish to process- Returns:
-
create2D
public static Range create2D(Device _device, int _globalWidth, int _globalHeight)
Create a two dimensional range0.._globalWidth * 0.._globalHeightchoosing suitable values forlocalWidthandlocalHeight.Note that for this range to be valid
_globalWidth > 0 && _globalHeight >0 && _localWidth>0 && _localHeight>0 && _localWidth*_localHeight < MAX_GROUP_SIZE && _globalWidth%_localWidth==0 && _globalHeight%_localHeight==0.To determine suitable values for
_localWidthand_localHeightwe extract the factors for_globalWidthand_globalHeightand then find the largest product (<= MAX_GROUP_SIZE) with the lowest perimeter.For example for
MAX_GROUP_SIZEof 16 we favor 4x4 over 1x16.- Parameters:
_globalWidth- the overall range we wish to process- Returns:
-
create2D
public static Range create2D(int _globalWidth, int _globalHeight, int _localWidth, int _localHeight)
-
create2D
public static Range create2D(int _globalWidth, int _globalHeight)
-
create3D
public static Range create3D(Device _device, int _globalWidth, int _globalHeight, int _globalDepth, int _localWidth, int _localHeight, int _localDepth)
Create a two dimensional range0.._globalWidth * 0.._globalHeight *0../_globalDepthin groups defined bylocalWidth*localHeight*localDepth.Note that for this range to be valid
_globalWidth > 0 && _globalHeight >0 _globalDepth >0 && _localWidth>0 && _localHeight>0 && _localDepth>0 && _localWidth*_localHeight*_localDepth < MAX_GROUP_SIZE && _globalWidth%_localWidth==0 && _globalHeight%_localHeight==0 && _globalDepth%_localDepth==0.- Parameters:
_globalWidth- the width of the 3D grid we wish to process_globalHeight- the height of the 3D grid we wish to process_globalDepth- the depth of the 3D grid we wish to process_localWidth- the width of the 3D group we wish to process_localHeight- the height of the 3D group we wish to process_localDepth- the depth of the 3D group we wish to process- Returns:
-
create3D
public static Range create3D(Device _device, int _globalWidth, int _globalHeight, int _globalDepth)
Create a three dimensional range0.._globalWidth * 0.._globalHeight *0../_globalDepthchoosing suitable values forlocalWidth,localHeightandlocalDepth.Note that for this range to be valid
_globalWidth > 0 && _globalHeight >0 _globalDepth >0 && _localWidth>0 && _localHeight>0 && _localDepth>0 && _localWidth*_localHeight*_localDepth < MAX_GROUP_SIZE && _globalWidth%_localWidth==0 && _globalHeight%_localHeight==0 && _globalDepth%_localDepth==0.To determine suitable values for
_localWidth,_localHeightand_lodalDepthwe extract the factors for_globalWidth,_globalHeightand_globalDepthand then find the largest product (<= MAX_GROUP_SIZE) with the lowest perimeter.For example for
MAX_GROUP_SIZEof 64 we favor 4x4x4 over 1x16x16.- Parameters:
_globalWidth- the width of the 3D grid we wish to process_globalHeight- the height of the 3D grid we wish to process_globalDepth- the depth of the 3D grid we wish to process- Returns:
-
create3D
public static Range create3D(int _globalWidth, int _globalHeight, int _globalDepth)
-
create3D
public static Range create3D(int _globalWidth, int _globalHeight, int _globalDepth, int _localWidth, int _localHeight, int _localDepth)
-
toString
public java.lang.String toString()
OverridetoString()- Overrides:
toStringin classjava.lang.Object
-
getLocalSize
public int getLocalSize(int _dim)
Get the localSize (of the group) given the requested dimension- Parameters:
_dim- 0=width, 1=height, 2=depth- Returns:
- The size of the group give the requested dimension
-
getGlobalSize
public int getGlobalSize(int _dim)
Get the globalSize (of the range) given the requested dimension- Parameters:
_dim- 0=width, 1=height, 2=depth- Returns:
- The size of the group give the requested dimension
-
getNumGroups
public int getNumGroups(int _dim)
Get the number of groups for the given dimension.This will essentially return globalXXXX/localXXXX for the given dimension (width, height, depth)
- Parameters:
_dim- The dim we are interested in 0, 1 or 2- Returns:
- the number of groups for the given dimension.
-
getWorkGroupSize
public int getWorkGroupSize()
- Returns:
- The product of all valid localSize dimensions
-
getDevice
public Device getDevice()
-
getGlobalSize_0
public int getGlobalSize_0()
- Returns:
- the globalSize_0
-
setGlobalSize_0
public void setGlobalSize_0(int globalSize_0)
- Parameters:
globalSize_0- the globalSize_0 to set
-
getLocalSize_0
public int getLocalSize_0()
- Returns:
- the localSize_0
-
setLocalSize_0
public void setLocalSize_0(int localSize_0)
- Parameters:
localSize_0- the localSize_0 to set
-
getGlobalSize_1
public int getGlobalSize_1()
- Returns:
- the globalSize_1
-
setGlobalSize_1
public void setGlobalSize_1(int globalSize_1)
- Parameters:
globalSize_1- the globalSize_1 to set
-
getLocalSize_1
public int getLocalSize_1()
- Returns:
- the localSize_1
-
setLocalSize_1
public void setLocalSize_1(int localSize_1)
- Parameters:
localSize_1- the localSize_1 to set
-
getGlobalSize_2
public int getGlobalSize_2()
- Returns:
- the globalSize_2
-
setGlobalSize_2
public void setGlobalSize_2(int globalSize_2)
- Parameters:
globalSize_2- the globalSize_2 to set
-
getLocalSize_2
public int getLocalSize_2()
- Returns:
- the localSize_2
-
setLocalSize_2
public void setLocalSize_2(int localSize_2)
- Parameters:
localSize_2- the localSize_2 to set
-
getDims
public int getDims()
Get the number of dims for this Range.- Returns:
- 0, 1 or 2 for one dimensional, two dimensional and three dimensional range respectively.
-
setDims
public void setDims(int dims)
- Parameters:
dims- the dims to set
-
isValid
public boolean isValid()
- Returns:
- the valid
-
setValid
public void setValid(boolean valid)
- Parameters:
valid- the valid to set
-
isLocalIsDerived
public boolean isLocalIsDerived()
- Returns:
- the localIsDerived
-
setLocalIsDerived
public void setLocalIsDerived(boolean localIsDerived)
- Parameters:
localIsDerived- the localIsDerived to set
-
getMaxWorkGroupSize
public int getMaxWorkGroupSize()
- Returns:
- the maxWorkGroupSize
-
setMaxWorkGroupSize
public void setMaxWorkGroupSize(int maxWorkGroupSize)
- Parameters:
maxWorkGroupSize- the maxWorkGroupSize to set
-
getMaxWorkItemSize
public int[] getMaxWorkItemSize()
- Returns:
- the maxWorkItemSize
-
setMaxWorkItemSize
public void setMaxWorkItemSize(int[] maxWorkItemSize)
- Parameters:
maxWorkItemSize- the maxWorkItemSize to set
-
-