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(); }
public BaseDataBuffer(float[] 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).asFloatPointer().put(data); workspaceGenerationId = workspace.getGenerationId(); setIndexer(FloatIndexer.create((FloatPointer) pointer)); //wrappedBuffer = pointer.asByteBuffer(); }
/** * Assert that the specified array is valid, in terms of workspaces: i.e., if it is attached (and not in a circular * workspace), assert that the workspace is open, and that the data is not from an old generation. * @param array Array to check * @param msg Message (prefix) to include in the exception, if required. May be null */ public static void assertValidArray(INDArray array, String msg){ if(array == null || !array.isAttached()){ return; } val ws = array.data().getParentWorkspace(); if (ws.getWorkspaceType() != MemoryWorkspace.Type.CIRCULAR) { if (!ws.isScopeActive()) { throw new ND4JWorkspaceException( (msg == null ? "" : msg + ": ") + "Array uses leaked workspace pointer " + "from workspace " + ws.getId() + "\nAll open workspaces: " + allOpenWorkspaces()); } if (ws.getGenerationId() != array.data().getGenerationId()) { throw new ND4JWorkspaceException( (msg == null ? "" : msg + ": ") + "Array outdated workspace pointer " + "from workspace " + ws.getId() + " (array generation " + array.data().getGenerationId() + ", current workspace generation " + ws.getGenerationId() + ")\nAll open workspaces: " + allOpenWorkspaces()); } } }
protected void checkWorkspace(String opName, INDArray array) { if (array.isAttached()) { val ws = array.data().getParentWorkspace(); if (ws.getWorkspaceType() != MemoryWorkspace.Type.CIRCULAR) { if (!ws.isScopeActive()) { throw new ND4JIllegalStateException("Op [" + opName + "] X argument uses leaked workspace pointer from workspace [" + ws.getId() + "]\nAll open workspaces: " + allOpenWorkspaces() + "\n" + SCOPE_PANIC_MSG); } if (ws.getGenerationId() != array.data().getGenerationId()) throw new ND4JIllegalStateException("Op [" + opName + "] X argument uses outdated workspace pointer from workspace [" + ws.getId() + "]\nAll open workspaces: " + allOpenWorkspaces() + "\n" + SCOPE_PANIC_MSG); } } }
workspaceGenerationId = workspace.getGenerationId();
workspaceGenerationId = getParentWorkspace().getGenerationId(); } else { switch (dataType()) {
this.attached = true; this.parentWorkspace = workspace; workspaceGenerationId = workspace.getGenerationId();
workspaceGenerationId = workspace.getGenerationId();