You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemds.apache.org by ba...@apache.org on 2024/01/05 16:07:03 UTC

(systemds) branch main updated: [MINOR] Vectorized string memory cost

This is an automated email from the ASF dual-hosted git repository.

baunsgaard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git


The following commit(s) were added to refs/heads/main by this push:
     new 7ecdb38a20 [MINOR] Vectorized string memory cost
7ecdb38a20 is described below

commit 7ecdb38a20d34ee095fcd7cfc07e4d754f82d18d
Author: Sebastian Baunsgaard <ba...@apache.org>
AuthorDate: Fri Jan 5 17:06:52 2024 +0100

    [MINOR] Vectorized string memory cost
---
 .../org/apache/sysds/utils/MemoryEstimates.java    | 26 ++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/sysds/utils/MemoryEstimates.java b/src/main/java/org/apache/sysds/utils/MemoryEstimates.java
index 43e9fddd25..5fd8b26701 100644
--- a/src/main/java/org/apache/sysds/utils/MemoryEstimates.java
+++ b/src/main/java/org/apache/sysds/utils/MemoryEstimates.java
@@ -189,12 +189,34 @@ public class MemoryEstimates {
 	 * @return The array memory cost
 	 */
 	public static final double stringArrayCost(String[] strings) {
-		long size = 0;
-		for(int i = 0; i < strings.length; i++)
+		double size = 0;
+		int i = 0;
+		int by8 = strings.length - strings.length %8 ;
+		for(;i < by8; i+= 8)
+			size += stringArrayCostVec8(strings, i);
+		for(; i < strings.length; i++)
 			size += stringCost(strings[i]);
 		return size;
 	}
 
+	private static final double stringArrayCostVec8(String[] strings, int r){
+		long size = 0;
+		size += stringCost(strings[r]);
+		size += stringCost(strings[r+1]);
+		size += stringCost(strings[r+2]);
+		size += stringCost(strings[r+3]);
+		size += stringCost(strings[r+4]);
+		size += stringCost(strings[r+5]);
+		size += stringCost(strings[r+6]);
+		size += stringCost(strings[r+7]);
+		return size;
+	}
+
+	public static final double stringArrayCost(int length, int avgStringLength){
+		// if null 16 object + 8 array ref
+		return  stringCost(avgStringLength) * length + 24.0d;
+	}
+
 	/**
 	 * Get the worst case memory usage of a single string.
 	 *