platform.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // ======================================================================== //
  2. // Copyright 2009-2019 Intel Corporation //
  3. // //
  4. // Licensed under the Apache License, Version 2.0 (the "License"); //
  5. // you may not use this file except in compliance with the License. //
  6. // You may obtain a copy of the License at //
  7. // //
  8. // http://www.apache.org/licenses/LICENSE-2.0 //
  9. // //
  10. // Unless required by applicable law or agreed to in writing, software //
  11. // distributed under the License is distributed on an "AS IS" BASIS, //
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
  13. // See the License for the specific language governing permissions and //
  14. // limitations under the License. //
  15. // ======================================================================== //
  16. #include "platform.h"
  17. namespace oidn {
  18. // ----------------------------------------------------------------------------
  19. // Common functions
  20. // ----------------------------------------------------------------------------
  21. void* alignedMalloc(size_t size, size_t alignment)
  22. {
  23. if (size == 0)
  24. return nullptr;
  25. assert((alignment & (alignment-1)) == 0);
  26. void* ptr = _mm_malloc(size, alignment);
  27. if (ptr == nullptr)
  28. throw std::bad_alloc();
  29. return ptr;
  30. }
  31. void alignedFree(void* ptr)
  32. {
  33. if (ptr)
  34. _mm_free(ptr);
  35. }
  36. // ----------------------------------------------------------------------------
  37. // System information
  38. // ----------------------------------------------------------------------------
  39. std::string getPlatformName()
  40. {
  41. std::string name;
  42. #if defined(__linux__)
  43. name = "Linux";
  44. #elif defined(__FreeBSD__)
  45. name = "FreeBSD";
  46. #elif defined(__CYGWIN__)
  47. name = "Cygwin";
  48. #elif defined(_WIN32)
  49. name = "Windows";
  50. #elif defined(__APPLE__)
  51. name = "macOS";
  52. #elif defined(__unix__)
  53. name = "Unix";
  54. #else
  55. return "Unknown";
  56. #endif
  57. #if defined(__x86_64__) || defined(_M_X64) || defined(__ia64__) || defined(__aarch64__)
  58. name += " (64-bit)";
  59. #else
  60. name += " (32-bit)";
  61. #endif
  62. return name;
  63. }
  64. std::string getCompilerName()
  65. {
  66. #if defined(__INTEL_COMPILER)
  67. int mayor = __INTEL_COMPILER / 100 % 100;
  68. int minor = __INTEL_COMPILER % 100;
  69. std::string version = "Intel Compiler ";
  70. version += toString(mayor);
  71. version += "." + toString(minor);
  72. #if defined(__INTEL_COMPILER_UPDATE)
  73. version += "." + toString(__INTEL_COMPILER_UPDATE);
  74. #endif
  75. return version;
  76. #elif defined(__clang__)
  77. return "Clang " __clang_version__;
  78. #elif defined(__GNUC__)
  79. return "GCC " __VERSION__;
  80. #elif defined(_MSC_VER)
  81. std::string version = toString(_MSC_FULL_VER);
  82. version.insert(4, ".");
  83. version.insert(9, ".");
  84. version.insert(2, ".");
  85. return "Visual C++ Compiler " + version;
  86. #else
  87. return "Unknown";
  88. #endif
  89. }
  90. std::string getBuildName()
  91. {
  92. #if defined(NDEBUG)
  93. return "Release";
  94. #else
  95. return "Debug";
  96. #endif
  97. }
  98. } // namespace oidn