[arrayfire] 275/408: modified cpu::getInfo to display CPU information
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Sep 21 19:12:13 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch debian/sid
in repository arrayfire.
commit 30dd47a75e87d364d6a183bd57723f6ab99d8ca8
Author: pradeep <pradeep at arrayfire.com>
Date: Tue Aug 18 11:01:20 2015 -0400
modified cpu::getInfo to display CPU information
---
CMakeModules/Version.cmake | 17 +++++
CMakeModules/version.h.in | 1 +
include/af/defines.h | 4 +
src/backend/cpu/platform.cpp | 173 +++++++++++++++++++++++++++++++++++++++++--
4 files changed, 190 insertions(+), 5 deletions(-)
diff --git a/CMakeModules/Version.cmake b/CMakeModules/Version.cmake
index fb0d719..608c56e 100644
--- a/CMakeModules/Version.cmake
+++ b/CMakeModules/Version.cmake
@@ -8,6 +8,23 @@ SET(AF_VERSION_PATCH "0")
SET(AF_VERSION "${AF_VERSION_MAJOR}.${AF_VERSION_MINOR}.${AF_VERSION_PATCH}")
SET(AF_API_VERSION ${AF_VERSION_MAJOR}${AF_VERSION_MINOR})
+# From CMake 3.0.0 CMAKE_<LANG>_COMPILER_ID is AppleClang for OSX machines
+# that use clang for compilations
+IF("${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
+ SET(COMPILER_NAME "AppleClang")
+ELSEIF("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
+ SET(COMPILER_NAME "LLVM Clang")
+ELSEIF("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
+ SET(COMPILER_NAME "GNU Compiler Collection(GCC/G++)")
+ELSEIF("${CMAKE_C_COMPILER_ID}" STREQUAL "Intel")
+ SET(COMPILER_NAME "Intel Compiler")
+ELSEIF("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
+ SET(COMPILER_NAME "Microsoft Visual Studio")
+ENDIF()
+
+SET(COMPILER_VERSION "${CMAKE_C_COMPILER_VERSION}")
+SET(AF_COMPILER_STRING "${COMPILER_NAME} ${COMPILER_VERSION}")
+
EXECUTE_PROCESS(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
diff --git a/CMakeModules/version.h.in b/CMakeModules/version.h.in
index 85f778b..71ecd3d 100644
--- a/CMakeModules/version.h.in
+++ b/CMakeModules/version.h.in
@@ -15,3 +15,4 @@
#define AF_VERSION_PATCH @AF_VERSION_PATCH@
#define AF_API_VERSION @AF_API_VERSION@
#define AF_REVISION "@GIT_COMMIT_HASH@"
+#define AF_CMPLR_STR "@AF_COMPILER_STRING@"
diff --git a/include/af/defines.h b/include/af/defines.h
index 28f7c96..f0d2919 100644
--- a/include/af/defines.h
+++ b/include/af/defines.h
@@ -50,6 +50,10 @@
typedef long long dim_t;
#endif
+#if defined(__arm__) || defined(_M_ARM)
+#define ARM_ARCH
+#endif
+
#include <stdlib.h>
typedef long long intl;
diff --git a/src/backend/cpu/platform.cpp b/src/backend/cpu/platform.cpp
index d6b4724..e663da7 100644
--- a/src/backend/cpu/platform.cpp
+++ b/src/backend/cpu/platform.cpp
@@ -10,6 +10,149 @@
#include <af/version.h>
#include <platform.hpp>
#include <sstream>
+#include <algorithm>
+#include <iostream>
+#include <string>
+
+#ifdef _WIN32
+#include <limits.h>
+#include <intrin.h>
+typedef unsigned __int32 uint32_t;
+#else
+#include <stdint.h>
+#endif
+
+using namespace std;
+
+#define MAX_INTEL_TOP_LVL 4
+
+class CPUID {
+ uint32_t regs[4];
+
+ public:
+ explicit CPUID(unsigned funcId, unsigned subFuncId) {
+#ifdef _WIN32
+ __cpuidex((int *)regs, (int)funcId, (int)subFuncId);
+
+#else
+ asm volatile
+ ("cpuid" : "=a" (regs[0]), "=b" (regs[1]), "=c" (regs[2]), "=d" (regs[3])
+ : "a" (funcId), "c" (subFuncId));
+#endif
+ }
+
+ inline const uint32_t &EAX() const { return regs[0]; }
+ inline const uint32_t &EBX() const { return regs[1]; }
+ inline const uint32_t &ECX() const { return regs[2]; }
+ inline const uint32_t &EDX() const { return regs[3]; }
+};
+
+class CPUInfo {
+ public:
+ CPUInfo();
+ string vendor() const { return mVendorId; }
+ string model() const { return mModelName; }
+ int threads() const { return mNumLogCpus; }
+
+ private:
+ // Bit positions for data extractions
+ static const uint32_t LVL_NUM = 0x000000FF;
+ static const uint32_t LVL_TYPE = 0x0000FF00;
+ static const uint32_t LVL_CORES = 0x0000FFFF;
+ static const uint32_t HTT_POS = 0x10000000;
+
+ // Attributes
+ string mVendorId;
+ string mModelName;
+ int mNumSMT;
+ int mNumCores;
+ int mNumLogCpus;
+ bool mIsHTT;
+};
+
+CPUInfo::CPUInfo()
+ : mVendorId(""), mModelName(""), mNumSMT(0), mNumCores(0), mNumLogCpus(0), mIsHTT(false)
+{
+#if defined(ARM_ARCH)
+ mVendorId = "Unknown";
+ mModelName= "Unknown";
+ mNumSMT = 1;
+ mNumCores = 1;
+#else
+ // Get vendor name EAX=0
+ CPUID cpuID1(1, 0);
+ mIsHTT = cpuID1.EDX() & HTT_POS;
+
+ CPUID cpuID0(0, 0);
+ uint32_t HFS = cpuID0.EAX();
+ mVendorId += string((const char *)&cpuID0.EBX(), 4);
+ mVendorId += string((const char *)&cpuID0.EDX(), 4);
+ mVendorId += string((const char *)&cpuID0.ECX(), 4);
+
+ string upVId = mVendorId;
+ for_each(upVId.begin(), upVId.end(), [](char& in) { in = ::toupper(in); });
+ // Get num of cores
+ if (upVId.find("INTEL") != std::string::npos) {
+ mVendorId = "Intel";
+ if(HFS >= 11) {
+ for (int lvl=0; lvl<MAX_INTEL_TOP_LVL; ++lvl) {
+ CPUID cpuID4(0x0B, lvl);
+ uint32_t currLevel = (LVL_TYPE & cpuID4.ECX())>>8;
+ switch(currLevel) {
+ case 0x01: mNumSMT = LVL_CORES & cpuID4.EBX(); break;
+ case 0x02: mNumLogCpus = LVL_CORES & cpuID4.EBX(); break;
+ default: break;
+ }
+ }
+ mNumCores = mNumLogCpus/mNumSMT;
+ } else {
+ if (HFS>=1) {
+ mNumLogCpus = (cpuID1.EBX() >> 16) & 0xFF;
+ if (HFS>=4) {
+ mNumCores = 1 + ((CPUID(4, 0).EAX() >> 26) & 0x3F);
+ }
+ }
+ if (mIsHTT) {
+ if (!(mNumCores>1)) {
+ mNumCores = 1;
+ mNumLogCpus = (mNumLogCpus >= 2 ? mNumLogCpus : 2);
+ }
+ } else {
+ mNumCores = mNumLogCpus = 1;
+ }
+ }
+ } else if (upVId.find("AMD") != std::string::npos) {
+ mVendorId = "AMD";
+ if (HFS>=1) {
+ mNumLogCpus = (cpuID1.EBX() >> 16) & 0xFF;
+ if (CPUID(0x80000000, 0).EAX() >=8) {
+ mNumCores = 1 + ((CPUID(0x80000008, 0).ECX() & 0xFF));
+ }
+ }
+ if (mIsHTT) {
+ if (!(mNumCores>1)) {
+ mNumCores = 1;
+ mNumLogCpus = (mNumLogCpus >= 2 ? mNumLogCpus : 2);
+ }
+ } else {
+ mNumCores = mNumLogCpus = 1;
+ }
+ } else {
+ mVendorId = "Unkown, probably ARM";
+ cout<< "Unexpected vendor id" <<endl;
+ }
+ // Get processor brand string
+ // This seems to be working for both Intel & AMD vendors
+ for(unsigned i=0x80000002; i<0x80000005; ++i) {
+ CPUID cpuID(i, 0);
+ mModelName += string((const char*)&cpuID.EAX(), 4);
+ mModelName += string((const char*)&cpuID.EBX(), 4);
+ mModelName += string((const char*)&cpuID.ECX(), 4);
+ mModelName += string((const char*)&cpuID.EDX(), 4);
+ }
+ mModelName = string(mModelName.c_str());
+#endif
+}
namespace cpu
{
@@ -35,8 +178,20 @@ static const char *get_system(void)
std::string getInfo()
{
std::ostringstream info;
+ static CPUInfo cinfo;
+
info << "ArrayFire v" << AF_VERSION
<< " (CPU, " << get_system() << ", build " << AF_REVISION << ")" << std::endl;
+#if defined(ARM_ARCH)
+ // Do nothing
+#else
+ info << string("[0] ") << cinfo.vendor() <<": " << cinfo.model() << " ";
+ info << "Max threads("<< cinfo.threads()<<") ";
+#ifndef NDEBUG
+ info << AF_CMPLR_STR;
+#endif
+ info << std::endl;
+#endif
return info.str();
}
@@ -47,11 +202,19 @@ bool isDoubleSupported(int device)
void devprop(char* d_name, char* d_platform, char *d_toolkit, char* d_compute)
{
- static bool flag;
- if(!flag) {
- printf("WARNING: af_devprop not supported for CPU\n");
- flag = 1;
- }
+ static CPUInfo cinfo;
+#if defined(ARM_ARCH)
+ snprintf(d_name, 64, "%s", "Unknown");
+ snprintf(d_platform, 10, "CPU");
+ snprintf(d_toolkit, 64, "%s", "Unknown");
+ snprintf(d_compute, 10, "%s", "Unknown");
+#else
+ snprintf(d_name, 64, "%s", cinfo.vendor().c_str());
+ snprintf(d_platform, 10, "CPU");
+ // report the compiler for toolkit
+ snprintf(d_toolkit, 64, "%s", AF_CMPLR_STR);
+ snprintf(d_compute, 10, "%s", "0.0");
+#endif
}
int getDeviceCount()
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git
More information about the debian-science-commits
mailing list