public class MPSNDArray extends NSObject
A MPSNDArray object is a MTLBuffer based storage container for multi-dimensional data.
Operations on MPSNDArrays will commonly implicitly reshape the multidimensional structure into a 2-dimensional structure by reinterpreting higher dimensions as a single dimensional array of matrix rows. For example a [a, b, c, d] NDArray passed to a matrix multiplication may be implicitly reinterpreted as a [a*b*c, d] matrix and a 2D matrix multiplication performed. In practice, the major row (the dimension in which successive elements appear adjacent to one another in memory) is the 0th dimension (represented as 'd' in the above example). It has both a dimension size indicating the number of elements and a storage size which may be slightly bigger to allow for performance improvement arising from better data alignment in memory. In principle, the rowBytes may also be used to create a 0th-dimension slice out of a larger array stored in the underlying MTLBuffer.
MPS will automatically manage the storage size of the major row ("rowBytes") though you may set it in the descriptor if you have a need to do so. Generally, it should be at least a multiple of 16 bytes. Dimensions after the 0th are a densely packed array of rows of size rowBytes. Thus, the 1st dimension is an array of rows. The 2nd dimension is an array of arrays of rows with identical size, and so forth. When the reduction to 2 dimensions is done, no data is moved. MPS just reinterprets a higher order N-1 dimensions of matrix rows as a single large 1-dimensional array of rows.
It is a common desire to reorder the dimensions of NDArrays or define a subregion thereof. A transpose or slice operation is performed by making a MPSNDArray view of the original. The dimensions to transpose or slice are given by the descriptor for the new view. If both a transpose and slice operation are defined, then the slice is performed first and the result of the slice is transposed. Because many MPS kernels can operate on transposed data at speed, MPS will usually defer doing a physical transpose operation until later, when it becomes clear that one is actually required. For this reason, conversions to formats that do not support deferred transposes and slices such as MPSMatrix MPSVector view or using -exportWithCommandBuffer: toBuffer:offset:rowStrides, may cause substantial new computation to be done and new memory to be allocated. These should be avoided except when necessary. As a general rule, transposes that do not involve the 0th dimension should be able to be handled by nearly everything natively. MPSNDArrayMatrixMultiplication and reductions can handle 0th dimension transposes. Other filters may insert a physical repacking operation. If you wish to force a physical repacking use MPSAliasingStrategyShallNotAlias. To avoid confusion with aliased NDArrays the parent property is provided. MPSNDArrays that alias share a common ancestor.
NSObject.Function_instanceMethodForSelector_ret, NSObject.Function_methodForSelector_ret| Modifier | Constructor and Description |
|---|---|
protected |
MPSNDArray(org.moe.natj.general.Pointer peer) |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
accessInstanceVariablesDirectly() |
static MPSNDArray |
alloc() |
static MPSNDArray |
allocWithZone(org.moe.natj.general.ptr.VoidPtr zone) |
MPSNDArray |
arrayViewWithCommandBufferDescriptorAliasing(MTLCommandBuffer cmdBuf,
MPSNDArrayDescriptor descriptor,
long aliasing)
Make a new representation of a MPSNDArray with a slice, transpose or other change in property
|
static boolean |
automaticallyNotifiesObserversForKey(java.lang.String key) |
static void |
cancelPreviousPerformRequestsWithTarget(java.lang.Object aTarget) |
static void |
cancelPreviousPerformRequestsWithTargetSelectorObject(java.lang.Object aTarget,
org.moe.natj.objc.SEL aSelector,
java.lang.Object anArgument) |
static NSArray<java.lang.String> |
classFallbacksForKeyedArchiver() |
static org.moe.natj.objc.Class |
classForKeyedUnarchiver() |
int |
dataType()
The type of data stored by each element in the array
|
long |
dataTypeSize()
The size of one element in the MPSNDArray
|
static java.lang.String |
debugDescription_static() |
static MPSNDArrayAllocator |
defaultAllocator()
Get a well known
|
static java.lang.String |
description_static() |
MPSNDArrayDescriptor |
descriptor()
Create a MPSNDArrayDescriptor that describes this MPSNDArray
|
MTLDevice |
device()
[@property] device
|
void |
exportDataWithCommandBufferToBufferDestinationDataTypeOffsetRowStrides(MTLCommandBuffer cmdBuf,
MTLBuffer buffer,
int destinationDataType,
long offset,
org.moe.natj.general.ptr.NIntPtr rowStrides)
Do a GPU side copy of the contents of a MPSNDArray to a MTLBuffer
|
static long |
hash_static() |
void |
importDataWithCommandBufferFromBufferSourceDataTypeOffsetRowStrides(MTLCommandBuffer cmdBuf,
MTLBuffer buffer,
int sourceDataType,
long offset,
org.moe.natj.general.ptr.NIntPtr rowStrides)
Do a GPU side copy of the contents of a MTLBuffer into a MPSNDArray
|
MPSNDArray |
init() |
MPSNDArray |
initWithDeviceDescriptor(MTLDevice device,
MPSNDArrayDescriptor descriptor)
Initialize an MPSNDArrayDescriptor object on a device
for given dimension sizes in descriptor.
|
MPSNDArray |
initWithDeviceScalar(MTLDevice device,
double value)
Create a 1-Dimensional length=1 NDArray to hold a scalar
|
static NSObject.Function_instanceMethodForSelector_ret |
instanceMethodForSelector(org.moe.natj.objc.SEL aSelector) |
static NSMethodSignature |
instanceMethodSignatureForSelector(org.moe.natj.objc.SEL aSelector) |
static boolean |
instancesRespondToSelector(org.moe.natj.objc.SEL aSelector) |
static boolean |
isSubclassOfClass(org.moe.natj.objc.Class aClass) |
static NSSet<java.lang.String> |
keyPathsForValuesAffectingValueForKey(java.lang.String key) |
java.lang.String |
label()
A used specified string to help identify the array during debugging.
|
long |
lengthOfDimension(long dimensionIndex)
The number of elements in the dimension at dimensionIndex
|
static MPSNDArray |
new_objc() |
long |
numberOfDimensions()
Number of dimensions in the NDArray
|
MPSNDArray |
parent()
The parent MPSNDArray that this object aliases
|
void |
readBytesStrideBytes(org.moe.natj.general.ptr.VoidPtr buffer,
org.moe.natj.general.ptr.NIntPtr strideBytesPerDimension)
Copy bytes from MPSNDArray into buffer
|
static boolean |
resolveClassMethod(org.moe.natj.objc.SEL sel) |
static boolean |
resolveInstanceMethod(org.moe.natj.objc.SEL sel) |
long |
resourceSize()
Get the number of bytes used to allocate underyling MTLResources
|
void |
setLabel(java.lang.String value)
A used specified string to help identify the array during debugging.
|
static void |
setVersion_static(long aVersion) |
static org.moe.natj.objc.Class |
superclass_static() |
void |
synchronizeOnCommandBuffer(MTLCommandBuffer commandBuffer)
Use a blit encoder if a discrete device to update CPU contents of underlying buffer with latest GPU value
|
static long |
version_static() |
void |
writeBytesStrideBytes(org.moe.natj.general.ptr.VoidPtr buffer,
org.moe.natj.general.ptr.NIntPtr strideBytesPerDimension)
Copy bytes from a buffer into the MPSNDArray
|
accessibilityActivate, accessibilityActivationPoint, accessibilityAssistiveTechnologyFocusedIdentifiers, accessibilityAttributedHint, accessibilityAttributedLabel, accessibilityAttributedUserInputLabels, accessibilityAttributedValue, accessibilityContainerType, accessibilityCustomActions, accessibilityCustomRotors, accessibilityDecrement, accessibilityDragSourceDescriptors, accessibilityDropPointDescriptors, accessibilityElementAtIndex, accessibilityElementCount, accessibilityElementDidBecomeFocused, accessibilityElementDidLoseFocus, accessibilityElementIsFocused, accessibilityElements, accessibilityElementsHidden, accessibilityFrame, accessibilityHint, accessibilityIncrement, accessibilityLabel, accessibilityLanguage, accessibilityNavigationStyle, accessibilityPath, accessibilityPerformEscape, accessibilityPerformMagicTap, accessibilityRespondsToUserInteraction, accessibilityScroll, accessibilityTextualContext, accessibilityTraits, accessibilityUserInputLabels, accessibilityValue, accessibilityViewIsModal, addObserverForKeyPathOptionsContext, attemptRecoveryFromErrorOptionIndex, attemptRecoveryFromErrorOptionIndexDelegateDidRecoverSelectorContextInfo, autoContentAccessingProxy, awakeAfterUsingCoder, awakeFromNib, class_objc, classForCoder, classForKeyedArchiver, copy, dealloc, debugDescription, description, dictionaryWithValuesForKeys, didChangeValueForKey, didChangeValueForKeyWithSetMutationUsingObjects, didChangeValuesAtIndexesForKey, doesNotRecognizeSelector, fileManagerShouldProceedAfterError, fileManagerWillProcessPath, finalize_objc, forwardingTargetForSelector, forwardInvocation, hash, indexOfAccessibilityElement, isAccessibilityElement, isEqual, isKindOfClass, isMemberOfClass, isProxy, methodForSelector, methodSignatureForSelector, mutableArrayValueForKey, mutableArrayValueForKeyPath, mutableCopy, mutableOrderedSetValueForKey, mutableOrderedSetValueForKeyPath, mutableSetValueForKey, mutableSetValueForKeyPath, observationInfo, observeValueForKeyPathOfObjectChangeContext, performSelector, performSelectorInBackgroundWithObject, performSelectorOnMainThreadWithObjectWaitUntilDone, performSelectorOnMainThreadWithObjectWaitUntilDoneModes, performSelectorOnThreadWithObjectWaitUntilDone, performSelectorOnThreadWithObjectWaitUntilDoneModes, performSelectorWithObject, performSelectorWithObjectAfterDelay, performSelectorWithObjectAfterDelayInModes, performSelectorWithObjectWithObject, prepareForInterfaceBuilder, provideImageDataBytesPerRowOrigin_Size_UserInfo, removeObserverForKeyPath, removeObserverForKeyPathContext, replacementObjectForCoder, replacementObjectForKeyedArchiver, respondsToSelector, self, setAccessibilityActivationPoint, setAccessibilityAttributedHint, setAccessibilityAttributedLabel, setAccessibilityAttributedUserInputLabels, setAccessibilityAttributedValue, setAccessibilityContainerType, setAccessibilityCustomActions, setAccessibilityCustomRotors, setAccessibilityDragSourceDescriptors, setAccessibilityDropPointDescriptors, setAccessibilityElements, setAccessibilityElementsHidden, setAccessibilityFrame, setAccessibilityHint, setAccessibilityLabel, setAccessibilityLanguage, setAccessibilityNavigationStyle, setAccessibilityPath, setAccessibilityRespondsToUserInteraction, setAccessibilityTextualContext, setAccessibilityTraits, setAccessibilityUserInputLabels, setAccessibilityValue, setAccessibilityViewIsModal, setIsAccessibilityElement, setNilValueForKey, setObservationInfo, setShouldGroupAccessibilityChildren, setValueForKey, setValueForKeyPath, setValueForUndefinedKey, setValuesForKeysWithDictionary, shouldGroupAccessibilityChildren, superclass, validateValueForKeyError, validateValueForKeyPathError, valueForKey, valueForKeyPath, valueForUndefinedKey, willChangeValueForKey, willChangeValueForKeyWithSetMutationUsingObjects, willChangeValuesAtIndexesForKeypublic static boolean accessInstanceVariablesDirectly()
public static MPSNDArray alloc()
public static MPSNDArray allocWithZone(org.moe.natj.general.ptr.VoidPtr zone)
public MPSNDArray arrayViewWithCommandBufferDescriptorAliasing(MTLCommandBuffer cmdBuf, MPSNDArrayDescriptor descriptor, long aliasing)
If possible, the views will merely record the slice or transpose without performing the operation. Many MPSKernels are able to operate on subregions of a MPSNDArray or operate on transposed data, so making a new copy of the data for these operations would be wasteful. A copy may be forced by a change in dataType, rowBytes, or when using a view with a MPSKernel that does not support the deferred operation. To force an operation to occur immediately, use MPSAliasingStrategyShallNotAlias Otherwise, it is likely that the new MPSNDArray will share a MTLBuffer with the parent and alias its memory.
cmdBuf - The command buffer on which to perform physical copies if any are requireddescriptor - A MPSNDArrayDescriptor describing the shape of the new view of the dataaliasing - A aliasing strategy to direct MPS how to respond to cases when aliasing can or can not
be performed.public static boolean automaticallyNotifiesObserversForKey(java.lang.String key)
public static void cancelPreviousPerformRequestsWithTarget(java.lang.Object aTarget)
public static void cancelPreviousPerformRequestsWithTargetSelectorObject(java.lang.Object aTarget,
org.moe.natj.objc.SEL aSelector,
java.lang.Object anArgument)
public static NSArray<java.lang.String> classFallbacksForKeyedArchiver()
public static org.moe.natj.objc.Class classForKeyedUnarchiver()
public int dataType()
public long dataTypeSize()
public static java.lang.String debugDescription_static()
public static MPSNDArrayAllocator defaultAllocator()
public static java.lang.String description_static()
public MPSNDArrayDescriptor descriptor()
The descriptor will describe the shape of the MPSNDArray after all deferred slicing and transposes have completed. A new descriptor is created each time to allow for further customization of the descriptor by the application.
public MTLDevice device()
The device on which the MSPNDArray may be used
public void exportDataWithCommandBufferToBufferDestinationDataTypeOffsetRowStrides(MTLCommandBuffer cmdBuf, MTLBuffer buffer, int destinationDataType, long offset, org.moe.natj.general.ptr.NIntPtr rowStrides)
To do a transpose or slice as part of the operation, make a MPSNDArray view first that encodes that operation.
cmdBuf - The command buffer on which to encode the operationbuffer - The destination to overwritedestinationDataType - The destination data type.offset - The byte offset to where the {0,0,0...}th element will be writtenrowStrides - An optional array of (numberOfDimensions-1) byte counts which describe
the byte offset from position 0 of the respective dimension to position 1.public static long hash_static()
public void importDataWithCommandBufferFromBufferSourceDataTypeOffsetRowStrides(MTLCommandBuffer cmdBuf, MTLBuffer buffer, int sourceDataType, long offset, org.moe.natj.general.ptr.NIntPtr rowStrides)
Copy data from provided buffer to the NDArray. Implicit transposes and slicing shall be honored.
cmdBuf - The command buffer on which to encode the operationbuffer - The destination to read fromsourceDataType - The source data type.offset - The byte offset in the buffer from where the {0,0,0...}th element is to be read.rowStrides - An optional array of (numberOfDimensions-1) byte counts which describe
the byte offset from position 0 of the respective dimension to position 1.public MPSNDArray init()
public MPSNDArray initWithDeviceDescriptor(MTLDevice device, MPSNDArrayDescriptor descriptor)
device - The device on which the data type will be created.descriptor - The MPSNDArrayDescriptor used for initializing the the NDArraypublic MPSNDArray initWithDeviceScalar(MTLDevice device, double value)
public static NSObject.Function_instanceMethodForSelector_ret instanceMethodForSelector(org.moe.natj.objc.SEL aSelector)
public static NSMethodSignature instanceMethodSignatureForSelector(org.moe.natj.objc.SEL aSelector)
public static boolean instancesRespondToSelector(org.moe.natj.objc.SEL aSelector)
public static boolean isSubclassOfClass(org.moe.natj.objc.Class aClass)
public static NSSet<java.lang.String> keyPathsForValuesAffectingValueForKey(java.lang.String key)
public java.lang.String label()
May be externally visible to tools like Instruments
public long lengthOfDimension(long dimensionIndex)
The dimension length is at least as large as the existing slice length. Views of this MPSNDArray may have differing dimension lengths.
public static MPSNDArray new_objc()
public long numberOfDimensions()
public MPSNDArray parent()
If the MPSNDArray was createrd as a array view of another MPSNDArray object, and aliases content in the same MTLBuffer, the original MPSNDArray will be retained as the parent here. Two MPSNDArrays alias if they share a common ancestor. Note that the parent may itself have a parent, and so forth.
public void readBytesStrideBytes(org.moe.natj.general.ptr.VoidPtr buffer,
org.moe.natj.general.ptr.NIntPtr strideBytesPerDimension)
The dimensionality and size of the copy region is given by the size of the MPSNDArray For subregions, use a MPSNDArray view.
buffer - A pointer to memory where to write the datastrideBytesPerDimension - An optional array of numberOfDimensions sizes, which gives the distance
in bytes from one element to the next in that dimension in buffer. The first value
is typically dataTypeSize. The next is a row bytes. The next is 2d matrix bytes,
and so forth. If the value is nil, these are calculated for you assuming that the
data is packed without additional space in between elements, rows, etc.
0 and negative values are permitted.public static boolean resolveClassMethod(org.moe.natj.objc.SEL sel)
public static boolean resolveInstanceMethod(org.moe.natj.objc.SEL sel)
public long resourceSize()
This is the size of the backing store of underlying MTLResources. It does not include all storage used by the object, for example the storage used to hold the MPSNDArray instantiation and MTLBuffer is not included. It only measures the size of the allocation used to hold the MPSNDArray data in the MTLBuffer. This value is subject to change between different devices and operating systems.
Except when -initWithBuffer:descriptor: is used, most MPSNDArrays are allocated initiallly without a backing store. The backing store is allocated lazily when it is needed, typically when the MPSNDArray is written to the first time. Consequently, in most cases, it should be inexpensive to make a MPSImage to see how much memory it will need, and release it if it is too large.
public void setLabel(java.lang.String value)
May be externally visible to tools like Instruments
public static void setVersion_static(long aVersion)
public static org.moe.natj.objc.Class superclass_static()
public void synchronizeOnCommandBuffer(MTLCommandBuffer commandBuffer)
commandBuffer - The commandBuffer on which we transfer the contents.public static long version_static()
public void writeBytesStrideBytes(org.moe.natj.general.ptr.VoidPtr buffer,
org.moe.natj.general.ptr.NIntPtr strideBytesPerDimension)
The dimensionality and size of the copy region is given by the size of the MPSNDArray For subregions, use a MPSNDArray view.
buffer - A pointer to memory where to read the datastrideBytesPerDimension - An optional array of numberOfDimensions sizes, which gives the distance
in bytes from one element to the next in that dimension in buffer. The first value
is typically dataTypeSize. The next is a row bytes. The next is 2d matrix bytes,
and so forth. If strideBytesPerDimension is nil, these are calculated for you assuming that the
data is packed without additional space in between elements, rows, etc.
0 and negative values are permitted.