| 756 | } |
| 757 | |
| 758 | bool mitk::nnInteractiveTool::GetCUDADeviceInfo(CUDADeviceInfo& info) const |
| 759 | { |
| 760 | auto prefs = GetPreferences(); |
| 761 | const auto gpuBackend = prefs->Get("nnInteractive/gpuBackend", "cuda:0"); |
| 762 | auto cudaDevice = parseCUDADevice(gpuBackend); |
| 763 | |
| 764 | if (!cudaDevice.has_value()) |
| 765 | return false; |
| 766 | |
| 767 | std::ostringstream pyCommands; pyCommands |
| 768 | << "import torch\n" |
| 769 | << "is_cuda_available = False\n" |
| 770 | << "try:\n" |
| 771 | << " if torch.cuda.is_available():\n" |
| 772 | << " name = torch.cuda.get_device_name(" << cudaDevice.value() << ")\n" |
| 773 | << " props = torch.cuda.get_device_properties(" << cudaDevice.value() << ")\n" |
| 774 | << " total_memory_mb = props.total_memory // (1024 ** 2)\n" |
| 775 | << " major = props.major\n" |
| 776 | << " minor = props.minor\n" |
| 777 | << " is_cuda_available = True\n" |
| 778 | << "except Exception:\n" |
| 779 | << " pass\n"; |
| 780 | |
| 781 | try |
| 782 | { |
| 783 | auto pythonContext = m_Impl->GetPythonContext(); |
| 784 | pythonContext->Execute(pyCommands.str()); |
| 785 | |
| 786 | if (!pythonContext->GetVariableAsBool("is_cuda_available").value_or(false)) |
| 787 | return false; |
| 788 | |
| 789 | info.Name = pythonContext->GetVariableAsString("name").value_or(""); |
| 790 | info.TotalMemoryMB = pythonContext->GetVariableAsInt("total_memory_mb").value_or(0); |
| 791 | info.Major = pythonContext->GetVariableAsInt("major").value_or(0); |
| 792 | info.Minor = pythonContext->GetVariableAsInt("minor").value_or(0); |
| 793 | |
| 794 | return true; |
| 795 | } |
| 796 | catch (...) |
| 797 | { |
| 798 | return false; |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | void mitk::nnInteractiveTool::StartSession() |
| 803 | { |
no test coverage detected