MCPcopy Create free account
hub / github.com/MITK/MITK / GetCUDADeviceInfo

Method GetCUDADeviceInfo

Modules/PythonSegmentation/src/mitknnInteractiveTool.cpp:758–800  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

756}
757
758bool 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
802void mitk::nnInteractiveTool::StartSession()
803{

Callers 1

ConstructLocalSessionMethod · 0.95

Calls 9

parseCUDADeviceFunction · 0.85
GetVariableAsBoolMethod · 0.80
GetVariableAsStringMethod · 0.80
GetVariableAsIntMethod · 0.80
GetPreferencesFunction · 0.70
GetMethod · 0.45
valueMethod · 0.45
GetPythonContextMethod · 0.45
ExecuteMethod · 0.45

Tested by

no test coverage detected