SerranoResourceManager
public class SerranoResourceManager
This is a framework level class
-
Table tracking allocated Tensor and its corresponding MTLBuffer
Declaration
Swift
public var tensorBufferTable: [Tensor: MTLBuffer]
-
The dictionary tracking the usage status of tensor
Declaration
Swift
public var tensorStatusTable: [Tensor: SerranoTensorStatus]
-
The operation queue when operate on
tensorBufferTable
andtensorStatus
Declaration
Swift
public var operationQueue: DispatchQueue
-
Readable label
Declaration
Swift
public var label: String
-
Description
Declaration
Swift
public var description: String
-
Undocumented
Declaration
Swift
public static let globalManager = SerranoResourceManager(label: "gloabal_resource_manager")
-
Undocumented
Declaration
Swift
public init(label: String = "Resource Manager")
-
Allocate unmanaged tensors for shapes.
Unmanaged
means that the alloated tensors will not be hold via strong refrence by manager.Declaration
Swift
public func allocateUnamangedTensors(_ shapes: [TensorShape]) -> [Tensor]
Parameters
shapes
shapes description
Return Value
return value description
-
Allocate unmanaged tensors for shapes.
Unmanaged
means that the alloated tensors will not be hold via strong refrence by manager.Declaration
Swift
public func allocateUnamangedTensor(_ shape: TensorShape) -> Tensor
Parameters
shapes
shapes description
Return Value
return value description
-
Allocate unamanged
MTLBuffers
.Warning
If engine has no available GPU device,
fatalError
raised.Declaration
Swift
public func allocateUnmanagedMTLBuffers(_ tensors: [Tensor]) -> [MTLBuffer]
Parameters
tensors
target tensors
Return Value
Array of
MTLBuffer
-
Allocate unamanged
MTLBuffer
.Warning
If engine has no available GPU device,
fatalError
raised.Declaration
Swift
public func allocateUnmanagedMTLBuffe(_ tensor: Tensor) -> MTLBuffer
Parameters
tensor
target tensor
Return Value
MTLBuffer
-
Request managed tensors for target shapes.
Note
All tensors requested by this method should be return manually by calling
returnTensors(_ tensors: [Tensor])
orreturnTensor(_ tensor: Tensor)
Warning
This method is desgined for framework internal usage. Usually user should not call this method.
Declaration
Swift
public func allocateTensors(_ shapes: [TensorShape]) -> [Tensor]
Parameters
shapes
target shapes
Return Value
tensors
-
Allocate single tensor object. This function actually call
allocateTensors(forShapes shapes: [TensorShape])
.Note
All tensors requested by this method should be return manually by calling
returnTensors(_ tensors: [Tensor])
orreturnTensor(_ tensor: Tensor)
Warning
This method is desgined for framework internal usage. Usually user should not call this method.
Declaration
Swift
public func allocateTensor(_ tensorShape: TensorShape) -> Tensor
Parameters
tensorShape
shape
Return Value
tensor
-
Return managed tensors.
Note
Tensor not managed by this manager or is a slice tensor will be ignored.
Declaration
Swift
public func returnTensors(_ tensors: [Tensor])
Parameters
tensors
returned tensors
-
Return single tensor to resource manager
Declaration
Swift
public func returnTensor(_ tensor: Tensor)
Parameters
tensor
tensor
-
Release target tensors. Actually clear corresponding entries in
tensorStatusTable
andtensorBufferTable
.Note
Tensor not managed by this manager or is a slice tensor will be ignored.
Declaration
Swift
public func releaseTensors(_ tensors: [Tensor])
Parameters
tensors
target tensors
-
Check if a managed tensor is availabel for reuse If the passed in tensor is a sliced tensor, we check the status of its root tensor.
Note
false
will be returned iftensor
is not managed by this manager.Declaration
Swift
public func isTensorAvailable(_ tensor: Tensor) -> Bool
-
Request
MTLBufferResource
for tensors.Note
If the passed in tensors are not mamaged by this resource manager, it will just call
allocateUnmanagedMTLBuffers(_ tensors: [Tensor])
.Declaration
Swift
public func allocateMTLBufferResources(_ tensors: [Tensor]) -> [MTLBufferResource]
Parameters
tensors
target tensors
Return Value
Array of
MTLBufferResource
-
Request
MTLBufferResource
for a tensor.Note
If the passed in tensor is not mamaged by this resource manager, it will just call
allocateUnmanagedMTLBuffer(_ tensor: Tensor)
.Declaration
Swift
public func allocateMTLBufferResource(_ tensor: Tensor) -> MTLBufferResource
Parameters
tensors
target tensor
Return Value
-
Release all managed resources
Warning
This function does not guranteen that all managed tensors and buffers would be released in memory, since if tensor or buffer objects are still used in other places, the ARC will nor clear it. Before calling this function, the caller must be clear that all managed resources are in idle states.Declaration
Swift
public func releaseAllResources()
-
Check if tensor is managed by this manager. If a tensor is managed by this manager, all its sliced tensors are managed by this manager.
Note
If the tensor is a sliced tensor, we will check if managing its root tensor.
Declaration
Swift
public func isManagingTensor(_ tensor: Tensor) -> Bool
Parameters
tensor
tensor description
Return Value
return value description
-
Check if a MTLBuffer is managed by this manager
Declaration
Swift
public func isManagingBufferr(_ buffer: MTLBuffer) -> Bool
Parameters
buffer
buffer description
Return Value
return value description