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

Method ConstructLocalSession

Modules/PythonSegmentation/src/mitknnInteractiveTool.cpp:955–1163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

953}
954
955void mitk::nnInteractiveTool::ConstructLocalSession()
956{
957 auto pythonContext = m_Impl->GetPythonContext();
958
959 // A client-only install (nninteractive-client) has no local inference backend
960 // and no PyTorch. Fail fast with an actionable message instead of letting the
961 // torch import below raise a raw traceback.
962 if (!this->IsLocalInferenceAvailable())
963 mitkThrow() << "This is a client-only nnInteractive installation, which supports remote "
964 "sessions only. Select Remote in Preferences -> Segmentation -> nnInteractive, "
965 "or uninstall and reinitialize in Full mode to enable local inference.";
966
967 bool useCUDADevice = false;
968
969 auto prefs = GetPreferences();
970 const auto backendPref = prefs->Get("nnInteractive/backend", "auto");
971 const auto gpuBackendPref = prefs->Get("nnInteractive/gpuBackend", "cuda:0");
972
973 if (backendPref != "cpu")
974 {
975 CUDADeviceInfo deviceInfo;
976
977 if (this->GetCUDADeviceInfo(deviceInfo))
978 {
979 MITK_INFO << "Found CUDA device: " << deviceInfo.Name;
980 MITK_INFO << " Compute capability: " << deviceInfo.Major << "." << deviceInfo.Minor;
981 MITK_INFO << " Total memory: " << deviceInfo.TotalMemoryMB << " MB";
982
983 bool switchToCUDADevice = true;
984
985 if (deviceInfo.Major < 6)
986 {
987 MITK_WARN << "Minimum required compute capability is 6.0";
988 switchToCUDADevice = false;
989 }
990
991 if (deviceInfo.TotalMemoryMB < 6000)
992 {
993 MITK_WARN << "Minimum required total memory is 6 GB";
994 switchToCUDADevice = false;
995 }
996
997 useCUDADevice = switchToCUDADevice;
998 }
999
1000 if (!useCUDADevice)
1001 {
1002 if (backendPref == "auto")
1003 {
1004 MITK_WARN << "No compatible CUDA device detected. Falling back to CPU processing.";
1005 }
1006 else
1007 {
1008 MITK_WARN << "CPU backend would have been auto-selected, but the CUDA backend has been manually enforced. "
1009 << "Continue at your own risk.";
1010 useCUDADevice = true;
1011 }
1012 }

Callers 1

StartSessionMethod · 0.95

Calls 13

GetCUDADeviceInfoMethod · 0.95
SetAutoZoomMethod · 0.95
GetVariableAsStringMethod · 0.80
ResetBackendMethod · 0.80
GetBoolMethod · 0.80
SetBackendMethod · 0.80
GetPreferencesFunction · 0.70
GetPythonContextMethod · 0.45
GetMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected