[ Top ] [ package ]
Synopsis
set of X86 utilities for cpu type and properties determination
EXAMPLES
Fortran example:
program test_feature
use ISO_C_BINDING
implicit none
#define IN_FORTRAN_CODE
#include <cpu_properties.h>
real(C_DOUBLE) :: s1, s2
integer(C_INT64_T) :: t1, t2
integer :: status
if(cpu_has_feature(FLAG_AVX2) .ne. 0) print *,'AVX2'
if(cpu_has_feature(FLAG_AVX) .ne. 0) print *,'AVX'
if(cpu_has_feature(FLAG_FMA) .ne. 0) print *,'FMA'
if(cpu_has_feature(FLAG_BMI) .ne. 0) print *,'BMI'
if(cpu_has_feature(FLAG_SSE4) .ne. 0) print *,'SSE4'
if(cpu_has_feature(FLAG_SSE3) .ne. 0) print *,'SSE3'
if(cpu_has_feature(FLAG_SSE2) .ne. 0) print *,'SSE2'
status = get_fp_status_ctl()
print 100,' FP status = ',status
100 format(A,Z8)
if(iand(FP_STATUS_PE,status) .ne. 0) print *,"Precision ON"
if(iand(FP_STATUS_UE,status) .ne. 0) print *,"Underflow ON"
if(iand(FP_STATUS_OE,status) .ne. 0) print *,"Overflow ON"
if(iand(FP_STATUS_ZE,status) .ne. 0) print *,"Zero divide ON"
print *,'CPU number =',get_cpu_number()
stop
end
result of Fortran program execution on i3-6100 CPU @ 3.70GHz :
AVX2
AVX
FMA
BMI
SSE4
SSE3
SSE2
FP status = 1FA0
Precision ON
C example:
#include <stdint.h>
#include <stdio.h>
#include <cpu_properties.h>
int main(int argc, char** argv)
{
uint64_t t1, t2;
double s1, s2;
int status;
printf("CPU speed: %lu Hz\n",get_cpu_freq());
printf("FLAGS: ");
if(cpu_has_feature(FLAG_SSE)) printf(" SSE");
if(cpu_has_feature(FLAG_SSE2)) printf(" SSE2");
if(cpu_has_feature(FLAG_SSE3)) printf(" SSE3");
if(cpu_has_feature(FLAG_SSE4)) printf(" SSE4");
if(cpu_has_feature(FLAG_AVX)) printf(" AVX");
if(cpu_has_feature(FLAG_FMA)) printf(" FMA");
if(cpu_has_feature(FLAG_AVX2)) printf(" AVX2");
printf("\n");
status = get_fp_status_ctl();
printf("FPU status = %8.8x\n",status);
printf("Precision status %s\n",status & FP_STATUS_PE ? "ON" : "OFF");
printf("Underflow status %s\n",status & FP_STATUS_UE ? "ON" : "OFF");
printf("Overflow status %s\n",status & FP_STATUS_OE ? "ON" : "OFF");
printf("Zero divide status %s\n",status & FP_STATUS_ZE ? "ON" : "OFF");
return(0);
}
result of C program execution on i3-6100 CPU @ 3.70GHz :
CPU speed: 3700000000 Hz
FLAGS: SSE SSE2 SSE3 SSE4 AVX FMA AVX2
FPU status = 00001fa0
Precision status ON
Underflow status OFF
Overflow status OFF
Zero divide status OFF
[ Top ] [ Functions ]
FUNCTION
determine whether certain capabilities are present on the current CPU e.g. AVX/AVX2/SSE2/FMA ...
Synopsis
C:
int cpu_has_feature(int feature);
Fortran:
interface
function cpu_has_feature(feature) result(status)
import C_INT
integer(C_INT), intent(IN), value :: feature
integer(C_INT) :: status
end function cpu_has_feature
end interface
#include <cpu_type.h>
is usable by C and Fortran programs alike
Fortran programs MUST use
#define IN_FORTRAN_CODE
before including cpu_type.h
ARGUMENTS
feature : feature symbol from cpu_type (#include <cpu_type.h>)
RESULT
1 is feature is supported by CPU, 0 otherwise
AUTHOR
M.Valin Recherche en Prevision Numerique 2016
[ Top ] [ Functions ]
FUNCTION
get the number of cores of this CPU
Synopsis
C:
int get_cpu_cores();
Fortran:
interface
function get_cpu_cores() result(ncores)
import C_INT
integer(C_INT) :: ncores
end function get_cpu_cores
end interface
ARGUMENTS
none
RESULT
the number of cores of this CPU (not one on X86 family cpus only)
AUTHOR
M.Valin Recherche en Prevision Numerique 2016
[ Top ] [ Functions ]
FUNCTION
get the CPU nominal frequency
Synopsis
C:
uint64_t get_cpu_freq();
Fortran:
interface
function get_cpu_freq() result(freq)
import C_INT64_T
integer(C_INT64_T) :: freq
end function get_cpu_freq
end interface
ARGUMENTS
none
RESULT
the CPU nominal frequency in Hertz (64 bit unsigned integer) (nonzero on X86 family cpus only)
AUTHOR
M.Valin Recherche en Prevision Numerique 2016
[ Top ] [ Functions ]
FUNCTION
get the number of hyperthreads of this CPU
Synopsis
C:
int get_cpu_hyperthreads();
Fortran:
interface
function get_cpu_hyperthreads() result(nhyperthreads)
import C_INT
integer(C_INT) :: nhyperthreads
end function get_cpu_hyperthreads
end interface
ARGUMENTS
none
RESULT
the number of hyperthreads of this CPU (not 1 on X86 family cpus only)
AUTHOR
M.Valin Recherche en Prevision Numerique 2016
[ Top ] [ Functions ]
FUNCTION
get the processor number of this CPU in the node
Synopsis
C:
int get_cpu_number();
Fortran:
interface
function get_cpu_number() result(id)
import C_INT
integer(C_INT) :: id
end function get_cpu_number
end interface
ARGUMENTS
none
RESULT
the APIC id of the current cpu (nozero on X86 family cpus only) to be correlated with /proc/cpuinfo to find actual CPU number
AUTHOR
M.Valin Recherche en Prevision Numerique 2016
[ Top ] [ Functions ]
FUNCTION
get floating point status word
Synopsis
C:
int get_fp_status_ctl();
Fortran:
interface
function get_fp_status_ctl() result(id)
import C_INT
integer(C_INT) :: id
end function get_fp_status_ctl
end interface
ARGUMENTS
none
RESULT
the floating point status word (nozero on X86 family cpus only)
AUTHOR
M.Valin Recherche en Prevision Numerique 2016
[ Top ] [ Functions ]
FUNCTION
set the floating point status and control word
Synopsis
C:
void set_fp_status_ctl(int id);
Fortran:
interface
subroutine set_fp_status_ctl(id)
import C_INT
integer(C_INT), intent(IN), value :: id
end subroutine set_fp_status_ctl
end interface
ARGUMENTS
id : integer value to store into the floating point status and control word
(X86 family cpus only)
AUTHOR
M.Valin Recherche en Prevision Numerique 2016