/** * 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 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 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); } }
/** * 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); }
@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); }