Skip to content

Commit

Permalink
keep improving the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Dec 12, 2023
1 parent 4b811e2 commit c939d93
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
package io.bioimage.modelrunner.tensor.shm;

import java.io.ByteArrayInputStream;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.UUID;

import com.sun.jna.Pointer;

Expand Down Expand Up @@ -95,17 +93,12 @@ public class SharedMemoryArrayMacOS implements SharedMemoryArray
*/
private boolean isNumpyFormat = false;

public static final int O_RDONLY = 0;
private static final int O_RDWR = 2; // Read-write mode
private static final int PROT_READ = 0x1; // Page can be read
private static final int PROT_WRITE = 0x2; // Page can be written
private static final int MAP_SHARED = 0x01; // Share changes

protected static final int MACOS_MAX_LENGTH = 30;

private SharedMemoryArrayMacOS(int size, String dtype, long[] shape)
{
this(("/shm-" + UUID.randomUUID()).substring(0, MACOS_MAX_LENGTH), size, dtype, shape);
this(SharedMemoryArray.createShmName(), size, dtype, shape);
}

private SharedMemoryArrayMacOS(String name, int size, String dtype, long[] shape)
Expand All @@ -130,23 +123,38 @@ private SharedMemoryArrayMacOS(String name, int size, String dtype, long[] shape
throw new RuntimeException("mmap failed, errno: " + Native.getLastError());
}
}


/**
* {@inheritDoc}
*/
public String getName() {
return this.memoryName;
}


/**
* {@inheritDoc}
*/
public String getNameForPython() {
return this.memoryName.substring("/".length());
}


/**
* {@inheritDoc}
*/
public Pointer getPointer() {
return this.pSharedMemory;
}


/**
* {@inheritDoc}
*/
public int getSharedMemoryBlock() {
return this.shmFd;
}


/**
* {@inheritDoc}
*/
public int getSize() {
return this.size;
}
Expand Down Expand Up @@ -307,15 +315,6 @@ private void addByteArray(byte[] arr) {
}
}

/**
* Adds the ByteType {@link RandomAccessibleInterval} data to the {@link ByteBuffer} provided.
* The position of the ByteBuffer is kept in the same place as it was received.
*
* @param tensor
* {@link RandomAccessibleInterval} to be mapped into byte buffer
* @param byteBuffer
* target bytebuffer
*/
private void buildInt8(RandomAccessibleInterval<ByteType> tensor)
{
tensor = Utils.transpose(tensor);
Expand All @@ -327,15 +326,6 @@ private void buildInt8(RandomAccessibleInterval<ByteType> tensor)
}
}

/**
* Adds the ByteType {@link RandomAccessibleInterval} data to the {@link ByteBuffer} provided.
* The position of the ByteBuffer is kept in the same place as it was received.
*
* @param tensor
* {@link RandomAccessibleInterval} to be mapped into byte buffer
* @param byteBuffer
* target bytebuffer
*/
private void buildUint8(RandomAccessibleInterval<UnsignedByteType> tensor)
{
tensor = Utils.transpose(tensor);
Expand All @@ -347,15 +337,6 @@ private void buildUint8(RandomAccessibleInterval<UnsignedByteType> tensor)
}
}

/**
* Adds the ByteType {@link RandomAccessibleInterval} data to the {@link ByteBuffer} provided.
* The position of the ByteBuffer is kept in the same place as it was received.
*
* @param tensor
* {@link RandomAccessibleInterval} to be mapped into byte buffer
* @param byteBuffer
* target bytebuffer
*/
private void buildInt16(RandomAccessibleInterval<ShortType> tensor)
{
tensor = Utils.transpose(tensor);
Expand All @@ -368,15 +349,6 @@ private void buildInt16(RandomAccessibleInterval<ShortType> tensor)
}
}

/**
* Adds the ByteType {@link RandomAccessibleInterval} data to the {@link ByteBuffer} provided.
* The position of the ByteBuffer is kept in the same place as it was received.
*
* @param tensor
* {@link RandomAccessibleInterval} to be mapped into byte buffer
* @param byteBuffer
* target bytebuffer
*/
private void buildUint16(RandomAccessibleInterval<UnsignedShortType> tensor)
{
tensor = Utils.transpose(tensor);
Expand All @@ -389,15 +361,6 @@ private void buildUint16(RandomAccessibleInterval<UnsignedShortType> tensor)
}
}

/**
* Adds the IntType {@link RandomAccessibleInterval} data to the {@link ByteBuffer} provided.
* The position of the ByteBuffer is kept in the same place as it was received.
*
* @param tensor
* {@link RandomAccessibleInterval} to be mapped into byte buffer
* @param byteBuffer
* target bytebuffer
*/
private void buildInt32(RandomAccessibleInterval<IntType> tensor)
{
tensor = Utils.transpose(tensor);
Expand All @@ -410,15 +373,6 @@ private void buildInt32(RandomAccessibleInterval<IntType> tensor)
}
}

/**
* Adds the IntType {@link RandomAccessibleInterval} data to the {@link ByteBuffer} provided.
* The position of the ByteBuffer is kept in the same place as it was received.
*
* @param tensor
* {@link RandomAccessibleInterval} to be mapped into byte buffer
* @param byteBuffer
* target bytebuffer
*/
private void buildUint32(RandomAccessibleInterval<UnsignedIntType> tensor)
{
tensor = Utils.transpose(tensor);
Expand All @@ -431,15 +385,6 @@ private void buildUint32(RandomAccessibleInterval<UnsignedIntType> tensor)
}
}

/**
* Adds the IntType {@link RandomAccessibleInterval} data to the {@link ByteBuffer} provided.
* The position of the ByteBuffer is kept in the same place as it was received.
*
* @param tensor
* {@link RandomAccessibleInterval} to be mapped into byte buffer
* @param byteBuffer
* target bytebuffer
*/
private void buildInt64(RandomAccessibleInterval<LongType> tensor)
{
tensor = Utils.transpose(tensor);
Expand All @@ -452,15 +397,6 @@ private void buildInt64(RandomAccessibleInterval<LongType> tensor)
}
}

/**
* Adds the FloatType {@link RandomAccessibleInterval} data to the {@link ByteBuffer} provided.
* The position of the ByteBuffer is kept in the same place as it was received.
*
* @param tensor
* {@link RandomAccessibleInterval} to be mapped into byte buffer
* @param byteBuffer
* target bytebuffer
*/
private void buildFloat32(RandomAccessibleInterval<FloatType> tensor)
{
tensor = Utils.transpose(tensor);
Expand All @@ -473,15 +409,6 @@ private void buildFloat32(RandomAccessibleInterval<FloatType> tensor)
}
}

/**
* Adds the DoubleType {@link RandomAccessibleInterval} data to the {@link ByteBuffer} provided.
* The position of the ByteBuffer is kept in the same place as it was received.
*
* @param tensor
* {@link RandomAccessibleInterval} to be mapped into byte buffer
* @param byteBuffer
* target bytebuffer
*/
private void buildFloat64(RandomAccessibleInterval<DoubleType> tensor)
{
tensor = Utils.transpose(tensor);
Expand Down Expand Up @@ -830,21 +757,33 @@ public static void main(String[] args){
}

@Override
/**
* {@inheritDoc}
*/
public <T extends RealType<T> & NativeType<T>> RandomAccessibleInterval<T> getSharedRAI() {
return buildFromSharedMemoryBlock(pSharedMemory, this.originalDims, false, this.originalDataType);
}

@Override
/**
* {@inheritDoc}
*/
public String getOriginalDataType() {
return this.originalDataType;
}

@Override
/**
* {@inheritDoc}
*/
public long[] getOriginalShape() {
return this.originalDims;
}

@Override
/**
* {@inheritDoc}
*/
public boolean isNumpyFormat() {
return this.isNumpyFormat;
}
Expand Down
Loading

0 comments on commit c939d93

Please sign in to comment.