### Question:
CudaAffinityManager extends BasicAffinityManager { @Override public Integer getDeviceForCurrentThread() { return getDeviceForThread(Thread.currentThread().getId()); } CudaAffinityManager(); @Override Integer getDeviceForCurrentThread(); @Override Integer getDeviceForThread(Thread thread); @Override Integer getDeviceForThread(long threadId); @Override void attachThreadToDevice(Thread thread, Integer deviceId); @Override void attachThreadToDevice(long threadId, Integer deviceId); @Override int getNumberOfDevices(); @Override void touch(INDArray array); @Override void touch(DataBuffer buffer); @Override synchronized INDArray replicateToDevice(Integer deviceId, INDArray array); @Override DataBuffer replicateToDevice(Integer deviceId, DataBuffer buffer); @Override void tagLocation(INDArray array, Location location); @Override void tagLocation(DataBuffer buffer, Location location); @Override Integer getDeviceForArray(@NonNull INDArray array); @Override void unsafeSetDevice(Integer deviceId); @Override void ensureLocation(INDArray array, Location location); @Override Location getActiveLocation(INDArray array); @Override boolean isCrossDeviceAccessSupported(); @Override void allowCrossDeviceAccess(boolean reallyAllow);  }### Answer:
@Test public void getDeviceForCurrentThread() throws Exception { CudaAffinityManager manager = new CudaAffinityManager(); Integer deviceId = manager.getDeviceForCurrentThread(); assertEquals(0, deviceId.intValue()); manager.attachThreadToDevice(Thread.currentThread().getId(), 1); assertEquals(1, manager.getDeviceForCurrentThread().intValue()); manager.attachThreadToDevice(Thread.currentThread().getId(), 0); assertEquals(0, manager.getDeviceForCurrentThread().intValue()); }
@Test public void getDeviceForAnotherThread2() throws Exception { CudaAffinityManager manager = new CudaAffinityManager(); Integer deviceId = manager.getDeviceForCurrentThread(); assertEquals(0, deviceId.intValue()); System.out.println("Current threadId: " + Thread.currentThread().getId()); Thread thread = new Thread(); long threadIdPrior = thread.getId(); System.out.println("Next threadId: " + thread.getId()); assertNotEquals(Thread.currentThread().getId(), thread.getId()); thread.start(); System.out.println("Current threadId: " + thread.getId()); assertEquals(threadIdPrior, thread.getId()); }