| 602 | } |
| 603 | |
| 604 | void removeDeviceContext(cl_device_id dev, cl_context ctx) { |
| 605 | if (getDevice()() == dev && getContext()() == ctx) { |
| 606 | AF_ERROR("Cannot pop the device currently in use", AF_ERR_ARG); |
| 607 | } |
| 608 | |
| 609 | DeviceManager& devMngr = DeviceManager::getInstance(); |
| 610 | |
| 611 | int deleteIdx = -1; |
| 612 | { |
| 613 | common::lock_guard_t lock(devMngr.deviceMutex); |
| 614 | |
| 615 | const int dCount = static_cast<int>(devMngr.mDevices.size()); |
| 616 | for (int i = static_cast<int>(devMngr.mUserDeviceOffset); i < dCount; |
| 617 | ++i) { |
| 618 | if (devMngr.mDevices[i]->operator()() == dev && |
| 619 | devMngr.mContexts[i]->operator()() == ctx) { |
| 620 | deleteIdx = i; |
| 621 | break; |
| 622 | } |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | if (deleteIdx < static_cast<int>(devMngr.mUserDeviceOffset)) { |
| 627 | AF_ERROR("Cannot pop ArrayFire internal devices", AF_ERR_ARG); |
| 628 | } else if (deleteIdx == -1) { |
| 629 | AF_ERROR("No matching device found", AF_ERR_ARG); |
| 630 | } else { |
| 631 | // remove memory management for device added by user outside of the lock |
| 632 | memoryManager().removeMemoryManagement(deleteIdx); |
| 633 | |
| 634 | common::lock_guard_t lock(devMngr.deviceMutex); |
| 635 | // FIXME: this case can potentially cause issues due to the |
| 636 | // modification of the device pool stl containers. |
| 637 | |
| 638 | // IF the current active device is enumerated at a position |
| 639 | // that lies ahead of the device that has been requested |
| 640 | // to be removed. We just pop the entries from pool since it |
| 641 | // has no side effects. |
| 642 | devMngr.mDevices.erase(devMngr.mDevices.begin() + deleteIdx); |
| 643 | devMngr.mContexts.erase(devMngr.mContexts.begin() + deleteIdx); |
| 644 | devMngr.mQueues.erase(devMngr.mQueues.begin() + deleteIdx); |
| 645 | devMngr.mPlatforms.erase(devMngr.mPlatforms.begin() + deleteIdx); |
| 646 | |
| 647 | // FIXME: add OpenGL Interop for user provided contexts later |
| 648 | devMngr.mIsGLSharingOn.erase(devMngr.mIsGLSharingOn.begin() + |
| 649 | deleteIdx); |
| 650 | |
| 651 | // OTHERWISE, update(decrement) the thread local active device ids |
| 652 | device_id_t& devId = tlocalActiveDeviceId(); |
| 653 | |
| 654 | if (deleteIdx < static_cast<int>(devId.first)) { |
| 655 | device_id_t newVals = make_pair(devId.first - 1, devId.second - 1); |
| 656 | devId = newVals; |
| 657 | } |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | bool synchronize_calls() { |
no test coverage detected