Class ThreadManager
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
concurrentBlockedOperation
(int totalSize, int blockSize, TensorOperation blockedOperation) Computes a specified blocked tensor operation concurrently by evenly dividing work among available threads (specified byConfigurations.getNumThreads()
).static void
concurrentOperation
(int totalSize, TensorOperation operation) Computes a specified tensor operation concurrently by evenly dividing work among available threads (specified byConfigurations.getNumThreads()
).static int
Gets the current parallelism level for the ThreadManager.protected static void
setParallelismLevel
(int parallelismLevel) Sets the number of threads to use in the thread pool.
-
Method Details
-
setParallelismLevel
protected static void setParallelismLevel(int parallelismLevel) Sets the number of threads to use in the thread pool.- Parameters:
parallelismLevel
- Number of threads to use in the thread pool. If this is less than 1, the parallelism will simply be set to 1.
-
getParallelismLevel
public static int getParallelismLevel()Gets the current parallelism level for the ThreadManager. That is, the number of threads used in the thread pool.- Returns:
- The current parallelism level for the ThreadManager.
-
concurrentOperation
Computes a specified tensor operation concurrently by evenly dividing work among available threads (specified by
Configurations.getNumThreads()
).WARNING: This method provides no guarantees of thread safety. It is the responsibility of the caller to ensure that
operation
is thread safe.- Parameters:
totalSize
- Total size of the outer loop for the operation.operation
- Operation to be computed.
-
concurrentBlockedOperation
public static void concurrentBlockedOperation(int totalSize, int blockSize, TensorOperation blockedOperation) Computes a specified blocked tensor operation concurrently by evenly dividing work among available threads (specified by
Configurations.getNumThreads()
).Unlike
concurrentOperation(int, TensorOperation)
this method respects the block size of the blocked operation. This means tasks split across threads will be aligned to block borders if possible which allows for the improved cache performance benefits of blocked ops to be fully realized. For this reason, it is not recommended to useconcurrentOperation(int, TensorOperation)
to compute a blocked operation concurrently.WARNING: This method provides no guarantees of thread safety. It is the responsibility of the caller to ensure that
blockedOperation
is thread safe.- Parameters:
totalSize
- Total size of the outer loop for the operation.blockSize
- Size of the block used in theblockedOperation
.blockedOperation
- Operation to be computed.
-