/** * Set the allocation mode for the nd4j context * The value must be one of: heap, java cpp, or direct * or an @link{IllegalArgumentException} is thrown * @param allocationModeForContext */ public static void setAllocationModeForContext(DataBuffer.AllocationMode allocationModeForContext) { setAllocationModeForContext(getAllocModeName(allocationModeForContext)); }
/** * Returns the data opType used for the runtime * * @return the datatype used for the runtime */ public static DataBuffer.Type dataType() { return DataTypeUtil.getDtypeFromContext(); }
/** * Returns the prefix for dynamically linked libraries on the * current OS. That is, returns "lib" on Apple, Linux and Sun, * and the empty String on Windows. * * @return The library prefix */ private static String createLibPrefix() { OSType osType = calculateOS(); switch (osType) { case APPLE: case LINUX: case SUN: return "lib"; case WINDOWS: return ""; } return ""; }
/** * Set the allocation mode for the nd4j context * The value must be one of: heap, java cpp, or direct * or an @link{IllegalArgumentException} is thrown * @param allocationModeForContext */ public static void setDTypeForContext(DataBuffer.Type allocationModeForContext) { try { lock.writeLock().lock(); dtype = allocationModeForContext; setDTypeForContext(getDTypeForName(allocationModeForContext)); } finally { lock.writeLock().unlock(); } }
/** * This method sets dataType for the current JVM runtime * @param dType */ public static void setDataType(@NonNull DataBuffer.Type dType) { DataTypeUtil.setDTypeForContext(dType); }
/** * Creates the name for the native library with the given base * name for the current operating system and architecture. * The resulting name will be of the form<br /> * baseName-OSType-ARCHType<br /> * where OSType and ARCHType are the <strong>lower case</strong> Strings * of the respective enum constants. Example: <br /> * jcuda-windows-x86<br /> * * @param baseName The base name of the library * @return The library name */ public static String createLibName(String baseName) { OSType osType = calculateOS(); ARCHType archType = calculateArch(); String libName = baseName; libName += "-" + osType.toString().toLowerCase(Locale.ENGLISH); libName += "-" + archType.toString().toLowerCase(Locale.ENGLISH); return libName; }
/** * * @param data * @param copy */ public BaseDataBuffer(double[] data, boolean copy) { allocationMode = AllocUtil.getAllocationModeFromContext(); initTypeAndSize(); pointer = new DoublePointer(data); indexer = DoubleIndexer.create((DoublePointer) pointer); //wrappedBuffer = pointer.asByteBuffer(); length = data.length; underlyingLength = data.length; }
public static String getArchName() { ARCHType archType = calculateArch(); switch (archType) { case X86: return "x86"; case X86_64: return "x86_64"; case ARM: return "arm"; case PPC: return "ppc"; case PPC_64: return "ppc64"; case RISC: return "risc"; default: return "unknown"; } }
/** * Prepend jni to the name for certain classes * @param clazz */ public static void loadJavaCpp(Class<?> clazz) { loadLibrary("jni" + clazz.getSimpleName()); }
/** * Returns the number of bytes * for the graph * * @return */ public long memoryForGraph() { return numElements() * DataTypeUtil.lengthForDtype(Nd4j.dataType()); }
@Override public X set(int i, X aX) { if(DataTypeUtil.getDtypeFromContext() == DataBuffer.Type.DOUBLE) container.putScalar(i,aX.doubleValue()); else { container.putScalar(i,aX.floatValue()); } return aX; }
/** * * @param data * @param copy */ public BaseDataBuffer(long[] data, boolean copy) { allocationMode = AllocUtil.getAllocationModeFromContext(); initTypeAndSize(); pointer = new LongPointer(data); setIndexer(LongIndexer.create((LongPointer) pointer)); length = data.length; underlyingLength = data.length; }
/** * Get the name of the os * for libary discovery on the classpath * @return */ public static String getOsName() { OSType osType = calculateOS(); switch (osType) { case APPLE: return "macosx"; case LINUX: return "linux"; case SUN: return "sun"; case WINDOWS: return "windows"; } return ""; }
@Override public void add(int i, X aX) { rangeCheck(i); growCapacity(i); moveForward(i); if(DataTypeUtil.getDtypeFromContext() == DataBuffer.Type.DOUBLE) container.putScalar(i,aX.doubleValue()); else { container.putScalar(i,aX.floatValue()); } size++; }
/** * * @param data * @param copy */ public BaseDataBuffer(int[] data, boolean copy) { allocationMode = AllocUtil.getAllocationModeFromContext(); initTypeAndSize(); pointer = new IntPointer(data); setIndexer(IntIndexer.create((IntPointer) pointer)); length = data.length; underlyingLength = data.length; // // log.info("Creating new buffer of size: {}; dtype: {}; B", data.length, dataType()); }
/** * Returns the extension for dynamically linked libraries on the * current OS. That is, returns "dylib" on Apple, "so" on Linux * and Sun, and "dll" on Windows. * * @return The library extension */ private static String createLibExtension() { OSType osType = calculateOS(); switch (osType) { case APPLE: return "dylib"; case LINUX: return "so"; case SUN: return "so"; case WINDOWS: return "dll"; } return ""; }
@Override public boolean add(X aX) { if(container == null) { container = Nd4j.create(10); } else if(size == container.length()) { growCapacity(size * 2); } if(DataTypeUtil.getDtypeFromContext() == DataBuffer.Type.DOUBLE) container.putScalar(size,aX.doubleValue()); else { container.putScalar(size,aX.floatValue()); } size++; return true; }
/** * * @param data * @param copy */ public BaseDataBuffer(float[] data, boolean copy) { allocationMode = AllocUtil.getAllocationModeFromContext(); initTypeAndSize(); pointer = new FloatPointer(data); setIndexer(FloatIndexer.create((FloatPointer) pointer)); //wrappedBuffer = pointer.asByteBuffer(); length = data.length; underlyingLength = data.length; }
public BaseDataBuffer(double[] data, boolean copy, MemoryWorkspace workspace) { allocationMode = AllocUtil.getAllocationModeFromContext(); length = data.length; underlyingLength = data.length; attached = true; parentWorkspace = workspace; initTypeAndSize(); //log.info("Allocating FloatPointer from array of {} elements", data.length); pointer = workspace.alloc(data.length * getElementSize(), dataType(), false).asDoublePointer().put(data); workspaceGenerationId = workspace.getGenerationId(); indexer = DoubleIndexer.create((DoublePointer) pointer); //wrappedBuffer = pointer.asByteBuffer(); }
public BaseDataBuffer(int[] data, boolean copy, MemoryWorkspace workspace) { allocationMode = AllocUtil.getAllocationModeFromContext(); length = data.length; underlyingLength = data.length; attached = true; parentWorkspace = workspace; initTypeAndSize(); //log.info("Allocating FloatPointer from array of {} elements", data.length); pointer = workspace.alloc(data.length * getElementSize(), dataType(), false).asIntPointer().put(data); workspaceGenerationId = workspace.getGenerationId(); indexer = IntIndexer.create((IntPointer) pointer); //wrappedBuffer = pointer.asByteBuffer(); }