@ Override public DataBuffer getConstantBuffer ( float [ ] array ) { // logger.info("getConstantBuffer(float[]) called"); ArrayDescriptor descriptor = new ArrayDescriptor ( array ) ; Integer deviceId = AtomicAllocator . getInstance ( ) . getDeviceId ( ) ; ensureMaps ( deviceId ) ; if ( ! buffersCache . get ( deviceId ) . containsKey ( descriptor ) ) { // we create new databuffer //logger.info("Creating new constant buffer..."); DataBuffer buffer = Nd4j . createBufferDetached ( array ) ; if ( constantOffsets . get ( deviceId ) . get ( ) + ( array . length * Nd4j . sizeOfDataType ( ) ) < MAX_CONSTANT_LENGTH ) { buffer . setConstant ( true ) ; // now we move data to constant memory, and keep happy moveToConstantSpace ( buffer ) ; buffersCache . get ( deviceId ) . put ( descriptor , buffer ) ; bytes . addAndGet ( array . length * Nd4j . sizeOfDataType ( ) ) ; } return buffer ; } // else logger.info("Reusing constant buffer..."); return buffersCache . get ( deviceId ) . get ( descriptor ) ; }
This method returns DataBuffer with contant equal to input array .