#if defined(__INTEL_LLVM_COMPILER)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wignored-attributes"
#endif
#include "sysinfo.h"
#include "intrinsics.h"
#include "estring.h"
#include "ref.h"
#if defined(__FREEBSD__)
#include <sys/cpuset.h>
#include <pthread_np.h>
typedef cpuset_t cpu_set_t;
#endif
namespace embree
{
NullTy null;
std::string getPlatformName()
{ … }
std::string getCompilerName()
{ … }
std::string getCPUVendor()
{ … }
CPU getCPUModel()
{ … }
std::string stringOfCPUModel(CPU model)
{ … }
#if defined(__X86_ASM__)
static const int EAX = …;
static const int EBX = …;
static const int ECX = …;
static const int EDX = …;
static const int CPU_FEATURE_BIT_SSE3 = …;
static const int CPU_FEATURE_BIT_SSSE3 = …;
static const int CPU_FEATURE_BIT_FMA3 = …;
static const int CPU_FEATURE_BIT_SSE4_1 = …;
static const int CPU_FEATURE_BIT_SSE4_2 = …;
static const int CPU_FEATURE_BIT_POPCNT = …;
static const int CPU_FEATURE_BIT_OXSAVE = …;
static const int CPU_FEATURE_BIT_AVX = …;
static const int CPU_FEATURE_BIT_F16C = …;
static const int CPU_FEATURE_BIT_RDRAND = …;
static const int CPU_FEATURE_BIT_SSE = …;
static const int CPU_FEATURE_BIT_SSE2 = …;
static const int CPU_FEATURE_BIT_LZCNT = …;
static const int CPU_FEATURE_BIT_BMI1 = …;
static const int CPU_FEATURE_BIT_AVX2 = …;
static const int CPU_FEATURE_BIT_BMI2 = …;
static const int CPU_FEATURE_BIT_AVX512F = …;
static const int CPU_FEATURE_BIT_AVX512DQ = …;
static const int CPU_FEATURE_BIT_AVX512PF = …;
static const int CPU_FEATURE_BIT_AVX512ER = …;
static const int CPU_FEATURE_BIT_AVX512CD = …;
static const int CPU_FEATURE_BIT_AVX512BW = …;
static const int CPU_FEATURE_BIT_AVX512VL = …;
static const int CPU_FEATURE_BIT_AVX512IFMA = …;
static const int CPU_FEATURE_BIT_AVX512VBMI = …;
#endif
#if defined(__X86_ASM__)
__noinline int64_t get_xcr0()
{ … }
#endif
int getCPUFeatures()
{ … }
std::string stringOfCPUFeatures(int features)
{ … }
std::string stringOfISA (int isa)
{ … }
bool hasISA(int features, int isa) { … }
std::string supportedTargetList (int features)
{ … }
}
#if defined(__WIN32__)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <psapi.h>
namespace embree
{
std::string getExecutableFileName() {
char filename[1024];
if (!GetModuleFileName(nullptr, filename, sizeof(filename)))
return std::string();
return std::string(filename);
}
unsigned int getNumberOfLogicalThreads()
{
static int nThreads = -1;
if (nThreads != -1) return nThreads;
typedef WORD (WINAPI *GetActiveProcessorGroupCountFunc)();
typedef DWORD (WINAPI *GetActiveProcessorCountFunc)(WORD);
HMODULE hlib = LoadLibrary("Kernel32");
GetActiveProcessorGroupCountFunc pGetActiveProcessorGroupCount = (GetActiveProcessorGroupCountFunc)GetProcAddress(hlib, "GetActiveProcessorGroupCount");
GetActiveProcessorCountFunc pGetActiveProcessorCount = (GetActiveProcessorCountFunc) GetProcAddress(hlib, "GetActiveProcessorCount");
if (pGetActiveProcessorGroupCount && pGetActiveProcessorCount)
{
int groups = pGetActiveProcessorGroupCount();
int totalProcessors = 0;
for (int i = 0; i < groups; i++)
totalProcessors += pGetActiveProcessorCount(i);
nThreads = totalProcessors;
}
else
{
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
nThreads = sysinfo.dwNumberOfProcessors;
}
assert(nThreads);
return nThreads;
}
int getTerminalWidth()
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
if (handle == INVALID_HANDLE_VALUE) return 80;
CONSOLE_SCREEN_BUFFER_INFO info;
memset(&info,0,sizeof(info));
GetConsoleScreenBufferInfo(handle, &info);
return info.dwSize.X;
}
double getSeconds()
{
LARGE_INTEGER freq, val;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&val);
return (double)val.QuadPart / (double)freq.QuadPart;
}
void sleepSeconds(double t) {
Sleep(DWORD(1000.0*t));
}
size_t getVirtualMemoryBytes()
{
PROCESS_MEMORY_COUNTERS info;
GetProcessMemoryInfo( GetCurrentProcess( ), &info, sizeof(info) );
return (size_t)info.QuotaPeakPagedPoolUsage;
}
size_t getResidentMemoryBytes()
{
PROCESS_MEMORY_COUNTERS info;
GetProcessMemoryInfo( GetCurrentProcess( ), &info, sizeof(info) );
return (size_t)info.WorkingSetSize;
}
}
#endif
#if defined(__LINUX__)
#include <stdio.h>
#include <unistd.h>
namespace embree
{
std::string getExecutableFileName()
{ … }
size_t getVirtualMemoryBytes()
{ … }
size_t getResidentMemoryBytes()
{ … }
}
#endif
#if defined (__FreeBSD__)
#include <sys/sysctl.h>
namespace embree
{
std::string getExecutableFileName()
{
const int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
char buf[4096];
memset(buf,0,sizeof(buf));
size_t len = sizeof(buf)-1;
if (sysctl(mib, 4, buf, &len, 0x0, 0) == -1)
return std::string();
return std::string(buf);
}
size_t getVirtualMemoryBytes() {
return 0;
}
size_t getResidentMemoryBytes() {
return 0;
}
}
#endif
#if defined(__MACOSX__)
#include <mach-o/dyld.h>
namespace embree
{
std::string getExecutableFileName()
{
char buf[4096];
uint32_t size = sizeof(buf);
if (_NSGetExecutablePath(buf, &size) != 0)
return std::string();
return std::string(buf);
}
size_t getVirtualMemoryBytes() {
return 0;
}
size_t getResidentMemoryBytes() {
return 0;
}
}
#endif
#if defined(__UNIX__)
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <pthread.h>
#if defined(__EMSCRIPTEN__)
#include <emscripten.h>
extern "C" {
extern int godot_js_os_hw_concurrency_get();
}
#endif
namespace embree
{
unsigned int getNumberOfLogicalThreads()
{ … }
int getTerminalWidth()
{ … }
double getSeconds() { … }
void sleepSeconds(double t) { … }
}
#endif
#if defined(__INTEL_LLVM_COMPILER)
#pragma clang diagnostic pop
#endif