@Override public void deallocate() { NativeOpsHolder.getInstance().getDeviceNativeOps().freeDevice(Workspace.this, null); } });
@Override public void deallocate() { NativeOpsHolder.getInstance().getDeviceNativeOps().freeDevice(Workspace.this, null); } });
protected void freeDevice(Pointer pointer, int deviceId) { NativeOps nativeOps = NativeOpsHolder.getInstance().getDeviceNativeOps(); nativeOps.freeDevice(pointer, new CudaPointer(0)); }
protected void freeDevice(Pointer pointer, int deviceId) { NativeOps nativeOps = NativeOpsHolder.getInstance().getDeviceNativeOps(); nativeOps.freeDevice(pointer, new CudaPointer(0)); }
NativeOpsHolder.getInstance().getDeviceNativeOps().freeDevice(pair.getDevicePointer(), null); pinnedCount.decrementAndGet();
NativeOpsHolder.getInstance().getDeviceNativeOps().freeDevice(pair.getDevicePointer(), null); pinnedCount.decrementAndGet();
@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(); }
@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 releases previously allocated memory chunk * * @param pointer * @param kind * @return */ @Override public void release(Pointer pointer, MemoryKind kind) { if (kind == MemoryKind.DEVICE) { NativeOpsHolder.getInstance().getDeviceNativeOps().freeDevice(pointer, null); } else if (kind == MemoryKind.HOST) { NativeOpsHolder.getInstance().getDeviceNativeOps().freeHost(pointer); } }
/** * This method releases previously allocated memory chunk * * @param pointer * @param kind * @return */ @Override public void release(Pointer pointer, MemoryKind kind) { if (kind == MemoryKind.DEVICE) { NativeOpsHolder.getInstance().getDeviceNativeOps().freeDevice(pointer, null); pointer.setNull(); } else if (kind == MemoryKind.HOST) { NativeOpsHolder.getInstance().getDeviceNativeOps().freeHost(pointer); pointer.setNull(); } }
@Override public void convertDataEx(DataBuffer.TypeEx typeSrc, Pointer source, DataBuffer.TypeEx typeDst, DataBuffer buffer) { Pointer srcPtr = null; Pointer dstPtr = null; long size = 0; long ssize = 0; val stream = ((CudaContext) AtomicAllocator.getInstance().getDeviceContext().getContext()).getOldStream(); if (buffer instanceof CompressedDataBuffer) { // compressing size = ((CompressedDataBuffer) buffer).getCompressionDescriptor().getCompressedLength(); ssize = ((CompressedDataBuffer) buffer).getCompressionDescriptor().getOriginalLength(); srcPtr = nativeOps.mallocDevice(ssize, null, 0); dstPtr = nativeOps.mallocDevice(size, null, 0); nativeOps.memcpyAsync(srcPtr, source, ssize, CudaConstants.cudaMemcpyHostToDevice, stream); } else { // decompressing throw new UnsupportedOperationException(); } convertDataEx(typeSrc, srcPtr, typeDst, dstPtr, buffer.length()); nativeOps.memcpyAsync(buffer.addressPointer(), dstPtr, size, CudaConstants.cudaMemcpyHostToHost, stream); stream.synchronize(); if (buffer instanceof CompressedDataBuffer) { nativeOps.freeDevice(srcPtr, null); nativeOps.freeDevice(dstPtr, 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); }
@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); }
long result = nativeOps.freeDevice(point.getPointers().getDevicePointer(), new CudaPointer(0)); if (result == 0) throw new RuntimeException("Can't deallocate [DEVICE] memory...");
long result = nativeOps.freeDevice(point.getPointers().getDevicePointer(), new CudaPointer(0)); if (result == 0) throw new RuntimeException("Can't deallocate [DEVICE] memory...");
nativeOps.freeDevice(dstPtr, null); nativeOps.freeDevice(srcPtr, null);