Rose2xaif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StateManager.hpp
Go to the documentation of this file.
1 
18 #if !defined(__STATEMANAGER_HPP)
19 #define __STATEMANAGER_HPP
20 
21 #include <string>
22 #include <map>
23 
24 #include "rose.h"
25 
26 #include "rose2xaif_config.hpp"
27 #include "util/Types.hpp"
28 #include "util/Utils.hpp"
29 #include "util/LogicException.hpp"
30 #if 0
31 #include "xaif/SoapXAIFInterface.hpp"
32 #endif
33 
34 #define VALUE_TYPE "ValType"
35 #define GRAD_TYPE "GradType"
36 
37 #define INACTIVE_DOUBLE_TYPE "InactiveDouble"
38 #define INACTIVE_FLOAT_TYPE "InactiveFloat"
39 
40 #define ACTIVE_FUNCTIONS_S "ACTIVE_FUNCTIONS"
41 #define INACTIVE_FUNCTIONS_S "INACTIVE_FUNCTIONS"
42 #define INTRINSIC_FUNCTIONS_S "INTRINSIC_FUNCTIONS"
43 #define ACTIVE_VARIABLE_S "ACTIVE_VARIABLES"
44 #define DEFINES_S "DEFINES"
45 #define UNINLINE_INCLUDES_S "UNINLINE_INCLUDES"
46 #define GENERAL_S "GENERAL"
47 #define UNEXPANDED_MACROS_S "UNEXPANDED_MACROS"
48 
49 #define SYSTEM_S "SYSTEM"
50 #define MODULES_S "MODULES"
51 #define IGNORE_FUNCTIONS_S "IGNORE_FUNCTIONS"
52 #define NO_PREFIX_FUNCTIONS_S "NO_PREFIX_FUNCTIONS"
53 #define SOURCE_FILES_S "SOURCE_FILES"
54 #define INTRINSIC_CONTROL_S "INTRINSIC_CONTROL"
55 #define STANDARD_INCLUDES_S "STANDARD_INCLUDES"
56 #define INACTIVE_TYPES_S "INACTIVE_TYPES"
57 #define INACTIVE_VARIABLES_S "INACTIVE_VARIABLES"
58 
59 #define INCLUDE_STR "INCLUDE"
60 #define DERIV_TYPE_STR "DERIV_TYPE"
61 
62 #define STRUCTURE_TYPE_STR "structure"
63 #define CLASS_TYPE_STR "class"
64 
65 #ifndef TRUE
66 #define TRUE 1
67 #endif
68 
69 #ifndef FALSE
70 #define FALSE 0
71 #endif
72 
73 namespace rose2xaif {
74 
92 typedef std::map<std::string, std::string> StringMap;
93 typedef std::map<std::string, StringMap> InitManager;
94 typedef std::map<std::string, StringPairList> InitManagerList;
95 
99 /*
100  const char * optv[] = {
101  "v:verbose <number>",
102  "m:module <string",
103  NULL
104  };
105  */
106 
122 
124 {
125 
126  // Singleton object management:
127  public:
128  static StateManager*
129  getInstance(const char* argv0 = "rose2xaif.exe");
130 
131  protected:
132  StateManager(const std::string& argv0 = "rose2xaif.exe");
133 
134  private:
136  unsigned int debugLevel;
137  std::string msgContext;
138  bool quiet;
141  bool admmflag;
142  std::string differentiationMode;
145 
146  public:
147  // Data
148  int flags;
150 
151  std::string prefix;
152  std::string varPrefix;
153  std::string classPrefix;
154  std::string typePrefix;
155  std::string funcPrefix;
156  std::string mapModel;
157  std::string headerFileName; // main generated header
158  std::string defaultInitFile; // default control file
159  std::string archInitFile; // architecture-specific init file
160  std::string baseDir; // Rose2XAIF installation directory
161  std::string arch; // architecture
163 
182 
183 
184  std::string strMacroDefinesLine;
185  std::string strIntrinsicMode;
186 
187  std::string gstrUnexpandedMacros;
188  std::string strGuard;
189 
190  //Sparse options set to differentiate between SparsLinC and no grad SparsLinC
191  std::string sparsederivtypename;
193  std::string sparseincludeheader;
194  bool naryflag;
195  int max_axpy;
196  bool adolcflag;
197 
198 
202  static const char* ourValWrapperName;
206  static const char* ourDerivWrapperName;
207 
208  /*
209  * Stores the list of ADOLC external functions to be differentiated
210  */
211  std::list<std::string> ADOLCExternalFunctionNames;
212  private:
213  // XAIF
214  std::string xaifSchemaLocation;
217  std::string xaifModule;
218  std::string templateFileName;
219  // Miscellaneous
221  int workflow;
222 
223  //SHK - This flag keep track of the filename option.
224  bool inputFileTypeIsC; // True is the input file name is .c/.C and false otherwise.
225  public:
227  public:
229  {
230  }
231 
232  void init(int flags, StringList& derivNames, std::string mapModel,
233  std::string headerFile, StringList& defines,
234  StringList& dirs, /*StringList& controlScripts,*/ int derivOrder);
235 
238  // Flags
239  enum
240  {
241  SAGE_SRC_F, //start with Sage++ parser output
242  CPLUSPLUS_F, //generating C++
243  USE_GCC_F, //use gcc preprocessor
244  NO_INLINE_USER_INCLUDE_F, //do not inline user include file
259  };
260 
261  int isFlag(int f) const
262  {
263  return flags & (1 << f);
264  }
265 
266  void setFlag(int f)
267  {
268  flags |= (1 << f);
269  }
270 
271  /* Get the value for a given section and key */
272  std::string getString(const char *sectionName, std::string key);
273 
274  /* Collect names of all active functions specified in the init files.
275  The names of intrinsic functions are added here also. */
276  static StringList&
278  static bool isActiveFuncName(std::string str);
279 
280  /* Collect names of all active functions specified in the init files.
281  The names of intrinsic functions are added here also. */
282  static StringList&
284 
285  /* Checks whether the typename is in the list of inactive typename lists.
286  */
287  static bool isInactiveFuncName(std::string str);
288  static bool isInactiveFuncName(const char* str)
289  {
290  return isInactiveFuncName(std::string(str));
291  }
292 
293  /* Collect names of all active variables specified in the init files. */
294  static StringList&
296 
297  /* Collect names of all active variables specified in the init files. */
298  static StringList&
300 
301 
302  /* Checks whether the function name is in the list of intrinsic
303  lists. */
304  static bool isIntrinsicName(std::string str);
305  static void addIntrinsicName(std::string str);
306 
307  /* Collect the function names that are not to be changed */
308  static StringList&
310 
311  /* Checks whether the funcname is in the list of NoPrefix funcname lists.
312  */
313  static bool isNoPrefixFuncName(std::string psz);
314 
315 
316  /* Collect the names of user include files that should not be inlined. */
317  static StringList&
319 
320  /* Collect the names of inactive types. Also add default
321  inactive float types. */
322  static StringList&
324 
325  /* Checks whether the typename is in the list of inactive typename lists.
326  */
327  static bool isInactiveTypeName(const char* psz);
328 
329  /* Checks whether the typename should be followed into.
330  */
331  static bool isNoFollowTypeName(const char* psz);
332 
333  /* We collect the names of user include files which are "standard"
334  (e.g., mpi.h). These names are also added to the no-inline list. */
335  static StringList&
337 
338  /* Collect all the include directories. */
339  static StringList&
340  getIncludeDirs();
341 
342  /*Check if any of the includes is a substring of fname*/
343  bool isFromIncludeDirs(std::string fname);
344 
345  /* Collect all control file names. */
346  static StringList&
347  getControlFiles();
348 
349  /* Build a line that defines macros to be sent to the C preprocessor
350  and returns it. */
351  std::string getMacroDefinesLine()
352  {
353  return strMacroDefinesLine;
354  }
355 
356  /* Get the mapping model */
357  enum
358  {
360  };
361 
362  std::string getHeaderFileName();
363 
364  /* Get the default value for the derivative order */
365  int getDerivOrder() const;
366  /* Set the derivative order */
367  void setDerivOrder(int derivOrder)
368  {
369  nDerivOrder = derivOrder;
370  }
371 
372  const char*
374  {
375  return prefix.c_str();
376  }
377  const char*
379  {
380  return varPrefix.c_str();
381  }
382  const char*
384  {
385  return classPrefix.c_str();
386  }
387  const char*
389  {
390  return typePrefix.c_str();
391  }
392  const char*
394  {
395  return funcPrefix.c_str();
396  }
398  {
399  return comment_group_size;
400  }
401 
402  void
403  setPrefix(std::string val)
404  {
405  prefix = val;
406  }
407  void
408  setVarPrefix(std::string val)
409  {
410  varPrefix = val;
411  }
412  void
413  setClassPrefix(std::string val)
414  {
415  classPrefix = val;
416  }
417  void
418  setTypePrefix(std::string val)
419  {
420  typePrefix = val;
421  }
422  void
423  setFuncPrefix(std::string val)
424  {
425  funcPrefix = val;
426  }
427  void setCommentGroup(int val)
428  {
429  comment_group_size = val;
430  }
431 
432  void load(std::string initFilename);
433 
434  std::string getDifferentiationMode() const
435  {
436  return differentiationMode;
437  }
438  void setDifferentiationMode(std::string a_differentiationMode)
439  {
440  differentiationMode = a_differentiationMode;
441  }
442 
443  /* Context for diagnostic messages */
444  std::string getContext()
445  {
446  return msgContext;
447  }
448  void setContext(std::string context)
449  {
450  msgContext = std::string(context);
451  }
452 
453  /* Generate disclaimer that will be prepended to all Rose2XAIF-generated code */
454  std::string getDisclaimer();
455 
456  /* Generate a header file with dense AXPY definitions */
458 
459  /* Generate a header file with sparse AXPY definitions */
461 
462  /* Get/set quiet flag */
463  void setQuiet(bool v)
464  {
465  quiet = v;
466  }
467  bool isQuiet()
468  {
469  return quiet;
470  }
471  unsigned int getDebugLevel() const
472  {
473  return debugLevel;
474  }
475  void setDebugLevel(unsigned int a_debugLevel)
476  {
477  debugLevel = a_debugLevel;
478  }
479  void setTemplate(SgFile *templateptr) {
480  if (myTemplateSgFile_p) {
481  THROW_LOGICEXCEPTION_MACRO("StateManager::setTemplate: already set");
482  }
483  myTemplateSgFile_p = templateptr;
484  }
485  SgFile * getTemplate() {
486  if (!myTemplateSgFile_p) {
487  THROW_LOGICEXCEPTION_MACRO("StateManager::getTemplate: not set");
488  }
489  return myTemplateSgFile_p;
490  }
491  void setTemplateFileName(std::string file)
492  {
493  templateFileName = file;
494  }
495  std::string getTemplateFile()
496  {
497  return templateFileName;
498  }
500  {
501  return xaifModule;
502  }
503  void setDifferentiationModule(std::string module)
504  {
505  xaifModule = module;
506  }
507  std::string getXaifSchemaLocation()
508  {
509  return xaifSchemaLocation;
510  }
511  void setXaifSchemaLocation(std::string location)
512  {
513  xaifSchemaLocation = location;
514  }
515  void setXaifInlinableIntrinsicsFile(std::string file)
516  {
518  }
520  {
522  }
523  void setXaifNonInlinableIntrinsicsFile(std::string file)
524  {
526  }
528  {
530  }
532  {
533  return xaifBoosterOptions;
534  }
536  {
537  xaifBoosterOptions = val;
538  }
540  {
541  return roseOptions;
542  }
544  {
545  roseOptions = val;
546  }
548  {
549  return inputFileTypeIsC;
550  }
551  void setInputFileTypeIsC(bool flag)
552  {
553  inputFileTypeIsC = flag;
554  }
556  {
557  return workflow;
558  }
559  void setWorkflow(int val)
560  {
561  workflow = val;
562  }
563 
565  {
566  return openMPflag;
567  }
568  void setOpenMPFlag(bool flag)
569  {
570  openMPflag = flag;
571  }
573  {
574  return sparsehandlingflag;
575  }
576  void setSparseHandlingFlag(bool flag)
577  {
578  sparsehandlingflag = flag;
579  }
582  }
585  }
586  bool getAdmmFlag()
587  {
588  return admmflag;
589  }
590  void setAdmmFlag(bool flag)
591  {
592  admmflag = flag;
593  }
594 
595  std::list<SgStatement*> markedStatements;
596 
597 #ifdef AD_FORTRAN_SPECIFIC
598  static SgType* makeActiveSgTypeP(SgFile* aFileP);
599 #endif
602  }
605  }
606 
607  /*
608  * Generates the header file for ADOL-C input external functions
609  */
611  /*
612  * Generates the source file for ADOL-C input external functions
613  */
615  /*
616  * Generates the function string for the original function call wrapper
617  */
618  std::string getZosfString(std::string functionname);
619  /*
620  * Generates the function string for scalar mode driver
621  */
622  std::string getFosfString(std::string functionname);
623  /*
624  * Generates the function string for vector mode driver
625  */
626  std::string getFovfString(std::string functionname);
627  /*
628  * Generates the function string for registering the driver functions
629  */
630  std::string getRegistrationFunctionString(std::string functionname);
631 
632 };
633 
634 } // namespace rose2xaif
635 
636 #endif /* __STATEMANAGER_HPP */