numElements); externalAllocations.add(new PointersPair(pointer, null)); deviceOffset.set(hostOffset.get()); PagedPointer ptr = workspace.getHostPointer().withOffset(prevOffset, numElements); numElements); externalAllocations.add(new PointersPair(pointer, null)); numElements); pinnedAllocations.add(new PointersPair(stepsCount.get(), requiredMemory, pointer, null));
if (pair.getDevicePointer() != null) { Nd4j.getMemoryManager().release(pair.getDevicePointer(), MemoryKind.DEVICE); if (pair.getHostPointer() != null) { Nd4j.getMemoryManager().release(pair.getHostPointer(), MemoryKind.HOST); if (pair2.getHostPointer() != null) Nd4j.getMemoryManager().release(pair2.getHostPointer(), MemoryKind.HOST); if (pair2.getDevicePointer() != null) Nd4j.getMemoryManager().release(pair2.getDevicePointer(), MemoryKind.DEVICE); if (pair.getHostPointer() != null) Nd4j.getMemoryManager().release(pair.getHostPointer(), MemoryKind.HOST); if (pair.getDevicePointer() != null) Nd4j.getMemoryManager().release(pair.getDevicePointer(), MemoryKind.DEVICE);
/** * This method basically deallocates workspace memory * * @param extended */ @Override public void destroyWorkspace(boolean extended) { if (workspace.getHostPointer() != null && workspace.getHostPointer().getOriginalPointer() != null && workspace.getHostPointer().getOriginalPointer() instanceof BytePointer) workspace.getHostPointer().getOriginalPointer().deallocate(); workspace.setHostPointer(null); currentSize.set(0); reset(); if (extended) { clearExternalAllocations(); } //cycleAllocations.set(0); //maxCycle.set(0); }
@Override public synchronized void destroyWorkspace(boolean extended) { currentSize.set(0); reset(); if (extended) clearExternalAllocations(); clearPinnedAllocations(extended); if (workspace.getHostPointer() != null) NativeOpsHolder.getInstance().getDeviceNativeOps().freeHost(workspace.getHostPointer()); if (workspace.getDevicePointer() != null) NativeOpsHolder.getInstance().getDeviceNativeOps().freeDevice(workspace.getDevicePointer(), null); workspace.setDevicePointer(null); workspace.setHostPointer(null); }
throw new RuntimeException(); long stepNumber = pair.getAllocationCycle(); long stepCurrent = stepsCount.get(); pinnedAllocations.remove(); if (pair.getDevicePointer() != null) { NativeOpsHolder.getInstance().getDeviceNativeOps().freeDevice(pair.getDevicePointer(), null); pinnedCount.decrementAndGet(); if (pair.getHostPointer() != null) { NativeOpsHolder.getInstance().getDeviceNativeOps().freeHost(pair.getHostPointer()); pinnedAllocationsSize.addAndGet(pair.getRequiredMemory() * -1); } else { break;
externalAllocations.add(new PointersPair(null, pointer)); return pointer; } else { PagedPointer pointer = new PagedPointer(memoryManager.allocate(requiredMemory, MemoryKind.HOST, initialize), numElements); externalAllocations.add(new PointersPair(pointer, null)); return pointer; return null; val ptr = workspace.getDevicePointer().withOffset(prevOffset, numElements); externalAllocations.add(new PointersPair(null, pointer)); pinnedAllocations.add(new PointersPair(stepsCount.get(), requiredMemory, null, pointer)); PagedPointer ptr = workspace.getHostPointer().withOffset(prevOffset, numElements); externalAllocations.add(new PointersPair(pointer, null)); pinnedAllocations.add(new PointersPair(stepsCount.get(), 0L, pointer, null));
@Override protected void init() { super.init(); if (currentSize.get() > 0) { //log.info("Allocating {} bytes at DEVICE & HOST space...", currentSize.get()); isInit.set(true); long bytes = currentSize.get(); if (isDebug.get()) log.info("Allocating [{}] workspace on device_{}, {} bytes...", id, Nd4j.getAffinityManager().getDeviceForCurrentThread(), bytes); if (isDebug.get()) { Nd4j.getWorkspaceManager().printAllocationStatisticsForCurrentThread(); } Pointer ptr = memoryManager.allocate((bytes + SAFETY_OFFSET), MemoryKind.HOST, false); if (ptr == null) throw new ND4JIllegalStateException("Can't allocate memory for workspace"); workspace.setHostPointer(new PagedPointer(ptr)); if (workspaceConfiguration.getPolicyMirroring() != MirroringPolicy.HOST_ONLY) workspace.setDevicePointer(new PagedPointer(memoryManager.allocate((bytes + SAFETY_OFFSET), MemoryKind.DEVICE, false))); //log.info("Workspace [{}] initialized successfully", id); } }
@Override public synchronized void destroyWorkspace(boolean extended) { currentSize.set(0); reset(); if (extended) clearExternalAllocations(); clearPinnedAllocations(extended); if (workspace.getHostPointer() != null) NativeOpsHolder.getInstance().getDeviceNativeOps().freeHost(workspace.getHostPointer()); if (workspace.getDevicePointer() != null) NativeOpsHolder.getInstance().getDeviceNativeOps().freeDevice(workspace.getDevicePointer(), null); workspace.setDevicePointer(null); workspace.setHostPointer(null); }
throw new RuntimeException(); long stepNumber = pair.getAllocationCycle(); long stepCurrent = stepsCount.get(); pinnedAllocations.remove(); if (pair.getDevicePointer() != null) { NativeOpsHolder.getInstance().getDeviceNativeOps().freeDevice(pair.getDevicePointer(), null); pinnedCount.decrementAndGet(); if (pair.getHostPointer() != null) { NativeOpsHolder.getInstance().getDeviceNativeOps().freeHost(pair.getHostPointer()); pinnedAllocationsSize.addAndGet(pair.getRequiredMemory() * -1); } else { break;
externalAllocations.add(new PointersPair(null, pointer)); return pointer; } else { PagedPointer pointer = new PagedPointer(memoryManager.allocate(requiredMemory, MemoryKind.HOST, initialize), numElements); externalAllocations.add(new PointersPair(pointer, null)); return pointer; return null; PagedPointer ptr = workspace.getDevicePointer().withOffset(prevOffset, numElements); externalAllocations.add(new PointersPair(null, pointer)); pinnedAllocations.add(new PointersPair(stepsCount.get(), requiredMemory, null, pointer)); PagedPointer ptr = workspace.getHostPointer().withOffset(prevOffset, numElements); externalAllocations.add(new PointersPair(pointer, null)); pinnedAllocations.add(new PointersPair(stepsCount.get(), 0L, pointer, null));
@Override protected void init() { if (workspaceConfiguration.getPolicyLocation() == LocationPolicy.MMAP) { throw new ND4JIllegalStateException("CUDA do not support MMAP workspaces yet"); } super.init(); if (currentSize.get() > 0) { //log.info("Allocating {} bytes at DEVICE & HOST space...", currentSize.get()); isInit.set(true); long bytes = currentSize.get(); if (isDebug.get()) log.info("Allocating [{}] workspace on device_{}, {} bytes...", id, Nd4j.getAffinityManager().getDeviceForCurrentThread(), bytes); if (isDebug.get()) { Nd4j.getWorkspaceManager().printAllocationStatisticsForCurrentThread(); } Pointer ptr = memoryManager.allocate((bytes + SAFETY_OFFSET), MemoryKind.HOST, false); if (ptr == null) throw new ND4JIllegalStateException("Can't allocate memory for workspace"); workspace.setHostPointer(new PagedPointer(ptr)); if (workspaceConfiguration.getPolicyMirroring() != MirroringPolicy.HOST_ONLY) workspace.setDevicePointer(new PagedPointer(memoryManager.allocate((bytes + SAFETY_OFFSET), MemoryKind.DEVICE, false))); //log.info("Workspace [{}] initialized successfully", id); } }
@Override protected void clearExternalAllocations() { if (isDebug.get()) log.info("Workspace [{}] device_{} threadId {} guid [{}]: clearing external allocations...", id, Nd4j.getAffinityManager().getDeviceForCurrentThread(), Thread.currentThread().getId(), guid); Nd4j.getExecutioner().commit(); try { for (PointersPair pair : externalAllocations) { if (pair.getHostPointer() != null) { NativeOpsHolder.getInstance().getDeviceNativeOps().freeHost(pair.getHostPointer()); if (isDebug.get()) log.info("deleting external host allocation... "); } if (pair.getDevicePointer() != null) { NativeOpsHolder.getInstance().getDeviceNativeOps().freeDevice(pair.getDevicePointer(), null); if (isDebug.get()) log.info("deleting external device allocation... "); } } } catch (Exception e) { log.error("RC: Workspace [{}] device_{} threadId {} guid [{}]: clearing external allocations...", id, Nd4j.getAffinityManager().getDeviceForCurrentThread(), Thread.currentThread().getId(), guid); throw new RuntimeException(e); } spilledAllocationsSize.set(0); externalCount.set(0); externalAllocations.clear(); }
/** * This method basically deallocates workspace memory * * @param extended */ @Override public void destroyWorkspace(boolean extended) { if (workspace.getHostPointer() != null && workspace.getHostPointer().getOriginalPointer() != null && workspace.getHostPointer().getOriginalPointer() instanceof BytePointer) workspace.getHostPointer().getOriginalPointer().deallocate(); workspace.setHostPointer(null); currentSize.set(0); reset(); if (extended) { clearExternalAllocations(); } //cycleAllocations.set(0); //maxCycle.set(0); }
externalAllocations.add(new PointersPair(pointer, null)); deviceOffset.set(hostOffset.get()); PagedPointer ptr = workspace.getHostPointer().withOffset(prevOffset, numElements); externalAllocations.add(new PointersPair(pointer, null)); PagedPointer pointer = new PagedPointer(memoryManager.allocate(requiredMemory, MemoryKind.HOST, initialize), numElements); pinnedAllocations.add(new PointersPair(stepsCount.get(), requiredMemory, pointer, null));
if (pair.getDevicePointer() != null) { Nd4j.getMemoryManager().release(pair.getDevicePointer(), MemoryKind.DEVICE); if (pair.getHostPointer() != null) { Nd4j.getMemoryManager().release(pair.getHostPointer(), MemoryKind.HOST); if (pair2.getHostPointer() != null) Nd4j.getMemoryManager().release(pair2.getHostPointer(), MemoryKind.HOST); if (pair2.getDevicePointer() != null) Nd4j.getMemoryManager().release(pair2.getDevicePointer(), MemoryKind.DEVICE); if (pair.getHostPointer() != null) Nd4j.getMemoryManager().release(pair.getHostPointer(), MemoryKind.HOST); if (pair.getDevicePointer() != null) Nd4j.getMemoryManager().release(pair.getDevicePointer(), MemoryKind.DEVICE);
@Override protected void clearExternalAllocations() { if (isDebug.get()) log.info("Workspace [{}] device_{} threadId {} guid [{}]: clearing external allocations...", id, Nd4j.getAffinityManager().getDeviceForCurrentThread(), Thread.currentThread().getId(), guid); Nd4j.getExecutioner().commit(); try { for (PointersPair pair : externalAllocations) { if (pair.getHostPointer() != null) { NativeOpsHolder.getInstance().getDeviceNativeOps().freeHost(pair.getHostPointer()); if (isDebug.get()) log.info("deleting external host allocation... "); } if (pair.getDevicePointer() != null) { NativeOpsHolder.getInstance().getDeviceNativeOps().freeDevice(pair.getDevicePointer(), null); if (isDebug.get()) log.info("deleting external device allocation... "); } } } catch (Exception e) { log.error("RC: Workspace [{}] device_{} threadId {} guid [{}]: clearing external allocations...", id, Nd4j.getAffinityManager().getDeviceForCurrentThread(), Thread.currentThread().getId(), guid); throw new RuntimeException(e); } spilledAllocationsSize.set(0); externalCount.set(0); externalAllocations.clear(); }