Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 #ifdef USE_INFERENCE 27 # include "Par04InferenceMessenger.hh" 28 29 # include "Par04InferenceSetup.hh" // for Pa 30 31 # include "G4UIcmdWithADoubleAndUnit.hh" // 32 # include "G4UIcmdWithAString.hh" // for G4U 33 # include "G4UIcmdWithAnInteger.hh" // for G 34 # include "G4UIdirectory.hh" // for G4UIdire 35 36 # include <CLHEP/Units/SystemOfUnits.h> // f 37 # include <G4ApplicationState.hh> // for G4S 38 # include <G4ThreeVector.hh> // for G4ThreeV 39 # include <G4UImessenger.hh> // for G4UImess 40 # include <string> // for stoi 41 class G4UIcommand; 42 43 //....oooOO0OOooo........oooOO0OOooo........oo 44 45 Par04InferenceMessenger::Par04InferenceMesseng 46 : G4UImessenger(), fInference(aInference) 47 { 48 fExampleDir = new G4UIdirectory("/Par04/"); 49 fExampleDir->SetGuidance("UI commands specif 50 51 fInferenceDir = new G4UIdirectory("/Par04/in 52 fInferenceDir->SetGuidance("Inference constr 53 54 fInferenceLibraryCmd = new G4UIcmdWithAStrin 55 fInferenceLibraryCmd->SetGuidance("Inference 56 fInferenceLibraryCmd->SetParameterName("Infe 57 fInferenceLibraryCmd->AvailableForStates(G4S 58 fInferenceLibraryCmd->SetToBeBroadcasted(tru 59 60 fSizeLatentVectorCmd = new G4UIcmdWithAnInte 61 fSizeLatentVectorCmd->SetGuidance("Set size 62 fSizeLatentVectorCmd->SetParameterName("Size 63 fSizeLatentVectorCmd->SetRange("SizeLatentVe 64 fSizeLatentVectorCmd->AvailableForStates(G4S 65 fSizeLatentVectorCmd->SetToBeBroadcasted(tru 66 67 fSizeConditionVectorCmd = 68 new G4UIcmdWithAnInteger("/Par04/inference 69 fSizeConditionVectorCmd->SetGuidance("Set si 70 fSizeConditionVectorCmd->SetParameterName("S 71 fSizeConditionVectorCmd->SetRange("SizeCondi 72 fSizeConditionVectorCmd->AvailableForStates( 73 fSizeConditionVectorCmd->SetToBeBroadcasted( 74 75 fModelPathNameCmd = new G4UIcmdWithAString(" 76 fModelPathNameCmd->SetGuidance("Model path a 77 fModelPathNameCmd->SetParameterName("Name", 78 fModelPathNameCmd->AvailableForStates(G4Stat 79 fModelPathNameCmd->SetToBeBroadcasted(true); 80 81 fProfileFlagCmd = new G4UIcmdWithAnInteger(" 82 fProfileFlagCmd->SetGuidance("Flag to save a 83 fProfileFlagCmd->SetParameterName("ProfileFl 84 fProfileFlagCmd->SetRange("ProfileFlag>-1"); 85 fProfileFlagCmd->AvailableForStates(G4State_ 86 fProfileFlagCmd->SetToBeBroadcasted(true); 87 88 fOptimizationFlagCmd = new G4UIcmdWithAnInte 89 fOptimizationFlagCmd->SetGuidance("Set optim 90 fOptimizationFlagCmd->SetParameterName("Opti 91 fOptimizationFlagCmd->SetRange("Optimization 92 fOptimizationFlagCmd->AvailableForStates(G4S 93 fOptimizationFlagCmd->SetToBeBroadcasted(tru 94 95 fMeshNbRhoCellsCmd = new G4UIcmdWithAnIntege 96 fMeshNbRhoCellsCmd->SetGuidance("Set number 97 fMeshNbRhoCellsCmd->SetParameterName("NbRhoC 98 fMeshNbRhoCellsCmd->SetRange("NbRhoCells>0") 99 fMeshNbRhoCellsCmd->AvailableForStates(G4Sta 100 fMeshNbRhoCellsCmd->SetToBeBroadcasted(true) 101 102 fMeshNbPhiCellsCmd = new G4UIcmdWithAnIntege 103 fMeshNbPhiCellsCmd->SetGuidance("Set number 104 fMeshNbPhiCellsCmd->SetParameterName("NbPhiC 105 fMeshNbPhiCellsCmd->SetRange("NbPhiCells>0") 106 fMeshNbPhiCellsCmd->AvailableForStates(G4Sta 107 fMeshNbPhiCellsCmd->SetToBeBroadcasted(true) 108 109 fMeshNbZCellsCmd = new G4UIcmdWithAnInteger( 110 fMeshNbZCellsCmd->SetGuidance("Set number of 111 fMeshNbZCellsCmd->SetParameterName("NbZCells 112 fMeshNbZCellsCmd->SetRange("NbZCells>0"); 113 fMeshNbZCellsCmd->AvailableForStates(G4State 114 fMeshNbZCellsCmd->SetToBeBroadcasted(true); 115 116 fMeshSizeRhoCellsCmd = new G4UIcmdWithADoubl 117 fMeshSizeRhoCellsCmd->SetGuidance("Set size 118 fMeshSizeRhoCellsCmd->SetParameterName("Size 119 fMeshSizeRhoCellsCmd->SetRange("Size>0."); 120 fMeshSizeRhoCellsCmd->SetUnitCategory("Lengt 121 fMeshSizeRhoCellsCmd->AvailableForStates(G4S 122 fMeshSizeRhoCellsCmd->SetToBeBroadcasted(tru 123 124 fMeshSizeZCellsCmd = new G4UIcmdWithADoubleA 125 fMeshSizeZCellsCmd->SetGuidance("Set size of 126 fMeshSizeZCellsCmd->SetParameterName("Size", 127 fMeshSizeZCellsCmd->SetRange("Size>0."); 128 fMeshSizeZCellsCmd->SetUnitCategory("Length" 129 fMeshSizeZCellsCmd->AvailableForStates(G4Sta 130 fMeshSizeZCellsCmd->SetToBeBroadcasted(true) 131 132 // Onnx Runtime Execution Provider flag comm 133 fCudaFlagCmd = new G4UIcmdWithAnInteger("/Pa 134 G4cout << "f CudaFlagCmd " << fCudaFlagCmd < 135 fCudaFlagCmd->SetGuidance("Whether to use CU 136 fCudaFlagCmd->SetParameterName("CudaFlag", f 137 fCudaFlagCmd->SetRange("CudaFlag>-1"); 138 fCudaFlagCmd->AvailableForStates(G4State_Idl 139 fCudaFlagCmd->SetToBeBroadcasted(true); 140 141 /// OnnxRuntime Execution Provider Options 142 /// Cuda 143 fCudaOptionsDir = new G4UIdirectory("/Par04/ 144 fCudaOptionsDir->SetGuidance("Commands for s 145 146 fCudaDeviceIdCmd = new G4UIcmdWithAString("/ 147 fCudaDeviceIdCmd->SetGuidance("Device ID of 148 fCudaDeviceIdCmd->SetParameterName("CudaDevi 149 fCudaDeviceIdCmd->AvailableForStates(G4State 150 fCudaDeviceIdCmd->SetToBeBroadcasted(true); 151 152 fCudaGpuMemLimitCmd = new G4UIcmdWithAString 153 fCudaGpuMemLimitCmd->SetGuidance("GPU Memory 154 fCudaGpuMemLimitCmd->SetParameterName("CudaG 155 fCudaGpuMemLimitCmd->AvailableForStates(G4St 156 fCudaGpuMemLimitCmd->SetToBeBroadcasted(true 157 158 fCudaArenaExtendedStrategyCmd = 159 new G4UIcmdWithAString("/Par04/inference/c 160 fCudaArenaExtendedStrategyCmd->SetGuidance( 161 "Strategy for extending the device memory 162 fCudaArenaExtendedStrategyCmd->SetParameterN 163 fCudaArenaExtendedStrategyCmd->AvailableForS 164 fCudaArenaExtendedStrategyCmd->SetToBeBroadc 165 166 fCudaCudnnConvAlgoSearchCmd = 167 new G4UIcmdWithAString("/Par04/inference/c 168 fCudaCudnnConvAlgoSearchCmd->SetGuidance("Se 169 fCudaCudnnConvAlgoSearchCmd->SetParameterNam 170 fCudaCudnnConvAlgoSearchCmd->AvailableForSta 171 fCudaCudnnConvAlgoSearchCmd->SetToBeBroadcas 172 173 fCudaDoCopyInDefaultStreamCmd = 174 new G4UIcmdWithAString("/Par04/inference/c 175 fCudaDoCopyInDefaultStreamCmd->SetGuidance(" 176 fCudaDoCopyInDefaultStreamCmd->SetParameterN 177 fCudaDoCopyInDefaultStreamCmd->AvailableForS 178 fCudaDoCopyInDefaultStreamCmd->SetToBeBroadc 179 180 fCudaCudnnConvUseMaxWorkspaceCmd = 181 new G4UIcmdWithAString("/Par04/inference/c 182 fCudaCudnnConvUseMaxWorkspaceCmd->SetGuidanc 183 fCudaCudnnConvUseMaxWorkspaceCmd->SetParamet 184 fCudaCudnnConvUseMaxWorkspaceCmd->AvailableF 185 fCudaCudnnConvUseMaxWorkspaceCmd->SetToBeBro 186 } 187 188 //....oooOO0OOooo........oooOO0OOooo........oo 189 190 Par04InferenceMessenger::~Par04InferenceMessen 191 { 192 delete fInferenceLibraryCmd; 193 delete fSizeLatentVectorCmd; 194 delete fSizeConditionVectorCmd; 195 delete fModelPathNameCmd; 196 delete fProfileFlagCmd; 197 delete fOptimizationFlagCmd; 198 delete fMeshNbRhoCellsCmd; 199 delete fMeshNbPhiCellsCmd; 200 delete fMeshNbZCellsCmd; 201 delete fMeshSizeRhoCellsCmd; 202 delete fMeshSizeZCellsCmd; 203 } 204 205 //....oooOO0OOooo........oooOO0OOooo........oo 206 207 void Par04InferenceMessenger::SetNewValue(G4UI 208 { 209 if (aCommand == fInferenceLibraryCmd) { 210 fInference->SetInferenceLibrary(aNewValue) 211 } 212 if (aCommand == fSizeLatentVectorCmd) { 213 fInference->SetSizeLatentVector(std::stoi( 214 } 215 if (aCommand == fSizeConditionVectorCmd) { 216 fInference->SetSizeConditionVector(std::st 217 } 218 if (aCommand == fModelPathNameCmd) { 219 fInference->SetModelPathName(aNewValue); 220 } 221 if (aCommand == fProfileFlagCmd) { 222 fInference->SetProfileFlag(std::stoi(aNewV 223 } 224 if (aCommand == fOptimizationFlagCmd) { 225 fInference->SetOptimizationFlag(std::stoi( 226 } 227 else if (aCommand == fMeshNbRhoCellsCmd) { 228 fInference->SetMeshNbOfCells(0, fMeshNbRho 229 } 230 else if (aCommand == fMeshNbPhiCellsCmd) { 231 fInference->SetMeshNbOfCells(1, fMeshNbPhi 232 fInference->SetMeshSizeOfCells(1, 233 2. * CLHEP: 234 } 235 else if (aCommand == fMeshNbZCellsCmd) { 236 fInference->SetMeshNbOfCells(2, fMeshNbZCe 237 } 238 else if (aCommand == fMeshSizeRhoCellsCmd) { 239 fInference->SetMeshSizeOfCells(0, fMeshSiz 240 } 241 else if (aCommand == fMeshSizeZCellsCmd) { 242 fInference->SetMeshSizeOfCells(2, fMeshSiz 243 } 244 /// Onnx Runtime Execution Provider Flags 245 /// Cuda 246 if (aCommand == fCudaFlagCmd) { 247 fInference->SetCudaFlag(std::stoi(aNewValu 248 } 249 if (aCommand == fCudaDeviceIdCmd) { 250 fInference->SetCudaDeviceId(aNewValue); 251 } 252 else if (aCommand == fCudaGpuMemLimitCmd) { 253 fInference->SetCudaGpuMemLimit(aNewValue); 254 } 255 else if (aCommand == fCudaArenaExtendedStrat 256 fInference->SetCudaArenaExtendedStrategy(a 257 } 258 else if (aCommand == fCudaCudnnConvAlgoSearc 259 fInference->SetCudaCudnnConvAlgoSearch(aNe 260 } 261 else if (aCommand == fCudaDoCopyInDefaultStr 262 fInference->SetCudaDoCopyInDefaultStream(a 263 } 264 else if (aCommand == fCudaCudnnConvUseMaxWor 265 fInference->SetCudaCudnnConvUseMaxWorkspac 266 } 267 } 268 269 //....oooOO0OOooo........oooOO0OOooo........oo 270 271 G4String Par04InferenceMessenger::GetCurrentVa 272 { 273 G4String cv; 274 275 if (aCommand == fInferenceLibraryCmd) { 276 cv = fInferenceLibraryCmd->ConvertToString 277 } 278 if (aCommand == fSizeLatentVectorCmd) { 279 cv = fSizeLatentVectorCmd->ConvertToString 280 } 281 if (aCommand == fSizeConditionVectorCmd) { 282 cv = fSizeConditionVectorCmd->ConvertToStr 283 } 284 if (aCommand == fModelPathNameCmd) { 285 cv = fModelPathNameCmd->ConvertToString(fI 286 } 287 if (aCommand == fProfileFlagCmd) { 288 cv = fSizeLatentVectorCmd->ConvertToString 289 } 290 if (aCommand == fOptimizationFlagCmd) { 291 cv = fSizeLatentVectorCmd->ConvertToString 292 } 293 else if (aCommand == fMeshNbRhoCellsCmd) { 294 cv = fMeshNbRhoCellsCmd->ConvertToString(f 295 } 296 else if (aCommand == fMeshNbPhiCellsCmd) { 297 cv = fMeshNbPhiCellsCmd->ConvertToString(f 298 } 299 else if (aCommand == fMeshNbZCellsCmd) { 300 cv = fMeshNbZCellsCmd->ConvertToString(fIn 301 } 302 else if (aCommand == fMeshSizeRhoCellsCmd) { 303 cv = fMeshSizeRhoCellsCmd->ConvertToString 304 } 305 else if (aCommand == fMeshSizeZCellsCmd) { 306 cv = fMeshSizeZCellsCmd->ConvertToString(f 307 } 308 /// Onnx Runtime Execution Provider Flags 309 /// Cuda 310 if (aCommand == fCudaDeviceIdCmd) { 311 cv = fCudaDeviceIdCmd->ConvertToString(fIn 312 } 313 else if (aCommand == fCudaGpuMemLimitCmd) { 314 cv = fCudaGpuMemLimitCmd->ConvertToString( 315 } 316 else if (aCommand == fCudaArenaExtendedStrat 317 cv = fCudaArenaExtendedStrategyCmd->Conver 318 } 319 else if (aCommand == fCudaCudnnConvAlgoSearc 320 cv = fCudaCudnnConvAlgoSearchCmd->ConvertT 321 } 322 else if (aCommand == fCudaDoCopyInDefaultStr 323 cv = fCudaDoCopyInDefaultStreamCmd->Conver 324 } 325 else if (aCommand == fCudaCudnnConvUseMaxWor 326 cv = fCudaCudnnConvUseMaxWorkspaceCmd->Con 327 fInference->GetCudaCudnnConvUseMaxWorksp 328 } 329 330 return cv; 331 } 332 333 #endif 334