9 #if BOOST_OS_WINDOWS || BOOST_OS_CYGWIN
13 # ifndef WIN32_LEAN_AND_MEAN
14 # define WIN32_LEAN_AND_MEAN
18 #elif BOOST_OS_UNIX || BOOST_OS_MACOS
19 # include <sys/param.h>
20 # include <sys/types.h>
24 # if BOOST_OS_BSD || BOOST_OS_MACOS
25 # include <sys/sysctl.h>
38 # if BOOST_COMP_GNUC || BOOST_COMP_CLANG || BOOST_COMP_PGI
40 # elif BOOST_COMP_MSVC || defined(BOOST_COMP_MSVC_EMULATED)
51 # if BOOST_COMP_GNUC || BOOST_COMP_CLANG || BOOST_COMP_PGI
52 inline auto cpuid(std::uint32_t level, std::uint32_t subfunction, std::uint32_t ex[4]) ->
void
54 __cpuid_count(level, subfunction, ex[0], ex[1], ex[2], ex[3]);
57 # elif BOOST_COMP_MSVC || defined(BOOST_COMP_MSVC_EMULATED)
58 inline auto cpuid(std::uint32_t level, std::uint32_t subfunction, std::uint32_t ex[4]) ->
void
60 __cpuidex(
reinterpret_cast<int*
>(ex), level, subfunction);
63 inline auto cpuid(std::uint32_t, std::uint32_t, std::uint32_t ex[4]) ->
void
70 inline auto cpuid(std::uint32_t, std::uint32_t, std::uint32_t ex[4]) ->
void
80 std::uint32_t ex[4] = {0};
81 cpuid(0x8000'0000, 0, ex);
82 std::uint32_t
const nExIds(ex[0]);
89 return "<unknown: compiler>";
91 return "<unknown: CPU>";
98 char cpuBrandString[0x40] = {0};
99 for(std::uint32_t i(0x8000'0000); i <= nExIds; ++i)
108 else if(i == 0x8000'0003)
112 else if(i == 0x8000'0004)
117 return std::string(cpuBrandString);
119 return std::string(
"unknown");
126 #if BOOST_OS_WINDOWS || BOOST_OS_CYGWIN
129 return si.dwPageSize;
130 #elif BOOST_OS_UNIX || BOOST_OS_MACOS
131 # if defined(_SC_PAGESIZE)
132 return static_cast<std::size_t
>(sysconf(_SC_PAGESIZE));
135 return =
static_cast<size_t>(getpagesize());
138 # error "getPageSize not implemented for this system!"
149 MEMORYSTATUSEX status;
150 status.dwLength =
sizeof(status);
151 GlobalMemoryStatusEx(&status);
152 return static_cast<std::size_t
>(status.ullTotalPhys);
154 #elif BOOST_OS_CYGWIN
157 status.dwLength =
sizeof(status);
158 GlobalMemoryStatus(&status);
159 return static_cast<std::size_t
>(status.dwTotalPhys);
161 #elif BOOST_OS_UNIX || BOOST_OS_MACOS
164 # if defined(CTL_HW) && (defined(HW_MEMSIZE) || defined(HW_PHYSMEM64))
167 # if defined(HW_MEMSIZE)
169 # elif defined(HW_PHYSMEM64)
173 std::uint64_t size(0);
174 std::size_t sizeLen{
sizeof(size)};
175 if(sysctl(mib, 2, &size, &sizeLen,
nullptr, 0) < 0)
176 throw std::logic_error(
"getTotalGlobalMemSizeBytes failed calling sysctl!");
177 return static_cast<std::size_t
>(size);
179 # elif defined(_SC_AIX_REALMEM)
180 return static_cast<std::size_t
>(sysconf(_SC_AIX_REALMEM)) *
static_cast<std::size_t
>(1024);
182 # elif defined(_SC_PHYS_PAGES)
183 return static_cast<std::size_t
>(sysconf(_SC_PHYS_PAGES)) *
getPageSize();
185 # elif defined(CTL_HW) \
186 && (defined(HW_PHYSMEM) || defined(HW_REALMEM))
189 # if defined(HW_REALMEM)
191 # elif defined(HW_PYSMEM)
195 std::uint32_t size(0);
196 std::size_t
const sizeLen{
sizeof(size)};
197 if(sysctl(mib, 2, &size, &sizeLen,
nullptr, 0) < 0)
198 throw std::logic_error(
"getTotalGlobalMemSizeBytes failed calling sysctl!");
199 return static_cast<std::size_t
>(size);
203 # error "getTotalGlobalMemSizeBytes not implemented for this system!"
212 MEMORYSTATUSEX status;
213 status.dwLength =
sizeof(status);
214 GlobalMemoryStatusEx(&status);
215 return static_cast<std::size_t
>(status.ullAvailPhys);
217 # if defined(_SC_AVPHYS_PAGES)
218 return static_cast<std::size_t
>(sysconf(_SC_AVPHYS_PAGES)) *
getPageSize();
221 return static_cast<std::size_t
>(get_avphys_pages()) *
getPageSize();
225 std::size_t len =
sizeof(free_pages);
226 if(sysctlbyname(
"vm.page_free_count", &free_pages, &len,
nullptr, 0) < 0)
228 throw std::logic_error(
"getFreeGlobalMemSizeBytes failed calling sysctl(vm.page_free_count)!");
231 return static_cast<std::size_t
>(free_pages) *
getPageSize();
233 # error "getFreeGlobalMemSizeBytes not implemented for this system!"
constexpr int UNKNOWN_CPU
auto getTotalGlobalMemSizeBytes() -> std::size_t
constexpr int UNKNOWN_COMPILER
auto cpuid(std::uint32_t, std::uint32_t, std::uint32_t ex[4]) -> void
auto getFreeGlobalMemSizeBytes() -> std::size_t
auto getCpuName() -> std::string
ALPAKA_FN_HOST auto memcpy(TQueue &queue, alpaka::detail::DevGlobalImplGeneric< TTag, TTypeDst > &viewDst, TViewSrc const &viewSrc) -> void