@ Override public Integer getDeviceForThread ( long threadId ) { if ( getNumberOfDevices ( ) == 1 ) return 0 ; Integer aff = affinityMap . get ( threadId ) ; if ( aff == null ) { Integer deviceId = getNextDevice ( threadId ) ; affinityMap . put ( threadId , deviceId ) ; affiliated . set ( new AtomicBoolean ( false ) ) ; if ( threadId == Thread . currentThread ( ) . getId ( ) ) { NativeOpsHolder . getInstance ( ) . getDeviceNativeOps ( ) . setDevice ( new CudaPointer ( deviceId ) ) ; //logger.error("setDevice({}) called for thread {}", deviceId, Thread.currentThread().getName()); affiliated . get ( ) . set ( true ) ; } return deviceId ; } else { if ( threadId == Thread . currentThread ( ) . getId ( ) ) { if ( affiliated . get ( ) == null ) affiliated . set ( new AtomicBoolean ( false ) ) ; if ( ! affiliated . get ( ) . get ( ) ) { NativeOpsHolder . getInstance ( ) . getDeviceNativeOps ( ) . setDevice ( new CudaPointer ( aff ) ) ; //logger.error("SCARY setDevice({}) called for thread {}", aff, threadId); affiliated . get ( ) . set ( true ) ; return aff ; } } return aff ; } /* return affinityMap.get(threadId); */ //return 0; }
This method returns deviceId for given thread identified by threadId