25
25
import io .bioimage .modelrunner .utils .CommonUtils ;
26
26
27
27
import java .io .IOException ;
28
- import java .nio .ByteBuffer ;
29
28
import java .util .Arrays ;
30
29
31
30
import ai .djl .ndarray .NDArray ;
@@ -61,7 +60,6 @@ private ShmBuilder()
61
60
*/
62
61
public static void build (NDArray tensor , String memoryName ) throws IllegalArgumentException , IOException
63
62
{
64
- System .out .println (tensor .getDataType ().asNumpy ());
65
63
switch (tensor .getDataType ())
66
64
{
67
65
case UINT8 :
@@ -91,7 +89,7 @@ private static void buildFromTensorUByte(NDArray tensor, String memoryName) thro
91
89
throw new IllegalArgumentException ("Model output tensor with shape " + Arrays .toString (arrayShape )
92
90
+ " is too big. Max number of elements per ubyte output tensor supported: " + Integer .MAX_VALUE / 1 );
93
91
SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new UnsignedByteType (), false , true );
94
- shma .setBuffer ( ByteBuffer . wrap (tensor .toByteArray () ));
92
+ shma .getDataBufferNoHeader (). put (tensor .toByteArray ());
95
93
if (PlatformDetection .isWindows ()) shma .close ();
96
94
}
97
95
@@ -103,7 +101,7 @@ private static void buildFromTensorInt(NDArray tensor, String memoryName) throws
103
101
+ " is too big. Max number of elements per int output tensor supported: " + Integer .MAX_VALUE / 4 );
104
102
105
103
SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new IntType (), false , true );
106
- shma .setBuffer ( ByteBuffer . wrap (tensor .toByteArray () ));
104
+ shma .getDataBufferNoHeader (). put (tensor .toByteArray ());
107
105
if (PlatformDetection .isWindows ()) shma .close ();
108
106
}
109
107
@@ -115,7 +113,7 @@ private static void buildFromTensorFloat(NDArray tensor, String memoryName) thro
115
113
+ " is too big. Max number of elements per float output tensor supported: " + Integer .MAX_VALUE / 4 );
116
114
117
115
SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new FloatType (), false , true );
118
- shma .setBuffer ( ByteBuffer . wrap (tensor .toByteArray () ));
116
+ shma .getDataBufferNoHeader (). put (tensor .toByteArray ());
119
117
if (PlatformDetection .isWindows ()) shma .close ();
120
118
}
121
119
@@ -127,7 +125,7 @@ private static void buildFromTensorDouble(NDArray tensor, String memoryName) thr
127
125
+ " is too big. Max number of elements per double output tensor supported: " + Integer .MAX_VALUE / 8 );
128
126
129
127
SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new DoubleType (), false , true );
130
- shma .setBuffer ( ByteBuffer . wrap (tensor .toByteArray () ));
128
+ shma .getDataBufferNoHeader (). put (tensor .toByteArray ());
131
129
if (PlatformDetection .isWindows ()) shma .close ();
132
130
}
133
131
@@ -140,7 +138,7 @@ private static void buildFromTensorLong(NDArray tensor, String memoryName) throw
140
138
141
139
142
140
SharedMemoryArray shma = SharedMemoryArray .readOrCreate (memoryName , arrayShape , new LongType (), false , true );
143
- shma .setBuffer ( ByteBuffer . wrap (tensor .toByteArray () ));
141
+ shma .getDataBufferNoHeader (). put (tensor .toByteArray ());
144
142
if (PlatformDetection .isWindows ()) shma .close ();
145
143
}
146
144
}
0 commit comments